Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
import { describe, expect, it } from "vite-plus/test";
import { ProviderDriverKind } from "@akeru/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",
"launchArgs",
]);
});
it("sources labels and descriptions from schema annotations", () => {
const codex = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("codex")];
expect(codex).toBeDefined();
const homePath = deriveProviderSettingsFields(codex!).find((field) => field.key === "homePath");
expect(homePath).toMatchObject({
label: "CODEX_HOME path",
description: "Custom Codex home and config directory.",
control: "text",
});
});
it("shows the auto-compaction threshold for Claude providers", () => {
const claude = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("claudeAgent")];
expect(claude).toBeDefined();
expect(deriveProviderSettingsFields(claude!).map((field) => field.key)).toEqual([
"binaryPath",
"homePath",
"autoCompactWindow",
"launchArgs",
]);
});
it("registers Kimi settings in the provider picker", () => {
const kimi = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("kimi")];
expect(kimi).toMatchObject({ label: "Kimi For Coding" });
expect(deriveProviderSettingsFields(kimi!)).toEqual([]);
expect(DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("cursor")]).toBeUndefined();
});
it("registers OpenCode Go in the provider picker", () => {
const openCodeGo = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencodeGo")];
expect(openCodeGo).toMatchObject({ label: "OpenCode Go" });
expect(deriveProviderSettingsFields(openCodeGo!)).toEqual([]);
});
it("preserves unknown config keys while omitting empty configurable fields", () => {
const codex = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("codex")];
expect(codex).toBeDefined();
const homePath = deriveProviderSettingsFields(codex!).find((field) => field.key === "homePath");
expect(homePath).toBeDefined();
const next = nextProviderConfigWithFieldValue(
{ forkOwned: 1, homePath: "/tmp/codex" },
homePath!,
"",
);
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);
});
});