From 87f01a408d0745f20d3b6d15e08353e37f61ae3c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 16:59:19 +0100 Subject: [PATCH] test: tighten pty fallback assertions --- ...sh-tools.exec-runtime.pty-fallback.test.ts | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/agents/bash-tools.exec-runtime.pty-fallback.test.ts b/src/agents/bash-tools.exec-runtime.pty-fallback.test.ts index eef7d50b059..3b8708a025b 100644 --- a/src/agents/bash-tools.exec-runtime.pty-fallback.test.ts +++ b/src/agents/bash-tools.exec-runtime.pty-fallback.test.ts @@ -2,6 +2,7 @@ import { afterEach, beforeAll, beforeEach, expect, test, vi } from "vitest"; import { onInternalDiagnosticEvent, resetDiagnosticEventsForTest, + type DiagnosticExecProcessCompletedEvent, type DiagnosticEventPayload, } from "../infra/diagnostic-events.js"; import type { ManagedRun, SpawnInput } from "../process/supervisor/index.js"; @@ -91,11 +92,10 @@ test("exec falls back when PTY spawn fails", async () => { expect(outcome.status).toBe("completed"); expect(outcome.aggregated).toContain("ok"); expect(warnings.join("\n")).toContain("PTY spawn failed"); - expect(supervisorSpawnMock).toHaveBeenNthCalledWith(1, expect.objectContaining({ mode: "pty" })); - expect(supervisorSpawnMock).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ mode: "child" }), - ); + const firstSpawnInput = supervisorSpawnMock.mock.calls[0]?.[0] as SpawnInput | undefined; + const secondSpawnInput = supervisorSpawnMock.mock.calls[1]?.[0] as SpawnInput | undefined; + expect(firstSpawnInput?.mode).toBe("pty"); + expect(secondSpawnInput?.mode).toBe("child"); }); test("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 () => await handle.promise; await flushDiagnosticEvents(); - const event = events.find((item) => item.type === "exec.process.completed"); - expect(event).toMatchObject({ - type: "exec.process.completed", - target: "host", - mode: "child", - outcome: "completed", - durationMs: expect.any(Number), - commandLength: command.length, - exitCode: 0, - sessionKey: "session-1", - }); + const event = events.find( + (item): item is DiagnosticExecProcessCompletedEvent => item.type === "exec.process.completed", + ); + expect(event).toBeDefined(); + expect(event?.type).toBe("exec.process.completed"); + expect(event?.target).toBe("host"); + expect(event?.mode).toBe("child"); + expect(event?.outcome).toBe("completed"); + expect(typeof event?.durationMs).toBe("number"); + expect(event?.commandLength).toBe(command.length); + expect(event?.exitCode).toBe(0); + expect(event?.sessionKey).toBe("session-1"); const serialized = JSON.stringify(event); expect(serialized).not.toContain("printf"); expect(serialized).not.toContain("super-secret-value");