Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { ProviderDriverKind } from "@t3tools/contracts";
3
4import { DRIVER_OPTION_BY_VALUE } from "./providerDriverMeta";
5import {
6 deriveProviderSettingsFields,
7 nextProviderConfigWithFieldValue,
8 readProviderConfigBoolean,
9 readProviderConfigString,
10} from "./ProviderSettingsForm";
11
12describe("ProviderSettingsForm helpers", () => {
13 it("derives visible provider config fields from the client definition schema", () => {
14 const codex = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("codex")];
15
16 expect(codex).toBeDefined();
17 expect(deriveProviderSettingsFields(codex!).map((field) => field.key)).toEqual([
18 "binaryPath",
19 "homePath",
20 "shadowHomePath",
21 "launchArgs",
22 ]);
23 });
24
25 it("sources labels and descriptions from schema annotations", () => {
26 const opencode = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencode")];
27 expect(opencode).toBeDefined();
28
29 const serverPassword = deriveProviderSettingsFields(opencode!).find(
30 (field) => field.key === "serverPassword",
31 );
32
33 expect(serverPassword).toMatchObject({
34 label: "Server password",
35 description: "Stored in plain text on disk.",
36 control: "password",
37 });
38 });
39
40 it("uses a dedicated environment field instead of legacy Cursor CLI settings", () => {
41 const cursor = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("cursor")];
42
43 expect(cursor).toBeDefined();
44 expect(deriveProviderSettingsFields(cursor!)).toEqual([]);
45 expect(cursor?.environmentFields).toEqual([
46 {
47 name: "CURSOR_API_KEY",
48 label: "Cursor API key",
49 description: "Required by the Cursor Agent SDK.",
50 placeholder: "Paste API key",
51 sensitive: true,
52 },
53 ]);
54 });
55
56 it("exposes ACP Registry as an instance-only configurable driver", () => {
57 const acpRegistry = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("acpRegistry")];
58
59 expect(acpRegistry).toBeDefined();
60 expect(acpRegistry?.hasDefaultInstance).toBe(false);
61 expect(deriveProviderSettingsFields(acpRegistry!).map((field) => field.key)).toEqual([
62 "agentId",
63 "commandPath",
64 "authMethodId",
65 ]);
66 });
67
68 it("derives a select control with its choices for the Antigravity sign-in method", () => {
69 const antigravity = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("antigravity")];
70 expect(antigravity).toBeDefined();
71
72 const fields = deriveProviderSettingsFields(antigravity!);
73 expect(fields.map((field) => field.key)).toEqual([
74 "authMethod",
75 "apiKey",
76 "gcpProject",
77 "gcpLocation",
78 "binaryPath",
79 ]);
80 const authMethod = fields.find((field) => field.key === "authMethod");
81 expect(authMethod).toMatchObject({ control: "select", clearWhenEmpty: "omit" });
82 expect(authMethod?.options?.map((option) => option.value)).toEqual([
83 "oauth-personal",
84 "oauth-business",
85 "gemini-api-key",
86 "agent-platform",
87 ]);
88 expect(fields.find((field) => field.key === "apiKey")?.control).toBe("password");
89 });
90
91 it("shows the auto-compaction threshold for Claude providers", () => {
92 const claude = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("claudeAgent")];
93 expect(claude).toBeDefined();
94
95 expect(deriveProviderSettingsFields(claude!).map((field) => field.key)).toEqual([
96 "binaryPath",
97 "homePath",
98 "autoCompactWindow",
99 "launchArgs",
100 ]);
101 });
102
103 it("preserves unknown config keys while omitting empty configurable fields", () => {
104 const opencode = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencode")];
105 expect(opencode).toBeDefined();
106
107 const serverUrl = deriveProviderSettingsFields(opencode!).find(
108 (field) => field.key === "serverUrl",
109 );
110 expect(serverUrl).toBeDefined();
111
112 const next = nextProviderConfigWithFieldValue(
113 { forkOwned: 1, serverUrl: "http://127.0.0.1:4096" },
114 serverUrl!,
115 "",
116 );
117
118 expect(next).toEqual({ forkOwned: 1 });
119 });
120
121 it("reads non-string config values as blank strings", () => {
122 expect(readProviderConfigString({ binaryPath: 123 }, "binaryPath")).toBe("");
123 });
124
125 it("omits false boolean fields when clearWhenEmpty is omit", () => {
126 const next = nextProviderConfigWithFieldValue(
127 { forkOwned: 1, experimental: true },
128 {
129 key: "experimental",
130 control: "switch",
131 label: "Experimental",
132 clearWhenEmpty: "omit",
133 defaultBooleanValue: false,
134 },
135 false,
136 );
137
138 expect(next).toEqual({ forkOwned: 1 });
139 });
140
141 it("omits true boolean fields when true is the default", () => {
142 const next = nextProviderConfigWithFieldValue(
143 { forkOwned: 1, experimental: false },
144 {
145 key: "experimental",
146 control: "switch",
147 label: "Experimental",
148 clearWhenEmpty: "omit",
149 defaultBooleanValue: true,
150 },
151 true,
152 );
153
154 expect(next).toEqual({ forkOwned: 1 });
155 });
156
157 it("stores false boolean fields when true is the default", () => {
158 const next = nextProviderConfigWithFieldValue(
159 undefined,
160 {
161 key: "experimental",
162 control: "switch",
163 label: "Experimental",
164 clearWhenEmpty: "omit",
165 defaultBooleanValue: true,
166 },
167 false,
168 );
169
170 expect(next).toEqual({ experimental: false });
171 });
172
173 it("preserves false boolean fields when clearWhenEmpty is persist", () => {
174 const next = nextProviderConfigWithFieldValue(
175 undefined,
176 {
177 key: "experimental",
178 control: "switch",
179 label: "Experimental",
180 clearWhenEmpty: "persist",
181 },
182 false,
183 );
184
185 expect(next).toEqual({ experimental: false });
186 });
187
188 it("reads non-boolean config values as false booleans", () => {
189 expect(readProviderConfigBoolean({ experimental: "true" }, "experimental")).toBe(false);
190 });
191
192 it("reads missing boolean config values from the supplied default", () => {
193 expect(readProviderConfigBoolean({}, "experimental", true)).toBe(true);
194 });
195});