151 lines
5 KiB
TypeScript
151 lines
5 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import {
|
|
buildConfigOptions,
|
|
buildEffortSelectOption,
|
|
buildModeSelectOption,
|
|
buildModelSelectOption,
|
|
formatVariantName,
|
|
parseModelSelection,
|
|
type ConfigOptionProvider,
|
|
} from "../../src/acp/config-option"
|
|
|
|
const providers: ConfigOptionProvider[] = [
|
|
{
|
|
id: "anthropic",
|
|
name: "Anthropic",
|
|
models: [
|
|
{ id: "claude/sonnet-4", name: "Claude Sonnet 4", variants: ["default", "high", "very-high"] },
|
|
{ id: "claude-haiku", name: "Claude Haiku" },
|
|
],
|
|
},
|
|
{ id: "openai", name: "OpenAI", models: [{ id: "gpt-5", name: "GPT-5", variants: ["minimal", "low"] }] },
|
|
]
|
|
|
|
describe("acp config options", () => {
|
|
test("builds the model select option with ACP verifier category", () => {
|
|
expect(
|
|
buildModelSelectOption({
|
|
providers,
|
|
currentModel: { providerID: "anthropic", modelID: "claude/sonnet-4" },
|
|
}),
|
|
).toEqual({
|
|
id: "model",
|
|
name: "Model",
|
|
category: "model",
|
|
type: "select",
|
|
currentValue: "anthropic/claude/sonnet-4",
|
|
options: [
|
|
{ value: "anthropic/claude-haiku", name: "Anthropic/Claude Haiku" },
|
|
{ value: "anthropic/claude/sonnet-4", name: "Anthropic/Claude Sonnet 4" },
|
|
{ value: "openai/gpt-5", name: "OpenAI/GPT-5" },
|
|
],
|
|
})
|
|
})
|
|
|
|
test("builds effort option from variants and falls back to default when current variant is invalid", () => {
|
|
expect(buildEffortSelectOption({ variants: ["low", "default", "high"], currentVariant: "missing" })).toEqual({
|
|
id: "effort",
|
|
name: "Effort",
|
|
description: "Available effort levels for this model",
|
|
category: "thought_level",
|
|
type: "select",
|
|
currentValue: "default",
|
|
options: [
|
|
{ value: "low", name: "Low" },
|
|
{ value: "default", name: "Default" },
|
|
{ value: "high", name: "High" },
|
|
],
|
|
})
|
|
})
|
|
|
|
test("effort fallback uses the first variant when default is absent", () => {
|
|
expect(buildEffortSelectOption({ variants: ["minimal", "low"], currentVariant: "missing" }).currentValue).toBe(
|
|
"minimal",
|
|
)
|
|
})
|
|
|
|
test("builds the mode select option with descriptions when present", () => {
|
|
expect(
|
|
buildModeSelectOption({
|
|
currentModeId: "build",
|
|
modes: [
|
|
{ id: "build", name: "Build", description: "Make code changes" },
|
|
{ id: "plan", name: "Plan" },
|
|
],
|
|
}),
|
|
).toEqual({
|
|
id: "mode",
|
|
name: "Session Mode",
|
|
category: "mode",
|
|
type: "select",
|
|
currentValue: "build",
|
|
options: [
|
|
{ value: "build", name: "Build", description: "Make code changes" },
|
|
{ value: "plan", name: "Plan" },
|
|
],
|
|
})
|
|
})
|
|
|
|
test("builds full config options with model, effort, and mode in stable order", () => {
|
|
const options = buildConfigOptions({
|
|
providers,
|
|
currentModel: { providerID: "anthropic", modelID: "claude/sonnet-4" },
|
|
currentVariant: "very-high",
|
|
modes: [
|
|
{ id: "build", name: "Build" },
|
|
{ id: "plan", name: "Plan" },
|
|
],
|
|
currentModeId: "plan",
|
|
})
|
|
|
|
expect(options.map((option) => option.id)).toEqual(["model", "effort", "mode"])
|
|
expect(options.map((option) => option.category)).toEqual(["model", "thought_level", "mode"])
|
|
expect(options[0]?.currentValue).toBe("anthropic/claude/sonnet-4")
|
|
expect(options[1]?.currentValue).toBe("very-high")
|
|
})
|
|
|
|
test("full config options omit effort for models without variants", () => {
|
|
expect(
|
|
buildConfigOptions({
|
|
providers,
|
|
currentModel: { providerID: "anthropic", modelID: "claude-haiku" },
|
|
}).map((option) => option.id),
|
|
).toEqual(["model"])
|
|
})
|
|
|
|
test("parses provider/model selections", () => {
|
|
expect(parseModelSelection("openai/gpt-5", providers)).toEqual({
|
|
model: { providerID: "openai", modelID: "gpt-5" },
|
|
})
|
|
})
|
|
|
|
test("parses provider/model/variant selections when the base model exposes that variant", () => {
|
|
expect(parseModelSelection("openai/gpt-5/low", providers)).toEqual({
|
|
model: { providerID: "openai", modelID: "gpt-5" },
|
|
variant: "low",
|
|
})
|
|
})
|
|
|
|
test("prefers exact slash-containing model ids before treating the tail as a variant", () => {
|
|
expect(parseModelSelection("anthropic/claude/sonnet-4", providers)).toEqual({
|
|
model: { providerID: "anthropic", modelID: "claude/sonnet-4" },
|
|
})
|
|
})
|
|
|
|
test("parses trailing variants for slash-containing model ids", () => {
|
|
expect(parseModelSelection("anthropic/claude/sonnet-4/high", providers)).toEqual({
|
|
model: { providerID: "anthropic", modelID: "claude/sonnet-4" },
|
|
variant: "high",
|
|
})
|
|
})
|
|
|
|
test("keeps unknown trailing segments in the model id when they are not valid variants", () => {
|
|
expect(parseModelSelection("anthropic/claude/sonnet-4/missing", providers)).toEqual({
|
|
model: { providerID: "anthropic", modelID: "claude/sonnet-4/missing" },
|
|
})
|
|
})
|
|
|
|
test("formats variant names for display", () => {
|
|
expect(formatVariantName("very_high-effort")).toBe("Very High Effort")
|
|
})
|
|
})
|