diff --git a/src/claude-mcp-entry.ts b/src/claude-mcp-entry.ts index 2219903145..83a9ce86a1 100644 --- a/src/claude-mcp-entry.ts +++ b/src/claude-mcp-entry.ts @@ -10,15 +10,17 @@ // Logs go through the shared bili.log tee because claude does not surface this // child's stderr. +import fs from "node:fs"; +import os from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; -import { resolveProxyOrigin, runMcpStdio } from "./mcp.js"; +import { resolveProxyOrigin, runMcpStdio, setClaudeSessionResolver } from "./mcp.js"; import { configureLogger, log as teeLog } from "./logger.js"; import { configureLogRetention } from "./log-retention.js"; import { logRetentionPolicy } from "./knobs.js"; import { defaultLogFile } from "./paths.js"; import { LAUNCHER_DEFAULT_HOST, ensureProxyRunning, healthUrl } from "./launcher.js"; -import { chooseWatchdogParentPid, planClaudeNativeBootstrap } from "./claude-native-bootstrap.js"; +import { chooseWatchdogParentPid, planClaudeNativeBootstrap, resolveClaudeHostPid } from "./claude-native-bootstrap.js"; import { repinClaudeManagedBaseUrl, readClaudeManagedBaseUrl } from "./plugin-install.js"; const WATCHDOG_INTERVAL_MS = 30000; @@ -31,6 +33,76 @@ function proxyScriptPath(): string { return path.join(path.dirname(fileURLToPath(import.meta.url)), "index.js"); } +// #6361: the host's CURRENT session id. claude /clear (or /new) starts a new +// session id but keeps this stdio child running, so the spawn-time +// CLAUDE_CODE_SESSION_ID env (mcp.ts's CONVERSATION_FROM_ENV) goes stale. The +// live id is rewritten by claude into /sessions/ +// .json on every /clear; the host pid is stable for this child's +// lifetime. mcp.ts's tools/call path re-reads this on each call and re-binds on +// change. Defensive about the file shape (sessionId/session_id/id; any read, +// parse, or shape failure → undefined, which means "no re-bind", never a crash). +const SESSION_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{3,255}$/; + +function claudeConfigDir(): string { + const fromEnv = process.env.CLAUDE_CONFIG_DIR?.trim(); + if (fromEnv && fromEnv.length > 0) return fromEnv; + return path.join(os.homedir(), ".claude"); +} + +/** Read + validate the session id from one claude sessions file. Exported for + * tests (pure: a config dir + pid in, an id or undefined out). */ +export function readClaudeSessionFile(configDir: string, pid: number): string | undefined { + let raw: string; + try { + raw = fs.readFileSync(path.join(configDir, "sessions", `${pid}.json`), "utf8"); + } catch { + return undefined; + } + let data: unknown; + try { + data = JSON.parse(raw); + } catch { + return undefined; + } + if (typeof data !== "object" || data === null) return undefined; + const obj = data as Record; + const sid = obj.sessionId ?? obj.session_id ?? obj.id; + if (typeof sid !== "string") return undefined; + const trimmed = sid.trim(); + return SESSION_ID_RE.test(trimmed) ? trimmed : undefined; +} + +let cachedHostPid: number | undefined; +let hostPidResolved = false; + +function hostPid(): number | undefined { + if (!hostPidResolved) { + hostPidResolved = true; + cachedHostPid = resolveClaudeHostPid(); + } + return cachedHostPid; +} + +/** The full resolver injected into mcp.ts: resolve the claude host pid (cached + * — it is stable for this child's lifetime) and read its current session id. */ +export function readClaudeSessionId(): string | undefined { + const pid = hostPid(); + if (pid === undefined) return undefined; + return readClaudeSessionFile(claudeConfigDir(), pid); +} + +// Test seams: the host pid is resolved once and cached; reset or pin it between +// cases (pinning bypasses the real process-tree walk). +export function _resetClaudeHostPidForTest(): void { + hostPidResolved = false; + cachedHostPid = undefined; +} + +export function _setClaudeHostPidForTest(pid: number | undefined): void { + hostPidResolved = true; + cachedHostPid = pid; +} + async function probeProxyHealth(origin: string): Promise { try { const res = await fetch(healthUrl(origin), { signal: AbortSignal.timeout(2000) }); @@ -130,6 +202,10 @@ export async function main(opts: WatchdogDeps & { runStdio?: () => void } = {}): configureLogRetention(logRetentionPolicy()); configureLogger(defaultLogFile()); const log = (msg: string) => teeLog("info", `[bili-claude-mcp] ${msg}`); + // #6361: arm the /clear session re-bind in every posture (attach/passthrough + // included — the tool calls still need to follow the host's current session). + // mcp.ts ignores it unless the shim is identity-bound (CLAUDE_CODE_SESSION_ID). + setClaudeSessionResolver(readClaudeSessionId); const plan = planClaudeNativeBootstrap(process.env); if (plan.action !== "start") { // attach (BILLION_CONTEXT_PROXY / BILI_PROVIDER_REWRITES) or passthrough diff --git a/src/mcp.ts b/src/mcp.ts index 88f1e6c015..72b1f37c63 100644 --- a/src/mcp.ts +++ b/src/mcp.ts @@ -278,6 +278,60 @@ export function _resetMcpBindingForTest(nextConversationId?: string): void { conversationId = nextConversationId; } +// #6361: claude /clear (or /new) starts a NEW session id but keeps this stdio +// child running — the spawn-time CLAUDE_CODE_SESSION_ID env (CONVERSATION_FROM_ENV) +// goes stale and NEITHER recovery path fires: the #656 404 adoption needs the +// bound id to be unknown (it is still registered + active, so calls succeed +// against it) and the #4168 409 re-bind needs a witness conflict (none occurs). +// The host's CURRENT session id lives in /sessions/ +// .json (rewritten on /clear; the host pid is stable for this child's +// lifetime). The claude entry (claude-mcp-entry.ts) injects a resolver that reads +// it; on each tools/call we re-read it and, when it differs from the bound id, +// re-bind + re-register so the new session enters plugin mode. Identity-bound +// hosts only (the resolver is injected solely by the claude entry); a per-call / +// native override still wins for the current call — it never touches this global. +let claudeSessionResolver: (() => string | undefined) | undefined; + +export function setClaudeSessionResolver(fn: (() => string | undefined) | undefined): void { + claudeSessionResolver = fn; +} + +/** Re-point the default binding at the host's current session id when it has + * changed under a live shim (claude /clear). Returns the new id when a re-bind + * happened, else undefined. The register is fire-and-forget (identity binding + * survives any arrival order, same as initialize); the binding update is + * synchronous so the in-flight forward already carries the new id. */ +export function maybeRebindConversation(): string | undefined { + if (!IDENTITY_BINDING || claudeSessionResolver === undefined) return undefined; + let current: string | undefined; + try { + current = claudeSessionResolver(); + } catch { + current = undefined; + } + if (!current || current === conversationId) return undefined; + const previous = conversationId; + conversationId = current; + process.stderr.write( + `[bili-mcp] host session id changed ${previous ?? "(none)"} → ${current} (claude /clear?); re-binding\n`, + ); + if (!registeredConversations.has(current)) { + registeredConversations.add(current); + void fetch(`${resolveProxyOrigin()}/__bili/plugin/register`, { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ conversationId: current, agent: "mcp", identity: true }), + signal: AbortSignal.timeout(5000), + }).catch(() => {}); + } + return current; +} + +// Test seam: clear the injected resolver between cases (it is module state). +export function _resetClaudeSessionResolverForTest(): void { + claudeSessionResolver = undefined; +} + const ERR_TOOL = -32602; async function handleMessage(msg: { @@ -404,6 +458,10 @@ async function handleMessage(msg: { const args = { ...rawArgs }; if (!keepForSearch) delete args.conversation_id; const routeOverride = nativeThreadId ?? (keepForSearch ? undefined : perCall || undefined); + // #6361: before forwarding, re-point the default binding at the + // host's current session id if claude /clear moved it (identity + // hosts only; a routeOverride above still wins for THIS call). + maybeRebindConversation(); // #1685: with no binding and no per-call id, forward anyway — the // proxy routes the id-less POST itself (outbound tool_use witness, // else single-active arbitration) and answers a loud 400 when it diff --git a/tests/issue6361-claude-clear-rebind-nonidentity.test.ts b/tests/issue6361-claude-clear-rebind-nonidentity.test.ts new file mode 100644 index 0000000000..1af9ea731d --- /dev/null +++ b/tests/issue6361-claude-clear-rebind-nonidentity.test.ts @@ -0,0 +1,33 @@ +// #6361 (gate direction 2 — non-identity host): the re-bind seam is scoped to +// identity-bound hosts only. This file loads src/mcp.ts WITHOUT +// CLAUDE_CODE_SESSION_ID (IDENTITY_BINDING is a module-load constant, so the +// direction needs its own process), mirroring the issue4580 precedent of +// importing the shim unbound: even with a resolver armed (as the claude entry +// does) and a fresh session id available, no re-bind may fire — an MCP child +// spawned without the session env keeps the pre-#6361 binding behavior +// exactly. +import { describe, test } from "node:test"; +import assert from "node:assert/strict"; + +delete process.env.CLAUDE_CODE_SESSION_ID; +process.env.BILI_CONVERSATION_ID = "nonidentity-bound-id"; + +const { _resetMcpBindingForTest, setClaudeSessionResolver, maybeRebindConversation, _resetClaudeSessionResolverForTest } = await import("../src/mcp.ts"); + +describe("#6361 shim: non-identity host — the re-bind seam stays a no-op", () => { + test("resolver armed + fresh id available → no re-bind, resolver never called", () => { + _resetMcpBindingForTest("nonidentity-bound-id"); + let resolverCalls = 0; + setClaudeSessionResolver(() => { + resolverCalls += 1; + return "fresh-session-after-clear"; + }); + try { + assert.equal(maybeRebindConversation(), undefined, "the identity gate must hold on a non-identity host"); + assert.equal(resolverCalls, 0, "the gate must short-circuit before the resolver runs"); + } finally { + _resetClaudeSessionResolverForTest(); + _resetMcpBindingForTest(); + } + }); +}); diff --git a/tests/issue6361-claude-clear-rebind.test.ts b/tests/issue6361-claude-clear-rebind.test.ts new file mode 100644 index 0000000000..d8c00f4802 --- /dev/null +++ b/tests/issue6361-claude-clear-rebind.test.ts @@ -0,0 +1,397 @@ +// #6361: Claude Code /clear (or /new) starts a NEW session id but keeps this +// stdio MCP child running — the spawn-time CLAUDE_CODE_SESSION_ID env +// (mcp.ts's CONVERSATION_FROM_ENV) goes stale, and NEITHER existing recovery +// path fires (the #656 404 adoption needs the bound id to be unknown — it is +// still registered + active, so calls succeed against it; the #4168 409 +// re-bind needs a witness conflict — none occurs). Tools silently run against +// the OLD session and the NEW session never enters plugin mode. +// +// Fix: the claude entry (claude-mcp-entry.ts) injects a resolver that reads the +// host's CURRENT session id from /sessions/ +// .json (rewritten on /clear; the host pid is stable for this child's +// lifetime). On each tools/call the shim re-reads it and, when it differs from +// the bound id, re-binds + re-registers so the new session enters plugin mode. +// +// Pins the contract at both layers: +// A. resolver — reads + validates the sessions file defensively (any read / +// parse / shape failure → undefined, i.e. "no re-bind", never a +// crash); honors CLAUDE_CONFIG_DIR + the (cached) host pid; +// B. shim — maybeRebindConversation re-points the default binding at the +// host's current id exactly when it changed, fires a register +// for the new id, and leaves the binding untouched for same-id / +// no-resolver / throwing-resolver / non-identity cases (gate +// ships both directions per #3617). +import { describe, test } from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import http from "node:http"; + +// Identity-bound shim: the captured binding goes stale on /clear. Must be set +// BEFORE src/mcp.ts loads (module-load-time constants). +process.env.CLAUDE_CODE_SESSION_ID = "env-stale-id-6361"; + +const { readClaudeSessionFile, readClaudeSessionId, _resetClaudeHostPidForTest, _setClaudeHostPidForTest } = await import("../src/claude-mcp-entry.ts"); +const { _resetMcpBindingForTest, forwardTool, setClaudeSessionResolver, maybeRebindConversation, _resetClaudeSessionResolverForTest } = await import("../src/mcp.ts"); +const { rmrf } = await import("./tmp-rm.ts"); + +const HOST_PID = 12345; + +function withEnv(vars: Record, fn: () => void | Promise): void | Promise { + const prev: Record = {}; + for (const [k, v] of Object.entries(vars)) { + prev[k] = process.env[k]; + if (v === undefined) delete process.env[k]; + else process.env[k] = v; + } + const restore = () => { + for (const [k, v] of Object.entries(prev)) { + if (v === undefined) delete process.env[k]; + else process.env[k] = v; + } + }; + const r = fn(); + if (r instanceof Promise) return r.finally(restore); + restore(); +} + +// A CLAUDE_CONFIG_DIR tree with one sessions file. `content` is the raw file +// body (string) or an object to JSON.stringify, or null for "no file". +function sessionsSandbox(content: unknown, pid: number = HOST_PID): { dir: string; cleanup(): void } { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bili-claude-sess-")); + const sessionsDir = path.join(dir, "sessions"); + fs.mkdirSync(sessionsDir, { recursive: true }); + if (content !== null) { + fs.writeFileSync(path.join(sessionsDir, `${pid}.json`), typeof content === "string" ? content : JSON.stringify(content)); + } + return { dir, cleanup: () => rmrf(dir) }; +} + +// ─────────────────────── Part A: claude session resolver ───────────────────── + +describe("#6361 resolver: readClaudeSessionFile reads + validates the sessions file", () => { + test("returns the sessionId from a well-formed file", () => { + const box = sessionsSandbox({ sessionId: "5b1cb753-1234-4abc-8def-0123456789ab" }); + try { + assert.equal(readClaudeSessionFile(box.dir, HOST_PID), "5b1cb753-1234-4abc-8def-0123456789ab"); + } finally { + box.cleanup(); + } + }); + + test("accepts the session_id and id fallback shapes", () => { + let box = sessionsSandbox({ session_id: "abc123" }); + try { + assert.equal(readClaudeSessionFile(box.dir, HOST_PID), "abc123"); + } finally { + box.cleanup(); + } + box = sessionsSandbox({ id: "def456" }); + try { + assert.equal(readClaudeSessionFile(box.dir, HOST_PID), "def456"); + } finally { + box.cleanup(); + } + }); + + test("sessionId wins over the fallbacks when several are present", () => { + const box = sessionsSandbox({ sessionId: "primary", session_id: "secondary", id: "third" }); + try { + assert.equal(readClaudeSessionFile(box.dir, HOST_PID), "primary"); + } finally { + box.cleanup(); + } + }); + + test("missing file → undefined", () => { + const box = sessionsSandbox(null); + try { + assert.equal(readClaudeSessionFile(box.dir, 99999), undefined); + } finally { + box.cleanup(); + } + }); + + test("malformed JSON → undefined", () => { + const box = sessionsSandbox("{ not json"); + try { + assert.equal(readClaudeSessionFile(box.dir, HOST_PID), undefined); + } finally { + box.cleanup(); + } + }); + + test("non-object JSON → undefined", () => { + const box = sessionsSandbox('"just a string"'); + try { + assert.equal(readClaudeSessionFile(box.dir, HOST_PID), undefined); + } finally { + box.cleanup(); + } + }); + + test("missing session field → undefined", () => { + const box = sessionsSandbox({ foo: "bar" }); + try { + assert.equal(readClaudeSessionFile(box.dir, HOST_PID), undefined); + } finally { + box.cleanup(); + } + }); + + test("non-string session field → undefined", () => { + const box = sessionsSandbox({ sessionId: 12345 }); + try { + assert.equal(readClaudeSessionFile(box.dir, HOST_PID), undefined); + } finally { + box.cleanup(); + } + }); + + test("invalid session-id shape → undefined (too short / space / path separator)", () => { + for (const bad of ["ab", "has space", "a/b"]) { + const box = sessionsSandbox({ sessionId: bad }); + try { + assert.equal(readClaudeSessionFile(box.dir, HOST_PID), undefined, `rejected ${JSON.stringify(bad)}`); + } finally { + box.cleanup(); + } + } + }); + + test("trims surrounding whitespace from the id", () => { + const box = sessionsSandbox({ sessionId: " padded-id-123 " }); + try { + assert.equal(readClaudeSessionFile(box.dir, HOST_PID), "padded-id-123"); + } finally { + box.cleanup(); + } + }); +}); + +describe("#6361 resolver: readClaudeSessionId wires CLAUDE_CONFIG_DIR + host pid", () => { + test("reads the file for the (pinned) host pid under CLAUDE_CONFIG_DIR", async () => { + const box = sessionsSandbox({ sessionId: "wired-session-1" }); + await withEnv({ CLAUDE_CONFIG_DIR: box.dir }, () => { + _setClaudeHostPidForTest(HOST_PID); + try { + assert.equal(readClaudeSessionId(), "wired-session-1"); + } finally { + _resetClaudeHostPidForTest(); + } + }); + box.cleanup(); + }); + + test("no resolvable host pid → undefined (no crash)", async () => { + const box = sessionsSandbox({ sessionId: "wired-session-1" }); + await withEnv({ CLAUDE_CONFIG_DIR: box.dir }, () => { + _setClaudeHostPidForTest(undefined); + try { + assert.equal(readClaudeSessionId(), undefined); + } finally { + _resetClaudeHostPidForTest(); + } + }); + box.cleanup(); + }); + + test("host pid set but no sessions file → undefined", async () => { + const box = sessionsSandbox(null); + await withEnv({ CLAUDE_CONFIG_DIR: box.dir }, () => { + _setClaudeHostPidForTest(HOST_PID); + try { + assert.equal(readClaudeSessionId(), undefined); + } finally { + _resetClaudeHostPidForTest(); + } + }); + box.cleanup(); + }); +}); + +// ─────────────────────── Part B: shim re-bind seam ─────────────────────────── + +type CapturedPost = { url: string; body: Record }; + +function mockProxy(script: Array<{ status: number; json: Record }>): Promise<{ url: string; posts: CapturedPost[]; stop(): Promise }> { + const posts: CapturedPost[] = []; + let i = 0; + const server = http.createServer((req, res) => { + let raw = ""; + req.on("data", (c) => { raw += c; }); + req.on("end", () => { + let body: Record = {}; + try { body = JSON.parse(raw); } catch { /* ignore */ } + posts.push({ url: req.url ?? "", body }); + const step = script[Math.min(i, script.length - 1)] ?? { status: 500, json: { ok: false, error: "mock exhausted" } }; + i += 1; + res.writeHead(step.status, { "content-type": "application/json" }); + res.end(JSON.stringify(step.json)); + }); + }); + return new Promise((resolveFn) => { + server.listen(0, "127.0.0.1", () => { + const port = (server.address() as import("node:net").AddressInfo).port; + resolveFn({ + url: `http://127.0.0.1:${port}`, + posts, + stop: () => new Promise((r) => { server.close(() => { r(); }); }), + }); + }); + }); +} + +function toolPosts(posts: CapturedPost[]): Record[] { + return posts.filter((p) => p.url === "/__bili/plugin/tool").map((p) => p.body); +} + +function registerPosts(posts: CapturedPost[]): Record[] { + return posts.filter((p) => p.url === "/__bili/plugin/register").map((p) => p.body); +} + +async function waitForUrl(posts: CapturedPost[], url: string, timeoutMs = 1500): Promise { + const t0 = Date.now(); + while (Date.now() - t0 < timeoutMs) { + if (posts.some((p) => p.url === url)) return true; + await new Promise((r) => setTimeout(r, 10)); + } + return posts.some((p) => p.url === url); +} + +describe("#6361 shim: maybeRebindConversation re-points at the host's current id", () => { + test("no resolver set → no re-bind (non-claude hosts leave the seam unset)", () => { + _resetMcpBindingForTest("bound-session-a"); + _resetClaudeSessionResolverForTest(); + assert.equal(maybeRebindConversation(), undefined); + }); + + test("resolver returns the SAME id → no re-bind", () => { + _resetMcpBindingForTest("same-session"); + setClaudeSessionResolver(() => "same-session"); + try { + assert.equal(maybeRebindConversation(), undefined); + } finally { + _resetClaudeSessionResolverForTest(); + _resetMcpBindingForTest(); + } + }); + + test("resolver returns a NEW id → re-binds and returns it", () => { + _resetMcpBindingForTest("old-session"); + setClaudeSessionResolver(() => "new-session"); + try { + assert.equal(maybeRebindConversation(), "new-session"); + } finally { + _resetClaudeSessionResolverForTest(); + _resetMcpBindingForTest(); + } + }); + + test("resolver returns undefined → no re-bind", () => { + _resetMcpBindingForTest("old-session"); + setClaudeSessionResolver(() => undefined); + try { + assert.equal(maybeRebindConversation(), undefined); + } finally { + _resetClaudeSessionResolverForTest(); + _resetMcpBindingForTest(); + } + }); + + test("resolver throws → no re-bind (defensive: a read error never crashes the shim)", () => { + _resetMcpBindingForTest("old-session"); + setClaudeSessionResolver(() => { throw new Error("boom"); }); + try { + assert.equal(maybeRebindConversation(), undefined); + } finally { + _resetClaudeSessionResolverForTest(); + _resetMcpBindingForTest(); + } + }); +}); + +describe("#6361 shim: tools/call sequence carries the re-bound id to the proxy", () => { + test("after a /clear re-bind, the forward hits the NEW session", async () => { + const mock = await mockProxy([{ status: 200, json: { ok: true } }]); + process.env.BILI_MCP_PROXY = mock.url; + _resetMcpBindingForTest("old-session"); + setClaudeSessionResolver(() => "new-session"); + try { + // Mirror the tools/call case: re-bind, then forward. + maybeRebindConversation(); + await forwardTool("acp_status", {}); + const tools = toolPosts(mock.posts); + assert.equal(tools.length, 1); + assert.equal(tools[0].conversationId, "new-session"); + } finally { + delete process.env.BILI_MCP_PROXY; + _resetClaudeSessionResolverForTest(); + _resetMcpBindingForTest(); + await mock.stop(); + } + }); + + test("no re-bind (same id) → the forward stays on the bound session", async () => { + const mock = await mockProxy([{ status: 200, json: { ok: true } }]); + process.env.BILI_MCP_PROXY = mock.url; + _resetMcpBindingForTest("bound-session"); + setClaudeSessionResolver(() => "bound-session"); + try { + maybeRebindConversation(); + await forwardTool("acp_status", {}); + const tools = toolPosts(mock.posts); + assert.equal(tools.length, 1); + assert.equal(tools[0].conversationId, "bound-session"); + } finally { + delete process.env.BILI_MCP_PROXY; + _resetClaudeSessionResolverForTest(); + _resetMcpBindingForTest(); + await mock.stop(); + } + }); + + test("no resolver → the forward stays on the bound session (other hosts)", async () => { + const mock = await mockProxy([{ status: 200, json: { ok: true } }]); + process.env.BILI_MCP_PROXY = mock.url; + _resetMcpBindingForTest("bound-session"); + _resetClaudeSessionResolverForTest(); + try { + maybeRebindConversation(); + await forwardTool("acp_status", {}); + const tools = toolPosts(mock.posts); + assert.equal(tools.length, 1); + assert.equal(tools[0].conversationId, "bound-session"); + } finally { + delete process.env.BILI_MCP_PROXY; + _resetMcpBindingForTest(); + await mock.stop(); + } + }); + + test("a re-bind fires a register for the NEW session (so it enters plugin mode)", async () => { + const mock = await mockProxy([{ status: 200, json: { ok: true } }]); + process.env.BILI_MCP_PROXY = mock.url; + // Unique id: registeredConversations is module state, so a fresh id + // guarantees the register branch runs. + const fresh = `fresh-session-${Math.random().toString(36).slice(2)}`; + _resetMcpBindingForTest("old-session"); + setClaudeSessionResolver(() => fresh); + try { + maybeRebindConversation(); + const landed = await waitForUrl(mock.posts, "/__bili/plugin/register"); + assert.equal(landed, true, "register POST landed"); + const regs = registerPosts(mock.posts); + assert.equal(regs.length, 1); + assert.equal(regs[0].conversationId, fresh); + assert.equal(regs[0].agent, "mcp"); + assert.equal(regs[0].identity, true); + } finally { + delete process.env.BILI_MCP_PROXY; + _resetClaudeSessionResolverForTest(); + _resetMcpBindingForTest(); + await mock.stop(); + } + }); +});