| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973 |
- import { stripAnsi, visibleWidth } from "../../src/tui/rendering/text.js";
- import { describe, expect, it, vi } from "vitest";
- import { TuiModelPicker } from "../../src/tui/features/model/picker.js";
- describe("TuiModelPicker", () => {
- it("selects each declared Kimi K3 effort without inventing a medium level", () => {
- const onSelect = vi.fn();
- const model = {
- providerId: "custom_provider:moonshotai",
- modelId: "kimi-k3",
- selected: true,
- effortOptions: ["low", "high", "max"],
- };
- const picker = new TuiModelPicker([model], onSelect, vi.fn());
- expect(stripAnsi(picker.render(80).join("\n"))).toContain("[ high ]");
- for (const [key, effort] of [
- ["\u001b[D", "low"],
- ["\u001b[C", "high"],
- ["\u001b[C", "max"],
- ] as const) {
- picker.handleInput(key);
- expect(stripAnsi(picker.render(80).join("\n"))).toContain(`[ ${effort} ]`);
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenLastCalledWith(model, effort);
- }
- });
- it("switches M3 context independently of thinking and restores the saved choice", () => {
- const model = {
- providerId: "minimax",
- modelId: "MiniMax-M3",
- selected: true,
- contextLimit: 512_000,
- contextWindowOptions: [512_000, 1_000_000],
- contextWindowOptionHints: { "1000000": "higher_usage" as const },
- thinkingConfig: { mode: "switchable", defaultValue: "true" },
- };
- const onSelect = vi.fn();
- const picker = new TuiModelPicker([model], onSelect, vi.fn());
- expect(stripAnsi(picker.render(100).join("\n"))).toContain("[ 512K ]");
- picker.handleInput("\t");
- picker.handleInput("\x1b[C");
- const rendered = stripAnsi(picker.render(100).join("\n"));
- expect(rendered).toContain("[ 1M ]");
- expect(rendered).toContain("Higher usage with this context window.");
- expect(rendered).toContain("[ Off ]");
- expect(onSelect).not.toHaveBeenCalled();
- expect(model.contextLimit).toBe(512_000);
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ contextLimit: 1_000_000, variant: "" }),
- );
- const reopened = new TuiModelPicker(
- [{ ...model, contextLimit: 1_000_000 }],
- onSelect,
- vi.fn(),
- );
- expect(stripAnsi(reopened.render(100).join("\n"))).toContain("[ 1M ]");
- reopened.handleInput("\x1b[Z");
- expect(stripAnsi(reopened.render(100).join("\n"))).toContain("[ 512K ]");
- });
- it("keeps context drafts while filtering, preserves effort and discards cancelled changes", () => {
- const model = {
- providerId: "minimax",
- modelId: "MiniMax-M3",
- contextLimit: 512_000,
- contextWindowOptions: [512_000, 1_000_000],
- effortOptions: ["low", "high"],
- };
- const onSelect = vi.fn();
- const onCancel = vi.fn();
- const picker = new TuiModelPicker([model], onSelect, onCancel);
- picker.handleInput("M3");
- picker.handleInput("\t");
- expect(stripAnsi(picker.render(100).join("\n"))).toContain("Search: M3");
- picker.handleInput("\x7f");
- picker.handleInput("\x7f");
- picker.handleInput("\x1b[C");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ contextLimit: 1_000_000 }),
- "high",
- );
- const cancelled = new TuiModelPicker([model], onSelect, onCancel);
- cancelled.handleInput("\t");
- cancelled.handleInput("\x1b");
- expect(onCancel).toHaveBeenCalledOnce();
- expect(onSelect).toHaveBeenCalledOnce();
- expect(model.contextLimit).toBe(512_000);
- });
- it("does not invent context choices and keeps the control usable in short viewports", () => {
- const onSelect = vi.fn();
- const fixed = {
- providerId: "work",
- modelId: "fixed",
- contextLimit: 200_000,
- };
- const picker = new TuiModelPicker([fixed], onSelect, vi.fn());
- picker.handleInput("\t");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(fixed);
- expect(stripAnsi(picker.render(100).join("\n"))).not.toContain(
- "tab context",
- );
- const switchable = new TuiModelPicker(
- [{ ...fixed, contextWindowOptions: [200_000, 1_000_000] }],
- vi.fn(),
- vi.fn(),
- );
- switchable.handleInput("\t");
- for (const height of [6, 8, 12]) {
- const lines = switchable.renderViewport(60, height);
- expect(lines.length).toBeLessThanOrEqual(height);
- expect(lines.every((line) => visibleWidth(line) <= 60)).toBe(true);
- expect(stripAnsi(lines.join("\n"))).toContain(
- height === 6 ? "1M ctx" : "[ 1M ]",
- );
- }
- });
- it("keeps model focus ahead of helper text in a short viewport", () => {
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "MiniMax-M3",
- displayName: "MiniMax-M3",
- },
- ],
- vi.fn(),
- vi.fn(),
- { unavailableHint: "Sign in to use this model" },
- );
- for (const height of [6, 8]) {
- const visible = stripAnsi(picker.renderViewport(40, height).join("\n"));
- expect(visible).toContain("›");
- expect(visible).toContain("MiniMax-M3");
- expect(visible.toLowerCase()).toContain("esc");
- }
- });
- it("keeps third-party provider onboarding available when the model roster is empty", () => {
- const onAddProvider = vi.fn();
- const picker = new TuiModelPicker([], vi.fn(), vi.fn(), { onAddProvider });
- expect(stripAnsi(picker.render(90).join("\n"))).toContain(
- "Add 3rd-party provider",
- );
- expect(stripAnsi(picker.render(90).join("\n"))).toContain(
- "No matching models",
- );
- picker.handleInput("\r");
- expect(onAddProvider).toHaveBeenCalledOnce();
- });
- it("groups models by provider and filters the grouped list while typing", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- providerName: "MiniMax",
- modelId: "MiniMax-M3",
- displayName: "MiniMax-M3",
- },
- {
- providerId: "minimax",
- providerName: "MiniMax",
- modelId: "MiniMax-M2.7",
- displayName: "MiniMax-M2.7",
- },
- {
- providerId: "deepseek",
- providerName: "DeepSeek",
- modelId: "deepseek-v4-pro",
- displayName: "deepseek-v4-pro",
- },
- ],
- onSelect,
- vi.fn(),
- );
- const initial = stripAnsi(picker.render(90).join("\n"));
- expect(initial).toContain("MiniMax · 2");
- expect(initial).toContain("DeepSeek · 1");
- picker.handleInput("deepseek");
- const filtered = stripAnsi(picker.render(90).join("\n"));
- expect(filtered).toContain("Search: deepseek");
- expect(filtered).toContain("DeepSeek · 1");
- expect(filtered).toContain("deepseek-v4-pro");
- expect(filtered).not.toContain("MiniMax-M3");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({
- providerId: "deepseek",
- modelId: "deepseek-v4-pro",
- }),
- );
- });
- it("confirms before deleting the focused custom provider and keeps plain d for search", async () => {
- const onDeleteProvider = vi.fn(async () => undefined);
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "custom_provider:openai",
- providerName: "OpenAI",
- providerSource: "custom_provider",
- providerKind: "custom",
- modelId: "gpt-4o",
- displayName: "GPT-4o",
- },
- {
- providerId: "custom_provider:openai",
- providerName: "OpenAI",
- providerSource: "custom_provider",
- providerKind: "custom",
- modelId: "gpt-4o-mini",
- displayName: "GPT-4o mini",
- },
- ],
- onSelect,
- vi.fn(),
- { onDeleteProvider, requestRender: vi.fn() },
- );
- expect(stripAnsi(picker.render(90).join("\n"))).toContain(
- "ctrl+d delete provider",
- );
- picker.handleInput("d");
- expect(stripAnsi(picker.render(90).join("\n"))).toContain("Search: d");
- expect(onDeleteProvider).not.toHaveBeenCalled();
- picker.handleInput("\x7f");
- picker.handleInput("\x04");
- const confirmation = stripAnsi(picker.render(90).join("\n"));
- expect(confirmation).toContain("Delete provider?");
- expect(confirmation).toContain("OpenAI");
- expect(confirmation).toContain("all 2 configured models");
- expect(onDeleteProvider).not.toHaveBeenCalled();
- picker.handleInput("\x1b");
- expect(stripAnsi(picker.render(90).join("\n"))).toContain("GPT-4o");
- picker.handleInput("\x04");
- picker.handleInput("\r");
- await vi.waitFor(() =>
- expect(onDeleteProvider).toHaveBeenCalledWith("custom_provider:openai"),
- );
- expect(onSelect).not.toHaveBeenCalled();
- });
- it("does not offer provider deletion for built-in models", () => {
- const onDeleteProvider = vi.fn(async () => undefined);
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- providerName: "MiniMax",
- providerSource: "provider",
- providerKind: "minimax-managed",
- modelId: "MiniMax-M3",
- displayName: "MiniMax-M3",
- },
- ],
- vi.fn(),
- vi.fn(),
- { onDeleteProvider, requestRender: vi.fn() },
- );
- expect(stripAnsi(picker.render(90).join("\n"))).not.toContain(
- "delete provider",
- );
- picker.handleInput("\x04");
- expect(stripAnsi(picker.render(90).join("\n"))).not.toContain(
- "Delete provider?",
- );
- expect(onDeleteProvider).not.toHaveBeenCalled();
- });
- it("keeps the provider and confirmation available when deletion fails", async () => {
- const picker = new TuiModelPicker(
- [
- {
- providerId: "custom_provider:openai",
- providerName: "OpenAI",
- providerSource: "custom_provider",
- providerKind: "custom",
- modelId: "gpt-4o",
- displayName: "GPT-4o",
- },
- ],
- vi.fn(),
- vi.fn(),
- {
- onDeleteProvider: vi.fn(async () => {
- throw new Error("storage unavailable");
- }),
- requestRender: vi.fn(),
- },
- );
- picker.handleInput("\x04");
- picker.handleInput("\r");
- await vi.waitFor(() =>
- expect(stripAnsi(picker.render(180).join("\n"))).toContain(
- "Couldn't delete provider",
- ),
- );
- expect(stripAnsi(picker.render(180).join("\n"))).toContain(
- "The provider and its models are unchanged.",
- );
- picker.handleInput("\x1b");
- expect(stripAnsi(picker.render(90).join("\n"))).toContain("GPT-4o");
- });
- it("searches Provider display names and restores the grouped list after an empty result", () => {
- const picker = new TuiModelPicker(
- [
- {
- providerId: "gateway-east",
- providerName: "Team Gateway",
- modelId: "model-a",
- displayName: "Model A",
- },
- {
- providerId: "gateway-west",
- providerName: "Other Gateway",
- modelId: "model-b",
- displayName: "Model B",
- },
- ],
- vi.fn(),
- vi.fn(),
- );
- picker.handleInput("team");
- let rendered = stripAnsi(picker.render(90).join("\n"));
- expect(rendered).toContain("Team Gateway · 1");
- expect(rendered).toContain("Model A");
- expect(rendered).not.toContain("Model B");
- picker.handleInput("x");
- rendered = stripAnsi(picker.render(90).join("\n"));
- expect(rendered).toContain("No matching models");
- expect(rendered).not.toContain("Model A");
- picker.handleInput("\x7f");
- rendered = stripAnsi(picker.render(90).join("\n"));
- expect(rendered).toContain("Team Gateway · 1");
- expect(rendered).toContain("Model A");
- });
- it("restores the Runtime-selected model after clearing a filter that hid it", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "MiniMax-M3",
- displayName: "MiniMax-M3",
- selected: true,
- },
- {
- providerId: "deepseek",
- modelId: "deepseek-v4-pro",
- displayName: "deepseek-v4-pro",
- },
- ],
- onSelect,
- vi.fn(),
- );
- picker.handleInput("deepseek");
- for (let index = 0; index < "deepseek".length; index += 1)
- picker.handleInput("\x7f");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ providerId: "minimax", modelId: "MiniMax-M3" }),
- );
- });
- it("keeps Think effort unchanged while left and right move the search cursor", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "provider",
- modelId: "model-a",
- displayName: "Model A",
- selected: true,
- effortOptions: ["low", "medium", "high"],
- },
- ],
- onSelect,
- vi.fn(),
- {},
- "low",
- );
- picker.handleInput("model");
- expect(stripAnsi(picker.render(90).join("\n"))).toContain("[ low ]");
- picker.handleInput("\u001b[C");
- expect(stripAnsi(picker.render(90).join("\n"))).toContain("[ low ]");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ modelId: "model-a" }),
- "low",
- );
- });
- it("renders Desktop-owned models and returns the selected model", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "MiniMax-M2.7",
- displayName: "MiniMax M2.7",
- selected: true,
- contextLimit: 204800,
- },
- {
- providerId: "provider-b",
- modelId: "model-b",
- displayName: "Model B",
- },
- ],
- onSelect,
- vi.fn(),
- );
- expect(picker.render(90).join("\n")).toContain("Models");
- expect(picker.render(90).join("\n")).toContain("MiniMax M2.7");
- expect(picker.render(90).join("\n")).toContain("Available models");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({
- providerId: "minimax",
- modelId: "MiniMax-M2.7",
- }),
- );
- });
- it("focuses the Runtime-selected model when reopening the picker", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "MiniMax-M3",
- displayName: "MiniMax-M3",
- selected: false,
- },
- {
- providerId: "custom_provider:innerTest",
- modelId: "MiniMax-M3",
- displayName: "m3.05",
- selected: true,
- },
- ],
- onSelect,
- vi.fn(),
- );
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({
- providerId: "custom_provider:innerTest",
- displayName: "m3.05",
- }),
- );
- });
- it.each(["\u001B", "\x03"])(
- "supports a prefiltered model list and Pi cancel input %j without inventing fallback models",
- (input) => {
- const onCancel = vi.fn();
- const picker = new TuiModelPicker([], vi.fn(), onCancel);
- expect(picker.render(70).join("\n")).toContain("No matching models");
- picker.handleInput(input);
- expect(onCancel).toHaveBeenCalledOnce();
- },
- );
- it("keeps managed models visible but rejects them when login is required", () => {
- const onSelect = vi.fn();
- const onUnavailable = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "MiniMax-M2.7",
- displayName: "MiniMax M2.7",
- providerKind: "minimax-managed",
- },
- ],
- onSelect,
- vi.fn(),
- {
- isUnavailable: () => true,
- onUnavailable,
- },
- );
- expect(picker.render(90).join("\n")).toContain("Login required");
- picker.handleInput("\r");
- expect(onUnavailable).toHaveBeenCalledOnce();
- expect(onSelect).not.toHaveBeenCalled();
- });
- it("keeps switchable Thinking as a draft until Enter applies the model selection", () => {
- // Regression caught: treating Thinking as a model-name suffix or persisting arrow keys immediately.
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "MiniMax-M3",
- displayName: "MiniMax-M3",
- selected: true,
- variant: "thinking",
- thinkingConfig: { mode: "switchable", defaultValue: "true" },
- },
- ],
- onSelect,
- vi.fn(),
- );
- expect(stripAnsi(picker.render(80).join("\n"))).toContain("Thinking");
- expect(stripAnsi(picker.render(80).join("\n"))).toContain("[ On ]");
- picker.handleInput("\u001b[D");
- expect(onSelect).not.toHaveBeenCalled();
- expect(stripAnsi(picker.render(80).join("\n"))).toContain("[ Off ]");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({
- providerId: "minimax",
- modelId: "MiniMax-M3",
- variant: "",
- }),
- );
- });
- it("uses each highlighted model Thinking state without leaking the previous draft", () => {
- // Regression caught: carrying one model's unsaved Thinking choice into the next highlighted model.
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "MiniMax-M3",
- displayName: "MiniMax-M3",
- variant: "thinking",
- thinkingConfig: { mode: "switchable", defaultValue: "true" },
- },
- {
- providerId: "provider-b",
- modelId: "model-b",
- displayName: "Model B",
- variant: "",
- thinkingConfig: { mode: "switchable", defaultValue: "false" },
- },
- ],
- onSelect,
- vi.fn(),
- );
- picker.handleInput("\u001b[D");
- picker.handleInput("\u001b[B");
- expect(stripAnsi(picker.render(80).join("\n"))).toContain("[ Off ]");
- picker.handleInput("\u001b[D");
- picker.handleInput("\u001b[A");
- expect(stripAnsi(picker.render(80).join("\n"))).toContain("[ Off ]");
- });
- it("keeps a stable panel height when highlighted models expose different controls", () => {
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "MiniMax-M3",
- displayName: "MiniMax-M3",
- selected: true,
- variant: "thinking",
- thinkingConfig: { mode: "switchable", defaultValue: "true" },
- },
- {
- providerId: "minimax",
- modelId: "MiniMax-M2.7-highspeed",
- displayName: "MiniMax-M2.7-highspeed",
- thinkingConfig: { mode: "hidden" },
- },
- ],
- vi.fn(),
- vi.fn(),
- );
- const thinkingRows = picker.render(90);
- expect(stripAnsi(thinkingRows.join("\n"))).toContain("Thinking");
- picker.handleInput("\u001b[B");
- const plainRows = picker.render(90);
- expect(stripAnsi(plainRows.join("\n"))).not.toContain("Thinking");
- expect(plainRows).toHaveLength(thinkingRows.length);
- });
- it("renders forced Thinking as read only and hides undisclosed Thinking configuration", () => {
- // Regression caught: exposing a switch for forced or hidden provider policy.
- const onSelect = vi.fn();
- const forced = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "MiniMax-M3",
- displayName: "MiniMax-M3",
- variant: "thinking",
- thinkingConfig: { mode: "forced_on" },
- },
- ],
- onSelect,
- vi.fn(),
- );
- const hidden = new TuiModelPicker(
- [
- {
- providerId: "provider-b",
- modelId: "model-b",
- displayName: "Model B",
- thinkingConfig: { mode: "hidden" },
- },
- ],
- vi.fn(),
- vi.fn(),
- );
- expect(stripAnsi(forced.render(80).join("\n"))).toContain("Thinking On");
- expect(stripAnsi(forced.render(80).join("\n"))).not.toContain("←/→");
- forced.handleInput("\u001b[D");
- forced.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ variant: "thinking" }),
- );
- expect(stripAnsi(hidden.render(80).join("\n"))).not.toContain("Thinking");
- });
- it("keeps catalog, empty, and footer states inside a narrow interaction card", () => {
- const picker = new TuiModelPicker(
- [
- {
- providerId: "provider-with-a-long-name",
- modelId: "model-with-a-deliberately-long-name",
- displayName: "A deliberately long Desktop model display name",
- },
- ],
- vi.fn(),
- vi.fn(),
- );
- const empty = new TuiModelPicker([], vi.fn(), vi.fn());
- expect(picker.render(24).every((line) => visibleWidth(line) <= 24)).toBe(
- true,
- );
- expect(empty.render(24).every((line) => visibleWidth(line) <= 24)).toBe(
- true,
- );
- });
- it("keeps provider deletion confirmation inside a narrow interaction card", () => {
- const picker = new TuiModelPicker(
- [
- {
- providerId: "custom_provider:provider-with-a-long-name",
- providerName: "Provider with a deliberately long display name",
- providerSource: "custom_provider",
- providerKind: "custom",
- modelId: "model-a",
- displayName: "Model A",
- },
- ],
- vi.fn(),
- vi.fn(),
- {
- onDeleteProvider: vi.fn(async () => undefined),
- requestRender: vi.fn(),
- },
- );
- picker.handleInput("\x04");
- expect(picker.render(24).every((line) => visibleWidth(line) <= 24)).toBe(
- true,
- );
- });
- it("keeps think effort as a draft until Enter applies it", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "custom_provider:byok",
- modelId: "byok-large-5",
- displayName: "byok-large-5",
- selected: true,
- effortOptions: ["low", "medium", "high", "xhigh", "max"],
- },
- ],
- onSelect,
- vi.fn(),
- );
- // Middle level mirrors what Runtime applies without an explicit choice.
- expect(stripAnsi(picker.render(80).join("\n"))).toContain("Think effort");
- expect(stripAnsi(picker.render(80).join("\n"))).toContain("[ high ]");
- picker.handleInput("\u001b[C");
- expect(onSelect).not.toHaveBeenCalled();
- expect(stripAnsi(picker.render(80).join("\n"))).toContain("[ xhigh ]");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ modelId: "byok-large-5" }),
- "xhigh",
- );
- });
- it("starts the selected row from the Session effort and clamps at the ends", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "custom_provider:byok",
- modelId: "byok-large-5",
- displayName: "byok-large-5",
- selected: true,
- effortOptions: ["low", "medium", "high"],
- },
- ],
- onSelect,
- vi.fn(),
- {},
- "low",
- );
- expect(stripAnsi(picker.render(80).join("\n"))).toContain("[ low ]");
- picker.handleInput("\u001b[D");
- expect(stripAnsi(picker.render(80).join("\n"))).toContain("[ low ]");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ modelId: "byok-large-5" }),
- "low",
- );
- });
- it("uses effort as the only control when legacy metadata also exposes Thinking", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "custom_provider:byok",
- modelId: "byok-large-5",
- displayName: "byok-large-5",
- selected: true,
- variant: "",
- thinkingConfig: { mode: "switchable", defaultValue: "false" },
- effortOptions: ["low", "medium", "high"],
- },
- ],
- onSelect,
- vi.fn(),
- );
- const rendered = stripAnsi(picker.render(90).join("\n"));
- expect(rendered).toContain("←/→ effort");
- expect(rendered).not.toContain("t thinking");
- expect(rendered).not.toContain("Thinking (");
- expect(rendered).not.toContain("[ Off ]");
- picker.handleInput("\u001b[D");
- expect(stripAnsi(picker.render(90).join("\n"))).toContain("[ low ]");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ modelId: "byok-large-5", variant: "" }),
- "low",
- );
- });
- it("applies the configured effort when a thinking-on model is confirmed without touching effort", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "deep-reasoner-1",
- displayName: "deep-reasoner-1",
- variant: "thinking",
- thinkingConfig: { mode: "switchable", defaultValue: "true" },
- effortOptions: ["xhigh"],
- },
- ],
- onSelect,
- vi.fn(),
- );
- picker.handleInput("\r");
- // Thinking is already on, so the Run must carry the configured level. Sending
- // the model without an effort lets the provider fall back to its own default.
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ modelId: "deep-reasoner-1" }),
- "xhigh",
- );
- });
- it("applies the configured effort when a forced-on model is confirmed", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "deep-reasoner-1",
- displayName: "deep-reasoner-1",
- variant: "thinking",
- thinkingConfig: { mode: "forced_on" },
- effortOptions: ["xhigh"],
- },
- ],
- onSelect,
- vi.fn(),
- );
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ modelId: "deep-reasoner-1" }),
- "xhigh",
- );
- });
- it("keeps an explicit legacy variant when Enter is pressed without choosing effort", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "custom_provider:byok",
- modelId: "byok-large-5",
- displayName: "byok-large-5",
- selected: true,
- variant: "",
- thinkingConfig: { mode: "switchable", defaultValue: "false" },
- effortOptions: ["low", "medium", "high"],
- },
- ],
- onSelect,
- vi.fn(),
- );
- const rendered = stripAnsi(picker.render(90).join("\n"));
- expect(rendered).not.toMatch(/\[\s*(?:low|medium|high)\s*\]/u);
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ modelId: "byok-large-5", variant: "" }),
- );
- });
- it("shows a fixed catalog effort without offering editable levels", () => {
- const onSelect = vi.fn();
- const model = {
- providerId: "minimax",
- modelId: "fixed",
- defaultEffort: "max",
- thinkingConfig: { mode: "forced_on" },
- };
- const picker = new TuiModelPicker([model], onSelect, vi.fn());
- const rendered = stripAnsi(picker.render(100).join("\n"));
- expect(rendered).toContain("Effort max (fixed)");
- expect(rendered).not.toContain("Thinking On");
- expect(rendered).not.toContain("←/→ effort");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(model, "max");
- });
- it("keeps the thinking switch usable alongside a fixed default effort", () => {
- const onSelect = vi.fn();
- const model = {
- providerId: "minimax",
- modelId: "fixed-switchable",
- defaultEffort: "max",
- thinkingConfig: { mode: "switchable", defaultValue: "true" },
- };
- const picker = new TuiModelPicker([model], onSelect, vi.fn());
- expect(stripAnsi(picker.render(100).join("\n"))).toContain(
- "Effort max (fixed)",
- );
- picker.handleInput("\x1b[C");
- expect(stripAnsi(picker.render(100).join("\n"))).not.toContain(
- "Effort max",
- );
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith({ ...model, variant: "" });
- const offModel = { ...model, variant: "" };
- const enable = new TuiModelPicker([offModel], onSelect, vi.fn());
- enable.handleInput("\x1b[C");
- expect(stripAnsi(enable.render(100).join("\n"))).toContain(
- "Effort max (fixed)",
- );
- enable.handleInput("\r");
- expect(onSelect).toHaveBeenLastCalledWith(
- { ...model, variant: "thinking" },
- "max",
- );
- });
- it("leaves models without effort levels untouched", () => {
- const onSelect = vi.fn();
- const picker = new TuiModelPicker(
- [
- {
- providerId: "minimax",
- modelId: "MiniMax-M3",
- displayName: "MiniMax-M3",
- selected: true,
- variant: "thinking",
- thinkingConfig: { mode: "switchable", defaultValue: "true" },
- },
- ],
- onSelect,
- vi.fn(),
- {},
- "high",
- );
- const rendered = stripAnsi(picker.render(80).join("\n"));
- expect(rendered).not.toContain("Think effort");
- expect(rendered).toContain("←/→ thinking");
- picker.handleInput("\u001b[D");
- picker.handleInput("\r");
- expect(onSelect).toHaveBeenCalledWith(
- expect.objectContaining({ variant: "" }),
- );
- });
- });
|