test: guard embedded three-hit mock calls · openclaw/openclaw@521ac5d
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -320,8 +320,9 @@ describe("runEmbeddedPiAgent", () => {
|
320 | 320 | enqueue: immediateEnqueue, |
321 | 321 | }); |
322 | 322 | |
323 | | -const resolveModelCall = (resolveModelAsyncMock as unknown as { mock: { calls: unknown[][] } }) |
324 | | -.mock.calls[0]; |
| 323 | +const resolveModelCall = ( |
| 324 | +resolveModelAsyncMock as unknown as { mock: { calls: unknown[][] } } |
| 325 | +).mock.calls.at(0); |
325 | 326 | expect(resolveModelCall?.[0]).toBe("openrouter"); |
326 | 327 | expect(resolveModelCall?.[1]).toBe("openrouter/auto"); |
327 | 328 | expect(resolveModelCall?.[2]).toBe(agentDir); |
@@ -369,7 +370,7 @@ describe("runEmbeddedPiAgent", () => {
|
369 | 370 | sessionId: "resume-123", |
370 | 371 | agentId: undefined, |
371 | 372 | }); |
372 | | -const firstCall = runEmbeddedAttemptMock.mock.calls[0]?.[0] as { sessionKey?: string }; |
| 373 | +const firstCall = runEmbeddedAttemptMock.mock.calls.at(0)?.[0] as { sessionKey?: string }; |
373 | 374 | expect(firstCall.sessionKey).toBe("agent:test:resolved"); |
374 | 375 | }); |
375 | 376 | |
@@ -410,7 +411,7 @@ describe("runEmbeddedPiAgent", () => {
|
410 | 411 | sessionId: "resume-124", |
411 | 412 | agentId: undefined, |
412 | 413 | }); |
413 | | -const firstCall = runEmbeddedAttemptMock.mock.calls[0]?.[0] as { sessionKey?: string }; |
| 414 | +const firstCall = runEmbeddedAttemptMock.mock.calls.at(0)?.[0] as { sessionKey?: string }; |
414 | 415 | expect(firstCall.sessionKey).toBeUndefined(); |
415 | 416 | }); |
416 | 417 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -75,7 +75,7 @@ describe("createFailoverDecisionLogger", () => {
|
75 | 75 | |
76 | 76 | logDecision("fallback_model"); |
77 | 77 | |
78 | | -const [message, details] = warnSpy.mock.calls[0] ?? []; |
| 78 | +const [message, details] = warnSpy.mock.calls.at(0) ?? []; |
79 | 79 | expect(message).toBe("embedded run failover decision"); |
80 | 80 | const observation = details as |
81 | 81 | | { |
@@ -115,10 +115,10 @@ describe("createFailoverDecisionLogger", () => {
|
115 | 115 | logDecision("surface_error"); |
116 | 116 | |
117 | 117 | expect( |
118 | | -(warnSpy.mock.calls[0]?.[1] as { consoleMessage?: string } | undefined)?.consoleMessage, |
| 118 | +(warnSpy.mock.calls.at(0)?.[1] as { consoleMessage?: string } | undefined)?.consoleMessage, |
119 | 119 | ).toContain("from=openai/gpt-5.4"); |
120 | 120 | expect( |
121 | | -(warnSpy.mock.calls[0]?.[1] as { consoleMessage?: string } | undefined)?.consoleMessage, |
| 121 | +(warnSpy.mock.calls.at(0)?.[1] as { consoleMessage?: string } | undefined)?.consoleMessage, |
122 | 122 | ).not.toContain("to=openai/gpt-5.4"); |
123 | 123 | }); |
124 | 124 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -83,7 +83,7 @@ describe("runEmbeddedPiAgent usage reporting", () => {
|
83 | 83 | workspaceDir: "/tmp/workspace", |
84 | 84 | allowGatewaySubagentBinding: true, |
85 | 85 | }); |
86 | | -const attemptInput = mockedRunEmbeddedAttempt.mock.calls[0]?.[0] as |
| 86 | +const attemptInput = mockedRunEmbeddedAttempt.mock.calls.at(0)?.[0] as |
87 | 87 | | { allowGatewaySubagentBinding?: boolean } |
88 | 88 | | undefined; |
89 | 89 | expect(attemptInput?.allowGatewaySubagentBinding).toBe(true); |
@@ -110,7 +110,7 @@ describe("runEmbeddedPiAgent usage reporting", () => {
|
110 | 110 | senderE164: "+15551234567", |
111 | 111 | }); |
112 | 112 | |
113 | | -const attemptInput = mockedRunEmbeddedAttempt.mock.calls[0]?.[0] as |
| 113 | +const attemptInput = mockedRunEmbeddedAttempt.mock.calls.at(0)?.[0] as |
114 | 114 | | { |
115 | 115 | senderId?: string; |
116 | 116 | senderName?: string; |
@@ -143,7 +143,7 @@ describe("runEmbeddedPiAgent usage reporting", () => {
|
143 | 143 | memoryFlushWritePath: "memory/2026-03-10.md", |
144 | 144 | }); |
145 | 145 | |
146 | | -const attemptInput = mockedRunEmbeddedAttempt.mock.calls[0]?.[0] as |
| 146 | +const attemptInput = mockedRunEmbeddedAttempt.mock.calls.at(0)?.[0] as |
147 | 147 | | { trigger?: string; memoryFlushWritePath?: string } |
148 | 148 | | undefined; |
149 | 149 | expect(attemptInput?.trigger).toBe("memory"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -584,7 +584,7 @@ describe("handleMessageUpdate commentary phase", () => {
|
584 | 584 | ); |
585 | 585 | |
586 | 586 | expect(onAgentEvent).toHaveBeenCalledTimes(1); |
587 | | -const event = onAgentEvent.mock.calls[0]?.[0] as |
| 587 | +const event = onAgentEvent.mock.calls.at(0)?.[0] as |
588 | 588 | | { stream?: string; data?: { text?: string; delta?: string } } |
589 | 589 | | undefined; |
590 | 590 | expect(event?.stream).toBe("assistant"); |
@@ -629,7 +629,7 @@ describe("handleMessageEnd", () => {
|
629 | 629 | }, |
630 | 630 | } as never); |
631 | 631 | |
632 | | -const warnCall = warn.mock.calls[0]; |
| 632 | +const warnCall = warn.mock.calls.at(0); |
633 | 633 | expect(warnCall?.[0]).toBe( |
634 | 634 | "Assistant reply looks like a tool call, but no structured tool invocation was emitted; treating it as text.", |
635 | 635 | ); |
@@ -839,7 +839,7 @@ describe("handleMessageEnd", () => {
|
839 | 839 | } as never); |
840 | 840 | |
841 | 841 | expect(onAgentEvent).toHaveBeenCalledTimes(1); |
842 | | -const event = onAgentEvent.mock.calls[0]?.[0] as |
| 842 | +const event = onAgentEvent.mock.calls.at(0)?.[0] as |
843 | 843 | | { stream?: string; data?: { text?: string; delta?: string; replace?: boolean } } |
844 | 844 | | undefined; |
845 | 845 | expect(event?.stream).toBe("assistant"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -41,7 +41,7 @@ describe("subscribeEmbeddedPiSession reply tags", () => {
|
41 | 41 | emit({ type: "message_end", message: assistantMessage }); |
42 | 42 | |
43 | 43 | expect(onBlockReply).toHaveBeenCalledTimes(1); |
44 | | -const payload = onBlockReply.mock.calls[0]?.[0]; |
| 44 | +const payload = onBlockReply.mock.calls.at(0)?.[0]; |
45 | 45 | expect(payload?.text).toBe("Hello"); |
46 | 46 | expect(payload?.replyToCurrent).toBe(true); |
47 | 47 | expect(payload?.replyToTag).toBe(true); |
@@ -61,8 +61,8 @@ describe("subscribeEmbeddedPiSession reply tags", () => {
|
61 | 61 | emit({ type: "message_end", message: assistantMessage }); |
62 | 62 | |
63 | 63 | expect(onBlockReply).toHaveBeenCalledTimes(2); |
64 | | -expect(onBlockReply.mock.calls[0]?.[0]?.text).toBe("Hello"); |
65 | | -expect(onBlockReply.mock.calls[1]?.[0]?.text).toBe("[["); |
| 64 | +expect(onBlockReply.mock.calls.at(0)?.[0]?.text).toBe("Hello"); |
| 65 | +expect(onBlockReply.mock.calls.at(1)?.[0]?.text).toBe("[["); |
66 | 66 | }); |
67 | 67 | |
68 | 68 | it("streams partial replies past reply_to tags split across chunks", () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。