Add completion, browser integration, and workspace improvements

This commit is contained in:
Knotty Wyvern
2026-10-07 11:25:17 -07:00
parent dd9fc64676
commit a8b1defb9d
86 changed files with 3524 additions and 203 deletions
+44
View File
@@ -0,0 +1,44 @@
import test from "node:test";
import assert from "node:assert/strict";
import { ContributionRegistry } from "../src/lib/plugins/registry.ts";
import { ExternalSession } from "../src/lib/plugins/externalSession.ts";
import type { PluginApi } from "../src/lib/plugins/sdk.ts";
test("browser contributions and view updates are revoked when the plugin stops", async () => {
const registry = new ContributionRegistry();
let api!: PluginApi;
let disposed = false;
const received: string[] = [];
const session = new ExternalSession("runestone.browser", {
workspace: { list: async () => [], read: async () => "", write: async () => {} },
settings: { read: async () => null, write: async () => {} }, assets: { read: async () => new Uint8Array() },
}, () => {}, () => {}, registry);
await session.start({ activate(value) {
api = value;
api.registerView({ id: "tab-test", title: "Browser", placement: "editor", icon: "globe", mount: () => {} });
api.registerTabDrop!(data => { received.push(data); });
api.contribute("browser", { mountSettings: () => () => {}, mountBookmarks: () => () => {}, open: async () => true });
api.onDispose(() => { disposed = true; });
} });
assert.ok(registry.get("browser"));
await session.dropTab("live-tab");
assert.deepEqual(received, ["live-tab"]);
api.updateViewTitle!("tab-test", "Example · User");
assert.equal(session.views.get("tab-test")?.title, "Example · User");
const icon = "data:image/png;base64,aW1hZ2U=";
api.updateViewIcon!("tab-test", icon);
assert.equal(session.views.get("tab-test")?.iconImage, icon);
assert.throws(() => api.updateViewIcon!("tab-test", "https://example.com/icon.png"), /Invalid/);
assert.throws(() => api.updateViewIcon!("tab-test", "data:text/html;base64,aW1hZ2U="), /Invalid/);
assert.throws(() => api.updateViewIcon!("tab-test", "data:image/png;base64," + "a".repeat(90_000)), /Invalid/);
api.updateViewIcon!("tab-test", null);
assert.equal(session.views.get("tab-test")?.iconImage, null);
await session.stop();
assert.equal(registry.get("browser"), undefined);
assert.equal(disposed, true);
assert.throws(() => api.updateViewTitle!("tab-test", "Other"), /disabled/);
assert.throws(() => api.updateViewIcon!("tab-test", icon), /disabled/);
await assert.rejects(session.dropTab("closed-tab"), /disabled/);
assert.throws(() => api.registerTabDrop!(() => {}), /disabled/);
assert.deepEqual(received, ["live-tab"]);
});