|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import { handleToolExecutionStart } from "./pi-embedded-subscribe.handlers.tools.js"; |
| 3 | + |
| 4 | +function createTestContext() { |
| 5 | + const onBlockReplyFlush = vi.fn(); |
| 6 | + const warn = vi.fn(); |
| 7 | + const ctx = { |
| 8 | + params: { |
| 9 | + runId: "run-test", |
| 10 | + onBlockReplyFlush, |
| 11 | + onAgentEvent: undefined, |
| 12 | + onToolResult: undefined, |
| 13 | + }, |
| 14 | + flushBlockReplyBuffer: vi.fn(), |
| 15 | + hookRunner: undefined, |
| 16 | + log: { |
| 17 | + debug: vi.fn(), |
| 18 | + warn, |
| 19 | + }, |
| 20 | + state: { |
| 21 | + toolMetaById: new Map<string, string | undefined>(), |
| 22 | + toolSummaryById: new Set<string>(), |
| 23 | + pendingMessagingTargets: new Map<string, unknown>(), |
| 24 | + pendingMessagingTexts: new Map<string, string>(), |
| 25 | + messagingToolSentTexts: [], |
| 26 | + messagingToolSentTextsNormalized: [], |
| 27 | + messagingToolSentTargets: [], |
| 28 | + }, |
| 29 | + shouldEmitToolResult: () => false, |
| 30 | + emitToolSummary: vi.fn(), |
| 31 | + trimMessagingToolSent: vi.fn(), |
| 32 | + } as const; |
| 33 | + |
| 34 | + return { ctx, warn, onBlockReplyFlush }; |
| 35 | +} |
| 36 | + |
| 37 | +describe("handleToolExecutionStart read path checks", () => { |
| 38 | + it("does not warn when read tool uses file_path alias", async () => { |
| 39 | + const { ctx, warn, onBlockReplyFlush } = createTestContext(); |
| 40 | + |
| 41 | + await handleToolExecutionStart( |
| 42 | + ctx as never, |
| 43 | + { |
| 44 | + type: "tool_execution_start", |
| 45 | + toolName: "read", |
| 46 | + toolCallId: "tool-1", |
| 47 | + args: { file_path: "/tmp/example.txt" }, |
| 48 | + } as never, |
| 49 | + ); |
| 50 | + |
| 51 | + expect(onBlockReplyFlush).toHaveBeenCalledTimes(1); |
| 52 | + expect(warn).not.toHaveBeenCalled(); |
| 53 | + }); |
| 54 | + |
| 55 | + it("warns when read tool has neither path nor file_path", async () => { |
| 56 | + const { ctx, warn } = createTestContext(); |
| 57 | + |
| 58 | + await handleToolExecutionStart( |
| 59 | + ctx as never, |
| 60 | + { |
| 61 | + type: "tool_execution_start", |
| 62 | + toolName: "read", |
| 63 | + toolCallId: "tool-2", |
| 64 | + args: {}, |
| 65 | + } as never, |
| 66 | + ); |
| 67 | + |
| 68 | + expect(warn).toHaveBeenCalledTimes(1); |
| 69 | + expect(String(warn.mock.calls[0]?.[0] ?? "")).toContain("read tool called without path"); |
| 70 | + }); |
| 71 | +}); |
0 commit comments