import { describe, expect, it } from "vitest"; import { buildTaskForest } from "@/lib/task-tree"; import type { TaskNode } from "@/lib/types"; function task(task_id: string, display_path: string, parent_task_id: string | null): TaskNode { return { task_id, display_path, parent_task_id, child_task_ids: [], task_kind: "task", phase: "phase-two", objective: task_id, status: "pending", blocked_reason: null, attempt_count: 0, validation_count: 0, decision_count: 0, current_spec_version: 1, acceptance_criteria: [], context_refs: [], created_at: "", updated_at: "" }; } describe("buildTaskForest", () => { it("keeps numeric task paths ordered and nests children", () => { const forest = buildTaskForest([task("p2", "0.2", "root"), task("root", "0", null), task("p1", "0.1", "root"), task("leaf", "0.1.1", "p1")]); expect(forest[0].task.task_id).toBe("root"); expect(forest[0].children.map((item) => item.task.task_id)).toEqual(["p1", "p2"]); expect(forest[0].children[0].children[0].task.task_id).toBe("leaf"); }); it("can replay only the ids visible at one planner turn", () => { const forest = buildTaskForest([task("root", "0", null), task("p1", "0.1", "root"), task("future", "0.2", "root")], new Set(["root", "p1"])); expect(forest[0].children.map((item) => item.task.task_id)).toEqual(["p1"]); }); });