Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
1031 lines
31 KiB
TypeScript
1031 lines
31 KiB
TypeScript
// Anthropic tests cover index plugin behavior.
|
|
import type {
|
|
ProviderResolveDynamicModelContext,
|
|
ProviderRuntimeModel,
|
|
} from "openclaw/plugin-sdk/plugin-entry";
|
|
import {
|
|
capturePluginRegistration,
|
|
registerSingleProviderPlugin,
|
|
} from "openclaw/plugin-sdk/plugin-test-runtime";
|
|
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const { readClaudeCliCredentialsForSetupMock, readClaudeCliCredentialsForRuntimeMock } = vi.hoisted(
|
|
() => ({
|
|
readClaudeCliCredentialsForSetupMock: vi.fn(),
|
|
readClaudeCliCredentialsForRuntimeMock: vi.fn(),
|
|
}),
|
|
);
|
|
|
|
vi.mock("./cli-auth-seam.js", () => {
|
|
return {
|
|
readClaudeCliCredentialsForSetup: readClaudeCliCredentialsForSetupMock,
|
|
readClaudeCliCredentialsForRuntime: readClaudeCliCredentialsForRuntimeMock,
|
|
};
|
|
});
|
|
|
|
import anthropicPlugin from "./index.js";
|
|
|
|
beforeEach(() => {
|
|
readClaudeCliCredentialsForSetupMock.mockReset();
|
|
readClaudeCliCredentialsForRuntimeMock.mockReset();
|
|
});
|
|
|
|
afterAll(() => {
|
|
vi.doUnmock("./cli-auth-seam.js");
|
|
vi.resetModules();
|
|
});
|
|
|
|
function createModelRegistry(models: ProviderRuntimeModel[]) {
|
|
return {
|
|
find(providerId: string, modelId: string) {
|
|
return (
|
|
models.find(
|
|
(model) =>
|
|
model.provider === providerId && model.id.toLowerCase() === modelId.toLowerCase(),
|
|
) ?? null
|
|
);
|
|
},
|
|
};
|
|
}
|
|
|
|
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
|
if (!value || typeof value !== "object") {
|
|
throw new Error(`expected ${label}`);
|
|
}
|
|
return value as Record<string, unknown>;
|
|
}
|
|
|
|
function expectFields(value: unknown, fields: Record<string, unknown>) {
|
|
const record = requireRecord(value, "record");
|
|
for (const [key, expected] of Object.entries(fields)) {
|
|
expect(record[key]).toEqual(expected);
|
|
}
|
|
}
|
|
|
|
function expectModelParams(models: unknown, modelId: string, params: Record<string, unknown>) {
|
|
const model = requireRecord(requireRecord(models, "models")[modelId], modelId);
|
|
expectFields(model.params, params);
|
|
}
|
|
|
|
function levelIds(profile: unknown): Array<unknown> {
|
|
const levels = requireRecord(profile, "thinking profile").levels;
|
|
expect(Array.isArray(levels), "thinking levels").toBe(true);
|
|
return (levels as Array<{ id?: unknown }>).map((level) => level.id);
|
|
}
|
|
|
|
const ANTHROPIC_SETUP_TOKEN = `sk-ant-oat01-${"a".repeat(80)}`;
|
|
|
|
describe("anthropic provider replay hooks", () => {
|
|
it("registers the claude-cli backend", () => {
|
|
const captured = capturePluginRegistration({ register: anthropicPlugin.register });
|
|
|
|
const backend = captured.cliBackends.find((entry) => entry.id === "claude-cli");
|
|
if (!backend) {
|
|
throw new Error("Expected claude-cli backend");
|
|
}
|
|
expect(backend.bundleMcp).toBe(true);
|
|
expectFields(backend.config, {
|
|
command: "claude",
|
|
modelArg: "--model",
|
|
sessionArg: "--session-id",
|
|
});
|
|
});
|
|
|
|
it("owns native reasoning output mode for Claude transports", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
expect(
|
|
provider.resolveReasoningOutputMode?.({
|
|
provider: "anthropic",
|
|
modelApi: "anthropic-messages",
|
|
modelId: "claude-sonnet-4-6",
|
|
} as never),
|
|
).toBe("native");
|
|
});
|
|
|
|
it("owns replay policy for Claude transports", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
expect(
|
|
provider.buildReplayPolicy?.({
|
|
provider: "anthropic",
|
|
modelApi: "anthropic-messages",
|
|
modelId: "claude-sonnet-4-6",
|
|
} as never),
|
|
).toEqual({
|
|
sanitizeMode: "full",
|
|
sanitizeToolCallIds: true,
|
|
toolCallIdMode: "strict",
|
|
preserveNativeAnthropicToolUseIds: true,
|
|
preserveSignatures: true,
|
|
repairToolUseResultPairing: true,
|
|
validateAnthropicTurns: true,
|
|
allowSyntheticToolResults: true,
|
|
});
|
|
});
|
|
|
|
it("preserves Fable thinking in its same-model replay policy", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
const fableContext = {
|
|
provider: "anthropic",
|
|
modelApi: "anthropic-messages",
|
|
modelId: "claude-fable-5",
|
|
};
|
|
|
|
expect(provider.buildReplayPolicy?.(fableContext)).toEqual({
|
|
sanitizeMode: "full",
|
|
sanitizeToolCallIds: true,
|
|
toolCallIdMode: "strict",
|
|
preserveNativeAnthropicToolUseIds: true,
|
|
preserveSignatures: true,
|
|
repairToolUseResultPairing: true,
|
|
validateAnthropicTurns: true,
|
|
allowSyntheticToolResults: true,
|
|
});
|
|
});
|
|
|
|
it("defaults provider api through plugin config normalization", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
expect(
|
|
requireRecord(
|
|
provider.normalizeConfig?.({
|
|
provider: "anthropic",
|
|
providerConfig: {
|
|
models: [{ id: "claude-sonnet-4-6", name: "Claude Sonnet 4.6" }],
|
|
},
|
|
} as never),
|
|
"normalized config",
|
|
).api,
|
|
).toBe("anthropic-messages");
|
|
});
|
|
|
|
it("defaults Claude CLI provider api through plugin config normalization", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
expect(
|
|
requireRecord(
|
|
provider.normalizeConfig?.({
|
|
provider: "claude-cli",
|
|
providerConfig: {
|
|
models: [{ id: "claude-sonnet-4-6", name: "Claude Sonnet 4.6" }],
|
|
},
|
|
} as never),
|
|
"normalized config",
|
|
).api,
|
|
).toBe("anthropic-messages");
|
|
});
|
|
|
|
it("does not default non-Anthropic provider api through plugin config normalization", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
const providerConfig = {
|
|
baseUrl: "https://chatgpt.com/backend-api/codex",
|
|
models: [{ id: "gpt-5.4", name: "GPT-5.4" }],
|
|
};
|
|
|
|
expect(
|
|
provider.normalizeConfig?.({
|
|
provider: "openai",
|
|
providerConfig,
|
|
} as never),
|
|
).toBe(providerConfig);
|
|
});
|
|
|
|
it("applies Anthropic pruning defaults through plugin hooks", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const next = provider.applyConfigDefaults?.({
|
|
provider: "anthropic",
|
|
env: {},
|
|
config: {
|
|
auth: {
|
|
profiles: {
|
|
"anthropic:api": { provider: "anthropic", mode: "api_key" },
|
|
},
|
|
},
|
|
agents: {
|
|
defaults: {
|
|
model: { primary: "anthropic/claude-opus-4-6" },
|
|
},
|
|
},
|
|
},
|
|
} as never);
|
|
|
|
expectFields(next?.agents?.defaults?.contextPruning, {
|
|
mode: "cache-ttl",
|
|
ttl: "1h",
|
|
});
|
|
expectFields(next?.agents?.defaults?.heartbeat, {
|
|
every: "30m",
|
|
});
|
|
expect(
|
|
next?.agents?.defaults?.models?.["anthropic/claude-opus-4-6"]?.params?.cacheRetention,
|
|
).toBe("short");
|
|
});
|
|
|
|
it("backfills Sonnet into API-key agent model allowlists", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const next = provider.applyConfigDefaults?.({
|
|
provider: "anthropic",
|
|
env: {},
|
|
config: {
|
|
auth: {
|
|
profiles: {
|
|
"anthropic:api": { provider: "anthropic", mode: "api_key" },
|
|
},
|
|
},
|
|
agents: {
|
|
defaults: {
|
|
model: { primary: "anthropic/claude-opus-4-6" },
|
|
models: {
|
|
"anthropic/claude-opus-4-6": {},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
} as never);
|
|
|
|
const models = next?.agents?.defaults?.models;
|
|
expectModelParams(models, "anthropic/claude-opus-4-6", { cacheRetention: "short" });
|
|
expectModelParams(models, "anthropic/claude-sonnet-4-6", { cacheRetention: "short" });
|
|
});
|
|
|
|
it("backfills Claude CLI allowlist defaults through plugin hooks for older configs", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const next = provider.applyConfigDefaults?.({
|
|
provider: "anthropic",
|
|
env: {},
|
|
config: {
|
|
auth: {
|
|
profiles: {
|
|
"anthropic:claude-cli": { provider: "claude-cli", mode: "oauth" },
|
|
},
|
|
},
|
|
agents: {
|
|
defaults: {
|
|
agentRuntime: { id: "claude-cli" },
|
|
model: { primary: "anthropic/claude-opus-4-7" },
|
|
models: {
|
|
"anthropic/claude-opus-4-7": {},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
} as never);
|
|
|
|
expectFields(next?.agents?.defaults?.heartbeat, {
|
|
every: "1h",
|
|
});
|
|
const models = requireRecord(next?.agents?.defaults?.models, "models");
|
|
for (const modelId of [
|
|
"anthropic/claude-opus-4-8",
|
|
"anthropic/claude-opus-4-7",
|
|
"anthropic/claude-sonnet-4-6",
|
|
"anthropic/claude-opus-4-6",
|
|
]) {
|
|
expect(models[modelId]).toEqual({ agentRuntime: { id: "claude-cli" } });
|
|
}
|
|
});
|
|
|
|
it("backfills raw and canonical Claude CLI policies for provider-qualified shorthand refs", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const next = provider.applyConfigDefaults?.({
|
|
provider: "anthropic",
|
|
env: {},
|
|
config: {
|
|
auth: {
|
|
profiles: {
|
|
"anthropic:claude-cli": { provider: "claude-cli", mode: "oauth" },
|
|
},
|
|
},
|
|
agents: {
|
|
defaults: {
|
|
model: { primary: "anthropic/opus-4.7" },
|
|
models: {
|
|
"anthropic/opus-4.7": { params: { maxTokens: 1200 } },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
} as never);
|
|
|
|
const models = requireRecord(next?.agents?.defaults?.models, "models");
|
|
expect(models["anthropic/opus-4.7"]).toEqual({
|
|
params: { maxTokens: 1200 },
|
|
agentRuntime: { id: "claude-cli" },
|
|
});
|
|
expect(models["anthropic/claude-opus-4-7"]).toEqual({
|
|
agentRuntime: { id: "claude-cli" },
|
|
});
|
|
});
|
|
|
|
it("backfills Claude CLI policy from per-agent shorthand refs selected under Claude CLI auth", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const next = provider.applyConfigDefaults?.({
|
|
provider: "anthropic",
|
|
env: {},
|
|
config: {
|
|
auth: {
|
|
profiles: {
|
|
"anthropic:claude-cli": { provider: "claude-cli", mode: "oauth" },
|
|
},
|
|
},
|
|
agents: {
|
|
defaults: {
|
|
models: {},
|
|
},
|
|
list: [
|
|
{
|
|
default: true,
|
|
id: "main",
|
|
model: { primary: "anthropic/opus-4.7" },
|
|
name: "Main",
|
|
workspace: "/tmp/openclaw-agent",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
} as never);
|
|
|
|
const models = requireRecord(next?.agents?.defaults?.models, "models");
|
|
expect(models["anthropic/opus-4.7"]).toEqual({ agentRuntime: { id: "claude-cli" } });
|
|
expect(models["anthropic/claude-opus-4-7"]).toEqual({
|
|
agentRuntime: { id: "claude-cli" },
|
|
});
|
|
});
|
|
|
|
it("backfills Claude CLI policy from shorthand model-map keys under Claude CLI auth", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const next = provider.applyConfigDefaults?.({
|
|
provider: "anthropic",
|
|
env: {},
|
|
config: {
|
|
auth: {
|
|
profiles: {
|
|
"anthropic:claude-cli": { provider: "claude-cli", mode: "oauth" },
|
|
},
|
|
},
|
|
agents: {
|
|
defaults: {
|
|
models: {
|
|
"anthropic/opus-4.7": { params: { maxTokens: 1200 } },
|
|
},
|
|
},
|
|
list: [
|
|
{
|
|
id: "main",
|
|
models: {
|
|
"anthropic/sonnet-4.6": { alias: "Sonnet shorthand" },
|
|
},
|
|
name: "Main",
|
|
workspace: "/tmp/openclaw-agent",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
} as never);
|
|
|
|
const models = requireRecord(next?.agents?.defaults?.models, "models");
|
|
expect(models["anthropic/opus-4.7"]).toEqual({
|
|
params: { maxTokens: 1200 },
|
|
agentRuntime: { id: "claude-cli" },
|
|
});
|
|
expect(models["anthropic/claude-opus-4-7"]).toEqual({
|
|
agentRuntime: { id: "claude-cli" },
|
|
});
|
|
expect(models["anthropic/sonnet-4.6"]).toEqual({ agentRuntime: { id: "claude-cli" } });
|
|
expect(models["anthropic/claude-sonnet-4-6"]).toEqual({
|
|
agentRuntime: { id: "claude-cli" },
|
|
});
|
|
});
|
|
|
|
it("does not backfill Claude CLI policy from an unselected rollback profile", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const next = provider.applyConfigDefaults?.({
|
|
provider: "anthropic",
|
|
env: {},
|
|
config: {
|
|
auth: {
|
|
order: {
|
|
anthropic: ["anthropic:oauth", "anthropic:claude-cli"],
|
|
},
|
|
profiles: {
|
|
"anthropic:oauth": { provider: "anthropic", mode: "oauth" },
|
|
"anthropic:claude-cli": { provider: "claude-cli", mode: "oauth" },
|
|
},
|
|
},
|
|
agents: {
|
|
defaults: {
|
|
model: { primary: "anthropic/opus-4.7" },
|
|
models: {
|
|
"anthropic/opus-4.7": { params: { maxTokens: 1200 } },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
} as never);
|
|
|
|
const models = requireRecord(next?.agents?.defaults?.models, "models");
|
|
expect(models["anthropic/opus-4.7"]).toEqual({ params: { maxTokens: 1200 } });
|
|
expect(models["anthropic/claude-opus-4-7"]).toBeUndefined();
|
|
});
|
|
|
|
it("backfills Claude CLI policy for unknown future Anthropic refs without guessing aliases", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const next = provider.applyConfigDefaults?.({
|
|
provider: "anthropic",
|
|
env: {},
|
|
config: {
|
|
auth: {
|
|
profiles: {
|
|
"anthropic:claude-cli": { provider: "claude-cli", mode: "oauth" },
|
|
},
|
|
},
|
|
agents: {
|
|
defaults: {
|
|
agentRuntime: { id: "claude-cli" },
|
|
model: { primary: "anthropic/opus-5.0" },
|
|
models: {
|
|
"anthropic/opus-5.0": { alias: "Future Opus" },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
} as never);
|
|
|
|
const models = requireRecord(next?.agents?.defaults?.models, "models");
|
|
expect(models["anthropic/opus-5.0"]).toEqual({
|
|
alias: "Future Opus",
|
|
agentRuntime: { id: "claude-cli" },
|
|
});
|
|
expect(models["anthropic/claude-opus-5-0"]).toBeUndefined();
|
|
});
|
|
|
|
it("resolves explicit claude-opus-4-8 refs from the 4.7 template family", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
const resolved = provider.resolveDynamicModel?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-opus-4-8",
|
|
modelRegistry: createModelRegistry([
|
|
{
|
|
id: "claude-opus-4-7",
|
|
name: "Claude Opus 4.7",
|
|
provider: "anthropic",
|
|
api: "anthropic-messages",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200_000,
|
|
maxTokens: 32_000,
|
|
} as ProviderRuntimeModel,
|
|
]),
|
|
} as ProviderResolveDynamicModelContext);
|
|
|
|
expectFields(resolved, {
|
|
provider: "anthropic",
|
|
id: "claude-opus-4-8",
|
|
api: "anthropic-messages",
|
|
reasoning: true,
|
|
contextWindow: 1_048_576,
|
|
contextTokens: 1_048_576,
|
|
maxTokens: 128_000,
|
|
});
|
|
const opus48Profile = provider.resolveThinkingProfile?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-opus-4-8",
|
|
} as never);
|
|
const opus48LevelIds = levelIds(opus48Profile);
|
|
expect(opus48LevelIds).toContain("xhigh");
|
|
expect(opus48LevelIds).toContain("adaptive");
|
|
expect(opus48LevelIds).toContain("max");
|
|
expect(requireRecord(opus48Profile, "opus 4.8 thinking profile").defaultLevel).toBe("off");
|
|
const opus47Profile = provider.resolveThinkingProfile?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-opus-4-7",
|
|
} as never);
|
|
const opus47LevelIds = levelIds(opus47Profile);
|
|
expect(opus47LevelIds).toContain("xhigh");
|
|
expect(opus47LevelIds).toContain("adaptive");
|
|
expect(opus47LevelIds).toContain("max");
|
|
expect(requireRecord(opus47Profile, "opus 4.7 thinking profile").defaultLevel).toBe("off");
|
|
const opus46Profile = provider.resolveThinkingProfile?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-opus-4-6",
|
|
} as never);
|
|
expect(levelIds(opus46Profile)).toContain("adaptive");
|
|
expect(requireRecord(opus46Profile, "opus 4.6 thinking profile").defaultLevel).toBe("adaptive");
|
|
expect(
|
|
provider
|
|
.resolveThinkingProfile?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-opus-4-6",
|
|
} as never)
|
|
?.levels.some((level) => level.id === "max"),
|
|
).toBe(true);
|
|
expect(
|
|
provider
|
|
.resolveThinkingProfile?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-opus-4-6",
|
|
} as never)
|
|
?.levels.some((level) => level.id === "xhigh"),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("resolves Claude Fable 5 with its always-adaptive model contract", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
const resolved = provider.resolveDynamicModel?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-fable-5",
|
|
modelRegistry: createModelRegistry([]),
|
|
} as ProviderResolveDynamicModelContext);
|
|
|
|
expectFields(resolved, {
|
|
provider: "anthropic",
|
|
id: "claude-fable-5",
|
|
api: "anthropic-messages",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 10, output: 50, cacheRead: 1, cacheWrite: 12.5 },
|
|
contextWindow: 1_000_000,
|
|
contextTokens: 1_000_000,
|
|
maxTokens: 128_000,
|
|
thinkingLevelMap: {
|
|
off: "low",
|
|
minimal: "low",
|
|
xhigh: "xhigh",
|
|
max: "max",
|
|
},
|
|
});
|
|
expect(requireRecord(resolved, "Fable model").mediaInput).toEqual({
|
|
image: { maxSidePx: 2576, preferredSidePx: 2576, tokenMode: "provider" },
|
|
});
|
|
|
|
const profile = provider.resolveThinkingProfile?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-fable-5",
|
|
} as never);
|
|
expect(levelIds(profile)).toStrictEqual([
|
|
"off",
|
|
"minimal",
|
|
"low",
|
|
"medium",
|
|
"high",
|
|
"xhigh",
|
|
"adaptive",
|
|
"max",
|
|
]);
|
|
expect(requireRecord(profile, "Fable thinking profile").defaultLevel).toBe("high");
|
|
|
|
const normalized = provider.normalizeResolvedModel?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-fable-5",
|
|
model: {
|
|
...(resolved as ProviderRuntimeModel),
|
|
reasoning: false,
|
|
},
|
|
} as never);
|
|
expect(normalized?.reasoning).toBe(true);
|
|
|
|
expect(
|
|
provider.resolveDynamicModel?.({
|
|
provider: "claude-cli",
|
|
modelId: "claude-fable-5",
|
|
modelRegistry: createModelRegistry([]),
|
|
} as ProviderResolveDynamicModelContext),
|
|
).toBeUndefined();
|
|
expect(
|
|
provider.resolveThinkingProfile?.({
|
|
provider: "claude-cli",
|
|
modelId: "claude-fable-5",
|
|
} as never),
|
|
).toEqual({
|
|
levels: [{ id: "off" }],
|
|
defaultLevel: "off",
|
|
});
|
|
expect(
|
|
provider
|
|
.resolveThinkingProfile?.({
|
|
provider: "claude-cli",
|
|
modelId: "claude-opus-4-6",
|
|
} as never)
|
|
?.levels.map((level) => level.id),
|
|
).toContain("max");
|
|
expect(
|
|
provider.isModernModelRef?.({
|
|
provider: "claude-cli",
|
|
modelId: "claude-fable-5",
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("resolves dated modern Claude refs without discovery templates", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const resolved = provider.resolveDynamicModel?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-opus-4.7-20260219",
|
|
modelRegistry: createModelRegistry([]),
|
|
} as ProviderResolveDynamicModelContext);
|
|
|
|
expectFields(resolved, {
|
|
provider: "anthropic",
|
|
id: "claude-opus-4.7-20260219",
|
|
api: "anthropic-messages",
|
|
input: ["text", "image"],
|
|
reasoning: true,
|
|
});
|
|
});
|
|
|
|
it("uses canonical model identity instead of a Fable-looking deployment alias", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
const model = {
|
|
id: "claude-fable-5-prod",
|
|
name: "Production Claude",
|
|
provider: "anthropic",
|
|
api: "anthropic-messages",
|
|
baseUrl: "https://api.anthropic.com",
|
|
reasoning: false,
|
|
input: ["text"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200_000,
|
|
maxTokens: 64_000,
|
|
params: { canonicalModelId: "claude-opus-4-8" },
|
|
} as ProviderRuntimeModel;
|
|
|
|
expectFields(
|
|
provider.normalizeResolvedModel?.({
|
|
provider: "anthropic",
|
|
modelId: model.id,
|
|
model,
|
|
} as never),
|
|
{
|
|
reasoning: false,
|
|
contextWindow: 1_048_576,
|
|
contextTokens: 1_048_576,
|
|
maxTokens: 128_000,
|
|
thinkingLevelMap: {
|
|
xhigh: "xhigh",
|
|
max: "max",
|
|
},
|
|
},
|
|
);
|
|
expect(
|
|
provider.resolveThinkingProfile?.({
|
|
provider: "anthropic",
|
|
modelId: model.id,
|
|
params: model.params,
|
|
} as never)?.defaultLevel,
|
|
).toBe("off");
|
|
});
|
|
|
|
it("does not forward-compat case-mismatched Anthropic model ids", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const resolved = provider.resolveDynamicModel?.({
|
|
provider: "anthropic",
|
|
modelId: "CLAUDE-OPUS-4-7",
|
|
modelRegistry: createModelRegistry([
|
|
{
|
|
id: "claude-opus-4-6",
|
|
name: "Claude Opus 4.6",
|
|
provider: "anthropic",
|
|
api: "anthropic-messages",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200_000,
|
|
maxTokens: 32_000,
|
|
} as ProviderRuntimeModel,
|
|
]),
|
|
} as ProviderResolveDynamicModelContext);
|
|
|
|
expect(resolved).toBeUndefined();
|
|
});
|
|
|
|
it("normalizes Claude Mythos Preview with native max but no xhigh thinking map", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const normalized = provider.normalizeResolvedModel?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-mythos-preview",
|
|
model: {
|
|
id: "claude-mythos-preview",
|
|
name: "Claude Mythos Preview",
|
|
provider: "anthropic",
|
|
api: "anthropic-messages",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200_000,
|
|
maxTokens: 64_000,
|
|
},
|
|
} as never);
|
|
|
|
expect(normalized?.thinkingLevelMap).toEqual({ max: "max" });
|
|
});
|
|
|
|
it("normalizes stale text-only modern Claude vision rows to image-capable", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const normalized = provider.normalizeResolvedModel?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-sonnet-4-6",
|
|
model: {
|
|
id: "claude-sonnet-4-6",
|
|
name: "Claude Sonnet 4.6",
|
|
provider: "anthropic",
|
|
api: "anthropic-messages",
|
|
reasoning: true,
|
|
input: ["text"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200_000,
|
|
maxTokens: 64_000,
|
|
thinkingLevelMap: { max: null },
|
|
},
|
|
} as never);
|
|
|
|
expect(normalized?.input).toEqual(["text", "image"]);
|
|
expect(normalized?.mediaInput).toEqual({
|
|
image: { maxSidePx: 1568, preferredSidePx: 1568, tokenMode: "provider" },
|
|
});
|
|
expect(normalized?.thinkingLevelMap).toEqual({ xhigh: null, max: null });
|
|
});
|
|
|
|
it("does not normalize numeric successors as known Claude contracts", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const normalized = provider.normalizeResolvedModel?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-opus-4-60",
|
|
model: {
|
|
id: "claude-opus-4-60",
|
|
name: "Claude Opus 4.60",
|
|
provider: "anthropic",
|
|
api: "anthropic-messages",
|
|
reasoning: true,
|
|
input: ["text"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200_000,
|
|
maxTokens: 64_000,
|
|
},
|
|
} as never);
|
|
|
|
expect(normalized).toBeUndefined();
|
|
});
|
|
|
|
it("merges partial Claude image media metadata with provider limits", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const normalized = provider.normalizeResolvedModel?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-opus-4-7",
|
|
model: {
|
|
id: "claude-opus-4-7",
|
|
name: "Claude Opus 4.7",
|
|
provider: "anthropic",
|
|
api: "anthropic-messages",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200_000,
|
|
maxTokens: 64_000,
|
|
mediaInput: { image: { maxBytes: 1 } },
|
|
},
|
|
} as never);
|
|
|
|
expect(normalized?.mediaInput).toEqual({
|
|
image: { maxBytes: 1, maxSidePx: 2576, preferredSidePx: 2576, tokenMode: "provider" },
|
|
});
|
|
});
|
|
|
|
it("normalizes GA 1M Claude variants to 1M context", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
for (const [runtimeProvider, modelId] of [
|
|
["anthropic", "claude-opus-4-8"],
|
|
["anthropic", "claude-opus-4-7"],
|
|
["claude-cli", "claude-opus-4.7-20260219"],
|
|
["anthropic", "claude-opus-4-6"],
|
|
["anthropic", "claude-sonnet-4-6"],
|
|
] as const) {
|
|
expectFields(
|
|
provider.normalizeResolvedModel?.({
|
|
provider: runtimeProvider,
|
|
modelId,
|
|
model: {
|
|
id: modelId,
|
|
name: "Claude Opus 4.7",
|
|
provider: runtimeProvider,
|
|
api: "anthropic-messages",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200_000,
|
|
contextTokens: 200_000,
|
|
maxTokens: 32_000,
|
|
},
|
|
} as never),
|
|
{
|
|
contextWindow: 1_048_576,
|
|
contextTokens: 1_048_576,
|
|
},
|
|
);
|
|
}
|
|
});
|
|
|
|
it("normalizes Claude Opus 4.8 to 128k max output tokens", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const normalized = provider.normalizeResolvedModel?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-opus-4-8",
|
|
model: {
|
|
id: "claude-opus-4-8",
|
|
name: "Claude Opus 4.8",
|
|
provider: "anthropic",
|
|
api: "anthropic-messages",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200_000,
|
|
maxTokens: 64_000,
|
|
},
|
|
} as never);
|
|
|
|
expectFields(normalized, {
|
|
contextWindow: 1_048_576,
|
|
contextTokens: 1_048_576,
|
|
maxTokens: 128_000,
|
|
});
|
|
});
|
|
|
|
it("does not normalize legacy Claude 4.5 models to 1M context", async () => {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
const normalized = provider.normalizeResolvedModel?.({
|
|
provider: "anthropic",
|
|
modelId: "claude-sonnet-4-5",
|
|
model: {
|
|
id: "claude-sonnet-4-5",
|
|
name: "Claude Sonnet 4.5",
|
|
provider: "anthropic",
|
|
api: "anthropic-messages",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 200_000,
|
|
contextTokens: 200_000,
|
|
maxTokens: 32_000,
|
|
},
|
|
} as never);
|
|
|
|
expect(normalized).toBeUndefined();
|
|
});
|
|
|
|
it("stores setup-token expiry from a bounded duration", async () => {
|
|
vi.useFakeTimers();
|
|
vi.setSystemTime(1_000);
|
|
try {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
const setupTokenAuth = provider.auth.find((entry) => entry.id === "setup-token");
|
|
if (!setupTokenAuth) {
|
|
throw new Error("expected Anthropic setup-token auth method");
|
|
}
|
|
|
|
const result = await setupTokenAuth.run({
|
|
opts: {
|
|
token: ANTHROPIC_SETUP_TOKEN,
|
|
tokenExpiresIn: "1h",
|
|
},
|
|
} as never);
|
|
|
|
expect(result?.profiles[0]?.credential).toMatchObject({
|
|
type: "token",
|
|
provider: "anthropic",
|
|
token: ANTHROPIC_SETUP_TOKEN,
|
|
expires: 3_601_000,
|
|
});
|
|
} finally {
|
|
vi.useRealTimers();
|
|
}
|
|
});
|
|
|
|
it("omits setup-token expiry when duration overflows the Date range", async () => {
|
|
vi.useFakeTimers();
|
|
vi.setSystemTime(8_640_000_000_000_000);
|
|
try {
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
const setupTokenAuth = provider.auth.find((entry) => entry.id === "setup-token");
|
|
if (!setupTokenAuth) {
|
|
throw new Error("expected Anthropic setup-token auth method");
|
|
}
|
|
|
|
const result = await setupTokenAuth.run({
|
|
opts: {
|
|
token: ANTHROPIC_SETUP_TOKEN,
|
|
tokenExpiresIn: "1h",
|
|
},
|
|
} as never);
|
|
|
|
expect(result?.profiles[0]?.credential).toEqual({
|
|
type: "token",
|
|
provider: "anthropic",
|
|
token: ANTHROPIC_SETUP_TOKEN,
|
|
});
|
|
} finally {
|
|
vi.useRealTimers();
|
|
}
|
|
});
|
|
|
|
it("resolves claude-cli synthetic oauth auth", async () => {
|
|
readClaudeCliCredentialsForRuntimeMock.mockReset();
|
|
readClaudeCliCredentialsForRuntimeMock.mockReturnValue({
|
|
type: "oauth",
|
|
provider: "anthropic",
|
|
access: "access-token",
|
|
refresh: "refresh-token",
|
|
expires: 123,
|
|
});
|
|
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
expect(
|
|
provider.resolveSyntheticAuth?.({
|
|
provider: "claude-cli",
|
|
} as never),
|
|
).toEqual({
|
|
apiKey: "access-token",
|
|
source: "Claude CLI native auth",
|
|
mode: "oauth",
|
|
expiresAt: 123,
|
|
});
|
|
expect(readClaudeCliCredentialsForRuntimeMock).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("resolves claude-cli synthetic token auth", async () => {
|
|
readClaudeCliCredentialsForRuntimeMock.mockReset();
|
|
readClaudeCliCredentialsForRuntimeMock.mockReturnValue({
|
|
type: "token",
|
|
provider: "anthropic",
|
|
token: "bearer-token",
|
|
expires: 123,
|
|
});
|
|
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
|
|
expect(
|
|
provider.resolveSyntheticAuth?.({
|
|
provider: "claude-cli",
|
|
} as never),
|
|
).toEqual({
|
|
apiKey: "bearer-token",
|
|
source: "Claude CLI native auth",
|
|
mode: "token",
|
|
expiresAt: 123,
|
|
});
|
|
});
|
|
|
|
it("stores a claude-cli auth profile during anthropic cli migration", async () => {
|
|
readClaudeCliCredentialsForSetupMock.mockReset();
|
|
readClaudeCliCredentialsForSetupMock.mockReturnValue({
|
|
type: "oauth",
|
|
provider: "anthropic",
|
|
access: "setup-access-token",
|
|
refresh: "refresh-token",
|
|
expires: 123,
|
|
});
|
|
|
|
const provider = await registerSingleProviderPlugin(anthropicPlugin);
|
|
const cliAuth = provider.auth.find((entry) => entry.id === "cli");
|
|
|
|
if (!cliAuth) {
|
|
throw new Error("expected Anthropic CLI auth method");
|
|
}
|
|
|
|
const result = await cliAuth.run({
|
|
config: {},
|
|
} as never);
|
|
|
|
expect(result?.profiles).toEqual([
|
|
{
|
|
profileId: "anthropic:claude-cli",
|
|
credential: {
|
|
type: "oauth",
|
|
provider: "claude-cli",
|
|
access: "setup-access-token",
|
|
refresh: "refresh-token",
|
|
expires: 123,
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
});
|