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