Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(agent-runtime): send a Claude Code identity subscription models accept

zszz3564854d33420
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index f7347948c..5ca31df02 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -113,6 +113,26 @@ being fetched on every subsequent poll.
- **Specs:** `03-runtime/08-error-codes.md` §3.2.
+## E2E-PROVIDER-anthropic-oauth-claude-code-identity
+
+- **Preconditions:** Built desktop, isolated Host data directory and Electron
+ profile, and a seeded Claude (Anthropic OAuth) account row with a synthetic,
+ unexpired credential. Every `api.anthropic.com` / `platform.claude.com`
+ request from Electron main and the agent sidecar is redirected to a local
+ fixture; no real Anthropic request is made.
+- **Steps:** Launch the app, type a prompt in the Composer, and press Enter.
+ The fixture rejects Claude Code identities older than 2.1.290 with HTTP 400
+ `claude_code_version_too_old`, as Claude Pro/Max models do (issue #2239),
+ and otherwise streams a reply.
+- **Expected:** The model request carries the OAuth bearer token, `x-app: cli`
+ and a `claude-cli/<version>` User-Agent of at least 2.1.290. The chat shows
+ the streamed reply and no version rejection.
+- **Automated coverage:** `pnpm test:e2e:anthropic-oauth-identity`
+ (`scripts/e2e-anthropic-oauth-identity.mjs`) and
+ `packages/agent-runtime/src/anthropic-oauth-identity.test.ts`.
+- **Specs:** `03-runtime/12-provider-config-schema.md`.
+
+
## E2E-TASK-DOCK-tab-content-isolation
- **Preconditions:** Isolated Electron renderer with synthetic todos and a running
diff --git a/package.json b/package.json
index ed2916eb2..67e1ac113 100644
--- a/package.json
+++ b/package.json
@@ -58,6 +58,7 @@
"test:e2e:project-edit": "node scripts/e2e-project-edit.mjs",
"test:e2e:provider-api-style": "node scripts/e2e-provider-api-style.mjs",
"test:e2e:hosted-search": "node scripts/e2e-hosted-search.mjs",
+ "test:e2e:anthropic-oauth-identity": "node scripts/e2e-anthropic-oauth-identity.mjs",
"test:e2e:oauth-retry": "node --test apps/desktop/test/anthropic-oauth-retry.test.mjs",
"test:e2e:boot": "node scripts/e2e-electron-boot.mjs",
"test:e2e:startup-animation": "node scripts/e2e-startup-animation.mjs",
diff --git a/packages/agent-runtime/src/anthropic-oauth-identity.test.ts b/packages/agent-runtime/src/anthropic-oauth-identity.test.ts
new file mode 100644
index 000000000..8f95a235f
--- /dev/null
+++ b/packages/agent-runtime/src/anthropic-oauth-identity.test.ts
@@ -0,0 +1,59 @@
+import { createServer, type IncomingHttpHeaders } from "node:http";
+import type { AddressInfo } from "node:net";
+import type { Model } from "@earendil-works/pi-ai";
+import { streamSimple } from "@earendil-works/pi-ai/api/anthropic-messages";
+import { describe, expect, it } from "vitest";
+
+const context = { messages: [{ role: "user", content: "hi", timestamp: 1 }] } as never;
+
+function modelAt(baseUrl: string) {
+ return {
+ id: "claude-fable-5-2",
+ name: "Claude Fable 5.2",
+ api: "anthropic-messages",
+ provider: "anthropic",
+ baseUrl,
+ reasoning: false,
+ input: ["text"],
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
+ contextWindow: 200_000,
+ maxTokens: 8_192,
+ } as Model<"anthropic-messages">;
+}
+
+/** Parses `claude-cli/<major>.<minor>.<patch>` into one comparable number. */
+function claudeCliVersion(userAgent: string | undefined): number {
+ const match = /^claude-cli\/(\d+)\.(\d+)\.(\d+)$/u.exec(userAgent ?? "");
+ expect(match, `unexpected user-agent ${userAgent}`).not.toBeNull();
+ const [major, minor, patch] = match!.slice(1).map(Number);
+ return major * 1_000_000 + minor * 1_000 + patch;
+}
+
+describe("Anthropic OAuth request identity", () => {
+ // Claude Pro/Max models such as claude-fable-5-2 reject older Claude Code
+ // identities with HTTP 400 `claude_code_version_too_old` (needs >= 2.1.290).
+ it("identifies as a Claude Code release that subscription-only models accept", async () => {
+ const requests: IncomingHttpHeaders[] = [];
+ const server = createServer((req, res) => {
+ requests.push(req.headers);
+ req.resume();
+ res.writeHead(400, { "content-type": "application/json" });
+ res.end(JSON.stringify({ type: "error", error: { type: "invalid_request_error", message: "fixture" } }));
+ });
+ await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
+ try {
+ const { port } = server.address() as AddressInfo;
+ const result = await streamSimple(modelAt(`http://127.0.0.1:${port}`), context, {
+ apiKey: "sk-ant-oat01-fixture",
+ maxRetries: 0,
+ }).result();
+ expect(result.stopReason).toBe("error");
+ } finally {
+ await new Promise<void>((resolve) => server.close(() => resolve()));
+ }
+
+ expect(requests).toHaveLength(1);
+ expect(requests[0]["x-app"]).toBe("cli");
+ expect(claudeCliVersion(requests[0]["user-agent"])).toBeGreaterThanOrEqual(2_001_290);
+ });
+});
diff --git a/patches/@[email protected] b/patches/@[email protected]
index 05e7c6013..e47b33457 100644
--- a/patches/@[email protected]
+++ b/patches/@[email protected]
@@ -9,6 +9,11 @@ index de2b2d8c209f5576c18b020de297d4ef5fad5960..037ecdaea6efcb76f827ba2dd69bc3a0
import Anthropic, {} from "@anthropic-ai/sdk";
import { ANTHROPIC_FEDERATION_RULE_ID_ENV, ANTHROPIC_IDENTITY_TOKEN_FILE_ENV, ANTHROPIC_ORGANIZATION_ID_ENV, ANTHROPIC_SERVICE_ACCOUNT_ID_ENV, ANTHROPIC_WORKSPACE_ID_ENV, } from "../env-api-keys.js";
import { calculateCost } from "../models.js";
+@@ -44,3 +47,3 @@ function mergeHeaders(...headerSources) {
+ // Stealth mode: Mimic Claude Code's tool naming exactly
+-const claudeCodeVersion = "2.1.280";
++const claudeCodeVersion = "2.1.322";
+ // Claude Code 2.x tool names (canonical casing)
@@ -377,8 +380,6 @@ async function* iterateAnthropicEvents(response, signal) {
}
export const stream = (model, context, options) => {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4c0fc7b36..d48e62539 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -206,7 +206,7 @@ overrides:
patchedDependencies:
'@earendil-works/[email protected]': f7df81a6d069cd0287276085d46d531684234acb7243dc032b1a1d73b17019da
- '@earendil-works/[email protected]': 07ea52be73bf9e7a5484acf9016967785b68fadc0c3b2fc68666a6b84e6609d4
+ '@earendil-works/[email protected]': 531d8160f4e83fe7d3ad9089fd256b6fd657d9fa09c3978e70d727ba7982b666
'@earendil-works/[email protected]': 1d20a271da819982a9d458d6064c51e5e06fc28637c2efa94d5683e5b3867d90
importers:
@@ -234,7 +234,7 @@ importers:
devDependencies:
'@earendil-works/pi-ai':
specifier: 1.5.0
- version: 1.5.0(patch_hash=07ea52be73bf9e7a5484acf9016967785b68fadc0c3b2fc68666a6b84e6609d4)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
+ version: 1.5.0(patch_hash=531d8160f4e83fe7d3ad9089fd256b6fd657d9fa09c3978e70d727ba7982b666)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
'@earendil-works/pi-mcp':
specifier: 1.5.0
version: 1.5.0
@@ -435,7 +435,7 @@ importers:
version: 1.5.0(patch_hash=f7df81a6d069cd0287276085d46d531684234acb7243dc032b1a1d73b17019da)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
'@earendil-works/pi-ai':
specifier: 1.5.0
- version: 1.5.0(patch_hash=07ea52be73bf9e7a5484acf9016967785b68fadc0c3b2fc68666a6b84e6609d4)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
+ version: 1.5.0(patch_hash=531d8160f4e83fe7d3ad9089fd256b6fd657d9fa09c3978e70d727ba7982b666)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
'@earendil-works/pi-coding-agent':
specifier: 1.5.0
version: 1.5.0(patch_hash=1d20a271da819982a9d458d6064c51e5e06fc28637c2efa94d5683e5b3867d90)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])
@@ -5105,7 +5105,7 @@ snapshots:
'@earendil-works/[email protected](patch_hash=f7df81a6d069cd0287276085d46d531684234acb7243dc032b1a1d73b17019da)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])':
dependencies:
- '@earendil-works/pi-ai': 1.5.0(patch_hash=07ea52be73bf9e7a5484acf9016967785b68fadc0c3b2fc68666a6b84e6609d4)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
+ '@earendil-works/pi-ai': 1.5.0(patch_hash=531d8160f4e83fe7d3ad9089fd256b6fd657d9fa09c3978e70d727ba7982b666)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
'@earendil-works/pi-schema': 1.5.0
transitivePeerDependencies:
- '@aws-sdk/credential-provider-node'
@@ -5120,7 +5120,7 @@ snapshots:
- ws
- zod
- '@earendil-works/[email protected](patch_hash=07ea52be73bf9e7a5484acf9016967785b68fadc0c3b2fc68666a6b84e6609d4)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])':
+ '@earendil-works/[email protected](patch_hash=531d8160f4e83fe7d3ad9089fd256b6fd657d9fa09c3978e70d727ba7982b666)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])':
dependencies:
'@anthropic-ai/sdk': 0.129.0([email protected])
'@aws-sdk/client-bedrock-runtime': 3.1127.0
@@ -5145,7 +5145,7 @@ snapshots:
- ws
- zod
- '@earendil-works/[email protected](patch_hash=07ea52be73bf9e7a5484acf9016967785b68fadc0c3b2fc68666a6b84e6609d4)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])':
+ '@earendil-works/[email protected](patch_hash=531d8160f4e83fe7d3ad9089fd256b6fd657d9fa09c3978e70d727ba7982b666)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])':
dependencies:
'@anthropic-ai/sdk': 0.129.0([email protected])
'@aws-sdk/client-bedrock-runtime': 3.1127.0
@@ -5177,7 +5177,7 @@ snapshots:
'@earendil-works/[email protected](patch_hash=1d20a271da819982a9d458d6064c51e5e06fc28637c2efa94d5683e5b3867d90)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])':
dependencies:
'@earendil-works/pi-agent-core': 1.5.0(patch_hash=f7df81a6d069cd0287276085d46d531684234acb7243dc032b1a1d73b17019da)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
- '@earendil-works/pi-ai': 1.5.0(patch_hash=07ea52be73bf9e7a5484acf9016967785b68fadc0c3b2fc68666a6b84e6609d4)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
+ '@earendil-works/pi-ai': 1.5.0(patch_hash=531d8160f4e83fe7d3ad9089fd256b6fd657d9fa09c3978e70d727ba7982b666)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
'@earendil-works/pi-codemode': 1.5.0
'@earendil-works/pi-mcp': 1.5.0
'@earendil-works/pi-tui': 1.5.0
diff --git a/scripts/e2e-anthropic-oauth-identity.mjs b/scripts/e2e-anthropic-oauth-identity.mjs
new file mode 100644
index 000000000..8a5793a56
--- /dev/null
+++ b/scripts/e2e-anthropic-oauth-identity.mjs
@@ -0,0 +1,243 @@
+#!/usr/bin/env node
+// Real desktop, preload, Host SQLite and agent sidecar with a signed-in
+// Anthropic (Claude Pro/Max) account. Only api.anthropic.com is local: the
+// fixture answers like Anthropic does for subscription-only models and
+// rejects Claude Code identities older than 2.1.290 with
+// `claude_code_version_too_old` (issue #2239).
+import assert from "node:assert/strict";
+import { spawn } from "node:child_process";
+import { once } from "node:events";
+import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
+import { createServer } from "node:http";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { resolveElectronBinary } from "./e2e/boot.mjs";
+import { Host, resolveHostBinary } from "./e2e/host.mjs";
+import { waitFor } from "./e2e/wait.mjs";
+
+const MINIMUM_CLAUDE_CODE = [2, 1, 290];
+const MODEL_ID = "claude-sonnet-4-5";
+const REPLY = "Fixture reply from Claude.";
+
+const root = realpathSync(mkdtempSync(join(tmpdir(), "pi-anthropic-oauth-identity-e2e-")));
+const dataDir = join(root, "data");
+const project = join(root, "project");
+mkdirSync(project);
+
+const requests = [];
+const versionOf = (userAgent) => /^claude-cli\/(\d+)\.(\d+)\.(\d+)$/u.exec(userAgent ?? "")?.slice(1).map(Number);
+const atLeast = (version, minimum) => {
+ for (let index = 0; index < minimum.length; index++) {
+ if (version[index] !== minimum[index]) return version[index] > minimum[index];
+ }
+ return true;
+};
+const sse = (res, events) => {
+ res.writeHead(200, { "content-type": "text/event-stream" });
+ for (const event of events) res.write(`event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`);
+ res.end();
+};
+const server = createServer(async (req, res) => {
+ let body = "";
+ for await (const chunk of req) body += chunk;
+ const url = new URL(req.url ?? "/", "http://fixture");
+ requests.push({ method: req.method, path: url.pathname, headers: req.headers });
+ if (req.method !== "POST" || url.pathname !== "/v1/messages") {
+ res.writeHead(404, { "content-type": "application/json" });
+ res.end(JSON.stringify({ type: "error", error: { type: "not_found_error", message: "fixture" } }));
+ return;
+ }
+ const version = versionOf(req.headers["user-agent"]);
+ if (!version || !atLeast(version, MINIMUM_CLAUDE_CODE)) {
+ res.writeHead(400, { "content-type": "application/json" });
+ res.end(JSON.stringify({ type: "error", error: { type: "invalid_request_error",
+ message: "claude_code_version_too_old: Claude Code 2.1.290 or later is required" } }));
+ return;
+ }
+ const { stream } = JSON.parse(body);
+ assert.equal(stream, true, "the desktop streams model replies");
+ sse(res, [
+ { type: "message_start", message: { id: "msg_fixture", type: "message", role: "assistant", model: MODEL_ID,
+ content: [], stop_reason: null, stop_sequence: null, usage: { input_tokens: 10, output_tokens: 0 } } },
+ { type: "content_block_start", index: 0, content_block: { type: "text", text: "" } },
+ { type: "content_block_delta", index: 0, delta: { type: "text_delta", text: REPLY } },
+ { type: "content_block_stop", index: 0 },
+ { type: "message_delta", delta: { stop_reason: "end_turn", stop_sequence: null }, usage: { output_tokens: 5 } },
+ { type: "message_stop" },
+ ]);
+});
+await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
+const fixtureOrigin = `http://127.0.0.1:${server.address().port}`;
+
+// Send every Anthropic request to the fixture, in Electron main (whose
+// global fetch becomes net.fetch) and in the sidecar (whose global fetch may
+// be replaced by the proxy-aware undici fetch). The accessor keeps
+// redirecting whichever fetch the process installs later, so no request can
+// reach the real service.
+const fetchHook = join(root, "anthropic-fixture-fetch.mjs");
+writeFileSync(fetchHook, `const FIXTURE = ${JSON.stringify(fixtureOrigin)};
+const ANTHROPIC_HOSTS = new Set(["api.anthropic.com", "platform.claude.com", "claude.ai", "console.anthropic.com"]);
+let inner = globalThis.fetch;
+const redirecting = (input, init) => {
+ const url = new URL(input instanceof Request ? input.url : String(input));
+ if (!ANTHROPIC_HOSTS.has(url.hostname)) return inner(input, init);
+ const target = FIXTURE + url.pathname + url.search;
+ return input instanceof Request ? inner(new Request(target, input), init) : inner(target, init);
+};
+Object.defineProperty(globalThis, "fetch", {
+ configurable: true,
+ enumerable: true,
+ get: () => redirecting,
+ set: (value) => { if (value !== redirecting) inner = value; },
+});
+`);
+
+const host = new Host(resolveHostBinary(), dataDir);
+await host.start();
+await host.call("workspace.set", { path: project });
+const { provider } = await host.call("providers.create", {
+ name: "Claude",
+ vendorKey: "anthropic",
+ type: "native",
+ authKind: "oauth",
+ baseUrl: "https://api.anthropic.com",
+});
+// The row as a completed Claude sign-in leaves it (VendorOAuth.completeRow).
+await host.call("providers.update", {
+ id: provider.id,
+ oauthAccountLabel: "[email protected]",
+ apiStyle: "anthropic_messages",
+ protocol: "anthropic",
+ defaultModelId: MODEL_ID,
+ models: [{ id: MODEL_ID, contextWindow: 200_000, maxTokens: 8_192, thinkingLevels: ["off"], defaultThinkingLevel: "off" }],
+});
+await host.call("secrets.set", {
+ secretRef: `secret:provider:${provider.id}:oauth`,
+ value: JSON.stringify({ type: "oauth", access: "sk-ant-oat01-e2e-fixture", refresh: "e2e-fixture-refresh",
+ expires: Date.now() + 24 * 60 * 60 * 1000 }),
+});
+await host.call("settings.set", {
+ language: "en",
+ defaultProviderId: provider.id,
+ defaultModelId: MODEL_ID,
+ defaultMode: "agent",
+ defaultPermissionMode: "auto",
+});
+await host.stop();
+
+const { appDir, electronBinary } = resolveElectronBinary();
+const port = Number(process.env.PI_ANTHROPIC_OAUTH_CDP_PORT || 9391);
+const env = {
+ ...process.env,
+ PI_DESKTOP_DATA_DIR: dataDir,
+ PI_DESKTOP_START_MAXIMIZED: "0",
+ ELECTRON_RENDERER_URL: "",
+ NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ""} --import=${fetchHook}`.trim(),
+};
+delete env.ELECTRON_RUN_AS_NODE;
+const child = spawn(electronBinary, [
+ `--remote-debugging-port=${port}`,
+ `--user-data-dir=${join(root, "profile")}`,
+ "--host-resolver-rules=MAP api.anthropic.com ~NOTFOUND, MAP platform.claude.com ~NOTFOUND, MAP claude.ai ~NOTFOUND",
+ ".",
+], { cwd: appDir, env, stdio: ["ignore", "pipe", "pipe"], detached: process.platform !== "win32" });
+const childClose = new Promise((resolve) => child.once("close", resolve));
+let output = "";
+child.stdout.on("data", (data) => { output += data; });
+child.stderr.on("data", (data) => { output += data; });
+
+let ws;
+try {
+ let target;
+ await waitFor(async () => {
+ try {
+ target = (await (await fetch(`http://127.0.0.1:${port}/json/list`)).json()).find((entry) =>
+ entry.type === "page" && entry.url.includes("index.html") && !entry.url.includes("plugin-launcher"));
+ return !!target;
+ } catch { return false; }
+ }, 30_000, "desktop CDP target");
+ ws = new WebSocket(target.webSocketDebuggerUrl);
+ await once(ws, "open");
+ let sequence = 0;
+ const pending = new Map();
+ ws.onmessage = ({ data }) => {
+ const message = JSON.parse(data);
+ const entry = pending.get(message.id);
+ if (!entry) return;
+ pending.delete(message.id);
+ if (message.error) entry.reject(new Error(JSON.stringify(message.error)));
+ else entry.resolve(message.result);
+ };
+ const send = (method, params = {}) => new Promise((resolve, reject) => {
+ const id = ++sequence;
+ pending.set(id, { resolve, reject });
+ ws.send(JSON.stringify({ id, method, params }));
+ });
+ const evaluate = async (expression) => {
+ const result = await send("Runtime.evaluate", { expression, awaitPromise: true, returnByValue: true });
+ if (result.exceptionDetails) {
+ throw new Error(result.exceptionDetails.exception?.description ?? JSON.stringify(result.exceptionDetails));
+ }
+ return result.result.value;
+ };
+ const key = async (name, code) => {
+ await send("Input.dispatchKeyEvent", { type: "keyDown", key: name, code: name, windowsVirtualKeyCode: code,
+ ...(name === "Enter" ? { text: "\r" } : {}) });
+ await send("Input.dispatchKeyEvent", { type: "keyUp", key: name, code: name, windowsVirtualKeyCode: code });
+ };
+
+ await waitFor(() => evaluate(`!!document.querySelector('[data-nav="settings"]') && !document.querySelector('.startup-splash')`),
+ 30_000, "desktop ready");
+ await waitFor(() => evaluate(`!!document.querySelector('.composer-input[contenteditable="true"]')`), 15_000, "composer ready");
+ await evaluate(`document.querySelector('.composer-input').focus()`);
+ await send("Input.insertText", { text: "Say hello." });
+ await key("Enter", 13);
+
+ try {
+ await waitFor(() => evaluate(`document.body.innerText.includes(${JSON.stringify(REPLY)})
+ || /claude_code_version_too_old/.test(document.body.innerText)`), 60_000, "assistant reply or provider error");
+ } catch (error) {
+ console.error("WINDOW_TEXT", (await evaluate("document.body.innerText")).slice(-3000));
+ throw error;
+ }
+ const transcript = await evaluate(`document.body.innerText`);
+ const inference = requests.filter((request) => request.path === "/v1/messages");
+ assert.ok(inference.length >= 1, "the sidecar reached the Anthropic fixture");
+ for (const request of inference) {
+ assert.equal(request.headers.authorization, "Bearer sk-ant-oat01-e2e-fixture", "OAuth credential is sent as a bearer token");
+ assert.equal(request.headers["x-app"], "cli");
+ const version = versionOf(request.headers["user-agent"]);
+ assert.ok(version, `Claude Code identity missing: ${request.headers["user-agent"]}`);
+ assert.ok(atLeast(version, MINIMUM_CLAUDE_CODE),
+ `Claude Code identity ${request.headers["user-agent"]} is older than ${MINIMUM_CLAUDE_CODE.join(".")}`);
+ }
+ assert.doesNotMatch(transcript, /claude_code_version_too_old/u, "the chat must not show the version rejection");
+ assert.ok(transcript.includes(REPLY), "the assistant reply is shown in the chat");
+ console.log("FIXTURE_REQUESTS", JSON.stringify(requests.map((request) => `${request.method} ${request.path} ${request.headers["user-agent"]}`)));
+ console.log(`PASS: a signed-in Claude account chat sends ${inference[0].headers["user-agent"]} and shows the reply`);
+} catch (error) {
+ console.error("FIXTURE_REQUESTS", JSON.stringify(requests.map((request) => ({ method: request.method, path: request.path,
+ userAgent: request.headers["user-agent"] }))));
+ console.error(output.slice(-4000));
+ throw error;
+} finally {
+ ws?.close();
+ try {
+ if (process.platform === "win32") child.kill("SIGTERM");
+ else process.kill(-child.pid, "SIGTERM");
+ } catch (error) {
+ if (error.code !== "ESRCH") throw error;
+ }
+ const exited = await Promise.race([childClose.then(() => true), new Promise((resolve) => setTimeout(resolve, 5000, false))]);
+ if (!exited) {
+ try {
+ if (process.platform === "win32") child.kill("SIGKILL");
+ else process.kill(-child.pid, "SIGKILL");
+ } catch (error) {
+ if (error.code !== "ESRCH") throw error;
+ }
+ }
+ server.closeAllConnections();
+ await new Promise((resolve) => server.close(resolve));
+ rmSync(root, { recursive: true, force: true });
+}