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