import test from "node:test"; import assert from "node:assert/strict"; import { TaskStore } from "../../../../src/lib/features/pm/model/store.ts"; import { newTask, readTask } from "../../../../src/lib/features/pm/storage/notes.ts"; import type { Workspace } from "../../../../src/lib/features/pm/model/model.ts"; test("subtask promotion retains checklist data and retries without duplicate cards", async () => { const parent = newTask("Parent", { status: "todo", tags: [], sessions: [], archived: false, subtasks: [{ id: "child", title: "Child", done: true }], priority: "high" }, "Keep the description"); const files = new Map([["Parent.md", parent.source]]); const parentId = readTask("Parent.md", parent.source)!.id; let fail = true; const workspace: Workspace = { async list(folder = "") { return [...files.keys()].filter(path => folder ? path.startsWith(`${folder}/`) : !path.startsWith(".")).map(path => ({ name: path.split("/").at(-1)!, rel_path: path, kind: "file" })); }, async read(path) { if (!files.has(path)) throw Error("Missing"); return files.get(path)!; }, async readOptional(path) { return files.get(path) ?? null; }, async create(path, source) { if (files.has(path)) throw Error("Exists"); files.set(path, source); }, async write(path, source, expected) { if (fail) throw Error("Write failed"); assert.equal(files.get(path), expected); files.set(path, source); }, }; const store = new TaskStore(workspace); await store.reload(); await assert.rejects(store.openSubtask(parentId, "child"), /Write failed/); fail = false; const child = await store.openSubtask(parentId, "child"); assert.equal(child.title, "Child"); assert.equal(child.status, "done"); assert.equal(child.priority, undefined); assert.equal(store.tasks.length, 2); const saved = readTask("Parent.md", files.get("Parent.md")!)!; assert.equal(saved.subtasks![0].taskId, child.id); assert.equal(saved.body, "Keep the description"); assert.equal(saved.priority, "high"); assert.equal((await store.openSubtask(parentId, "child")).id, child.id); assert.equal(store.tasks.length, 2); });