Skip to content

Commit 77e6873

Browse files
Handle omitted false provider booleans
- drop false switch values when settings declare `clearWhenEmpty: omit` - add coverage for boolean field read/write behavior
1 parent e5b9956 commit 77e6873

3 files changed

Lines changed: 64 additions & 7 deletions

File tree

‎apps/web/src/components/settings/ProviderSettingsForm.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DRIVER_OPTION_BY_VALUE } from "./providerDriverMeta";
55
import {
66
deriveProviderSettingsFields,
77
nextProviderConfigWithFieldValue,
8+
readProviderConfigBoolean,
89
readProviderConfigString,
910
} from "./ProviderSettingsForm";
1011

@@ -56,4 +57,38 @@ describe("ProviderSettingsForm helpers", () => {
5657
it("reads non-string config values as blank strings", () => {
5758
expect(readProviderConfigString({ binaryPath: 123 }, "binaryPath")).toBe("");
5859
});
60+
61+
it("omits false boolean fields when clearWhenEmpty is omit", () => {
62+
const next = nextProviderConfigWithFieldValue(
63+
{ forkOwned: 1, experimental: true },
64+
{
65+
key: "experimental",
66+
control: "switch",
67+
label: "Experimental",
68+
clearWhenEmpty: "omit",
69+
},
70+
false,
71+
);
72+
73+
expect(next).toEqual({ forkOwned: 1 });
74+
});
75+
76+
it("preserves false boolean fields when clearWhenEmpty is persist", () => {
77+
const next = nextProviderConfigWithFieldValue(
78+
undefined,
79+
{
80+
key: "experimental",
81+
control: "switch",
82+
label: "Experimental",
83+
clearWhenEmpty: "persist",
84+
},
85+
false,
86+
);
87+
88+
expect(next).toEqual({ experimental: false });
89+
});
90+
91+
it("reads non-boolean config values as false booleans", () => {
92+
expect(readProviderConfigBoolean({ experimental: "true" }, "experimental")).toBe(false);
93+
});
5994
});

‎apps/web/src/components/settings/ProviderSettingsForm.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ export function nextProviderConfigWithFieldValue(
119119
config !== null && typeof config === "object" ? { ...(config as Record<string, unknown>) } : {};
120120

121121
if (typeof value === "boolean") {
122-
base[field.key] = value;
122+
if (field.clearWhenEmpty === "omit" && value === false) {
123+
delete base[field.key];
124+
} else {
125+
base[field.key] = value;
126+
}
123127
return Object.keys(base).length > 0 ? base : undefined;
124128
}
125129

‎packages/contracts/src/settings.ts‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ export const CodexSettings = makeProviderSettingsSchema(
155155
Schema.annotateKey({
156156
title: "CODEX_HOME path",
157157
description: "Custom Codex home and config directory.",
158-
providerSettingsForm: { placeholder: "~/.codex", clearWhenEmpty: "omit" },
158+
providerSettingsForm: {
159+
placeholder: "~/.codex",
160+
clearWhenEmpty: "omit",
161+
},
159162
}),
160163
),
161164
shadowHomePath: TrimmedString.pipe(
@@ -164,7 +167,10 @@ export const CodexSettings = makeProviderSettingsSchema(
164167
title: "Shadow home path",
165168
description:
166169
"Account-specific Codex home. Keeps auth.json separate while sharing state from CODEX_HOME.",
167-
providerSettingsForm: { placeholder: "~/.codex-t3/personal", clearWhenEmpty: "omit" },
170+
providerSettingsForm: {
171+
placeholder: "~/.codex-t3/personal",
172+
clearWhenEmpty: "omit",
173+
},
168174
}),
169175
),
170176
customModels: Schema.Array(Schema.String).pipe(
@@ -209,7 +215,10 @@ export const ClaudeSettings = makeProviderSettingsSchema(
209215
Schema.annotateKey({
210216
title: "Launch arguments",
211217
description: "Additional CLI arguments passed on session start.",
212-
providerSettingsForm: { placeholder: "e.g. --chrome", clearWhenEmpty: "omit" },
218+
providerSettingsForm: {
219+
placeholder: "e.g. --chrome",
220+
clearWhenEmpty: "omit",
221+
},
213222
}),
214223
),
215224
},
@@ -237,7 +246,10 @@ export const CursorSettings = makeProviderSettingsSchema(
237246
Schema.annotateKey({
238247
title: "API endpoint",
239248
description: "Override the Cursor API endpoint for this instance.",
240-
providerSettingsForm: { placeholder: "https://...", clearWhenEmpty: "omit" },
249+
providerSettingsForm: {
250+
placeholder: "https://...",
251+
clearWhenEmpty: "omit",
252+
},
241253
}),
242254
),
243255
customModels: Schema.Array(Schema.String).pipe(
@@ -260,15 +272,21 @@ export const OpenCodeSettings = makeProviderSettingsSchema(
260272
Schema.annotateKey({
261273
title: "Binary path",
262274
description: "Path to the OpenCode binary.",
263-
providerSettingsForm: { placeholder: "opencode", clearWhenEmpty: "omit" },
275+
providerSettingsForm: {
276+
placeholder: "opencode",
277+
clearWhenEmpty: "omit",
278+
},
264279
}),
265280
),
266281
serverUrl: TrimmedString.pipe(
267282
Schema.withDecodingDefault(Effect.succeed("")),
268283
Schema.annotateKey({
269284
title: "Server URL",
270285
description: "Leave blank to let T3 Code spawn the server when needed.",
271-
providerSettingsForm: { placeholder: "http://127.0.0.1:4096", clearWhenEmpty: "omit" },
286+
providerSettingsForm: {
287+
placeholder: "http://127.0.0.1:4096",
288+
clearWhenEmpty: "omit",
289+
},
272290
}),
273291
),
274292
serverPassword: TrimmedString.pipe(

0 commit comments

Comments
 (0)