Skip to content

Commit 3674bd3

Browse files
committed
test: cover backend settings helpers
1 parent ca42235 commit 3674bd3

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { describe, expect, it } from "vitest";
2+
import {
3+
backendSettingsEqual,
4+
backendSettingsSnapshot,
5+
buildBackendConfigPatch,
6+
buildBackendSettingsPreview,
7+
clampBackendNumberForTests,
8+
cloneBackendPluginConfig,
9+
formatBackendNumberValue,
10+
} from "../lib/codex-manager/backend-settings-helpers.js";
11+
12+
describe("backend settings helpers", () => {
13+
it("clones fallback chains defensively", () => {
14+
const cloned = cloneBackendPluginConfig({ unsupportedCodexFallbackChain: { a: ["b"] } } as never);
15+
expect(cloned.unsupportedCodexFallbackChain).toEqual({ a: ["b"] });
16+
expect(cloned.unsupportedCodexFallbackChain).not.toBe((({ unsupportedCodexFallbackChain: { a: ["b"] } } as never).unsupportedCodexFallbackChain));
17+
});
18+
19+
it("formats and clamps backend numeric values", () => {
20+
expect(formatBackendNumberValue({ unit: "percent" } as never, 4.6)).toBe("5%");
21+
expect(formatBackendNumberValue({ unit: "count" } as never, 2.2)).toBe("2");
22+
expect(clampBackendNumberForTests("fetchTimeoutMs", 10)).toBeGreaterThanOrEqual(1000);
23+
});
24+
25+
it("builds snapshots, equality, preview and patches", () => {
26+
const left = { fetchTimeoutMs: 60000, streamStallTimeoutMs: 45000, liveAccountSync: true, sessionAffinity: true, preemptiveQuotaEnabled: true, preemptiveQuotaRemainingPercent5h: 5, preemptiveQuotaRemainingPercent7d: 5 } as never;
27+
const right = { ...left } as never;
28+
expect(backendSettingsSnapshot(left)).toEqual(backendSettingsSnapshot(right));
29+
expect(backendSettingsEqual(left, right)).toBe(true);
30+
const preview = buildBackendSettingsPreview(left, { theme: {} } as never, "fetchTimeoutMs", { highlightPreviewToken: (text) => `[${text}]` });
31+
expect(preview.label).toContain("live sync");
32+
expect(preview.hint).toContain("timeouts");
33+
expect(buildBackendConfigPatch({ ...left, fetchTimeoutMs: 10 } as never)).toHaveProperty("fetchTimeoutMs");
34+
});
35+
});

0 commit comments

Comments
 (0)