test: tighten bash tool assertions

This commit is contained in:
Peter Steinberger
2026-05-09 14:58:21 +01:00
parent 8eaca55cbb
commit b21414e49e
3 changed files with 23 additions and 16 deletions

View File

@@ -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 () => {

View File

@@ -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");
});

View File

@@ -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();
}