test: guard gateway call assertions · openclaw/openclaw@067666d
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -142,7 +142,7 @@ describe("parseMessageWithAttachments", () => {
|
142 | 142 | // ctx.MediaPaths so the workspace stage surfaces a real path. |
143 | 143 | expect(parsed.message).toBe("read this"); |
144 | 144 | expect(saveMediaBufferMock).toHaveBeenCalledOnce(); |
145 | | -expect(saveMediaBufferMock.mock.calls[0]?.[1]).toBe("application/pdf"); |
| 145 | +expect(saveMediaBufferMock.mock.calls.at(0)?.[1]).toBe("application/pdf"); |
146 | 146 | expect(logs).toHaveLength(0); |
147 | 147 | }); |
148 | 148 | |
@@ -155,7 +155,7 @@ describe("parseMessageWithAttachments", () => {
|
155 | 155 | ]); |
156 | 156 | expect(parsed.offloadedRefs).toHaveLength(1); |
157 | 157 | expect(parsed.offloadedRefs[0]?.mimeType).toBe("application/octet-stream"); |
158 | | -expect(saveMediaBufferMock.mock.calls[0]?.[1]).toBe("application/octet-stream"); |
| 158 | +expect(saveMediaBufferMock.mock.calls.at(0)?.[1]).toBe("application/octet-stream"); |
159 | 159 | expect(parsed.message).toBe("take a look"); |
160 | 160 | expect(logs).toHaveLength(0); |
161 | 161 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -56,7 +56,7 @@ describe("handleControlUiHttpRequest auto-detected root", () => {
|
56 | 56 | |
57 | 57 | expect(handled).toBe(true); |
58 | 58 | expect(res.statusCode).toBe(200); |
59 | | -expect(String(end.mock.calls[0]?.[0] ?? "")).toBe("console.log('hi');"); |
| 59 | +expect(String(end.mock.calls.at(0)?.[0] ?? "")).toBe("console.log('hi');"); |
60 | 60 | }); |
61 | 61 | }); |
62 | 62 | |
@@ -77,7 +77,7 @@ describe("handleControlUiHttpRequest auto-detected root", () => {
|
77 | 77 | |
78 | 78 | expect(handled).toBe(true); |
79 | 79 | expect(res.statusCode).toBe(200); |
80 | | -expect(String(end.mock.calls[0]?.[0] ?? "")).toBe("<html>fallback-hardlink</html>\n"); |
| 80 | +expect(String(end.mock.calls.at(0)?.[0] ?? "")).toBe("<html>fallback-hardlink</html>\n"); |
81 | 81 | }); |
82 | 82 | }); |
83 | 83 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -667,8 +667,8 @@ describe("createManagedOutgoingImageBlocks", () => {
|
667 | 667 | expect(blocks).toHaveLength(1); |
668 | 668 | expect(requireBlock(blocks).type).toBe("image"); |
669 | 669 | expect(onPrepareError).toHaveBeenCalledTimes(1); |
670 | | -expect(onPrepareError.mock.calls[0]?.[0]).toBeInstanceOf(Error); |
671 | | -expect(onPrepareError.mock.calls[0]?.[0]?.message).toMatch( |
| 670 | +expect(onPrepareError.mock.calls.at(0)?.[0]).toBeInstanceOf(Error); |
| 671 | +expect(onPrepareError.mock.calls.at(0)?.[0]?.message).toMatch( |
672 | 672 | /Managed image attachment .* could not be prepared/i, |
673 | 673 | ); |
674 | 674 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -201,7 +201,7 @@ describe("createGatewayCloseHandler", () => {
|
201 | 201 | await close({ reason: "SIGTERM" }); |
202 | 202 | |
203 | 203 | expect(drainActiveSessionsForShutdown).toHaveBeenCalledTimes(1); |
204 | | -expect(drainActiveSessionsForShutdown.mock.calls[0]?.[0]?.reason).toBe("shutdown"); |
| 204 | +expect(drainActiveSessionsForShutdown.mock.calls.at(0)?.[0]?.reason).toBe("shutdown"); |
205 | 205 | }); |
206 | 206 | |
207 | 207 | it("drains the active-session tracker with reason=restart when restartExpectedMs is set", async () => { |
@@ -216,7 +216,7 @@ describe("createGatewayCloseHandler", () => {
|
216 | 216 | await close({ reason: "gateway restarting", restartExpectedMs: 1234 }); |
217 | 217 | |
218 | 218 | expect(drainActiveSessionsForShutdown).toHaveBeenCalledTimes(1); |
219 | | -expect(drainActiveSessionsForShutdown.mock.calls[0]?.[0]?.reason).toBe("restart"); |
| 219 | +expect(drainActiveSessionsForShutdown.mock.calls.at(0)?.[0]?.reason).toBe("restart"); |
220 | 220 | }); |
221 | 221 | |
222 | 222 | it("records a warning and continues shutdown when the session-end drain reports a timeout", async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -89,7 +89,7 @@ describe("agent handler session create events", () => {
|
89 | 89 | req: { id: "req-agent-create-event" } as never, |
90 | 90 | }); |
91 | 91 | |
92 | | -const responseCall = respond.mock.calls[0] as |
| 92 | +const responseCall = respond.mock.calls.at(0) as |
93 | 93 | | [boolean, { status?: string; runId?: string }, unknown, { runId?: string }] |
94 | 94 | | undefined; |
95 | 95 | expect(responseCall?.[0]).toBe(true); |
@@ -99,7 +99,7 @@ describe("agent handler session create events", () => {
|
99 | 99 | expect(responseCall?.[3]?.runId).toBe("idem-agent-create-event"); |
100 | 100 | await vi.waitFor( |
101 | 101 | () => { |
102 | | -const call = broadcastToConnIds.mock.calls[0] as |
| 102 | +const call = broadcastToConnIds.mock.calls.at(0) as |
103 | 103 | | [ |
104 | 104 | string, |
105 | 105 | { sessionKey?: string; reason?: string }, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -77,15 +77,15 @@ function requireRecord(value: unknown): Record<string, unknown> {
|
77 | 77 | } |
78 | 78 | |
79 | 79 | function requireFirstCallArg(mock: { mock: { calls: readonly (readonly unknown[])[] } }) { |
80 | | -const call = mock.mock.calls[0]; |
| 80 | +const call = mock.mock.calls.at(0); |
81 | 81 | if (!call) { |
82 | 82 | throw new Error("Expected first mock call"); |
83 | 83 | } |
84 | 84 | return call[0]; |
85 | 85 | } |
86 | 86 | |
87 | 87 | function requireRespondPayload(respond: ReturnType<typeof vi.fn>): Record<string, unknown> { |
88 | | -const call = respond.mock.calls[0]; |
| 88 | +const call = respond.mock.calls.at(0); |
89 | 89 | if (!call) { |
90 | 90 | throw new Error("Expected respond call"); |
91 | 91 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -48,7 +48,7 @@ describe("diagnostics gateway methods", () => {
|
48 | 48 | }); |
49 | 49 | |
50 | 50 | expect(respond).toHaveBeenCalledTimes(1); |
51 | | -expect(respond.mock.calls[0]).toEqual([ |
| 51 | +expect(respond.mock.calls.at(0)).toEqual([ |
52 | 52 | true, |
53 | 53 | { |
54 | 54 | generatedAt: now.toISOString(), |
@@ -84,7 +84,9 @@ describe("diagnostics gateway methods", () => {
|
84 | 84 | }, |
85 | 85 | undefined, |
86 | 86 | ]); |
87 | | -expect(Object.keys(respond.mock.calls[0]?.[1] as Record<string, unknown>).toSorted()).toEqual([ |
| 87 | +expect( |
| 88 | +Object.keys(respond.mock.calls.at(0)?.[1] as Record<string, unknown>).toSorted(), |
| 89 | +).toEqual([ |
88 | 90 | "capacity", |
89 | 91 | "count", |
90 | 92 | "dropped", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1311,7 +1311,7 @@ describe("doctor.memory.remHarness", () => {
|
1311 | 1311 | await invokeDoctorMemoryRemHarness(respond); |
1312 | 1312 | |
1313 | 1313 | expectRecordFields(mockCallArg(previewRemHarness), { candidateLimit: 25 }); |
1314 | | -const payload = respond.mock.calls[0]?.[1] as { |
| 1314 | +const payload = respond.mock.calls.at(0)?.[1] as { |
1315 | 1315 | ok: boolean; |
1316 | 1316 | deep: { candidateLimit: number; truncated: boolean; candidates: unknown[] }; |
1317 | 1317 | }; |
@@ -1327,7 +1327,7 @@ describe("doctor.memory.remHarness", () => {
|
1327 | 1327 | await invokeDoctorMemoryRemHarness(respond, { limit: 500 }); |
1328 | 1328 | |
1329 | 1329 | expectRecordFields(mockCallArg(previewRemHarness), { candidateLimit: 100 }); |
1330 | | -const payload = respond.mock.calls[0]?.[1] as { |
| 1330 | +const payload = respond.mock.calls.at(0)?.[1] as { |
1331 | 1331 | deep: { candidateLimit: number }; |
1332 | 1332 | }; |
1333 | 1333 | expect(payload.deep.candidateLimit).toBe(100); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -100,7 +100,7 @@ describe("node.pending handlers", () => {
|
100 | 100 | isWebchatConnect: () => false, |
101 | 101 | }); |
102 | 102 | |
103 | | -const call = respond.mock.calls[0] as RespondCall | undefined; |
| 103 | +const call = respond.mock.calls.at(0) as RespondCall | undefined; |
104 | 104 | expect(call?.[0]).toBe(false); |
105 | 105 | expect(call?.[2]?.message).toContain("connected device identity"); |
106 | 106 | }); |
@@ -166,7 +166,7 @@ describe("node.pending handlers", () => {
|
166 | 166 | timeoutMs: 3_000, |
167 | 167 | }); |
168 | 168 | expect(mocks.maybeSendNodeWakeNudge).not.toHaveBeenCalled(); |
169 | | -const call = respond.mock.calls[0] as |
| 169 | +const call = respond.mock.calls.at(0) as |
170 | 170 | | [boolean, { nodeId?: string; revision?: number; wakeTriggered?: boolean }, unknown?] |
171 | 171 | | undefined; |
172 | 172 | expect(call?.[0]).toBe(true); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -356,7 +356,7 @@ describe("createPluginApprovalHandlers", () => {
|
356 | 356 | }, |
357 | 357 | ); |
358 | 358 | await handlers["plugin.approval.request"](opts); |
359 | | -const result = respond.mock.calls[0]?.[1] as Record<string, unknown> | undefined; |
| 359 | +const result = respond.mock.calls.at(0)?.[1] as Record<string, unknown> | undefined; |
360 | 360 | expectPluginApprovalId(result?.id, "generated plugin approval id"); |
361 | 361 | }); |
362 | 362 | |
@@ -374,7 +374,7 @@ describe("createPluginApprovalHandlers", () => {
|
374 | 374 | await handlers["plugin.approval.request"](opts); |
375 | 375 | |
376 | 376 | expect(createSpy).toHaveBeenCalledTimes(1); |
377 | | -expectPluginApprovalId(createSpy.mock.calls[0]?.[2], "manager.create approval id"); |
| 377 | +expectPluginApprovalId(createSpy.mock.calls.at(0)?.[2], "manager.create approval id"); |
378 | 378 | }); |
379 | 379 | |
380 | 380 | it("rejects plugin-provided id field", async () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。