test: guard before tool call mock calls · openclaw/openclaw@c6cfd12
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -38,7 +38,7 @@ describe("runEmbeddedPiAgent cron before_agent_reply seam", () => {
|
38 | 38 | |
39 | 39 | expect(mockedGlobalHookRunner.runBeforeAgentReply).toHaveBeenCalledTimes(1); |
40 | 40 | const [hookPayload, hookContext] = |
41 | | -mockedGlobalHookRunner.runBeforeAgentReply.mock.calls[0] ?? []; |
| 41 | +mockedGlobalHookRunner.runBeforeAgentReply.mock.calls.at(0) ?? []; |
42 | 42 | expect(hookPayload).toEqual({ |
43 | 43 | cleanedBody: "__openclaw_memory_core_short_term_promotion_dream__", |
44 | 44 | }); |
@@ -94,7 +94,7 @@ describe("runEmbeddedPiAgent cron before_agent_reply seam", () => {
|
94 | 94 | promptMode: "none", |
95 | 95 | }); |
96 | 96 | |
97 | | -const [attemptParams] = (mockedRunEmbeddedAttempt.mock.calls[0] ?? []) as [ |
| 97 | +const [attemptParams] = (mockedRunEmbeddedAttempt.mock.calls.at(0) ?? []) as [ |
98 | 98 | { modelRun?: boolean; promptMode?: string }?, |
99 | 99 | ]; |
100 | 100 | expect(attemptParams?.modelRun).toBe(true); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -410,7 +410,7 @@ describe("handleToolExecutionEnd media emission", () => {
|
410 | 410 | |
411 | 411 | expect(ctx.emitToolOutput).toHaveBeenCalledTimes(1); |
412 | 412 | const emitToolOutput = vi.mocked(ctx.emitToolOutput); |
413 | | -const [toolName, summary, output, options] = emitToolOutput.mock.calls[0] ?? []; |
| 413 | +const [toolName, summary, output, options] = emitToolOutput.mock.calls.at(0) ?? []; |
414 | 414 | expect(toolName).toBe("tts"); |
415 | 415 | expect(summary).toBeUndefined(); |
416 | 416 | expect(output).toBe("remote tool output"); |
@@ -486,7 +486,7 @@ describe("handleToolExecutionEnd media emission", () => {
|
486 | 486 | |
487 | 487 | expect(ctx.emitToolOutput).toHaveBeenCalledTimes(1); |
488 | 488 | const emitToolOutput = vi.mocked(ctx.emitToolOutput); |
489 | | -const [calledToolName, summary, output, options] = emitToolOutput.mock.calls[0] ?? []; |
| 489 | +const [calledToolName, summary, output, options] = emitToolOutput.mock.calls.at(0) ?? []; |
490 | 490 | expect(calledToolName).toBe(toolName); |
491 | 491 | expect(summary).toBeUndefined(); |
492 | 492 | expect(output).toBe(providerInventoryText); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -83,7 +83,7 @@ describe("subscribeEmbeddedPiSession", () => {
|
83 | 83 | await Promise.resolve(); |
84 | 84 | |
85 | 85 | expect(onBlockReply).toHaveBeenCalledTimes(1); |
86 | | -expect(onBlockReply.mock.calls[0]?.[0]?.text).toBe("Short chunk."); |
| 86 | +expect(onBlockReply.mock.calls.at(0)?.[0]?.text).toBe("Short chunk."); |
87 | 87 | expect(onBlockReplyFlush).toHaveBeenCalledTimes(1); |
88 | 88 | }); |
89 | 89 | |
@@ -157,7 +157,7 @@ describe("subscribeEmbeddedPiSession", () => {
|
157 | 157 | await Promise.resolve(); |
158 | 158 | |
159 | 159 | expect(onBlockReply).toHaveBeenCalledTimes(1); |
160 | | -expect(onBlockReply.mock.calls[0]?.[0]?.text).toBe("Final reply before lifecycle end."); |
| 160 | +expect(onBlockReply.mock.calls.at(0)?.[0]?.text).toBe("Final reply before lifecycle end."); |
161 | 161 | expect(onBlockReplyFlush).toHaveBeenCalledTimes(1); |
162 | 162 | }); |
163 | 163 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -64,7 +64,7 @@ describe("pi tool definition adapter logging", () => {
|
64 | 64 | |
65 | 65 | await def.execute("call-edit-1", { path: "notes.txt" }, undefined, undefined, extensionContext); |
66 | 66 | |
67 | | -expect(vi.mocked(logError).mock.calls[0]?.[0]).toContain( |
| 67 | +expect(vi.mocked(logError).mock.calls.at(0)?.[0]).toContain( |
68 | 68 | '[tools] edit failed: Missing required parameter: edits (received: path). Supply correct parameters before retrying. raw_params={"path":"notes.txt"}', |
69 | 69 | ); |
70 | 70 | }); |
@@ -139,7 +139,7 @@ describe("pi tool definition adapter logging", () => {
|
139 | 139 | expect(details?.status).toBe("error"); |
140 | 140 | expect(details?.tool).toBe("web_search"); |
141 | 141 | expect(details?.error).toBe("This operation was aborted"); |
142 | | -expect(vi.mocked(logError).mock.calls[0]?.[0]).toContain( |
| 142 | +expect(vi.mocked(logError).mock.calls.at(0)?.[0]).toContain( |
143 | 143 | "[tools] web_search failed: This operation was aborted", |
144 | 144 | ); |
145 | 145 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1009,12 +1009,12 @@ describe("before_tool_call requireApproval handling", () => {
|
1009 | 1009 | |
1010 | 1010 | expect(result.blocked).toBe(false); |
1011 | 1011 | expect(mockCallGateway).toHaveBeenCalledTimes(2); |
1012 | | -const requestCall = mockCallGateway.mock.calls[0]; |
| 1012 | +const requestCall = mockCallGateway.mock.calls.at(0); |
1013 | 1013 | expect(requestCall?.[0]).toBe("plugin.approval.request"); |
1014 | 1014 | requireRecord(requestCall?.[1], "approval request gateway client"); |
1015 | 1015 | expect(requireRecord(requestCall?.[2], "approval request params").twoPhase).toBe(true); |
1016 | 1016 | expect(requestCall?.[3]).toEqual({ expectFinal: false }); |
1017 | | -const waitCall = mockCallGateway.mock.calls[1]; |
| 1017 | +const waitCall = mockCallGateway.mock.calls.at(1); |
1018 | 1018 | expect(waitCall?.[0]).toBe("plugin.approval.waitDecision"); |
1019 | 1019 | requireRecord(waitCall?.[1], "approval wait gateway client"); |
1020 | 1020 | expect(waitCall?.[2]).toEqual({ id: "server-id-1" }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -490,14 +490,16 @@ export async function runBeforeToolCallHook(args: {
|
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
493 | | -recordToolCall( |
494 | | -sessionState, |
495 | | -toolName, |
496 | | -params, |
497 | | -args.toolCallId, |
498 | | -args.ctx.loopDetection, |
499 | | -loopScope, |
500 | | -); |
| 493 | +if (args.ctx.loopDetection?.enabled !== false) { |
| 494 | +recordToolCall( |
| 495 | +sessionState, |
| 496 | +toolName, |
| 497 | +params, |
| 498 | +args.toolCallId, |
| 499 | +args.ctx.loopDetection, |
| 500 | +loopScope, |
| 501 | +); |
| 502 | +} |
501 | 503 | } |
502 | 504 | |
503 | 505 | const hookRunner = getGlobalHookRunner(); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。