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("derives a select control with its choices for the Antigravity sign-in method", () => {
41 const antigravity = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("antigravity")];
42 expect(antigravity).toBeDefined();
43
44 const fields = deriveProviderSettingsFields(antigravity!);
45 expect(fields.map((field) => field.key)).toEqual([
46 "authMethod",
47 "apiKey",
48 "gcpProject",
49 "gcpLocation",
50 "binaryPath",
51 ]);
52 const authMethod = fields.find((field) => field.key === "authMethod");
53 expect(authMethod).toMatchObject({ control: "select", clearWhenEmpty: "omit" });
54 expect(authMethod?.options?.map((option) => option.value)).toEqual([
55 "oauth-personal",
56 "oauth-business",
57 "gemini-api-key",
58 "agent-platform",
59 ]);
60 expect(fields.find((field) => field.key === "apiKey")?.control).toBe("password");
61 });
62
63 it("shows the auto-compaction threshold for Claude providers", () => {
64 const claude = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("claudeAgent")];
65 expect(claude).toBeDefined();
66
67 expect(deriveProviderSettingsFields(claude!).map((field) => field.key)).toEqual([
68 "binaryPath",
69 "homePath",
70 "autoCompactWindow",
71 "launchArgs",
72 ]);
73 });
74
75 it("preserves unknown config keys while omitting empty configurable fields", () => {
76 const opencode = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencode")];
77 expect(opencode).toBeDefined();
78
79 const serverUrl = deriveProviderSettingsFields(opencode!).find(
80 (field) => field.key === "serverUrl",
81 );
82 expect(serverUrl).toBeDefined();
83
84 const next = nextProviderConfigWithFieldValue(
85 { forkOwned: 1, serverUrl: "http://127.0.0.1:4096" },
86 serverUrl!,
87 "",
88 );
89
90 expect(next).toEqual({ forkOwned: 1 });
91 });
92
93 it("reads non-string config values as blank strings", () => {
94 expect(readProviderConfigString({ binaryPath: 123 }, "binaryPath")).toBe("");
95 });
96
97 it("omits false boolean fields when clearWhenEmpty is omit", () => {
98 const next = nextProviderConfigWithFieldValue(
99 { forkOwned: 1, experimental: true },
100 {
101 key: "experimental",
102 control: "switch",
103 label: "Experimental",
104 clearWhenEmpty: "omit",
105 defaultBooleanValue: false,
106 },
107 false,
108 );
109
110 expect(next).toEqual({ forkOwned: 1 });
111 });
112
113 it("omits true boolean fields when true is the default", () => {
114 const next = nextProviderConfigWithFieldValue(
115 { forkOwned: 1, experimental: false },
116 {
117 key: "experimental",
118 control: "switch",
119 label: "Experimental",
120 clearWhenEmpty: "omit",
121 defaultBooleanValue: true,
122 },
123 true,
124 );
125
126 expect(next).toEqual({ forkOwned: 1 });
127 });
128
129 it("stores false boolean fields when true is the default", () => {
130 const next = nextProviderConfigWithFieldValue(
131 undefined,
132 {
133 key: "experimental",
134 control: "switch",
135 label: "Experimental",
136 clearWhenEmpty: "omit",
137 defaultBooleanValue: true,
138 },
139 false,
140 );
141
142 expect(next).toEqual({ experimental: false });
143 });
144
145 it("preserves false boolean fields when clearWhenEmpty is persist", () => {
146 const next = nextProviderConfigWithFieldValue(
147 undefined,
148 {
149 key: "experimental",
150 control: "switch",
151 label: "Experimental",
152 clearWhenEmpty: "persist",
153 },
154 false,
155 );
156
157 expect(next).toEqual({ experimental: false });
158 });
159
160 it("reads non-boolean config values as false booleans", () => {
161 expect(readProviderConfigBoolean({ experimental: "true" }, "experimental")).toBe(false);
162 });
163
164 it("reads missing boolean config values from the supplied default", () => {
165 expect(readProviderConfigBoolean({}, "experimental", true)).toBe(true);
166 });
167});