test: tighten bash tool assertions · openclaw/openclaw@b21414e
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -40,16 +40,20 @@ describe("exec foreground failures", () => {
|
40 | 40 | command: longDelayCmd, |
41 | 41 | }); |
42 | 42 | |
43 | | -expect(result.content[0]).toMatchObject({ type: "text" }); |
| 43 | +expect(result.content[0]?.type).toBe("text"); |
44 | 44 | expect((result.content[0] as { text?: string }).text).toMatch(/timed out/i); |
45 | 45 | expect((result.content[0] as { text?: string }).text).toMatch(/re-run with a higher timeout/i); |
46 | | -expect(result.details).toMatchObject({ |
47 | | -status: "failed", |
48 | | -exitCode: null, |
49 | | -aggregated: "", |
50 | | -}); |
51 | | -expect((result.details as { durationMs?: number }).durationMs).toBeTypeOf("number"); |
52 | | -expect((result.details as { durationMs?: number }).durationMs).toBeGreaterThanOrEqual(0); |
| 46 | +const details = result.details as { |
| 47 | +status?: string; |
| 48 | +exitCode?: number | null; |
| 49 | +aggregated?: string; |
| 50 | +durationMs?: number; |
| 51 | +}; |
| 52 | +expect(details.status).toBe("failed"); |
| 53 | +expect(details.exitCode).toBeNull(); |
| 54 | +expect(details.aggregated).toBe(""); |
| 55 | +expect(details.durationMs).toBeTypeOf("number"); |
| 56 | +expect(details.durationMs).toBeGreaterThanOrEqual(0); |
53 | 57 | }); |
54 | 58 | |
55 | 59 | it("rejects invalid host values before launching a command", async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -418,9 +418,7 @@ describeNonWin("exec script preflight", () => {
|
418 | 418 | const text = result.content.find((c) => c.type === "text")?.text ?? ""; |
419 | 419 | |
420 | 420 | expect(text).not.toMatch(/exec preflight:/); |
421 | | -expect(result.details).toMatchObject({ |
422 | | -status: expect.stringMatching(/completed|failed/), |
423 | | -}); |
| 421 | +expect((result.details as { status?: string }).status).toMatch(/completed|failed/); |
424 | 422 | }); |
425 | 423 | }); |
426 | 424 | |
@@ -436,7 +434,7 @@ describeNonWin("exec script preflight", () => {
|
436 | 434 | }); |
437 | 435 | const text = result.content.find((c) => c.type === "text")?.text?.trim(); |
438 | 436 | |
439 | | -expect(result.details).toMatchObject({ status: "completed" }); |
| 437 | +expect((result.details as { status?: string }).status).toBe("completed"); |
440 | 438 | expect(text).toBe("ok"); |
441 | 439 | }); |
442 | 440 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -128,9 +128,7 @@ test("process poll clamps long waits to 30 seconds", async () => {
|
128 | 128 | |
129 | 129 | test("process poll schema advertises the 30 second wait cap", () => { |
130 | 130 | const timeoutSchema = processSchema.properties.timeout; |
131 | | -expect(timeoutSchema).toMatchObject({ |
132 | | -description: expect.stringContaining("max 30000 ms"), |
133 | | -}); |
| 131 | +expect((timeoutSchema as { description?: string }).description).toContain("max 30000 ms"); |
134 | 132 | }); |
135 | 133 | |
136 | 134 | test("process poll aborts while waiting for completion", async () => { |
@@ -149,7 +147,14 @@ test("process poll aborts while waiting for completion", async () => {
|
149 | 147 | await vi.advanceTimersByTimeAsync(500); |
150 | 148 | controller.abort(); |
151 | 149 | |
152 | | -await expect(pollPromise).rejects.toMatchObject({ name: "AbortError" }); |
| 150 | +let err: unknown; |
| 151 | +try { |
| 152 | +await pollPromise; |
| 153 | +} catch (caught) { |
| 154 | +err = caught; |
| 155 | +} |
| 156 | +expect(err).toBeInstanceOf(Error); |
| 157 | +expect((err as Error).name).toBe("AbortError"); |
153 | 158 | } finally { |
154 | 159 | vi.useRealTimers(); |
155 | 160 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。