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