

























@@ -834,6 +834,60 @@ describe("runCliAgent spawn path", () => {
834834}
835835});
836836837+it("defers prepared backend cleanup to the Claude live session lifecycle", async () => {
838+let stdoutListener: ((chunk: string) => void) | undefined;
839+const stdin = {
840+write: vi.fn((_data: string, cb?: (err?: Error | null) => void) => {
841+stdoutListener?.(
842+[
843+JSON.stringify({ type: "system", subtype: "init", session_id: "live-session-cleanup" }),
844+JSON.stringify({
845+type: "result",
846+session_id: "live-session-cleanup",
847+result: "ok",
848+}),
849+].join("\n") + "\n",
850+);
851+cb?.();
852+}),
853+end: vi.fn(),
854+};
855+supervisorSpawnMock.mockImplementation(async (...args: unknown[]) => {
856+const input = (args[0] ?? {}) as { onStdout?: (chunk: string) => void };
857+stdoutListener = input.onStdout;
858+return {
859+runId: "live-cleanup-run",
860+pid: 2346,
861+startedAtMs: Date.now(),
862+ stdin,
863+wait: vi.fn(() => new Promise(() => {})),
864+cancel: vi.fn(),
865+};
866+});
867+const preparedBackendCleanup = vi.fn(async () => {});
868+const context = buildPreparedCliRunContext({
869+provider: "claude-cli",
870+model: "sonnet",
871+runId: "run-live-cleanup",
872+prompt: "first",
873+backend: {
874+args: ["-p", "--strict-mcp-config", "--mcp-config", "/tmp/mcp-cleanup.json"],
875+liveSession: "claude-stdio",
876+},
877+mcpConfigHash: "cleanup-mcp-config",
878+});
879+context.preparedBackend.cleanup = preparedBackendCleanup;
880+881+const result = await executePreparedCliRun(context);
882+883+expect(result.text).toBe("ok");
884+expect(context.preparedBackend.cleanup).toBeUndefined();
885+expect(preparedBackendCleanup).not.toHaveBeenCalled();
886+887+resetClaudeLiveSessionsForTest();
888+await vi.waitFor(() => expect(preparedBackendCleanup).toHaveBeenCalledOnce());
889+});
890+837891it("accepts Claude live stream-json lines larger than 256 KiB", async () => {
838892const largeText = "x".repeat(270 * 1024);
839893let stdoutListener: ((chunk: string) => void) | undefined;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。