test: guard gateway status helper records · openclaw/openclaw@38de1a7
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -70,24 +70,28 @@ function createOptions(
|
70 | 70 | } |
71 | 71 | |
72 | 72 | function requireRecord(value: unknown): Record<string, unknown> { |
73 | | -expect(value).toBeTruthy(); |
74 | | -expect(typeof value).toBe("object"); |
75 | | -expect(Array.isArray(value)).toBe(false); |
| 73 | +if (!value || typeof value !== "object" || Array.isArray(value)) { |
| 74 | + throw new Error("Expected record"); |
| 75 | +} |
76 | 76 | return value as Record<string, unknown>; |
77 | 77 | } |
78 | 78 | |
79 | 79 | function requireFirstCallArg(mock: { mock: { calls: readonly (readonly unknown[])[] } }) { |
80 | 80 | const call = mock.mock.calls[0]; |
81 | | -expect(call).toBeTruthy(); |
82 | | -return call?.[0]; |
| 81 | +if (!call) { |
| 82 | +throw new Error("Expected first mock call"); |
| 83 | +} |
| 84 | +return call[0]; |
83 | 85 | } |
84 | 86 | |
85 | 87 | function requireRespondPayload(respond: ReturnType<typeof vi.fn>): Record<string, unknown> { |
86 | 88 | const call = respond.mock.calls[0]; |
87 | | -expect(call).toBeTruthy(); |
88 | | -expect(call?.[0]).toBe(true); |
89 | | -expect(call?.[2]).toBeUndefined(); |
90 | | -return requireRecord(call?.[1]); |
| 89 | +if (!call) { |
| 90 | +throw new Error("Expected respond call"); |
| 91 | +} |
| 92 | +expect(call[0]).toBe(true); |
| 93 | +expect(call[2]).toBeUndefined(); |
| 94 | +return requireRecord(call[1]); |
91 | 95 | } |
92 | 96 | |
93 | 97 | describe("channelsHandlers channels.status", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -23,16 +23,18 @@ import {
|
23 | 23 | const { createSessionStoreDir, openClient, getHarness } = setupGatewaySessionsTestHarness(); |
24 | 24 | |
25 | 25 | function requireRecord(value: unknown): Record<string, unknown> { |
26 | | -expect(value).toBeTruthy(); |
27 | | -expect(typeof value).toBe("object"); |
28 | | -expect(Array.isArray(value)).toBe(false); |
| 26 | +if (!value || typeof value !== "object" || Array.isArray(value)) { |
| 27 | + throw new Error("Expected record"); |
| 28 | +} |
29 | 29 | return value as Record<string, unknown>; |
30 | 30 | } |
31 | 31 | |
32 | 32 | function requireFirstCallArg(mock: { mock: { calls: readonly (readonly unknown[])[] } }) { |
33 | 33 | const call = mock.mock.calls[0]; |
34 | | -expect(call).toBeTruthy(); |
35 | | -return call?.[0]; |
| 34 | +if (!call) { |
| 35 | +throw new Error("Expected first mock call"); |
| 36 | +} |
| 37 | +return call[0]; |
36 | 38 | } |
37 | 39 | |
38 | 40 | test("webchat clients cannot patch, delete, compact, or restore sessions", async () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。