test: guard exec host socket mock calls · openclaw/openclaw@897bc1c
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -8,6 +8,21 @@ vi.mock("./jsonl-socket.js", () => ({
|
8 | 8 | |
9 | 9 | import { requestExecHostViaSocket } from "./exec-host.js"; |
10 | 10 | |
| 11 | +type JsonlSocketCall = { |
| 12 | +socketPath: string; |
| 13 | +requestLine: string; |
| 14 | +timeoutMs: number; |
| 15 | +accept: (msg: unknown) => unknown; |
| 16 | +}; |
| 17 | + |
| 18 | +function requireJsonlSocketCall(): JsonlSocketCall { |
| 19 | +const call = requestJsonlSocketMock.mock.calls.at(0)?.[0]; |
| 20 | +if (!call) { |
| 21 | +throw new Error("expected requestJsonlSocket call"); |
| 22 | +} |
| 23 | +return call as JsonlSocketCall; |
| 24 | +} |
| 25 | + |
11 | 26 | describe("requestExecHostViaSocket", () => { |
12 | 27 | beforeEach(() => { |
13 | 28 | requestJsonlSocketMock.mockReset(); |
@@ -45,17 +60,7 @@ describe("requestExecHostViaSocket", () => {
|
45 | 60 | }), |
46 | 61 | ).resolves.toEqual({ ok: true, payload: { success: true } }); |
47 | 62 | |
48 | | -const call = requestJsonlSocketMock.mock.calls[0]?.[0] as |
49 | | -| { |
50 | | -socketPath: string; |
51 | | -requestLine: string; |
52 | | -timeoutMs: number; |
53 | | -accept: (msg: unknown) => unknown; |
54 | | -} |
55 | | -| undefined; |
56 | | -if (!call) { |
57 | | -throw new Error("expected requestJsonlSocket call"); |
58 | | -} |
| 63 | +const call = requireJsonlSocketCall(); |
59 | 64 | |
60 | 65 | expect(call.socketPath).toBe("/tmp/socket"); |
61 | 66 | expect(call.timeoutMs).toBe(20_000); |
@@ -102,8 +107,6 @@ describe("requestExecHostViaSocket", () => {
|
102 | 107 | }), |
103 | 108 | ).resolves.toBeNull(); |
104 | 109 | |
105 | | -expect( |
106 | | -(requestJsonlSocketMock.mock.calls[0]?.[0] as { timeoutMs?: number } | undefined)?.timeoutMs, |
107 | | -).toBe(123); |
| 110 | +expect(requireJsonlSocketCall().timeoutMs).toBe(123); |
108 | 111 | }); |
109 | 112 | }); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。