import test from "node:test"; import assert from "node:assert/strict"; import { ExternalSession } from "../../../src/lib/plugins/externalSession.ts"; import { ContributionRegistry } from "../../../src/lib/plugins/registry.ts"; import type { PluginApi } from "../../../src/lib/plugins/sdk.ts"; test("file access stops before plugin cleanup, and plugins get no Git API", async () => { const calls: unknown[] = []; let api!: PluginApi; const session = new ExternalSession("test.files", { workspace: { list: async () => [], read: async () => "", write: async () => {} }, settings: { read: async () => null, write: async () => {} }, assets: { read: async () => new Uint8Array() }, openFile: async path => { calls.push(path); }, }, () => {}, () => {}, new ContributionRegistry()); await session.start({ activate(value) { api = value; } }); // Git is a native feature of RuneStone. The plugin API has no Git member. assert.equal("git" in api, false); await api.openFile!("notes.md"); assert.deepEqual(calls, ["notes.md"]); await session.stop(); assert.throws(() => api.openFile!("notes.md"), /disabled/); }); test("view replacement rejects unknown destinations and stops after disposal", async () => { let api!: PluginApi; const calls: unknown[] = []; const session = new ExternalSession("test.boards", { workspace: { list: async () => [], read: async () => "", write: async () => {} }, settings: { read: async () => null, write: async () => {} }, assets: { read: async () => new Uint8Array() }, }, () => {}, () => {}, new ContributionRegistry(), undefined, undefined, undefined, (current, next) => calls.push([current, next]), (document, next) => calls.push([document, next])); await session.start({ activate(value) { api = value; for (const id of ["a", "b"]) api.registerView({ id, title: id, placement: "editor", mount() {} }); api.registerView({ id: "sidebar", title: "Sidebar", placement: "sidebar", navigation: true, icon: "git", mount() {} }); } }); api.replaceView!("a", "b"); api.replaceDocumentWithView!({ id: "legacy", path: "Board.md" }, "b"); assert.deepEqual(calls, [["a", "b"], [{ id: "legacy", path: "Board.md" }, "b"]]); assert.throws(() => api.replaceView!("missing", "b"), /Unknown/); assert.throws(() => api.replaceDocumentWithView!({ id: "legacy", path: "Board.md" }, "missing"), /Unknown/); await session.stop(); assert.throws(() => api.replaceView!("a", "b"), /disabled/); });