|
1 | 1 | // Tool loop detection tests cover repeated-call hashing, ping-pong detection, |
2 | 2 | // unknown-tool thresholds, and circuit-breaker escalation. |
3 | | -import { describe, expect, it } from "vitest"; |
| 3 | +import { describe, expect, it, vi } from "vitest"; |
4 | 4 | import type { ToolLoopDetectionConfig } from "../config/types.tools.js"; |
5 | 5 | import type { SessionState } from "../logging/diagnostic-session-state.js"; |
| 6 | + |
| 7 | +// Recognize a provider-docked send tool by name (only "telegram" here) so the |
| 8 | +// volatility strip applies to it without pulling in the channel-plugin registry; the |
| 9 | +// real detector is covered by embedded-agent-messaging's own tests. |
| 10 | +const isMessagingToolSendActionMock = vi.hoisted(() => |
| 11 | + vi.fn((toolName: string): boolean => toolName === "telegram"), |
| 12 | +); |
| 13 | +vi.mock("./embedded-agent-messaging.js", () => ({ |
| 14 | + isMessagingToolSendAction: isMessagingToolSendActionMock, |
| 15 | +})); |
6 | 16 | import { |
7 | 17 | CRITICAL_THRESHOLD, |
8 | 18 | GLOBAL_CIRCUIT_BREAKER_THRESHOLD, |
@@ -1013,6 +1023,19 @@ describe("tool-loop-detection", () => { |
1013 | 1023 | } |
1014 | 1024 | }); |
1015 | 1025 |
|
| 1026 | + it("escalates provider-docked send-tool loops (e.g. telegram) whose result carries fresh ids", () => { |
| 1027 | + const state = createState(); |
| 1028 | + const params = { to: "telegram:123", text: "ping" }; |
| 1029 | + for (let i = 0; i < CRITICAL_THRESHOLD; i += 1) { |
| 1030 | + recordSend(state, "telegram", params, sendPayload(i), i); |
| 1031 | + } |
| 1032 | + const loopResult = detectToolCallLoop(state, "telegram", params, enabledLoopDetectionConfig); |
| 1033 | + expect(loopResult.stuck).toBe(true); |
| 1034 | + if (loopResult.stuck) { |
| 1035 | + expect(loopResult.level).toBe("critical"); |
| 1036 | + } |
| 1037 | + }); |
| 1038 | + |
1016 | 1039 | it("escalates sibling delivery actions (reply) the same as send", () => { |
1017 | 1040 | const state = createState(); |
1018 | 1041 | const params = { action: "reply", target: "feishu:oc_chat", text: "ping" }; |
|
0 commit comments