Make Project Management a native feature
- Move the storage and model of the plugin into src/lib/features/pm/ as pure TypeScript, so the skill can still bundle them. - Move the DOM interface onto the host menus, the shared tooltip, and the host icons. - A ribbon button opens Project Management. Board tabs keep the owner runestone.pm and the board-<hex> view IDs through view patterns. - Read only .runestone/pm/. Offer the plugin migration, with backups, for legacy notes. - A save, move, or delete reads only that card again. Watcher paths reach the feature. - Add Settings → Project Management and the projectManagement section. View states move to localStorage. - Background reads the boards from workspace.json. Remove api.backgrounds and the boards service. - Add yaml 2.9.1. Use the host markdown-it. - Move 18 plugin test files to tests/unit/features/pm/ and add native tests.
This commit is contained in:
@@ -0,0 +1,514 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { newBoardSource, parseBoard, boardDocument } from "../../../../src/lib/features/pm/storage/board.ts";
|
||||
import { TaskStore } from "../../../../src/lib/features/pm/model/store.ts";
|
||||
import { newTask, readTask, adoptNote } from "../../../../src/lib/features/pm/storage/notes.ts";
|
||||
import type { Workspace, TaskFields } from "../../../../src/lib/features/pm/model/model.ts";
|
||||
|
||||
const fields: TaskFields = {
|
||||
status: "todo",
|
||||
tags: ["shared"],
|
||||
sessions: [
|
||||
{
|
||||
id: "session",
|
||||
start: "2026-10-08T16:00:00Z",
|
||||
end: "2026-10-08T17:00:00Z",
|
||||
timeZone: "America/Vancouver",
|
||||
},
|
||||
],
|
||||
due: { date: "2026-10-30" },
|
||||
plan: { start: "2026-10-05", end: "2026-10-31" },
|
||||
archived: false,
|
||||
};
|
||||
function fixture() {
|
||||
const first = newBoardSource(),
|
||||
second = newBoardSource();
|
||||
const files = new Map<string, string>([
|
||||
["Project/Launch.md", first],
|
||||
["Project/Personal.md", second],
|
||||
["Task.md", newTask("Task", fields, "Keep this description.").source],
|
||||
]);
|
||||
let fail = false;
|
||||
const writes: string[] = [];
|
||||
const workspace: Workspace = {
|
||||
async readOptional(path) {
|
||||
return files.get(path) ?? null;
|
||||
},
|
||||
async list(parent = "") {
|
||||
const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
const prefix = parent ? parent + "/" : "";
|
||||
if (!path.startsWith(prefix)) continue;
|
||||
const parts = path.slice(prefix.length).split("/");
|
||||
entries.set(parts[0], {
|
||||
name: parts[0],
|
||||
rel_path: prefix + parts[0],
|
||||
kind: parts.length > 1 ? "folder" : "file",
|
||||
});
|
||||
}
|
||||
return [...entries.values()];
|
||||
},
|
||||
async read(path) {
|
||||
const source = files.get(path);
|
||||
if (source === undefined) throw Error("Missing");
|
||||
return source;
|
||||
},
|
||||
async write(path, source, expected) {
|
||||
if (fail) throw Error("Disk failure");
|
||||
assert.equal(files.get(path), expected);
|
||||
writes.push(path);
|
||||
files.set(path, source);
|
||||
},
|
||||
async create(path, source) {
|
||||
if (files.has(path)) throw Error("Exists");
|
||||
files.set(path, source);
|
||||
},
|
||||
};
|
||||
const a = new TaskStore(workspace, {
|
||||
id: parseBoard(first).id,
|
||||
path: "Project/Launch.md",
|
||||
});
|
||||
const b = new TaskStore(workspace, {
|
||||
id: parseBoard(second).id,
|
||||
path: "Project/Personal.md",
|
||||
});
|
||||
const all = new TaskStore(workspace);
|
||||
return {
|
||||
files,
|
||||
workspace,
|
||||
a,
|
||||
b,
|
||||
all,
|
||||
writes,
|
||||
failWrites() {
|
||||
fail = true;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test("a shared task synchronizes status lists and keeps one schedule", async () => {
|
||||
const { a, b, all, files, writes } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
await b.adopt("Task.md");
|
||||
await a.reload();
|
||||
const original = a.tasks[0];
|
||||
writes.length = 0;
|
||||
await a.moveTask(original, "done");
|
||||
await b.reload();
|
||||
await all.reload();
|
||||
assert.deepEqual(writes, ["Task.md"]);
|
||||
assert.equal(a.board.listFor(a.scopedTasks[0])?.id, "done");
|
||||
assert.equal(b.board.listFor(b.scopedTasks[0])?.id, "done");
|
||||
assert.equal(b.scopedTasks[0].status, "done");
|
||||
assert.equal(all.scopedTasks.length, 1);
|
||||
assert.equal(all.scopedTasks[0].id, original.id);
|
||||
assert.deepEqual(all.scopedTasks[0].plan, fields.plan);
|
||||
assert.deepEqual(all.scopedTasks[0].sessions, fields.sessions);
|
||||
assert.deepEqual(all.scopedTasks[0].due, fields.due);
|
||||
assert.equal(all.scopedTasks[0].body, original.body);
|
||||
assert.equal(files.size, 3);
|
||||
await b.save(b.scopedTasks[0], { due: { date: "2026-11-01" } });
|
||||
await a.reload();
|
||||
assert.equal(a.scopedTasks[0].due?.date, "2026-11-01");
|
||||
});
|
||||
|
||||
test("leaving a Done list reopens completion and removal affects only one board", async () => {
|
||||
const { a, b, all } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
await b.adopt("Task.md");
|
||||
await a.reload();
|
||||
await a.moveTask(a.tasks[0], "done");
|
||||
await a.changeBoard(() => a.board.add("This week", null));
|
||||
await a.moveTask(a.tasks[0], a.board.value.lists.at(-1)!.id);
|
||||
assert.equal(a.tasks[0].status, "todo");
|
||||
await a.removeFromBoard(a.tasks[0]);
|
||||
assert.equal(a.scopedTasks.length, 0);
|
||||
await b.reload();
|
||||
await all.reload();
|
||||
assert.equal(b.scopedTasks.length, 1);
|
||||
assert.equal(all.scopedTasks.length, 1);
|
||||
assert.equal(all.scopedTasks[0].archived, false);
|
||||
});
|
||||
|
||||
test("All tasks moves synchronize memberships in one write and append to destination lists", async () => {
|
||||
const { a, b, all, writes } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
await b.adopt("Task.md");
|
||||
await a.create("Existing done", { ...fields, status: "done" }, "");
|
||||
await all.reload();
|
||||
const task = all.tasks.find((task) => task.title === "Task")!;
|
||||
writes.length = 0;
|
||||
await all.moveTask(task, "done");
|
||||
assert.deepEqual(writes, ["Task.md"]);
|
||||
for (const board of [a, b]) {
|
||||
await board.reload();
|
||||
const saved = board.scopedTasks.find((item) => item.id === task.id)!;
|
||||
assert.equal(saved.status, "done");
|
||||
assert.equal(board.board.listFor(saved)?.id, "done");
|
||||
assert.deepEqual(saved.sessions, task.sessions);
|
||||
assert.deepEqual(saved.plan, task.plan);
|
||||
assert.deepEqual(saved.due, task.due);
|
||||
assert.equal(saved.body, task.body);
|
||||
}
|
||||
assert.deepEqual(
|
||||
a.cardsInList("done").map((task) => task.title),
|
||||
["Existing done", "Task"],
|
||||
);
|
||||
assert.deepEqual(
|
||||
b.scopedTasks.map((task) => task.title),
|
||||
["Task"],
|
||||
);
|
||||
});
|
||||
|
||||
test("status changes use each board's designated list and preserve unmatched placements", async () => {
|
||||
const { a, b, all } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
await b.adopt("Task.md");
|
||||
await a.changeBoard(() => a.board.add("Released", "done"));
|
||||
const destination = a.board.value.lists.at(-1)!.id;
|
||||
await a.changeBoard(() =>
|
||||
a.board.update((board) => {
|
||||
board.defaults.done = destination;
|
||||
}),
|
||||
);
|
||||
await b.changeBoard(() => b.board.remove("done"));
|
||||
await all.reload();
|
||||
const previous = all.tasks[0].placements![b.board.reference!.id];
|
||||
await all.save(all.tasks[0], { status: "done" });
|
||||
await a.reload();
|
||||
await b.reload();
|
||||
assert.equal(a.board.listFor(a.tasks[0])?.id, destination);
|
||||
assert.deepEqual(b.tasks[0].placements![b.board.reference!.id], previous);
|
||||
assert.equal(b.tasks[0].status, "done");
|
||||
});
|
||||
|
||||
test("status changes preserve absent memberships and unavailable board placements", async () => {
|
||||
const { a, b, all, files } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
await all.reload();
|
||||
await all.moveTask(all.tasks[0], "doing");
|
||||
assert.equal(
|
||||
Object.hasOwn(all.tasks[0].placements!, b.board.reference!.id),
|
||||
false,
|
||||
);
|
||||
await a.reload();
|
||||
const previous = a.tasks[0].placements![a.board.reference!.id];
|
||||
files.delete("Project/Launch.md");
|
||||
await all.moveTask(all.tasks[0], "done");
|
||||
assert.deepEqual(all.tasks[0].placements![a.board.reference!.id], previous);
|
||||
});
|
||||
|
||||
test("failed All tasks moves preserve every placement and the shared status", async () => {
|
||||
const { a, b, all, files, failWrites } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
await b.adopt("Task.md");
|
||||
await all.reload();
|
||||
const before = all.tasks[0];
|
||||
failWrites();
|
||||
await assert.rejects(all.moveTask(before, "done"), /Disk failure/);
|
||||
assert.equal(files.get("Task.md"), before.source);
|
||||
assert.deepEqual(all.tasks[0], before);
|
||||
});
|
||||
|
||||
test("board creation does not collect every workspace task", async () => {
|
||||
const { a, b } = fixture();
|
||||
await a.reload();
|
||||
await b.reload();
|
||||
assert.equal(a.scopedTasks.length, 0);
|
||||
await a.create("New", fields, "");
|
||||
await b.reload();
|
||||
assert.equal(a.scopedTasks.length, 1);
|
||||
assert.equal(b.scopedTasks.length, 0);
|
||||
assert.equal(a.board.listFor(a.scopedTasks[0])?.id, "todo");
|
||||
});
|
||||
|
||||
test("moving or deleting a board never moves or deletes its tasks", async () => {
|
||||
const { a, all, files } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
const taskSource = files.get("Task.md");
|
||||
files.set("Elsewhere/Renamed.md", files.get("Project/Launch.md")!);
|
||||
files.delete("Project/Launch.md");
|
||||
await a.reload();
|
||||
assert.equal(a.board.reference?.path, "Elsewhere/Renamed.md");
|
||||
assert.equal(a.board.name, "Renamed");
|
||||
assert.equal(a.scopedTasks.length, 1);
|
||||
files.delete("Elsewhere/Renamed.md");
|
||||
await a.reload();
|
||||
await all.reload();
|
||||
assert.equal(a.board.available, false);
|
||||
assert.equal(all.scopedTasks.length, 1);
|
||||
assert.equal(files.get("Task.md"), taskSource);
|
||||
await assert.rejects(a.create("Lost", fields, ""), /unavailable/);
|
||||
});
|
||||
|
||||
test("invalid and duplicate boards do not block the workspace schedule", async () => {
|
||||
const { a, all, files } = fixture();
|
||||
files.set("Copy.md", files.get("Project/Launch.md")!);
|
||||
files.set(
|
||||
"Project/Personal.md",
|
||||
files.get("Project/Personal.md")!.replace("schema: 1", "schema: 99"),
|
||||
);
|
||||
await all.reload();
|
||||
await a.reload();
|
||||
assert.equal(all.tasks.length, 1);
|
||||
assert.equal(all.boards.length, 0);
|
||||
assert.equal(a.board.available, false);
|
||||
assert.ok(all.issues.some((issue) => issue.includes("Duplicate board ID")));
|
||||
assert.ok(all.issues.some((issue) => issue.includes("unsupported format")));
|
||||
});
|
||||
|
||||
test("failed placement writes preserve both membership and status", async () => {
|
||||
const { a, files, failWrites } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
const source = files.get("Task.md");
|
||||
failWrites();
|
||||
await assert.rejects(a.moveTask(a.tasks[0], "done"), /Disk failure/);
|
||||
assert.equal(files.get("Task.md"), source);
|
||||
assert.equal(a.tasks[0].status, "todo");
|
||||
assert.equal(a.board.listFor(a.tasks[0])?.id, "todo");
|
||||
});
|
||||
|
||||
test("an open stale card cannot overwrite another board's edit", async () => {
|
||||
const { a, b, files } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
await b.adopt("Task.md");
|
||||
await a.reload();
|
||||
const stale = a.tasks[0];
|
||||
await b.moveTask(b.tasks[0], "doing");
|
||||
const source = files.get("Task.md");
|
||||
await assert.rejects(a.moveTask(stale, "done"), /task changed/);
|
||||
assert.equal(files.get("Task.md"), source);
|
||||
});
|
||||
|
||||
test("board properties and prose survive edits and boards cannot become task notes", async () => {
|
||||
const { a, files } = fixture();
|
||||
const source =
|
||||
files
|
||||
.get("Project/Launch.md")!
|
||||
.replace("runestone_pm:", "owner: Ada # keep\nrunestone_pm:") +
|
||||
"Board description.\n";
|
||||
files.set("Project/Launch.md", source);
|
||||
await a.reload();
|
||||
await a.changeBoard(() => a.board.add("Review", null));
|
||||
const saved = files.get("Project/Launch.md")!;
|
||||
assert.ok(saved.includes("owner: Ada # keep"));
|
||||
assert.ok(saved.endsWith("Board description.\n"));
|
||||
assert.equal(readTask("Board.md", saved), null);
|
||||
assert.throws(() => adoptNote("Board.md", saved), /already contains Project Management data/);
|
||||
assert.equal(boardDocument("# A normal note", "Board.md"), null);
|
||||
});
|
||||
|
||||
test("renaming a board resolves its current path and preserves shared tasks and lists", async () => {
|
||||
const { a, b, all, files, writes } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
await b.adopt("Task.md");
|
||||
await a.changeBoard(() => a.board.add("Review", null));
|
||||
const source = files.get("Project/Launch.md")!;
|
||||
const taskSource = files.get("Task.md");
|
||||
files.set("Moved/Launch.md", source);
|
||||
files.delete("Project/Launch.md");
|
||||
writes.length = 0;
|
||||
await a.renameBoard(" Release 1.2 ", async (document, name) => {
|
||||
assert.equal(document.path, "Moved/Launch.md");
|
||||
assert.equal(document.id, parseBoard(source).id);
|
||||
assert.equal(name, "Release 1.2");
|
||||
files.set("Moved/Release 1.2.md", files.get(document.path)!);
|
||||
files.delete(document.path);
|
||||
return "Moved/Release 1.2.md";
|
||||
});
|
||||
assert.equal(a.board.name, "Release 1.2");
|
||||
assert.equal(a.board.reference?.path, "Moved/Release 1.2.md");
|
||||
assert.equal(a.board.value.lists.at(-1)?.name, "Review");
|
||||
assert.equal(files.get("Moved/Release 1.2.md"), source);
|
||||
assert.equal(files.get("Task.md"), taskSource);
|
||||
assert.deepEqual(writes, []);
|
||||
await b.reload();
|
||||
await all.reload();
|
||||
assert.equal(a.scopedTasks.length, 1);
|
||||
assert.equal(b.scopedTasks.length, 1);
|
||||
assert.equal(all.scopedTasks.length, 1);
|
||||
await a.changeBoard(() => a.board.add("After rename", null));
|
||||
await a.moveTask(a.scopedTasks[0], "doing");
|
||||
assert.equal(a.board.listFor(a.scopedTasks[0])?.id, "doing");
|
||||
});
|
||||
|
||||
test("failed renames and unavailable boards preserve workspace files", async () => {
|
||||
const { a, all, files } = fixture();
|
||||
await a.reload();
|
||||
const before = [...files];
|
||||
await assert.rejects(
|
||||
a.renameBoard("Personal", async () => {
|
||||
throw Error("Exists");
|
||||
}),
|
||||
/Exists/,
|
||||
);
|
||||
assert.equal(a.board.reference?.path, "Project/Launch.md");
|
||||
assert.deepEqual([...files], before);
|
||||
const rename = async () => {
|
||||
assert.fail("Rename must not run");
|
||||
return "";
|
||||
};
|
||||
await assert.rejects(all.renameBoard("All", rename), /available board/);
|
||||
files.set("Copy.md", files.get("Project/Launch.md")!);
|
||||
await assert.rejects(a.renameBoard("Duplicate", rename), /available board/);
|
||||
files.delete("Copy.md");
|
||||
files.delete("Project/Launch.md");
|
||||
await assert.rejects(a.renameBoard("Missing", rename), /available board/);
|
||||
});
|
||||
|
||||
test("board transfers preserve metadata and other memberships in one card write", async () => {
|
||||
const { a, b, all, files, workspace, writes } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
await b.adopt("Task.md");
|
||||
const destination = await a.createBoard("Destination");
|
||||
const target = new TaskStore(workspace, destination);
|
||||
await target.reload();
|
||||
await target.create("Already there", { ...fields, status: "doing" }, "");
|
||||
await a.reload();
|
||||
await a.save(a.tasks.find((task) => task.title === "Task")!, {
|
||||
priority: "high", color: "pink", labels: ["bug"], assignees: ["Ada"],
|
||||
customFields: [{ name: "Customer", value: "Keep" }],
|
||||
});
|
||||
files.set("Task.md", files.get("Task.md")!.replace("runestone_pm:", "owner: Ada # keep\nrunestone_pm:"));
|
||||
await a.reload();
|
||||
const before = a.tasks.find((task) => task.title === "Task")!;
|
||||
writes.length = 0;
|
||||
await a.transferTask(before, destination.id, "doing");
|
||||
assert.deepEqual(writes, [before.path]);
|
||||
assert.equal(a.scopedTasks.length, 0);
|
||||
await target.reload();
|
||||
await b.reload();
|
||||
await all.reload();
|
||||
const saved = target.tasks.find((task) => task.id === before.id)!;
|
||||
const { placements: _oldPlacements, source: _oldSource, ...oldDetails } = before;
|
||||
const { placements: _newPlacements, source: _newSource, ...newDetails } = saved;
|
||||
assert.deepEqual(newDetails, oldDetails);
|
||||
assert.deepEqual(saved.placements![b.board.reference!.id], before.placements![b.board.reference!.id]);
|
||||
assert.equal(Object.hasOwn(saved.placements!, a.board.reference!.id), false);
|
||||
assert.equal(saved.placements![destination.id].listId, "doing");
|
||||
assert.ok(saved.source.includes("owner: Ada # keep"));
|
||||
assert.deepEqual(target.cardsInList("doing").map((task) => task.title), ["Already there", "Task"]);
|
||||
assert.equal(b.scopedTasks.length, 1);
|
||||
assert.equal(all.tasks.filter((task) => task.id === before.id).length, 1);
|
||||
});
|
||||
|
||||
test("hidden cards transfer to existing memberships, custom lists, and Unlisted without copies", async () => {
|
||||
const { a, b, workspace, files } = fixture();
|
||||
await a.reload();
|
||||
await a.create("Private", fields, "");
|
||||
const privateCard = a.scopedTasks[0];
|
||||
assert.ok(privateCard.path.startsWith(".runestone/pm/cards/"));
|
||||
await a.save(privateCard, { placements: {
|
||||
...privateCard.placements,
|
||||
[b.board.reference!.id]: { listId: "todo", order: "a" },
|
||||
} });
|
||||
await b.reload();
|
||||
await b.changeBoard(() => b.board.add("Review", null));
|
||||
const reviewId = b.board.value.lists.at(-1)!.id;
|
||||
const before = a.tasks.find((task) => task.id === privateCard.id)!;
|
||||
const paths = [...files.keys()];
|
||||
await a.transferTask(before, b.board.reference!.id, reviewId);
|
||||
await b.reload();
|
||||
assert.equal(b.scopedTasks.length, 1);
|
||||
assert.equal(b.board.listFor(b.scopedTasks[0])?.id, reviewId);
|
||||
assert.equal(b.scopedTasks[0].body, privateCard.body);
|
||||
assert.deepEqual([...files.keys()], paths);
|
||||
const managed = await b.createBoard("Unlisted destination");
|
||||
await b.transferTask(b.scopedTasks[0], managed.id, null);
|
||||
const target = new TaskStore(workspace, managed);
|
||||
await target.reload();
|
||||
assert.equal(target.scopedTasks.length, 1);
|
||||
assert.equal(target.scopedTasks[0].placements![managed.id].listId, null);
|
||||
assert.equal(target.scopedTasks[0].status, "todo");
|
||||
});
|
||||
|
||||
test("transfers reject missing, duplicated, deleted, and archived destinations without card changes", async () => {
|
||||
for (const condition of ["missing", "duplicate", "deleted", "archived", "list"] as const) {
|
||||
const { a, b, files, workspace, writes } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
const before = a.scopedTasks[0];
|
||||
let destination = b.board.reference!;
|
||||
if (condition === "missing") files.delete(destination.path);
|
||||
if (condition === "duplicate") files.set("Copy.md", files.get(destination.path)!);
|
||||
if (condition === "deleted") {
|
||||
await b.reload();
|
||||
await b.changeBoard(() => b.board.deleteBoard());
|
||||
}
|
||||
if (condition === "archived") {
|
||||
destination = await a.createBoard("Archived");
|
||||
const target = new TaskStore(workspace, destination);
|
||||
await target.reload();
|
||||
await target.changeBoard(() => target.board.manage({ archived: true }));
|
||||
}
|
||||
if (condition === "list") {
|
||||
await b.reload();
|
||||
await b.changeBoard(() => b.board.remove("doing"));
|
||||
}
|
||||
writes.length = 0;
|
||||
await assert.rejects(a.transferTask(before, destination.id, "doing"), /destination/);
|
||||
assert.equal(files.get(before.path), before.source, condition);
|
||||
assert.deepEqual(writes, [], condition);
|
||||
assert.deepEqual(a.scopedTasks[0], before, condition);
|
||||
}
|
||||
});
|
||||
|
||||
test("transfers require a current source membership and active source board", async () => {
|
||||
const { a, b, all, files } = fixture();
|
||||
await all.reload();
|
||||
await assert.rejects(all.transferTask(all.tasks[0], b.board.reference!.id, "todo"), /active board/);
|
||||
await a.reload();
|
||||
await assert.rejects(a.transferTask(a.tasks[0], b.board.reference!.id, "todo"), /no longer belongs/);
|
||||
await a.adopt("Task.md");
|
||||
const before = a.scopedTasks[0];
|
||||
await assert.rejects(a.transferTask(before, a.board.reference!.id, "todo"), /different destination/);
|
||||
files.delete(a.board.reference!.path);
|
||||
await assert.rejects(a.transferTask(before, b.board.reference!.id, "todo"), /active board/);
|
||||
assert.equal(files.get(before.path), before.source);
|
||||
});
|
||||
|
||||
test("stale cards and failed transfer writes preserve every membership", async () => {
|
||||
const { a, b, files, failWrites, writes } = fixture();
|
||||
await a.adopt("Task.md");
|
||||
const stale = a.scopedTasks[0];
|
||||
await b.reload();
|
||||
await b.save(b.tasks[0], { body: "An external edit." });
|
||||
const external = files.get(stale.path);
|
||||
await assert.rejects(a.transferTask(stale, b.board.reference!.id, "done"), /card changed/);
|
||||
assert.equal(files.get(stale.path), external);
|
||||
const current = a.scopedTasks[0];
|
||||
writes.length = 0;
|
||||
failWrites();
|
||||
await assert.rejects(a.transferTask(current, b.board.reference!.id, "done"), /Disk failure/);
|
||||
assert.equal(files.get(current.path), current.source);
|
||||
assert.deepEqual(a.scopedTasks[0], current);
|
||||
assert.deepEqual(writes, []);
|
||||
});
|
||||
|
||||
test("detail board changes save draft fields and membership atomically with stale-write protection", async () => {
|
||||
const { a, b, files, writes, failWrites } = fixture();
|
||||
await a.reload(); await a.adopt("Task.md"); await b.reload();
|
||||
const task = a.tasks[0]; const original = files.get(task.path);
|
||||
writes.length = 0;
|
||||
await a.saveToBoard(task, b.board.reference!.id, "doing", { body: "Draft preserved", priority: "highest" });
|
||||
assert.equal(writes.length, 1);
|
||||
const changed = readTask(task.path, files.get(task.path)!)!;
|
||||
assert.equal(changed.body, "Draft preserved"); assert.equal(changed.priority, "highest");
|
||||
assert.equal(changed.status, "doing"); assert.equal(changed.placements?.[a.board.reference!.id], undefined);
|
||||
assert.equal(changed.placements?.[b.board.reference!.id]?.listId, "doing");
|
||||
await assert.rejects(a.saveToBoard(task, b.board.reference!.id, "todo", { body: "Stale draft" }), /changed/);
|
||||
const saved = files.get(task.path); failWrites();
|
||||
await assert.rejects(b.saveToBoard(changed, a.board.reference!.id, "todo", { body: "Failed draft" }), /Disk failure/);
|
||||
assert.equal(files.get(task.path), saved); assert.notEqual(saved, original);
|
||||
});
|
||||
|
||||
test("pasted relative paths reuse one card and reject paths outside the workspace", async () => {
|
||||
const { a, files } = fixture(); await a.reload();
|
||||
const original = readTask("Task.md", files.get("Task.md")!)!;
|
||||
await a.createOrLink("./Task.md", { ...fields, listId: "doing" });
|
||||
assert.equal(a.tasks.length, 1); assert.equal(a.tasks[0].id, original.id);
|
||||
assert.equal(a.tasks[0].placements?.[a.board.reference!.id]?.listId, "doing");
|
||||
const before = new Map(files);
|
||||
for (const path of ["../Task.md", "D:/Task.md", "/Task.md", "https://example.com/Task.md"])
|
||||
await assert.rejects(a.createOrLink(path, fields), /relative Markdown path/);
|
||||
assert.deepEqual(files, before);
|
||||
});
|
||||
Reference in New Issue
Block a user