

























@@ -81,6 +81,38 @@ describe("runHeartbeatOnce heartbeat response tool", () => {
8181]);
8282}
838384+function replyCall(replySpy: ReturnType<typeof vi.fn>): unknown[] {
85+const call = replySpy.mock.calls.at(0);
86+if (!call) {
87+throw new Error("Expected reply call");
88+}
89+return call;
90+}
91+92+function replyContext(replySpy: ReturnType<typeof vi.fn>): { Body?: string } {
93+const context = replyCall(replySpy).at(0);
94+if (!context || typeof context !== "object") {
95+throw new Error("Expected reply context");
96+}
97+return context as { Body?: string };
98+}
99+100+function replyOptions(replySpy: ReturnType<typeof vi.fn>): {
101+enableHeartbeatTool?: boolean;
102+forceHeartbeatTool?: boolean;
103+sourceReplyDeliveryMode?: string;
104+} {
105+const options = replyCall(replySpy).at(1);
106+if (!options || typeof options !== "object") {
107+throw new Error("Expected reply options");
108+}
109+return options as {
110+enableHeartbeatTool?: boolean;
111+forceHeartbeatTool?: boolean;
112+sourceReplyDeliveryMode?: string;
113+};
114+}
115+84116async function runWithToolResponse(response: HeartbeatToolResponse) {
85117return await withTempTelegramHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {
86118const cfg = createConfig({ tmpDir, storePath });
@@ -136,12 +168,8 @@ describe("runHeartbeatOnce heartbeat response tool", () => {
136168});
137169138170return {
139-calledCtx: replySpy.mock.calls[0]?.[0] as { Body?: string },
140-calledOpts: replySpy.mock.calls[0]?.[1] as {
141-enableHeartbeatTool?: boolean;
142-forceHeartbeatTool?: boolean;
143-sourceReplyDeliveryMode?: string;
144-},
171+calledCtx: replyContext(replySpy),
172+calledOpts: replyOptions(replySpy),
145173};
146174});
147175}
@@ -226,9 +254,7 @@ describe("runHeartbeatOnce heartbeat response tool", () => {
226254deps: createDeps({ sendTelegram, getReplyFromConfig: replySpy }),
227255});
228256229-const calledOpts = replySpy.mock.calls[0]?.[1] as {
230-sourceReplyDeliveryMode?: string;
231-};
257+const calledOpts = replyOptions(replySpy);
232258expect(result.status).toBe("ran");
233259expect(calledOpts.sourceReplyDeliveryMode).toBe("message_tool_only");
234260expectTelegramSend(sendTelegram, {
@@ -302,12 +328,8 @@ describe("runHeartbeatOnce heartbeat response tool", () => {
302328deps: createDeps({ sendTelegram, getReplyFromConfig: replySpy }),
303329});
304330305-const calledCtx = replySpy.mock.calls[0]?.[0] as { Body?: string };
306-const calledOpts = replySpy.mock.calls[0]?.[1] as {
307-enableHeartbeatTool?: boolean;
308-forceHeartbeatTool?: boolean;
309-sourceReplyDeliveryMode?: string;
310-};
331+const calledCtx = replyContext(replySpy);
332+const calledOpts = replyOptions(replySpy);
311333expect(calledCtx.Body).toContain("HEARTBEAT_OK");
312334expect(calledCtx.Body).not.toContain("heartbeat_respond");
313335expect(calledOpts.enableHeartbeatTool).toBeUndefined();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。