test: guard auto-reply helper assertions · openclaw/openclaw@5b4940e
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -299,7 +299,6 @@ function expectRecordFields(record: Record<string, unknown>, fields: Record<stri
|
299 | 299 | |
300 | 300 | function requireMockCall(mock: unknown, index: number, label: string): unknown[] { |
301 | 301 | const call = (mock as { mock?: { calls?: unknown[][] } }).mock?.calls?.[index]; |
302 | | -expect(call).toBeDefined(); |
303 | 302 | if (!call) { |
304 | 303 | throw new Error(`missing ${label} call ${index + 1}`); |
305 | 304 | } |
@@ -343,7 +342,6 @@ function requireMockCallArgWithFields(
|
343 | 342 | const record = value as Record<string, unknown>; |
344 | 343 | return Object.entries(fields).every(([key, expected]) => record[key] === expected); |
345 | 344 | }); |
346 | | -expect(found).toBeDefined(); |
347 | 345 | if (!found) { |
348 | 346 | throw new Error(`missing ${label}`); |
349 | 347 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -51,7 +51,6 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
51 | 51 | |
52 | 52 | function mockCallArgs(mock: ReturnType<typeof vi.fn>, label: string, callIndex = 0): unknown[] { |
53 | 53 | const call = mock.mock.calls[callIndex] as unknown[] | undefined; |
54 | | -expect(call).toBeDefined(); |
55 | 54 | if (!call) { |
56 | 55 | throw new Error(`expected ${label} mock call ${callIndex}`); |
57 | 56 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -598,15 +598,19 @@ type MockWithCalls = {
|
598 | 598 | |
599 | 599 | function mockCallArg(mock: MockWithCalls, callIndex = 0, argIndex = 0): unknown { |
600 | 600 | const call = mock.mock.calls[callIndex]; |
601 | | -expect(call).toBeDefined(); |
602 | | -return call?.[argIndex]; |
| 601 | +if (!call) { |
| 602 | +throw new Error(`Expected mock call ${callIndex}`); |
| 603 | +} |
| 604 | +return call[argIndex]; |
603 | 605 | } |
604 | 606 | |
605 | 607 | function expectRecordFields( |
606 | 608 | record: unknown, |
607 | 609 | expected: Record<string, unknown>, |
608 | 610 | ): Record<string, unknown> { |
609 | | -expect(record).toBeDefined(); |
| 611 | +if (!record || typeof record !== "object") { |
| 612 | +throw new Error("Expected record"); |
| 613 | +} |
610 | 614 | const actual = record as Record<string, unknown>; |
611 | 615 | for (const [key, value] of Object.entries(expected)) { |
612 | 616 | expect(actual[key]).toEqual(value); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -36,7 +36,6 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
36 | 36 | |
37 | 37 | function gatewayRequest(callIndex = 0) { |
38 | 38 | const call = callGatewayMock.mock.calls[callIndex] as unknown[] | undefined; |
39 | | -expect(call).toBeDefined(); |
40 | 39 | if (!call) { |
41 | 40 | throw new Error(`expected gateway call ${callIndex}`); |
42 | 41 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -26,8 +26,10 @@ function buildParams(commandBody: string) {
|
26 | 26 | function mockCall(mock: unknown, index = 0): Array<unknown> { |
27 | 27 | const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? []; |
28 | 28 | const call = calls.at(index); |
29 | | -expect(call, `mock call ${index + 1}`).toBeDefined(); |
30 | | -return call as Array<unknown>; |
| 29 | +if (!call) { |
| 30 | +throw new Error(`Expected mock call ${index + 1}`); |
| 31 | +} |
| 32 | +return call; |
31 | 33 | } |
32 | 34 | |
33 | 35 | function mockFirstObjectArg(mock: unknown): Record<string, unknown> { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -68,8 +68,10 @@ function buildPluginsParams(commandBodyNormalized: string, workspaceDir: string)
|
68 | 68 | function mockCall(mock: unknown, index = 0): Array<unknown> { |
69 | 69 | const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? []; |
70 | 70 | const call = calls.at(index); |
71 | | -expect(call, `mock call ${index + 1}`).toBeDefined(); |
72 | | -return call as Array<unknown>; |
| 71 | +if (!call) { |
| 72 | +throw new Error(`Expected mock call ${index + 1}`); |
| 73 | +} |
| 74 | +return call; |
73 | 75 | } |
74 | 76 | |
75 | 77 | function mockFirstObjectArg(mock: unknown): Record<string, unknown> { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -108,8 +108,10 @@ function buildResetParams(
|
108 | 108 | function mockCall(mock: unknown, index = 0): Array<unknown> { |
109 | 109 | const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? []; |
110 | 110 | const call = calls.at(index); |
111 | | -expect(call, `mock call ${index + 1}`).toBeDefined(); |
112 | | -return call as Array<unknown>; |
| 111 | +if (!call) { |
| 112 | +throw new Error(`Expected mock call ${index + 1}`); |
| 113 | +} |
| 114 | +return call; |
113 | 115 | } |
114 | 116 | |
115 | 117 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -179,13 +179,17 @@ type SessionBindingBindInput = {
|
179 | 179 | |
180 | 180 | function firstFocusTargetSessionParams(): FocusTargetSessionParams { |
181 | 181 | const firstCall = hoisted.resolveFocusTargetSessionMock.mock.calls[0]; |
182 | | -expect(firstCall).toBeDefined(); |
| 182 | +if (!firstCall) { |
| 183 | +throw new Error("Expected focus target session call"); |
| 184 | +} |
183 | 185 | return firstCall[0] as FocusTargetSessionParams; |
184 | 186 | } |
185 | 187 | |
186 | 188 | function firstSessionBindingBindInput(): SessionBindingBindInput { |
187 | 189 | const firstCall = hoisted.sessionBindingBindMock.mock.calls[0]; |
188 | | -expect(firstCall).toBeDefined(); |
| 190 | +if (!firstCall) { |
| 191 | +throw new Error("Expected session binding bind call"); |
| 192 | +} |
189 | 193 | return firstCall[0] as SessionBindingBindInput; |
190 | 194 | } |
191 | 195 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4315,7 +4315,9 @@ describe("sendPolicy deny — suppress delivery, not processing (#53328)", () =>
|
4315 | 4315 | expect(tailDispatchEvent?.sendPolicy).toBe("deny"); |
4316 | 4316 | expect(tailDispatchEvent?.suppressUserDelivery).toBe(true); |
4317 | 4317 | expect(tailDispatchEvent?.suppressReplyLifecycle).toBe(true); |
4318 | | -expect(tailDispatchCall?.[1]).toBeDefined(); |
| 4318 | +if (tailDispatchCall?.[1] === undefined) { |
| 4319 | +throw new Error("Expected tail dispatch metadata"); |
| 4320 | +} |
4319 | 4321 | }); |
4320 | 4322 | |
4321 | 4323 | it("suppresses final reply delivery when sendPolicy is deny", async () => { |
@@ -4656,7 +4658,9 @@ describe("sendPolicy deny — suppress delivery, not processing (#53328)", () =>
|
4656 | 4658 | expect(replyDispatchEvent?.suppressReplyLifecycle).toBe(false); |
4657 | 4659 | expect(replyDispatchEvent?.sourceReplyDeliveryMode).toBe("message_tool_only"); |
4658 | 4660 | expect(replyDispatchEvent?.sendPolicy).toBe("allow"); |
4659 | | -expect(replyDispatchCall?.[1]).toBeDefined(); |
| 4661 | +if (replyDispatchCall?.[1] === undefined) { |
| 4662 | +throw new Error("Expected reply dispatch metadata"); |
| 4663 | +} |
4660 | 4664 | }); |
4661 | 4665 | |
4662 | 4666 | it("preserves hook-blocked metadata when source delivery is message-tool-only", async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -115,8 +115,10 @@ function parseInlineDirectivesForTest(body: string) {
|
115 | 115 | |
116 | 116 | function mockCallInput(mock: { mock: { calls: unknown[][] } }, index = 0): Record<string, unknown> { |
117 | 117 | const call = mock.mock.calls[index]; |
118 | | -expect(call).toBeDefined(); |
119 | | -const input = call?.[0]; |
| 118 | +if (!call) { |
| 119 | +throw new Error(`Expected mock call ${index}`); |
| 120 | +} |
| 121 | +const input = call[0]; |
120 | 122 | expect(typeof input).toBe("object"); |
121 | 123 | expect(input).not.toBeNull(); |
122 | 124 | return input as Record<string, unknown>; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。