|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import type { ToolCall, ToolResult } from "@intx/types/runtime"; |
| 3 | +import { isIdempotentTaskBatch } from "./idempotent-task-exempt.js"; |
| 4 | + |
| 5 | +function call(name: string, id = "c1"): ToolCall { |
| 6 | + return { id, name, arguments: {} }; |
| 7 | +} |
| 8 | + |
| 9 | +function taskResult(): ToolResult { |
| 10 | + return { callId: "c1", content: "{}" }; |
| 11 | +} |
| 12 | + |
| 13 | +describe("isIdempotentTaskBatch", () => { |
| 14 | + test("manage_tasks batch is exempt", () => { |
| 15 | + expect(isIdempotentTaskBatch([call("manage_tasks")], [taskResult()])).toBe( |
| 16 | + true, |
| 17 | + ); |
| 18 | + }); |
| 19 | + |
| 20 | + test("todowrite alias is exempt", () => { |
| 21 | + expect(isIdempotentTaskBatch([call("todowrite")], [taskResult()])).toBe( |
| 22 | + true, |
| 23 | + ); |
| 24 | + }); |
| 25 | + |
| 26 | + test("update_plan hidden alias is exempt", () => { |
| 27 | + expect(isIdempotentTaskBatch([call("update_plan")], [taskResult()])).toBe( |
| 28 | + true, |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + test("repeated task-only batches stay exempt", () => { |
| 33 | + expect( |
| 34 | + isIdempotentTaskBatch( |
| 35 | + [call("todowrite", "c1"), call("todowrite", "c2")], |
| 36 | + [taskResult(), { callId: "c2", content: "{}" }], |
| 37 | + ), |
| 38 | + ).toBe(true); |
| 39 | + }); |
| 40 | + |
| 41 | + test("a real tool in the batch is never exempt", () => { |
| 42 | + expect( |
| 43 | + isIdempotentTaskBatch( |
| 44 | + [call("todowrite"), call("run_shell")], |
| 45 | + [taskResult(), { callId: "c2", content: "{}" }], |
| 46 | + ), |
| 47 | + ).toBe(false); |
| 48 | + }); |
| 49 | + |
| 50 | + test("non-task tools are never exempt", () => { |
| 51 | + expect(isIdempotentTaskBatch([call("run_shell")], [taskResult()])).toBe( |
| 52 | + false, |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + test("empty batches are never exempt", () => { |
| 57 | + expect(isIdempotentTaskBatch([], [])).toBe(false); |
| 58 | + }); |
| 59 | +}); |
0 commit comments