Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ChatComposer.attachButton.test.tsx

116 lines4.3 KB

1import {
2 ProviderDriverKind,
3 type ModelCapabilities,
4 type ServerProviderModel,
5} from "@t3tools/contracts";
6import { describe, expect, it } from "vite-plus/test";
7​
8import { getComposerProviderState } from "./composerProviderState";
9​
10// The composer derives the attach button's disabled state from the active
11// model's resolved input capabilities:
12//
13// attachButtonDisabled = !inputCapabilities.images && !inputCapabilities.files
14//
15// There is no extractable helper for this one-liner policy; it lives inline in
16// ChatComposer. These tests exercise the real capability-resolution path
17// (ModelCapabilities -> getComposerProviderState -> inputCapabilities) across
18// the matrix that drives the disabled flag, so a regression in capability
19// resolution surfaces as a wrong button state rather than a silent miscompile.
20​
21const PROVIDER: ProviderDriverKind = ProviderDriverKind.make("devin");
22const MODEL = "test-model";
23​
24function modelWith(caps: ModelCapabilities): ReadonlyArray<ServerProviderModel> {
25 return [{ slug: MODEL, name: MODEL, isCustom: false, capabilities: caps }];
27​
28function attachButtonDisabled(inputCapabilities: {
29 images: boolean;
30 audio: boolean;
31 files: boolean;
32}): boolean {
33 return !inputCapabilities.images && !inputCapabilities.files;
35​
36describe("attach button disabled derivation", () => {
37 it("disables the button when the model accepts neither images nor files", () => {
38 const state = getComposerProviderState({
39 provider: PROVIDER,
40 model: MODEL,
41 models: modelWith({ optionDescriptors: [], inputImages: false, inputFiles: false }),
42 modelOptions: undefined,
43 planModeEnabled: true,
44 });
45​
46 expect(state.inputCapabilities).toEqual({ images: false, audio: true, files: false });
47 expect(attachButtonDisabled(state.inputCapabilities)).toBe(true);
48 });
49​
50 it("keeps the button enabled when only images are unsupported (files still accepted)", () => {
51 const state = getComposerProviderState({
52 provider: PROVIDER,
53 model: MODEL,
54 models: modelWith({ optionDescriptors: [], inputImages: false }),
55 modelOptions: undefined,
56 planModeEnabled: true,
57 });
58​
59 expect(state.inputCapabilities).toEqual({ images: false, audio: true, files: true });
60 expect(attachButtonDisabled(state.inputCapabilities)).toBe(false);
61 });
62​
63 it("keeps the button enabled when only files are unsupported (images still accepted)", () => {
64 const state = getComposerProviderState({
65 provider: PROVIDER,
66 model: MODEL,
67 models: modelWith({ optionDescriptors: [], inputFiles: false }),
68 modelOptions: undefined,
69 planModeEnabled: true,
70 });
71​
72 expect(state.inputCapabilities).toEqual({ images: true, audio: true, files: false });
73 expect(attachButtonDisabled(state.inputCapabilities)).toBe(false);
74 });
75​
76 it("keeps the button enabled when the model declares no capability restrictions", () => {
77 const state = getComposerProviderState({
78 provider: PROVIDER,
79 model: MODEL,
80 models: modelWith({ optionDescriptors: [] }),
81 modelOptions: undefined,
82 planModeEnabled: true,
83 });
84​
85 expect(state.inputCapabilities).toEqual({ images: true, audio: true, files: true });
86 expect(attachButtonDisabled(state.inputCapabilities)).toBe(false);
87 });
88​
89 it("keeps the button enabled when capabilities are entirely absent (permissive default)", () => {
90 const state = getComposerProviderState({
91 provider: PROVIDER,
92 model: MODEL,
93 models: modelWith({}),
94 modelOptions: undefined,
95 planModeEnabled: true,
96 });
97​
98 expect(state.inputCapabilities).toEqual({ images: true, audio: true, files: true });
99 expect(attachButtonDisabled(state.inputCapabilities)).toBe(false);
100 });
101​
102 it("disables the button when images and files are both false but audio is supported", () => {
103 // Audio support must not keep the attach button alive — the single attach
104 // button only handles images and files.
105 const state = getComposerProviderState({
106 provider: PROVIDER,
107 model: MODEL,
108 models: modelWith({ optionDescriptors: [], inputImages: false, inputFiles: false }),
109 modelOptions: undefined,
110 planModeEnabled: true,
111 });
112​
113 expect(state.inputCapabilities.audio).toBe(true);
114 expect(attachButtonDisabled(state.inputCapabilities)).toBe(true);
115 });
116});