/** * Tests for 9plan_queue_pull tool */ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; import { handleQueuePull } from "../../../src/tools/queue-pull.js"; import { createMockSessionStore, createMockPlan } from "../../helpers/mocks.js"; import { NinePlanError } from "../../../src/types.js"; describe("handleQueuePull", () => { const mockStore = createMockSessionStore(); beforeEach(() => { mockStore.getSessionPath.mockReturnValue("/tmp/9plan/sessions/test-session"); }); afterEach(() => { vi.clearAllMocks(); }); it("should pull plan and return formatted response", () => { mockStore.pullPlan.mockReturnValue( createMockPlan({ id: "abc12", goal: "Test goal", }), ); const result = handleQueuePull(mockStore, "test-session", {}); expect(mockStore.pullPlan).toHaveBeenCalled(); expect(result.content).toHaveLength(1); expect(result.content[0]!.type).toBe("text"); expect(result.content[0]!.text).toContain("[Session: test-session]"); expect(result.content[0]!.text).toContain("Active plan: abc12"); }); it("should include plan path in response", () => { mockStore.pullPlan.mockReturnValue( createMockPlan({ id: "abc12", goal: "Test goal", }), ); const result = handleQueuePull(mockStore, "test-session", {}); expect(result.content[0]!.text).toContain( "/tmp/9plan/sessions/test-session/plans/abc12.txt", ); }); it("should include instructions for reviewing plan", () => { mockStore.pullPlan.mockReturnValue( createMockPlan({ id: "abc12", goal: "Build the authentication module", }), ); const result = handleQueuePull(mockStore, "test-session", {}); // The response tells users to review the plan before starting expect(result.content[0]!.text).toContain("Review for any ambiguities"); }); it("should handle QUEUE_EMPTY with completed count", () => { mockStore.pullPlan.mockImplementation(() => { throw new NinePlanError( "QUEUE_EMPTY", "The queue is empty", "Use history search", ); }); mockStore.getCompletedCount.mockReturnValue(10); const result = handleQueuePull(mockStore, "test-session", {}); expect(result.content[0]!.text).toContain("Queue is empty"); expect(result.content[0]!.text).toContain("10"); }); it("should handle PLAN_ALREADY_ACTIVE with active plan info", () => { mockStore.pullPlan.mockImplementation(() => { throw new NinePlanError( "PLAN_ALREADY_ACTIVE", "Plan xyz99 is already active", "Complete or defer the active plan", ); }); mockStore.getActivePlan.mockReturnValue( createMockPlan({ id: "xyz99", goal: "Active task", }), ); const result = handleQueuePull(mockStore, "test-session", {}); expect(result.content[0]!.text).toContain("already active"); expect(result.content[0]!.text).toContain("xyz99"); }); });