toolPlanAdapter.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. extractPlanStepsFromToolInput,
  4. isMainAgentToolProjectionSource,
  5. } from "../src/tool-plan-adapter.js";
  6. describe("tool plan adapter", () => {
  7. it("extracts TodoWrite plan steps for main agent tools", () => {
  8. expect(
  9. extractPlanStepsFromToolInput({
  10. kind: "TodoWrite",
  11. input: {
  12. todos: [
  13. { content: "Inspect logs", status: "completed" },
  14. { content: "Patch projection", status: "in_progress" },
  15. ],
  16. },
  17. }),
  18. ).toEqual([
  19. { id: "Inspect logs", title: "Inspect logs", status: "completed" },
  20. { id: "Patch projection", title: "Patch projection", status: "in_progress" },
  21. ]);
  22. });
  23. it("detects nested tool payloads that must not drive the main task plan", () => {
  24. expect(isMainAgentToolProjectionSource({ toolCallId: "call_main" })).toBe(true);
  25. expect(isMainAgentToolProjectionSource({ source: "subagent" })).toBe(false);
  26. expect(isMainAgentToolProjectionSource({ parentToolCallId: "call_agent" })).toBe(false);
  27. expect(isMainAgentToolProjectionSource({ parentToolUseId: "call_agent" })).toBe(false);
  28. expect(
  29. isMainAgentToolProjectionSource({
  30. _meta: { claudeCode: { parentToolUseId: "call_agent" } },
  31. }),
  32. ).toBe(false);
  33. });
  34. });