test: guard process queue calls · openclaw/openclaw@ca6a513
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -48,6 +48,18 @@ function createDeferred(): { promise: Promise<void>; resolve: () => void } {
|
48 | 48 | return { promise, resolve }; |
49 | 49 | } |
50 | 50 | |
| 51 | +function mockCallArg( |
| 52 | +mock: { mock: { calls: readonly unknown[][] } }, |
| 53 | +label: string, |
| 54 | +argIndex: number, |
| 55 | +): unknown { |
| 56 | +const [call] = mock.mock.calls; |
| 57 | +if (!call) { |
| 58 | +throw new Error(`expected ${label} call`); |
| 59 | +} |
| 60 | +return call[argIndex]; |
| 61 | +} |
| 62 | + |
51 | 63 | function enqueueBlockedMainTask<T = void>( |
52 | 64 | onRelease?: () => Promise<T> | T, |
53 | 65 | ): { |
@@ -153,7 +165,7 @@ describe("command queue", () => {
|
153 | 165 | const task = enqueueCommand(async () => {}); |
154 | 166 | |
155 | 167 | expect(diagnosticMocks.logLaneEnqueue).toHaveBeenCalledTimes(1); |
156 | | -expect(diagnosticMocks.logLaneEnqueue.mock.calls[0]?.[1]).toBe(1); |
| 168 | +expect(mockCallArg(diagnosticMocks.logLaneEnqueue, "logLaneEnqueue", 1)).toBe(1); |
157 | 169 | |
158 | 170 | await task; |
159 | 171 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,18 @@ const { createPtyAdapterMock } = vi.hoisted(() => ({
|
4 | 4 | createPtyAdapterMock: vi.fn(), |
5 | 5 | })); |
6 | 6 | |
| 7 | +function firstPtyAdapterParams(): { args?: string[] } { |
| 8 | +const [call] = createPtyAdapterMock.mock.calls; |
| 9 | +if (!call) { |
| 10 | +throw new Error("expected createPtyAdapter call"); |
| 11 | +} |
| 12 | +const [params] = call; |
| 13 | +if (typeof params !== "object" || params === null || Array.isArray(params)) { |
| 14 | +throw new Error("expected createPtyAdapter params to be an object"); |
| 15 | +} |
| 16 | +return params; |
| 17 | +} |
| 18 | + |
7 | 19 | vi.mock("../../agents/shell-utils.js", () => ({ |
8 | 20 | getShellConfig: () => ({ shell: "sh", args: ["-c"] }), |
9 | 21 | })); |
@@ -59,7 +71,7 @@ describe("process supervisor PTY command contract", () => {
|
59 | 71 | |
60 | 72 | expect(exit.reason).toBe("exit"); |
61 | 73 | expect(createPtyAdapterMock).toHaveBeenCalledTimes(1); |
62 | | -const params = createPtyAdapterMock.mock.calls[0]?.[0] as { args?: string[] }; |
| 74 | +const params = firstPtyAdapterParams(); |
63 | 75 | expect(params.args).toEqual(["-c", command]); |
64 | 76 | }); |
65 | 77 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。