

























@@ -93,8 +93,10 @@ function expectAfterToolCallPayload(params: {
9393expectedContext: Record<string, unknown>;
9494}) {
9595const { event, context } = requireAfterToolCallCall(params.index);
96-expect(event).toEqual(expect.objectContaining(params.expectedEvent));
97-expect(context).toEqual(expect.objectContaining(params.expectedContext));
96+const { durationMs, ...stableEvent } = event;
97+expect(typeof durationMs).toBe("number");
98+expect(stableEvent).toEqual(params.expectedEvent);
99+expect(context).toEqual(params.expectedContext);
98100}
99101100102let handleToolExecutionStart: typeof import("../agents/pi-embedded-subscribe.handlers.tools.js").handleToolExecutionStart;
@@ -155,6 +157,7 @@ describe("after_tool_call hook wiring", () => {
155157error: undefined,
156158runId: "test-run-1",
157159toolCallId: "wired-hook-call-1",
160+result: { content: [{ type: "text", text: "file contents" }] },
158161},
159162expectedContext: {
160163toolName: "read",
@@ -165,7 +168,6 @@ describe("after_tool_call hook wiring", () => {
165168toolCallId: "wired-hook-call-1",
166169},
167170});
168-expect(typeof getAfterToolCallCall().event?.durationMs).toBe("number");
169171});
170172171173it("includes error in after_tool_call event on tool failure", async () => {
@@ -279,13 +281,41 @@ describe("after_tool_call hook wiring", () => {
279281expect(hookMocks.runner.runAfterToolCall).toHaveBeenCalledTimes(2);
280282expectAfterToolCallPayload({
281283index: 0,
282-expectedEvent: { runId: "run-a", params: { path: "/tmp/path-a.txt" } },
283-expectedContext: {},
284+expectedEvent: {
285+toolName: "read",
286+params: { path: "/tmp/path-a.txt" },
287+runId: "run-a",
288+toolCallId: sharedToolCallId,
289+result: { content: [{ type: "text", text: "done-a" }] },
290+error: undefined,
291+},
292+expectedContext: {
293+toolName: "read",
294+agentId: "agent-a",
295+sessionKey: "session-a",
296+sessionId: "ephemeral-a",
297+runId: "run-a",
298+toolCallId: sharedToolCallId,
299+},
284300});
285301expectAfterToolCallPayload({
286302index: 1,
287-expectedEvent: { runId: "run-b", params: { path: "/tmp/path-b.txt" } },
288-expectedContext: {},
303+expectedEvent: {
304+toolName: "read",
305+params: { path: "/tmp/path-b.txt" },
306+runId: "run-b",
307+toolCallId: sharedToolCallId,
308+result: { content: [{ type: "text", text: "done-b" }] },
309+error: undefined,
310+},
311+expectedContext: {
312+toolName: "read",
313+agentId: "agent-b",
314+sessionKey: "session-b",
315+sessionId: "ephemeral-b",
316+runId: "run-b",
317+toolCallId: sharedToolCallId,
318+},
289319});
290320});
291321});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。