task-tree.test.ts 1.3 KB

123456789101112131415161718192021
  1. import { describe, expect, it } from "vitest";
  2. import { buildTaskForest } from "@/lib/task-tree";
  3. import type { TaskNode } from "@/lib/types";
  4. function task(task_id: string, display_path: string, parent_task_id: string | null): TaskNode {
  5. 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: "" };
  6. }
  7. describe("buildTaskForest", () => {
  8. it("keeps numeric task paths ordered and nests children", () => {
  9. const forest = buildTaskForest([task("p2", "0.2", "root"), task("root", "0", null), task("p1", "0.1", "root"), task("leaf", "0.1.1", "p1")]);
  10. expect(forest[0].task.task_id).toBe("root");
  11. expect(forest[0].children.map((item) => item.task.task_id)).toEqual(["p1", "p2"]);
  12. expect(forest[0].children[0].children[0].task.task_id).toBe("leaf");
  13. });
  14. it("can replay only the ids visible at one planner turn", () => {
  15. const forest = buildTaskForest([task("root", "0", null), task("p1", "0.1", "root"), task("future", "0.2", "root")], new Set(["root", "p1"]));
  16. expect(forest[0].children.map((item) => item.task.task_id)).toEqual(["p1"]);
  17. });
  18. });