| 1 | import assert from "node:assert/strict"; |
| 2 | import { createProjectTreeRuntimeProjection, projectTreeApplyRuntimeTopics } from "../lib/projectTreeRuntime"; |
| 3 | import type { ProjectNode, ProjectRuntimeTopic } from "../lib/types"; |
| 4 | |
| 5 | const children: ProjectNode[] = ["first", "second"].map(id => ({ key: id, kind: "session", label: `Title ${id}`, |
| 6 | root: "/repo", topicId: "topic", sessionPath: `/sessions/${id}`, preview: `Preview ${id}`, children: [] })); |
| 7 | const topic: ProjectNode = { key: "topic", kind: "topic", label: "Saved title", root: "/repo", topicId: "topic", children }; |
| 8 | const tree: ProjectNode[] = [{ key: "project", kind: "project", label: "Project", root: "/repo", children: [topic] }]; |
| 9 | const runtime: ProjectRuntimeTopic[] = [{ scope: "project", workspaceRoot: "/repo", node: { ...topic, label: "Runtime title", |
| 10 | children: children.map(child => ({ ...child, label: "Path fallback", preview: "", running: true, status: "thinking" })) } }]; |
| 11 | const next = projectTreeApplyRuntimeTopics(tree, runtime); |
| 12 | assert.equal(next[0].children![0].label, "Saved title"); |
| 13 | for (const child of next[0].children![0].children!) { |
| 14 | assert.equal(child.label, `Title ${child.key}`); |
| 15 | assert.equal(child.preview, `Preview ${child.key}`); |
| 16 | assert.equal(child.running, true); |
| 17 | } |
| 18 | assert.equal(projectTreeApplyRuntimeTopics(next, runtime), next, "identical runtime overlay preserves tree identity"); |
| 19 | const projection = createProjectTreeRuntimeProjection(); |
| 20 | projection.apply(tree, runtime); |
| 21 | const pagedAway = projection.apply([{ ...tree[0], children: [] }], runtime); |
| 22 | assert.equal(pagedAway[0].children![0].children![0].preview, "Preview first", "resident catalog metadata survives paging"); |
| 23 | console.log("PASS: memory-only runtime topics preserve catalog metadata and structural sharing"); |
| 24 |