Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProviderSettingsForm.test.ts

144 lines4.2 KB

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("shows the auto-compaction threshold for Claude providers", () => {
41 const claude = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("claudeAgent")];
42 expect(claude).toBeDefined();
43​
44 expect(deriveProviderSettingsFields(claude!).map((field) => field.key)).toEqual([
45 "binaryPath",
46 "homePath",
47 "autoCompactWindow",
48 "launchArgs",
49 ]);
50 });
51​
52 it("preserves unknown config keys while omitting empty configurable fields", () => {
53 const opencode = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencode")];
54 expect(opencode).toBeDefined();
55​
56 const serverUrl = deriveProviderSettingsFields(opencode!).find(
57 (field) => field.key === "serverUrl",
58 );
59 expect(serverUrl).toBeDefined();
60​
61 const next = nextProviderConfigWithFieldValue(
62 { forkOwned: 1, serverUrl: "http://127.0.0.1:4096" },
63 serverUrl!,
64 "",
65 );
66​
67 expect(next).toEqual({ forkOwned: 1 });
68 });
69​
70 it("reads non-string config values as blank strings", () => {
71 expect(readProviderConfigString({ binaryPath: 123 }, "binaryPath")).toBe("");
72 });
73​
74 it("omits false boolean fields when clearWhenEmpty is omit", () => {
75 const next = nextProviderConfigWithFieldValue(
76 { forkOwned: 1, experimental: true },
77 {
78 key: "experimental",
79 control: "switch",
80 label: "Experimental",
81 clearWhenEmpty: "omit",
82 defaultBooleanValue: false,
83 },
84 false,
85 );
86​
87 expect(next).toEqual({ forkOwned: 1 });
88 });
89​
90 it("omits true boolean fields when true is the default", () => {
91 const next = nextProviderConfigWithFieldValue(
92 { forkOwned: 1, experimental: false },
93 {
94 key: "experimental",
95 control: "switch",
96 label: "Experimental",
97 clearWhenEmpty: "omit",
98 defaultBooleanValue: true,
99 },
100 true,
101 );
102​
103 expect(next).toEqual({ forkOwned: 1 });
104 });
105​
106 it("stores false boolean fields when true is the default", () => {
107 const next = nextProviderConfigWithFieldValue(
108 undefined,
109 {
110 key: "experimental",
111 control: "switch",
112 label: "Experimental",
113 clearWhenEmpty: "omit",
114 defaultBooleanValue: true,
115 },
116 false,
117 );
118​
119 expect(next).toEqual({ experimental: false });
120 });
121​
122 it("preserves false boolean fields when clearWhenEmpty is persist", () => {
123 const next = nextProviderConfigWithFieldValue(
124 undefined,
125 {
126 key: "experimental",
127 control: "switch",
128 label: "Experimental",
129 clearWhenEmpty: "persist",
130 },
131 false,
132 );
133​
134 expect(next).toEqual({ experimental: false });
135 });
136​
137 it("reads non-boolean config values as false booleans", () => {
138 expect(readProviderConfigBoolean({ experimental: "true" }, "experimental")).toBe(false);
139 });
140​
141 it("reads missing boolean config values from the supplied default", () => {
142 expect(readProviderConfigBoolean({}, "experimental", true)).toBe(true);
143 });
144});