Просмотр исходного кода

test(任务树): 验证数值排序 嵌套 与 Planner 可见性回放

覆盖 0.1/0.2 等路径按数值排序、子任务嵌套,以及只展示某次 Planner Turn 已可见 Task 的场景,防止未来任务提前出现在历史回放中。
SamLee 18 часов назад
Родитель
Сommit
621db298f6
1 измененных файлов с 21 добавлено и 0 удалено
  1. 21 0
      visualization/frontend/tests/task-tree.test.ts

+ 21 - 0
visualization/frontend/tests/task-tree.test.ts

@@ -0,0 +1,21 @@
+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"]);
+  });
+});