import { describe, expect, it } from "vite-plus/test"; import { ProviderInstanceId, type ModelSelection, type ServerConfig } from "@t3tools/contracts"; import { buildModelOptions, groupByProvider, resolveDefaultableModelSelection, resolveNewTaskModelSelection, resolveSelectableModelSelection, type ModelOption,} from "./modelOptions"; describe("mobile model options", () => { it("groups models by provider and flags legacy entries", () => { const config = { providers: [ { instanceId: "codex", driver: "codex", displayName: "Codex", enabled: true, installed: true, auth: { status: "authenticated" }, models: [ { slug: "gpt-5.6-sol", name: "GPT-5.6 Sol", isCustom: false, capabilities: null, }, { slug: "gpt-5.4", name: "GPT-5.4", isCustom: false, isLegacy: true, capabilities: null, }, ], }, ], } as unknown as ServerConfig; expect(groupByProvider(buildModelOptions(config, null))).toMatchObject([ { providerKey: "codex", providerLabel: "Codex", models: [ { key: "codex:gpt-5.6-sol", label: "GPT-5.6 Sol", subtitle: "", isLegacy: false }, { key: "codex:gpt-5.4", label: "GPT-5.4", isLegacy: true }, ], }, ]); }); it("distinguishes same-name OpenCode models without changing their routing", () => { const sources = [ { id: "anthropic", label: "Anthropic" }, { id: "github-copilot", label: "GitHub Copilot" }, { id: "opencode", label: "OpenCode Zen" }, ]; const config = { providers: [ { instanceId: "opencode_work", driver: "opencode", displayName: "OpenCode Work", enabled: true, installed: true, auth: { status: "authenticated" }, models: sources.map((source) => ({ slug: `${source.id}/claude-fable-5`, name: "Claude Fable 5", subProvider: source.label, isCustom: false, capabilities: null, })), }, ], } as unknown as ServerConfig; const selection = { instanceId: ProviderInstanceId.make("opencode_work"), model: "github-copilot/claude-fable-5", }; const options = buildModelOptions(config, selection); expect(options).toMatchObject( sources.map((source) => ({ key: `opencode_work:${source.id}/claude-fable-5`, label: "Claude Fable 5", subtitle: source.label, providerLabel: "OpenCode Work", selection: { instanceId: "opencode_work", model: `${source.id}/claude-fable-5`, }, })), ); expect(groupByProvider(options)).toEqual([ { providerKey: "opencode_work", providerLabel: "OpenCode Work", models: options }, ]); }); it("normalizes a legacy fallback selection against current capabilities", () => { const config = { providers: [ { instanceId: "codex", driver: "codex", displayName: "Codex", enabled: true, installed: true, auth: { status: "authenticated" }, models: [ { slug: "gpt-test", name: "GPT Test", isCustom: false, capabilities: { optionDescriptors: [ { id: "serviceTier", label: "Service Tier", type: "select", options: [ { id: "default", label: "Standard", isDefault: true }, { id: "priority", label: "Fast" }, ], currentValue: "default", }, ], }, }, ], }, ], } as unknown as ServerConfig; const [option] = buildModelOptions(config, { instanceId: ProviderInstanceId.make("codex"), model: "gpt-test", options: [{ id: "fastMode", value: true }], }); expect(option?.capabilities?.optionDescriptors?.[0]?.id).toBe("serviceTier"); expect(option?.selection.options).toEqual([{ id: "serviceTier", value: "default" }]); }); it("rejects stored selections whose provider is not usable", () => { const config = { providers: [ { instanceId: "codex", driver: "codex", enabled: true, installed: true, auth: { status: "authenticated" }, models: [], }, { instanceId: "claudeAgent", driver: "claudeAgent", enabled: false, installed: true, auth: { status: "authenticated" }, models: [], }, ], } as unknown as ServerConfig; const usable = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol", }; const disabled = { instanceId: ProviderInstanceId.make("claudeAgent"), model: "claude-sonnet-5", }; const removed = { instanceId: ProviderInstanceId.make("codex_personal"), model: "gpt-5.6-sol", }; expect(resolveSelectableModelSelection(config, usable)).toBe(usable); expect(resolveSelectableModelSelection(config, disabled)).toBeNull(); expect(resolveSelectableModelSelection(config, removed)).toBeNull(); // No config (environment offline) — nothing to validate against. expect(resolveSelectableModelSelection(null, disabled)).toBe(disabled); }); it("keeps legacy models out of implicit defaults", () => { const config = { providers: [ { instanceId: "codex", driver: "codex", displayName: "Codex", enabled: true, installed: true, auth: { status: "authenticated" }, models: [ { slug: "gpt-5.6-sol", name: "GPT-5.6 Sol", isCustom: false, capabilities: null }, { slug: "gpt-5.4", name: "GPT-5.4", isCustom: false, isLegacy: true, capabilities: null, }, ], }, ], } as unknown as ServerConfig; const current = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" }; const legacy = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" }; expect(resolveDefaultableModelSelection(config, current)).toBe(current); // A legacy last-used selection falls through to the provider default. expect(resolveDefaultableModelSelection(config, legacy)).toBeNull(); // Offline: nothing to validate against, selection passes through. expect(resolveDefaultableModelSelection(null, legacy)).toBe(legacy); }); it("resolves new tasks from draft, project, sticky, then provider defaults", () => { const draft = { instanceId: ProviderInstanceId.make("codex"), model: "draft" }; const project = { instanceId: ProviderInstanceId.make("codex"), model: "project" }; const sticky = { instanceId: ProviderInstanceId.make("codex"), model: "sticky" }; const providerDefault = { selection: { instanceId: ProviderInstanceId.make("codex"), model: "default" }, isDefault: true, } as ModelOption; const resolve = ( draftSelection: ModelSelection | null, projectDefaultSelection: ModelSelection | null, stickySelection: ModelSelection | null, ) => resolveNewTaskModelSelection({ draftSelection, projectDefaultSelection, stickySelection, modelOptions: [providerDefault], }); expect(resolve(draft, project, sticky)).toBe(draft); expect(resolve(null, project, sticky)).toBe(project); expect(resolve(null, null, sticky)).toBe(sticky); expect(resolve(null, null, null)).toBe(providerDefault.selection); });});
import { describe, expect, it } from "vite-plus/test";
import { ProviderInstanceId, type ModelSelection, type ServerConfig } from "@t3tools/contracts";
import {
buildModelOptions,
groupByProvider,
resolveDefaultableModelSelection,
resolveNewTaskModelSelection,
resolveSelectableModelSelection,
type ModelOption,
} from "./modelOptions";
describe("mobile model options", () => {
it("groups models by provider and flags legacy entries", () => {
const config = {
providers: [
{
instanceId: "codex",
driver: "codex",
displayName: "Codex",
enabled: true,
installed: true,
auth: { status: "authenticated" },
models: [
{
slug: "gpt-5.6-sol",
name: "GPT-5.6 Sol",
isCustom: false,
capabilities: null,
},
{
slug: "gpt-5.4",
name: "GPT-5.4",
isCustom: false,
isLegacy: true,
capabilities: null,
},
],
},
],
} as unknown as ServerConfig;
expect(groupByProvider(buildModelOptions(config, null))).toMatchObject([
{
providerKey: "codex",
providerLabel: "Codex",
models: [
{ key: "codex:gpt-5.6-sol", label: "GPT-5.6 Sol", subtitle: "", isLegacy: false },
{ key: "codex:gpt-5.4", label: "GPT-5.4", isLegacy: true },
],
},
]);
});
it("distinguishes same-name OpenCode models without changing their routing", () => {
const sources = [
{ id: "anthropic", label: "Anthropic" },
{ id: "github-copilot", label: "GitHub Copilot" },
{ id: "opencode", label: "OpenCode Zen" },
];
const config = {
providers: [
{
instanceId: "opencode_work",
driver: "opencode",
displayName: "OpenCode Work",
enabled: true,
installed: true,
auth: { status: "authenticated" },
models: sources.map((source) => ({
slug: `${source.id}/claude-fable-5`,
name: "Claude Fable 5",
subProvider: source.label,
isCustom: false,
capabilities: null,
})),
},
],
} as unknown as ServerConfig;
const selection = {
instanceId: ProviderInstanceId.make("opencode_work"),
model: "github-copilot/claude-fable-5",
};
const options = buildModelOptions(config, selection);
expect(options).toMatchObject(
sources.map((source) => ({
key: `opencode_work:${source.id}/claude-fable-5`,
label: "Claude Fable 5",
subtitle: source.label,
providerLabel: "OpenCode Work",
selection: {
instanceId: "opencode_work",
model: `${source.id}/claude-fable-5`,
},
})),
);
expect(groupByProvider(options)).toEqual([
{ providerKey: "opencode_work", providerLabel: "OpenCode Work", models: options },
]);
});
it("normalizes a legacy fallback selection against current capabilities", () => {
const config = {
providers: [
{
instanceId: "codex",
driver: "codex",
displayName: "Codex",
enabled: true,
installed: true,
auth: { status: "authenticated" },
models: [
{
slug: "gpt-test",
name: "GPT Test",
isCustom: false,
capabilities: {
optionDescriptors: [
{
id: "serviceTier",
label: "Service Tier",
type: "select",
options: [
{ id: "default", label: "Standard", isDefault: true },
{ id: "priority", label: "Fast" },
],
currentValue: "default",
},
],
},
},
],
},
],
} as unknown as ServerConfig;
const [option] = buildModelOptions(config, {
instanceId: ProviderInstanceId.make("codex"),
model: "gpt-test",
options: [{ id: "fastMode", value: true }],
});
expect(option?.capabilities?.optionDescriptors?.[0]?.id).toBe("serviceTier");
expect(option?.selection.options).toEqual([{ id: "serviceTier", value: "default" }]);
});
it("rejects stored selections whose provider is not usable", () => {
const config = {
providers: [
{
instanceId: "codex",
driver: "codex",
enabled: true,
installed: true,
auth: { status: "authenticated" },
models: [],
},
{
instanceId: "claudeAgent",
driver: "claudeAgent",
enabled: false,
installed: true,
auth: { status: "authenticated" },
models: [],
},
],
} as unknown as ServerConfig;
const usable = {
instanceId: ProviderInstanceId.make("codex"),
model: "gpt-5.6-sol",
};
const disabled = {
instanceId: ProviderInstanceId.make("claudeAgent"),
model: "claude-sonnet-5",
};
const removed = {
instanceId: ProviderInstanceId.make("codex_personal"),
model: "gpt-5.6-sol",
};
expect(resolveSelectableModelSelection(config, usable)).toBe(usable);
expect(resolveSelectableModelSelection(config, disabled)).toBeNull();
expect(resolveSelectableModelSelection(config, removed)).toBeNull();
// No config (environment offline) — nothing to validate against.
expect(resolveSelectableModelSelection(null, disabled)).toBe(disabled);
});
it("keeps legacy models out of implicit defaults", () => {
const config = {
providers: [
{
instanceId: "codex",
driver: "codex",
displayName: "Codex",
enabled: true,
installed: true,
auth: { status: "authenticated" },
models: [
{ slug: "gpt-5.6-sol", name: "GPT-5.6 Sol", isCustom: false, capabilities: null },
{
slug: "gpt-5.4",
name: "GPT-5.4",
isCustom: false,
isLegacy: true,
capabilities: null,
},
],
},
],
} as unknown as ServerConfig;
const current = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" };
const legacy = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" };
expect(resolveDefaultableModelSelection(config, current)).toBe(current);
// A legacy last-used selection falls through to the provider default.
expect(resolveDefaultableModelSelection(config, legacy)).toBeNull();
// Offline: nothing to validate against, selection passes through.
expect(resolveDefaultableModelSelection(null, legacy)).toBe(legacy);
});
it("resolves new tasks from draft, project, sticky, then provider defaults", () => {
const draft = { instanceId: ProviderInstanceId.make("codex"), model: "draft" };
const project = { instanceId: ProviderInstanceId.make("codex"), model: "project" };
const sticky = { instanceId: ProviderInstanceId.make("codex"), model: "sticky" };
const providerDefault = {
selection: { instanceId: ProviderInstanceId.make("codex"), model: "default" },
isDefault: true,
} as ModelOption;
const resolve = (
draftSelection: ModelSelection | null,
projectDefaultSelection: ModelSelection | null,
stickySelection: ModelSelection | null,
) =>
resolveNewTaskModelSelection({
draftSelection,
projectDefaultSelection,
stickySelection,
modelOptions: [providerDefault],
});
expect(resolve(draft, project, sticky)).toBe(draft);
expect(resolve(null, project, sticky)).toBe(project);
expect(resolve(null, null, sticky)).toBe(sticky);
expect(resolve(null, null, null)).toBe(providerDefault.selection);
});
});