mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 01:20:43 +00:00
test: tighten bash tool assertions
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user