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 ]);
22 });
23
24 it("sources labels and descriptions from schema annotations", () => {
25 const opencode = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencode")];
26 expect(opencode).toBeDefined();
27
28 const serverPassword = deriveProviderSettingsFields(opencode!).find(
29 (field) => field.key === "serverPassword",
30 );
31
32 expect(serverPassword).toMatchObject({
33 label: "Server password",
34 description: "Stored in plain text on disk.",
35 control: "password",
36 });
37 });
38
39 it("uses a dedicated environment field instead of legacy Cursor CLI settings", () => {
40 const cursor = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("cursor")];
41
42 expect(cursor).toBeDefined();
43 expect(deriveProviderSettingsFields(cursor!)).toEqual([]);
44 expect(cursor?.environmentFields).toEqual([
45 {
46 name: "CURSOR_API_KEY",
47 label: "Cursor API key",
48 description: "Required by the Cursor Agent SDK.",
49 placeholder: "Paste API key",
50 sensitive: true,
51 },
52 ]);
53 });
54
55 it("exposes ACP Registry as an instance-only configurable driver", () => {
56 const acpRegistry = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("acpRegistry")];
57
58 expect(acpRegistry).toBeDefined();
59 expect(acpRegistry?.hasDefaultInstance).toBe(false);
60 expect(deriveProviderSettingsFields(acpRegistry!).map((field) => field.key)).toEqual([
61 "agentId",
62 "commandPath",
63 "authMethodId",
64 ]);
65 });
66
67 it("preserves unknown config keys while omitting empty configurable fields", () => {
68 const opencode = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencode")];
69 expect(opencode).toBeDefined();
70
71 const serverUrl = deriveProviderSettingsFields(opencode!).find(
72 (field) => field.key === "serverUrl",
73 );
74 expect(serverUrl).toBeDefined();
75
76 const next = nextProviderConfigWithFieldValue(
77 { forkOwned: 1, serverUrl: "http://127.0.0.1:4096" },
78 serverUrl!,
79 "",
80 );
81
82 expect(next).toEqual({ forkOwned: 1 });
83 });
84
85 it("reads non-string config values as blank strings", () => {
86 expect(readProviderConfigString({ binaryPath: 123 }, "binaryPath")).toBe("");
87 });
88
89 it("omits false boolean fields when clearWhenEmpty is omit", () => {
90 const next = nextProviderConfigWithFieldValue(
91 { forkOwned: 1, experimental: true },
92 {
93 key: "experimental",
94 control: "switch",
95 label: "Experimental",
96 clearWhenEmpty: "omit",
97 defaultBooleanValue: false,
98 },
99 false,
100 );
101
102 expect(next).toEqual({ forkOwned: 1 });
103 });
104
105 it("omits true boolean fields when true is the default", () => {
106 const next = nextProviderConfigWithFieldValue(
107 { forkOwned: 1, experimental: false },
108 {
109 key: "experimental",
110 control: "switch",
111 label: "Experimental",
112 clearWhenEmpty: "omit",
113 defaultBooleanValue: true,
114 },
115 true,
116 );
117
118 expect(next).toEqual({ forkOwned: 1 });
119 });
120
121 it("stores false boolean fields when true is the default", () => {
122 const next = nextProviderConfigWithFieldValue(
123 undefined,
124 {
125 key: "experimental",
126 control: "switch",
127 label: "Experimental",
128 clearWhenEmpty: "omit",
129 defaultBooleanValue: true,
130 },
131 false,
132 );
133
134 expect(next).toEqual({ experimental: false });
135 });
136
137 it("preserves false boolean fields when clearWhenEmpty is persist", () => {
138 const next = nextProviderConfigWithFieldValue(
139 undefined,
140 {
141 key: "experimental",
142 control: "switch",
143 label: "Experimental",
144 clearWhenEmpty: "persist",
145 },
146 false,
147 );
148
149 expect(next).toEqual({ experimental: false });
150 });
151
152 it("reads non-boolean config values as false booleans", () => {
153 expect(readProviderConfigBoolean({ experimental: "true" }, "experimental")).toBe(false);
154 });
155
156 it("reads missing boolean config values from the supplied default", () => {
157 expect(readProviderConfigBoolean({}, "experimental", true)).toBe(true);
158 });
159});