authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-04 23:24:43-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-04 23:24:43-07:00
log07d2497db89014ccd71aa077fc809aff47e4af91
treecdeb663ba62343b1bfb750496f11a488c0f2e5da
parente5a87e8b9ca9db21e0291ddbd54438c5fe56b277
signature Signed by PGP key B5690EEEBB952194

test(web): keep provider field readers private (#9952)


2 files changed, 2 insertions(+), 20 deletions(-)

apps/web/src/components/settings/ProviderSettingsForm.test.ts-14
...@@ -5,8 +5,6 @@ import { DRIVER_OPTION_BY_VALUE } from "./providerDriverMeta";...@@ -5,8 +5,6 @@ import { DRIVER_OPTION_BY_VALUE } from "./providerDriverMeta";
5import {5import {
6 deriveProviderSettingsFields,6 deriveProviderSettingsFields,
7 nextProviderConfigWithFieldValue,7 nextProviderConfigWithFieldValue,
8 readProviderConfigBoolean,
9 readProviderConfigString,
10} from "./ProviderSettingsForm";8} from "./ProviderSettingsForm";
119
12describe("ProviderSettingsForm helpers", () => {10describe("ProviderSettingsForm helpers", () => {
...@@ -90,10 +88,6 @@ describe("ProviderSettingsForm helpers", () => {...@@ -90,10 +88,6 @@ describe("ProviderSettingsForm helpers", () => {
90 expect(next).toEqual({ forkOwned: 1 });88 expect(next).toEqual({ forkOwned: 1 });
91 });89 });
9290
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", () => {91 it("omits false boolean fields when clearWhenEmpty is omit", () => {
98 const next = nextProviderConfigWithFieldValue(92 const next = nextProviderConfigWithFieldValue(
99 { forkOwned: 1, experimental: true },93 { forkOwned: 1, experimental: true },
...@@ -156,12 +150,4 @@ describe("ProviderSettingsForm helpers", () => {...@@ -156,12 +150,4 @@ describe("ProviderSettingsForm helpers", () => {
156150
157 expect(next).toEqual({ experimental: false });151 expect(next).toEqual({ experimental: false });
158 });152 });
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});153});
apps/web/src/components/settings/ProviderSettingsForm.tsx+2-6
...@@ -119,17 +119,13 @@ export function deriveProviderSettingsFields(...@@ -119,17 +119,13 @@ export function deriveProviderSettingsFields(
119 });119 });
120}120}
121121
122export function readProviderConfigString(config: unknown, key: string): string {122function readProviderConfigString(config: unknown, key: string): string {
123 if (config === null || typeof config !== "object") return "";123 if (config === null || typeof config !== "object") return "";
124 const value = (config as Record<string, unknown>)[key];124 const value = (config as Record<string, unknown>)[key];
125 return typeof value === "string" ? value : "";125 return typeof value === "string" ? value : "";
126}126}
127127
128export function readProviderConfigBoolean(128function readProviderConfigBoolean(config: unknown, key: string, defaultValue = false): boolean {
129 config: unknown,
130 key: string,
131 defaultValue = false,
132): boolean {
133 if (config === null || typeof config !== "object") return defaultValue;129 if (config === null || typeof config !== "object") return defaultValue;
134 const value = (config as Record<string, unknown>)[key];130 const value = (config as Record<string, unknown>)[key];
135 return typeof value === "boolean" ? value : defaultValue;131 return typeof value === "boolean" ? value : defaultValue;