
























@@ -2,6 +2,7 @@ import { afterEach, beforeAll, beforeEach, expect, test, vi } from "vitest";
22import {
33onInternalDiagnosticEvent,
44resetDiagnosticEventsForTest,
5+type DiagnosticExecProcessCompletedEvent,
56type DiagnosticEventPayload,
67} from "../infra/diagnostic-events.js";
78import type { ManagedRun, SpawnInput } from "../process/supervisor/index.js";
@@ -91,11 +92,10 @@ test("exec falls back when PTY spawn fails", async () => {
9192expect(outcome.status).toBe("completed");
9293expect(outcome.aggregated).toContain("ok");
9394expect(warnings.join("\n")).toContain("PTY spawn failed");
94-expect(supervisorSpawnMock).toHaveBeenNthCalledWith(1, expect.objectContaining({ mode: "pty" }));
95-expect(supervisorSpawnMock).toHaveBeenNthCalledWith(
96-2,
97-expect.objectContaining({ mode: "child" }),
98-);
95+const firstSpawnInput = supervisorSpawnMock.mock.calls[0]?.[0] as SpawnInput | undefined;
96+const secondSpawnInput = supervisorSpawnMock.mock.calls[1]?.[0] as SpawnInput | undefined;
97+expect(firstSpawnInput?.mode).toBe("pty");
98+expect(secondSpawnInput?.mode).toBe("child");
9999});
100100101101test("exec cleans session state when PTY fallback spawn also fails", async () => {
@@ -138,17 +138,18 @@ test("exec emits bounded process diagnostics without command text", async () =>
138138await handle.promise;
139139await flushDiagnosticEvents();
140140141-const event = events.find((item) => item.type === "exec.process.completed");
142-expect(event).toMatchObject({
143-type: "exec.process.completed",
144-target: "host",
145-mode: "child",
146-outcome: "completed",
147-durationMs: expect.any(Number),
148-commandLength: command.length,
149-exitCode: 0,
150-sessionKey: "session-1",
151-});
141+const event = events.find(
142+(item): item is DiagnosticExecProcessCompletedEvent => item.type === "exec.process.completed",
143+);
144+expect(event).toBeDefined();
145+expect(event?.type).toBe("exec.process.completed");
146+expect(event?.target).toBe("host");
147+expect(event?.mode).toBe("child");
148+expect(event?.outcome).toBe("completed");
149+expect(typeof event?.durationMs).toBe("number");
150+expect(event?.commandLength).toBe(command.length);
151+expect(event?.exitCode).toBe(0);
152+expect(event?.sessionKey).toBe("session-1");
152153const serialized = JSON.stringify(event);
153154expect(serialized).not.toContain("printf");
154155expect(serialized).not.toContain("super-secret-value");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。