From b21414e49e7a55848e53ff9eff17cdaa534d5129 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 14:58:21 +0100 Subject: [PATCH] test: tighten bash tool assertions --- ...ash-tools.exec-foreground-failures.test.ts | 20 +++++++++++-------- .../bash-tools.exec.script-preflight.test.ts | 6 ++---- .../bash-tools.process.poll-timeout.test.ts | 13 ++++++++---- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/agents/bash-tools.exec-foreground-failures.test.ts b/src/agents/bash-tools.exec-foreground-failures.test.ts index 34e6d91197e..5593fbfc7fd 100644 --- a/src/agents/bash-tools.exec-foreground-failures.test.ts +++ b/src/agents/bash-tools.exec-foreground-failures.test.ts @@ -40,16 +40,20 @@ describe("exec foreground failures", () => { command: longDelayCmd, }); - expect(result.content[0]).toMatchObject({ type: "text" }); + expect(result.content[0]?.type).toBe("text"); expect((result.content[0] as { text?: string }).text).toMatch(/timed out/i); expect((result.content[0] as { text?: string }).text).toMatch(/re-run with a higher timeout/i); - expect(result.details).toMatchObject({ - status: "failed", - exitCode: null, - aggregated: "", - }); - expect((result.details as { durationMs?: number }).durationMs).toBeTypeOf("number"); - expect((result.details as { durationMs?: number }).durationMs).toBeGreaterThanOrEqual(0); + const details = result.details as { + status?: string; + exitCode?: number | null; + aggregated?: string; + durationMs?: number; + }; + expect(details.status).toBe("failed"); + expect(details.exitCode).toBeNull(); + expect(details.aggregated).toBe(""); + expect(details.durationMs).toBeTypeOf("number"); + expect(details.durationMs).toBeGreaterThanOrEqual(0); }); it("rejects invalid host values before launching a command", async () => { diff --git a/src/agents/bash-tools.exec.script-preflight.test.ts b/src/agents/bash-tools.exec.script-preflight.test.ts index 8086ca6e080..727b6ac08f0 100644 --- a/src/agents/bash-tools.exec.script-preflight.test.ts +++ b/src/agents/bash-tools.exec.script-preflight.test.ts @@ -418,9 +418,7 @@ describeNonWin("exec script preflight", () => { const text = result.content.find((c) => c.type === "text")?.text ?? ""; expect(text).not.toMatch(/exec preflight:/); - expect(result.details).toMatchObject({ - status: expect.stringMatching(/completed|failed/), - }); + expect((result.details as { status?: string }).status).toMatch(/completed|failed/); }); }); @@ -436,7 +434,7 @@ describeNonWin("exec script preflight", () => { }); const text = result.content.find((c) => c.type === "text")?.text?.trim(); - expect(result.details).toMatchObject({ status: "completed" }); + expect((result.details as { status?: string }).status).toBe("completed"); expect(text).toBe("ok"); }); diff --git a/src/agents/bash-tools.process.poll-timeout.test.ts b/src/agents/bash-tools.process.poll-timeout.test.ts index 3b873f7b7e2..5e4b2cb7db0 100644 --- a/src/agents/bash-tools.process.poll-timeout.test.ts +++ b/src/agents/bash-tools.process.poll-timeout.test.ts @@ -128,9 +128,7 @@ test("process poll clamps long waits to 30 seconds", async () => { test("process poll schema advertises the 30 second wait cap", () => { const timeoutSchema = processSchema.properties.timeout; - expect(timeoutSchema).toMatchObject({ - description: expect.stringContaining("max 30000 ms"), - }); + expect((timeoutSchema as { description?: string }).description).toContain("max 30000 ms"); }); test("process poll aborts while waiting for completion", async () => { @@ -149,7 +147,14 @@ test("process poll aborts while waiting for completion", async () => { await vi.advanceTimersByTimeAsync(500); controller.abort(); - await expect(pollPromise).rejects.toMatchObject({ name: "AbortError" }); + let err: unknown; + try { + await pollPromise; + } catch (caught) { + err = caught; + } + expect(err).toBeInstanceOf(Error); + expect((err as Error).name).toBe("AbortError"); } finally { vi.useRealTimers(); }