Files
openclaw/extensions/anthropic/cli-context-window.test.ts
Ayaan Zaidi 041938bc2f feat(ui): add a Claude CLI 200K/1M context-window switch to the model picker (#127951)
Adds a generic plugin-declared selectable-context-window surface mirroring thinkingLevels: ModelCatalogEntry.contextWindows + contextWindowDefault through catalog normalization and the gateway protocol, session validation on sessions.create/patch, and a 200K/1M switch inside the Control UI model picker for Claude CLI 5-series models. The Anthropic plugin owns the option mapping: explicit 1m → `[1m]` argv suffix, 200k → bare id + CLAUDE_CODE_DISABLE_1M_CONTEXT=1, omitted → bare id (shipped default argv). Run budgets follow the selection on both CLI and native paths, so a 200K session gets a matching auto-compact window instead of a silent 1M budget.

Review fixes landed in this PR: run-owner prepared-fact plumbing so ordinary replies honor the selection; atomic catalog overlay merge and normalization for the options/default tuple; one-owner tuple reads in the picker; sessions.create key-presence patch semantics; native-run budget capping.

Feature direction and in-picker switch shape by @obviyus (maintainer review).
2026-08-22 23:25:23 +05:30

46 lines
1.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildAnthropicCliBackend } from "./cli-backend.js";
describe("Claude CLI context-window selection", () => {
it("maps selectable windows to native model ids and process env", () => {
const backend = buildAnthropicCliBackend();
const resolveModelId = backend.resolveModelId;
const prepareExecution = backend.prepareExecution;
// Omitted selection must stay on the bare id: the CLI already defaults
// Claude 5 to 1M, and suffixed argv would regress CLIs without [1m] support.
expect(resolveModelId?.({ modelId: "claude-fable-5" })).toBe("claude-fable-5");
expect(resolveModelId?.({ modelId: "claude-fable-5", contextWindow: "200k" })).toBe(
"claude-fable-5",
);
expect(
prepareExecution?.({
workspaceDir: "/tmp/openclaw-claude-cli",
provider: "claude-cli",
modelId: "claude-fable-5",
contextWindow: "200k",
contextTokenBudget: 200_000,
}),
).toEqual({
env: {
CLAUDE_CODE_AUTO_COMPACT_WINDOW: "200000",
CLAUDE_CODE_DISABLE_1M_CONTEXT: "1",
},
});
expect(resolveModelId?.({ modelId: "claude-fable-5", contextWindow: "1m" })).toBe(
"claude-fable-5[1m]",
);
expect(
prepareExecution?.({
workspaceDir: "/tmp/openclaw-claude-cli",
provider: "claude-cli",
modelId: "claude-fable-5",
contextWindow: "1m",
contextTokenBudget: 1_000_000,
}),
).toEqual({ env: { CLAUDE_CODE_AUTO_COMPACT_WINDOW: "1000000" } });
expect(backend.config.clearEnv).toContain("CLAUDE_CODE_DISABLE_1M_CONTEXT");
expect(resolveModelId?.({ modelId: "claude-opus-4-8" })).toBe("claude-opus-4-8");
});
});