- 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.
64 lines
4.0 KiB
TypeScript
64 lines
4.0 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { newTask, readTask, editTask, adoptNote } from "../../../../src/lib/features/pm/storage/notes.ts";
|
|
import { DescriptionDraft } from "../../../../src/lib/features/pm/storage/description-draft.ts";
|
|
import { defaultBoardPath } from "../../../../src/lib/features/pm/model/workspace-default.ts";
|
|
import { defaultBoard } from "../../../../src/lib/features/pm/storage/board.ts";
|
|
import { catalogPath, boardMarkdown } from "../../../../src/lib/features/pm/storage/catalog.ts";
|
|
import type { Workspace } from "../../../../src/lib/features/pm/model/model.ts";
|
|
|
|
function fixture() {
|
|
const files = new Map<string, string>();
|
|
const workspace: Workspace = {
|
|
async list() { throw new Error("No task scan expected"); },
|
|
async read(path) { if (!files.has(path)) throw new Error("Missing"); return files.get(path)!; },
|
|
async readOptional(path) { return files.get(path) ?? null; },
|
|
async create(path, source) { if (files.has(path)) throw new Error("Exists"); files.set(path, source); },
|
|
async write(path, source, expected) { if (files.get(path) !== expected) throw new Error("Conflict"); files.set(path, source); },
|
|
};
|
|
return { files, workspace };
|
|
}
|
|
const fields = { status: "todo" as const, tags: [], sessions: [], archived: false };
|
|
test("new captures record immutable timestamps and existing legacy cards keep an unknown date", () => {
|
|
const before = Date.now();
|
|
const note = newTask("Timestamp", fields);
|
|
const task = readTask(note.path, note.source)!;
|
|
assert.ok(Date.parse(task.createdAt!) >= before && Date.parse(task.createdAt!) <= Date.now());
|
|
const edited = readTask(task.path, editTask(task, { body: "Updated", status: "done", placements: { next: { listId: "done" } } }))!;
|
|
assert.equal(edited.createdAt, task.createdAt);
|
|
assert.throws(() => editTask(task, { createdAt: undefined }), /cannot change/);
|
|
assert.throws(() => editTask(task, { createdAt: "2026-01-01T00:00:00Z" }), /cannot change/);
|
|
assert.ok(Date.parse(readTask("Old.md", adoptNote("Old.md", "Original note"))!.createdAt!) >= before);
|
|
const legacy = readTask(note.path, note.source.replace(/^ createdAt:.*\n/m, ""))!;
|
|
assert.equal(readTask(legacy.path, editTask(legacy, { title: "Legacy edit" }))!.createdAt, undefined);
|
|
assert.equal(adoptNote(legacy.path, legacy.source), legacy.source);
|
|
});
|
|
test("description drafts persist separately, cancel clears them, and stale writers cannot overwrite drafts", async () => {
|
|
const { files, workspace } = fixture();
|
|
const draft = new DescriptionDraft(workspace, "task");
|
|
assert.equal(await draft.load(), null);
|
|
await draft.save("Uncommitted text");
|
|
const other = new DescriptionDraft(workspace, "task");
|
|
assert.equal(await other.load(), "Uncommitted text");
|
|
await draft.save("Newer draft");
|
|
await assert.rejects(other.save("Stale draft"), /Conflict/);
|
|
await draft.save(null);
|
|
assert.equal(await new DescriptionDraft(workspace, "task").load(), null);
|
|
assert.ok([...files.keys()].every(path => !path.includes("/cards/")));
|
|
});
|
|
test("default board resolves without scanning cards and keeps unavailable selections fixed", async () => {
|
|
const { files, workspace } = fixture();
|
|
const board = defaultBoard("chosen");
|
|
const catalog = { schema: 1, boards: [{ name: "Chosen", value: board }], defaultBoardId: "chosen", unknown: "keep" };
|
|
files.set(catalogPath, JSON.stringify(catalog));
|
|
assert.equal(await defaultBoardPath(workspace), "pm-board:chosen");
|
|
files.set(catalogPath, JSON.stringify({ ...catalog, boards: [] }));
|
|
assert.equal(await defaultBoardPath(workspace), undefined);
|
|
assert.equal(JSON.parse(files.get(catalogPath)!).defaultBoardId, "chosen");
|
|
files.set("Legacy.md", boardMarkdown(board));
|
|
files.set(catalogPath, JSON.stringify({ ...catalog, boards: [], defaultBoardPath: "Legacy.md" }));
|
|
assert.equal(await defaultBoardPath(workspace), "Legacy.md");
|
|
files.set(catalogPath, JSON.stringify({ ...catalog, boards: [], defaultBoardPath: "Legacy.md", deletedBoardIds: ["chosen"] }));
|
|
assert.equal(await defaultBoardPath(workspace), undefined);
|
|
});
|