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("shows the auto-compaction threshold for Claude providers", () => {
69 const claude = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("claudeAgent")];
70 expect(claude).toBeDefined();
71
72 expect(deriveProviderSettingsFields(claude!).map((field) => field.key)).toEqual([
73 "binaryPath",
74 "homePath",
75 "autoCompactWindow",
76 "launchArgs",
77 ]);
78 });
79
80 it("preserves unknown config keys while omitting empty configurable fields", () => {
81 const opencode = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencode")];
82 expect(opencode).toBeDefined();
83
84 const serverUrl = deriveProviderSettingsFields(opencode!).find(
85 (field) => field.key === "serverUrl",
86 );
87 expect(serverUrl).toBeDefined();
88
89 const next = nextProviderConfigWithFieldValue(
90 { forkOwned: 1, serverUrl: "http://127.0.0.1:4096" },
91 serverUrl!,
92 "",
93 );
94
95 expect(next).toEqual({ forkOwned: 1 });
96 });
97
98 it("reads non-string config values as blank strings", () => {
99 expect(readProviderConfigString({ binaryPath: 123 }, "binaryPath")).toBe("");
100 });
101
102 it("omits false boolean fields when clearWhenEmpty is omit", () => {
103 const next = nextProviderConfigWithFieldValue(
104 { forkOwned: 1, experimental: true },
105 {
106 key: "experimental",
107 control: "switch",
108 label: "Experimental",
109 clearWhenEmpty: "omit",
110 defaultBooleanValue: false,
111 },
112 false,
113 );
114
115 expect(next).toEqual({ forkOwned: 1 });
116 });
117
118 it("omits true boolean fields when true is the default", () => {
119 const next = nextProviderConfigWithFieldValue(
120 { forkOwned: 1, experimental: false },
121 {
122 key: "experimental",
123 control: "switch",
124 label: "Experimental",
125 clearWhenEmpty: "omit",
126 defaultBooleanValue: true,
127 },
128 true,
129 );
130
131 expect(next).toEqual({ forkOwned: 1 });
132 });
133
134 it("stores false boolean fields when true is the default", () => {
135 const next = nextProviderConfigWithFieldValue(
136 undefined,
137 {
138 key: "experimental",
139 control: "switch",
140 label: "Experimental",
141 clearWhenEmpty: "omit",
142 defaultBooleanValue: true,
143 },
144 false,
145 );
146
147 expect(next).toEqual({ experimental: false });
148 });
149
150 it("preserves false boolean fields when clearWhenEmpty is persist", () => {
151 const next = nextProviderConfigWithFieldValue(
152 undefined,
153 {
154 key: "experimental",
155 control: "switch",
156 label: "Experimental",
157 clearWhenEmpty: "persist",
158 },
159 false,
160 );
161
162 expect(next).toEqual({ experimental: false });
163 });
164
165 it("reads non-boolean config values as false booleans", () => {
166 expect(readProviderConfigBoolean({ experimental: "true" }, "experimental")).toBe(false);
167 });
168
169 it("reads missing boolean config values from the supplied default", () => {
170 expect(readProviderConfigBoolean({}, "experimental", true)).toBe(true);
171 });
172});