- 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.
108 lines
4.1 KiB
TypeScript
108 lines
4.1 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
imageMarkdown,
|
|
imageReferences,
|
|
imagePath,
|
|
parseImage,
|
|
saveImages,
|
|
maxImageBytes,
|
|
} from "../../../../src/lib/features/pm/storage/images.ts";
|
|
import type { Workspace } from "../../../../src/lib/features/pm/model/model.ts";
|
|
const id = "12345678-1234-1234-1234-123456789abc";
|
|
const data = "data:image/png;base64,aGVsbG8=";
|
|
|
|
test("image references preserve surrounding text and restrict private paths", () => {
|
|
const markdown = imageMarkdown("shot [one]\n\\test.png", id);
|
|
assert.equal(markdown, ``);
|
|
const body = `Before\n${markdown}\nAfter`;
|
|
assert.deepEqual(imageReferences(body), [
|
|
{ id, name: "shot one test.png", markdown, index: 7 },
|
|
]);
|
|
assert.deepEqual(
|
|
imageReferences(
|
|
" ",
|
|
),
|
|
[],
|
|
);
|
|
assert.throws(() => imagePath("../../secret"), /invalid/);
|
|
});
|
|
test("saved image data rejects unsupported and executable sources", () => {
|
|
assert.equal(parseImage(JSON.stringify({ schema: 1, data })), data);
|
|
for (const value of [
|
|
null,
|
|
{},
|
|
{ schema: 1, data: "https://example.com/image.png" },
|
|
{ schema: 1, data: "data:image/svg+xml;base64,PHN2Zz4=" },
|
|
{ schema: 1, data: "data:image/png;base64,***=" },
|
|
])
|
|
assert.throws(() => parseImage(JSON.stringify(value)));
|
|
assert.throws(
|
|
() => parseImage("x".repeat(Math.ceil(maxImageBytes / 3) * 4 + 257)),
|
|
/50 MiB/,
|
|
);
|
|
});
|
|
test("save writes only referenced images, protects existing files, and permits retry", async () => {
|
|
const files = new Map<string, string>();
|
|
const writes: string[] = [];
|
|
const workspace: Workspace = {
|
|
async list() {
|
|
return [];
|
|
},
|
|
async read(path) {
|
|
return files.get(path)!;
|
|
},
|
|
async readOptional(path) {
|
|
return files.get(path) ?? null;
|
|
},
|
|
async create(path, source) {
|
|
if (files.has(path)) throw new Error("Already exists");
|
|
files.set(path, source);
|
|
writes.push(path);
|
|
},
|
|
async write() {
|
|
throw new Error("Unexpected overwrite");
|
|
},
|
|
};
|
|
const pending = new Map([
|
|
[id, data],
|
|
["87654321-1234-1234-1234-123456789abc", data],
|
|
]);
|
|
const body = imageMarkdown("Screenshot", id);
|
|
await saveImages(workspace, body, pending);
|
|
assert.deepEqual(writes, [".runestone/pm/.gitignore", imagePath(id)]);
|
|
await saveImages(workspace, body, pending);
|
|
assert.equal(writes.length, 2);
|
|
files.set(imagePath(id), "other image");
|
|
await assert.rejects(saveImages(workspace, body, pending), /Already exists/);
|
|
assert.equal(files.get(imagePath(id)), "other image");
|
|
});
|
|
|
|
test("attachment metadata saves staged images without description references", async () => {
|
|
const files = new Map<string, string>();
|
|
const workspace: Workspace = {
|
|
async list() { return []; },
|
|
async read(path) { return files.get(path)!; },
|
|
async readOptional(path) { return files.get(path) ?? null; },
|
|
async create(path, source) { files.set(path, source); },
|
|
async write() { throw new Error("Unexpected overwrite"); },
|
|
};
|
|
await saveImages(workspace, "", new Map([[id, data]]), [{ id, name: "Attachment.png" }]);
|
|
assert.equal(parseImage(files.get(imagePath(id))!), data);
|
|
});
|
|
|
|
test("image storage accepts exactly 50 MiB and rejects one extra byte", async () => {
|
|
assert.equal(maxImageBytes, 50 * 1024 * 1024);
|
|
const data = `data:image/png;base64,${Buffer.alloc(maxImageBytes).toString("base64")}`;
|
|
const files = new Map<string, string>();
|
|
const workspace: Workspace = {
|
|
async list() { return []; }, async read(path) { return files.get(path)!; }, async readOptional(path) { return files.get(path) ?? null; },
|
|
async write() { throw new Error("Unexpected overwrite"); },
|
|
async create(path, source) { files.set(path, source); },
|
|
};
|
|
await saveImages(workspace, "", new Map([[id, data]]), [{ id, name: "large.png" }]);
|
|
assert.equal(parseImage(files.get(imagePath(id))!), data);
|
|
const tooLarge = `data:image/png;base64,${Buffer.alloc(maxImageBytes + 1).toString("base64")}`;
|
|
assert.throws(() => parseImage(JSON.stringify({ schema: 1, data: tooLarge })), /50 MiB/);
|
|
});
|