


















@@ -1,5 +1,6 @@
11import type { AssistantMessage } from "@earendil-works/pi-ai";
22import { describe, expect, it, vi } from "vitest";
3+import { HEARTBEAT_RESPONSE_TOOL_NAME } from "../auto-reply/heartbeat-tool-response.js";
34import * as agentEvents from "../infra/agent-events.js";
45import {
56THINKING_TAG_CASES,
@@ -1218,4 +1219,61 @@ describe("subscribeEmbeddedPiSession", () => {
12181219replayInvalid: true,
12191220});
12201221});
1222+1223+it("notifies the runner once when a heartbeat response tool result is recorded", async () => {
1224+const { session, emit } = createStubSessionHarness();
1225+const onHeartbeatToolResponse = vi.fn();
1226+const subscription = subscribeEmbeddedPiSession({
1227+ session,
1228+runId: "run-heartbeat-terminal",
1229+sessionKey: "agent:main:main",
1230+ onHeartbeatToolResponse,
1231+});
1232+1233+const result = {
1234+details: {
1235+status: "recorded",
1236+outcome: "no_change",
1237+notify: false,
1238+summary: "Nothing needs attention.",
1239+},
1240+};
1241+emitToolRun({
1242+ emit,
1243+toolName: HEARTBEAT_RESPONSE_TOOL_NAME,
1244+toolCallId: "heartbeat-1",
1245+args: {
1246+outcome: "no_change",
1247+notify: false,
1248+summary: "Nothing needs attention.",
1249+},
1250+isError: false,
1251+ result,
1252+});
1253+emitToolRun({
1254+ emit,
1255+toolName: HEARTBEAT_RESPONSE_TOOL_NAME,
1256+toolCallId: "heartbeat-2",
1257+args: {
1258+outcome: "no_change",
1259+notify: false,
1260+summary: "Nothing needs attention.",
1261+},
1262+isError: false,
1263+ result,
1264+});
1265+await flushBlockReplyCallbacks();
1266+1267+expect(subscription.getHeartbeatToolResponse()).toEqual({
1268+outcome: "no_change",
1269+notify: false,
1270+summary: "Nothing needs attention.",
1271+});
1272+expect(onHeartbeatToolResponse).toHaveBeenCalledTimes(1);
1273+expect(onHeartbeatToolResponse).toHaveBeenCalledWith({
1274+outcome: "no_change",
1275+notify: false,
1276+summary: "Nothing needs attention.",
1277+});
1278+});
12211279});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。