-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathProviderSettingsForm.test.ts
More file actions
138 lines (116 loc) · 4.05 KB
/
ProviderSettingsForm.test.ts
File metadata and controls
138 lines (116 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { describe, expect, it } from "vitest";
import { ProviderDriverKind } from "@t3tools/contracts";
import { DRIVER_OPTION_BY_VALUE } from "./providerDriverMeta";
import {
deriveProviderSettingsFields,
nextProviderConfigWithFieldValue,
readProviderConfigBoolean,
readProviderConfigString,
} from "./ProviderSettingsForm";
describe("ProviderSettingsForm helpers", () => {
it("derives visible provider config fields from the client definition schema", () => {
const codex = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("codex")];
expect(codex).toBeDefined();
expect(deriveProviderSettingsFields(codex!).map((field) => field.key)).toEqual([
"binaryPath",
"homePath",
"shadowHomePath",
]);
});
it("sources labels and descriptions from schema annotations", () => {
const opencode = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencode")];
expect(opencode).toBeDefined();
const serverPassword = deriveProviderSettingsFields(opencode!).find(
(field) => field.key === "serverPassword",
);
expect(serverPassword).toMatchObject({
label: "Server password",
description: "Stored in plain text on disk.",
control: "password",
});
});
it("exposes Pi as an active configurable driver", () => {
const pi = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("pi")];
expect(pi).toBeDefined();
expect(pi?.label).toBe("Pi");
expect(deriveProviderSettingsFields(pi!).map((field) => field.key)).toEqual(["binaryPath"]);
});
it("preserves unknown config keys while omitting empty configurable fields", () => {
const opencode = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencode")];
expect(opencode).toBeDefined();
const serverUrl = deriveProviderSettingsFields(opencode!).find(
(field) => field.key === "serverUrl",
);
expect(serverUrl).toBeDefined();
const next = nextProviderConfigWithFieldValue(
{ forkOwned: 1, serverUrl: "http://127.0.0.1:4096" },
serverUrl!,
"",
);
expect(next).toEqual({ forkOwned: 1 });
});
it("reads non-string config values as blank strings", () => {
expect(readProviderConfigString({ binaryPath: 123 }, "binaryPath")).toBe("");
});
it("omits false boolean fields when clearWhenEmpty is omit", () => {
const next = nextProviderConfigWithFieldValue(
{ forkOwned: 1, experimental: true },
{
key: "experimental",
control: "switch",
label: "Experimental",
clearWhenEmpty: "omit",
defaultBooleanValue: false,
},
false,
);
expect(next).toEqual({ forkOwned: 1 });
});
it("omits true boolean fields when true is the default", () => {
const next = nextProviderConfigWithFieldValue(
{ forkOwned: 1, experimental: false },
{
key: "experimental",
control: "switch",
label: "Experimental",
clearWhenEmpty: "omit",
defaultBooleanValue: true,
},
true,
);
expect(next).toEqual({ forkOwned: 1 });
});
it("stores false boolean fields when true is the default", () => {
const next = nextProviderConfigWithFieldValue(
undefined,
{
key: "experimental",
control: "switch",
label: "Experimental",
clearWhenEmpty: "omit",
defaultBooleanValue: true,
},
false,
);
expect(next).toEqual({ experimental: false });
});
it("preserves false boolean fields when clearWhenEmpty is persist", () => {
const next = nextProviderConfigWithFieldValue(
undefined,
{
key: "experimental",
control: "switch",
label: "Experimental",
clearWhenEmpty: "persist",
},
false,
);
expect(next).toEqual({ experimental: false });
});
it("reads non-boolean config values as false booleans", () => {
expect(readProviderConfigBoolean({ experimental: "true" }, "experimental")).toBe(false);
});
it("reads missing boolean config values from the supplied default", () => {
expect(readProviderConfigBoolean({}, "experimental", true)).toBe(true);
});
});