Add completion, browser integration, and workspace improvements
This commit is contained in:
@@ -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"]);
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { CompletionHub, eligible } from '../src/lib/completion/hub.ts';
|
||||
import type { CompletionSnapshot } from '../src/lib/completion/contracts.ts';
|
||||
const snapshot = (): CompletionSnapshot => ({ documentId: 'doc', revision: 1, text: 'The ', caret: 4, selectionEnd: 4, focused: true, kind: 'prose' });
|
||||
const tick = () => new Promise(resolve => setTimeout(resolve, 0));
|
||||
test('sensitive fields, composition, selections, code blocks and link targets are excluded', () => {
|
||||
assert(eligible(snapshot()));
|
||||
for (const change of [{ sensitive: true }, { composing: true }, { readOnly: true }, { selectionEnd: 0 }, { focused: false }]) assert(!eligible({ ...snapshot(), ...change }));
|
||||
for (const text of ['```js\nlet ', '[name](http', '| cell ', '`source', '---\nname: ']) assert(!eligible({ ...snapshot(), text, caret: text.length, selectionEnd: text.length }));
|
||||
assert(eligible({ ...snapshot(), kind: 'code', text: 'let ', caret: 4 }));
|
||||
});
|
||||
test('a new revision blocks stale insertion even when the provider ignores cancellation', async () => {
|
||||
const hub = new CompletionHub(); let state = snapshot(), emit!: (text: string) => void, finish!: (text: string) => void, visible = '', edits = 0;
|
||||
hub.registerProvider({ id: 'model', complete: (_request, publish) => { emit = publish; return new Promise(resolve => finish = resolve); } });
|
||||
const field = hub.registerSurface({ id: 'field', snapshot: () => state, preview: text => visible = text || '', insert: () => { edits++; return true; } });
|
||||
field.request(); emit('harbor'); assert.equal(visible, 'harbor');
|
||||
state = { ...state, revision: 2, text: 'The old ', caret: 8, selectionEnd: 8 };
|
||||
assert.equal(field.accept(), false); finish('late'); await tick(); assert.equal(visible, ''); assert.equal(edits, 0); field.dispose();
|
||||
});
|
||||
test('acceptance is explicit and provider removal clears all surfaces', async () => {
|
||||
const hub = new CompletionHub(); let visible = '', inserted = '';
|
||||
const remove = hub.registerProvider({ id: 'model', complete: async () => 'quiet harbor' });
|
||||
const field = hub.registerSurface({ id: 'field', snapshot, preview: text => visible = text || '', insert: text => { inserted = text; return true; } });
|
||||
field.request(); await tick(); assert.equal(inserted, ''); assert.equal(visible, 'quiet harbor');
|
||||
assert(field.accept(true)); assert.equal(inserted, 'quiet '); assert.equal(visible, '');
|
||||
field.request(); await tick(); remove(); assert.equal(visible, ''); assert.equal(field.accept(), false); field.dispose();
|
||||
});
|
||||
test('moving between fields cancels the previous request', async () => {
|
||||
const hub = new CompletionHub(); const signals: AbortSignal[] = [];
|
||||
hub.registerProvider({ id: 'model', complete: request => { signals.push(request.signal); return new Promise(() => {}); } });
|
||||
const a = hub.registerSurface({ id: 'a', snapshot, preview() {}, insert: () => true });
|
||||
const b = hub.registerSurface({ id: 'b', snapshot, preview() {}, insert: () => true });
|
||||
a.request(); b.request(); assert(signals[0].aborted); assert(!signals[1].aborted); a.dispose(); b.dispose();
|
||||
});
|
||||
@@ -11,6 +11,24 @@ function fixture() {
|
||||
}, () => {}, () => {});
|
||||
return { session, writes: () => writes };
|
||||
}
|
||||
|
||||
test("native Markdown discovery remains optional and is revoked on disable", async () => {
|
||||
let api!: PluginApi;
|
||||
let scans = 0;
|
||||
const session = new ExternalSession("org.test.scan", {
|
||||
workspace: { list: async () => [], listMarkdown: async () => { scans++; return ["Notes/task.md"]; }, read: async () => "", write: async () => {} },
|
||||
settings: { read: async () => null, write: async () => {} },
|
||||
assets: { read: async () => new Uint8Array() },
|
||||
}, () => {}, () => {});
|
||||
await session.start({ activate(value) { api = value; } });
|
||||
assert.deepEqual(await api.workspace.listMarkdown!(), ["Notes/task.md"]);
|
||||
await session.stop();
|
||||
assert.throws(() => api.workspace.listMarkdown!(), /disabled/);
|
||||
assert.equal(scans, 1);
|
||||
const old = fixture().session;
|
||||
await old.start({ activate(value) { assert.equal(value.workspace.listMarkdown, undefined); } });
|
||||
await old.stop();
|
||||
});
|
||||
test("external commands run and all host access stops before cleanup", async () => {
|
||||
const { session, writes } = fixture(); let api!: PluginApi; let ran = 0;
|
||||
await session.start({ activate(value) {
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
await mkdir(".audit", { recursive: true });
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\smoke-workspace";
|
||||
const files = new Map([
|
||||
["notes/welcome.md", "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n"],
|
||||
["notes/second.md", "# Second note\n"],
|
||||
["src/hello.py", "print('hello')\n"],
|
||||
]);
|
||||
const callbacks = new Map();
|
||||
const listeners = new Map();
|
||||
let sequence = 0;
|
||||
const calls = [];
|
||||
const emit = (event, payload) => {
|
||||
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
|
||||
};
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
calls.push({ command, args });
|
||||
if (command === "plugin:event|listen") {
|
||||
const list = listeners.get(args.event) || []; list.push(args.handler); listeners.set(args.event, list); return args.handler;
|
||||
}
|
||||
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "smoke-workspace", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") {
|
||||
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
files.set(args.rel, args.contents); emit("workspace-event", { root, kind: "modify", paths: [args.rel] }); return;
|
||||
}
|
||||
if (command === "workspace_list") {
|
||||
const prefix = args.rel ? args.rel + "/" : "";
|
||||
const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
|
||||
const tail = path.slice(prefix.length); const name = tail.split("/")[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === "workspace_create") { if (files.has(args.rel)) throw new Error("exists"); files.set(args.rel, ""); return; }
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "pty_open") {
|
||||
const data = [...new TextEncoder().encode("READY 🪨\r\n\x1b[6n")];
|
||||
emit("pty-data", { id: args.id, data: data.slice(0, 8) });
|
||||
emit("pty-data", { id: args.id, data: data.slice(8) });
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
return;
|
||||
}
|
||||
if (command.startsWith("pty_")) return;
|
||||
if (command === "plugin:dialog|message") return "Cancel";
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
window.__TEST__ = { files, calls, emit, root };
|
||||
});
|
||||
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/.vite/deps/@codemirror_view.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
for (const count of [3, 1000, 5000]) {
|
||||
const result = await page.evaluate(async count => {
|
||||
const { EditorView } = await import("/node_modules/.vite/deps/@codemirror_view.js");
|
||||
const view = window.__CM__;
|
||||
const source = Array.from({ length: count }, (_, i) => "## Heading " + i + "\n\n**Bold** and *italic*\n\n").join("");
|
||||
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: "" } });
|
||||
view.focus();
|
||||
const clipboardData = new DataTransfer();
|
||||
clipboardData.setData("text/plain", source);
|
||||
view.contentDOM.dispatchEvent(new ClipboardEvent("paste", { bubbles: true, cancelable: true, clipboardData }));
|
||||
view.dispatch({ selection: { anchor: 0 } });
|
||||
const { forceParsing, syntaxTree } = await import("/node_modules/.vite/deps/@codemirror_language.js");
|
||||
forceParsing(view, view.state.doc.length, 5000);
|
||||
const nodes = [];
|
||||
syntaxTree(view.state).iterate({ enter(node) { if (node.name === "StrongEmphasis") nodes.push(node.from); } });
|
||||
const marks = [];
|
||||
for (const set of view.state.facet(EditorView.decorations)) {
|
||||
if (typeof set !== "function") set.between(0, view.state.doc.length, (from, to, decoration) => { if (decoration.spec.class === "writer-strong") marks.push(from); });
|
||||
}
|
||||
return { correctSource: view.state.sliceDoc() === source, nodes: nodes.length, marks: marks.length };
|
||||
}, count);
|
||||
console.log({ count, ...result });
|
||||
assert.equal(result.correctSource, true);
|
||||
assert.equal(result.nodes, count);
|
||||
assert.equal(result.marks, count);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
} finally { await browser.close(); }
|
||||
@@ -81,7 +81,15 @@ try {
|
||||
await page.getByRole("navigation", { name: "Workspace files" }).click({ button: "right", position: { x: 100, y: 350 } });
|
||||
await file.waitFor();
|
||||
assert.deepEqual(await metrics(file), reference, "Pane and file menus share styles");
|
||||
await dismiss();
|
||||
assert.equal(await item("Show in Explorer").locator("svg.action-icon").count(), 1);
|
||||
await page.keyboard.press("End");
|
||||
assert.equal(await item("Show in Explorer").evaluate(node => node === document.activeElement), true);
|
||||
await page.keyboard.press("Enter");
|
||||
await file.waitFor({ state: "detached" });
|
||||
assert.equal(await page.evaluate(() => window.tabMenuTest.revealed), "", "Pane action opens the workspace root");
|
||||
await row.click({ button: "right" });
|
||||
await item("Show in Explorer").click();
|
||||
assert.equal(await page.evaluate(() => window.tabMenuTest.revealed), "a.md", "File action reveals the selected file");
|
||||
await page.locator('[data-tree-rel="notes"]').click({ button: "right" });
|
||||
assert.deepEqual(await metrics(file), reference, "Folder and file menus share styles");
|
||||
await dismiss();
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const origin = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
||||
const errors = [];
|
||||
await mkdir(".audit", { recursive: true });
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const callbacks = new Map(), listeners = new Map();
|
||||
let sequence = 0;
|
||||
const emit = (event, payload) => { for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload }); };
|
||||
const manifest = (id, name) => ({ schemaVersion: 1, id, name, author: "Test", description: "Access test", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" });
|
||||
const plugins = [manifest("runestone.local-autocomplete", "Local Autocomplete"), manifest("runestone.browser", "Browser"), manifest("org.example.tasks", "Tasks")];
|
||||
const modules = {
|
||||
"runestone.local-autocomplete": `export function activate(api) {
|
||||
window.accessTest = { mounts: 0, disposed: 0, settings: 0 };
|
||||
api.settings.subscribe?.(() => { window.accessTest.settings++; });
|
||||
api.registerView({ id: 'settings', title: 'Local Autocomplete', placement: 'editor', mount(container, context) {
|
||||
window.accessTest.mounts++;
|
||||
container.innerHTML = '<h2>Local Autocomplete</h2><label>Model<input aria-label="Model"></label><button>Save model</button><p class="mount-context"></p>';
|
||||
container.querySelector('p').textContent = context?.surface;
|
||||
container.querySelector('button').onclick = () => api.settings.write({ model: container.querySelector('input').value });
|
||||
return () => { window.accessTest.disposed++; };
|
||||
}});
|
||||
api.registerCommand({ id: 'configure', title: 'Configure local autocomplete', run: () => api.openView('settings') });
|
||||
api.registerCommand({ id: 'fail', title: 'Failed command', run: () => { throw Error('Command failed for test'); } });
|
||||
}`,
|
||||
"runestone.browser": `export function activate(api) {
|
||||
api.registerCommand({ id: 'new-tab', title: 'New browser tab', run() {
|
||||
const id = 'tab-' + Date.now(); api.registerView({ id, title: 'Browser instance', placement: 'editor', mount(container) { container.textContent = 'Browser content'; } }); api.openView(id);
|
||||
}});
|
||||
}`,
|
||||
"org.example.tasks": `export function activate(api) {
|
||||
api.registerView({ id: 'tasks', title: 'All tasks', icon: 'list', navigation: true, placement: 'editor', mount(container) { container.textContent = 'Task content'; } });
|
||||
api.registerView({ id: 'dialog', title: 'Task summary', mount(container) { container.textContent = 'Task summary content'; } });
|
||||
}`,
|
||||
};
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === 'plugin:event|listen') { const ids = listeners.get(args.event) || []; ids.push(args.handler); listeners.set(args.event, ids); return args.handler; }
|
||||
if (command === 'plugin:event|unlisten') { callbacks.delete(args.eventId); return; }
|
||||
if (command === 'workspace_last_path') return null;
|
||||
if (command === 'plugins_snapshot') return { root: 'C:/test/plugins', plugins: plugins.map(manifest => ({ manifest, hash: 'test', enabled: !(manifest.id === 'runestone.local-autocomplete' && localStorage.getItem('disabled')), installedAt: 1, path: 'C:/test/plugins/' + manifest.id, error: null, removal: false })) };
|
||||
if (command === 'plugins_load') return modules[args.id];
|
||||
if (command === 'plugins_data') {
|
||||
if (args.value !== null) { localStorage.setItem('settings:' + args.id, args.value); emit('plugin-settings-changed', args.id); }
|
||||
return localStorage.getItem('settings:' + args.id) || 'null';
|
||||
}
|
||||
if (command === 'plugins_set_enabled') { if (!args.enabled) localStorage.setItem('disabled', 'true'); emit('plugins-changed', {}); return; }
|
||||
if (command === 'plugins_release' || command === 'settings_open_window') return;
|
||||
if (command.startsWith('plugin:window|')) return false;
|
||||
throw new Error('Unhandled IPC: ' + command);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
window.addEventListener('storage', event => { if (event.key?.startsWith('settings:')) emit('plugin-settings-changed', event.key.slice(9)); if (event.key === 'disabled') emit('plugins-changed', {}); });
|
||||
});
|
||||
const main = await context.newPage(), settings = await context.newPage();
|
||||
for (const page of [main, settings]) { page.setDefaultTimeout(10000); page.on('pageerror', error => errors.push(error.message)); }
|
||||
try {
|
||||
await main.goto(origin);
|
||||
const open = main.getByRole('button', { name: 'Open tab or view', exact: true });
|
||||
await open.click();
|
||||
const menu = main.getByRole('menu', { name: 'Open tab or view', exact: true });
|
||||
await menu.waitFor();
|
||||
assert.equal(await menu.getByRole('menuitem').count(), 3);
|
||||
assert.equal(await menu.getByText('Local Autocomplete').count(), 0);
|
||||
await open.click(); await menu.waitFor({ state: 'detached' });
|
||||
await open.focus(); await main.keyboard.press('Enter'); await main.keyboard.press('End'); await main.keyboard.press('Escape');
|
||||
assert(await open.evaluate(element => element === document.activeElement));
|
||||
await open.click(); await menu.getByRole('menuitem', { name: /New browser tab/ }).click();
|
||||
await main.getByText('Browser content', { exact: true }).waitFor();
|
||||
await open.click(); assert.equal(await menu.getByRole('menuitem').count(), 3);
|
||||
await menu.getByRole('menuitem', { name: /Task summary/ }).click();
|
||||
await main.getByRole('dialog', { name: 'Task summary' }).waitFor();
|
||||
await main.keyboard.press('Escape');
|
||||
await open.click(); await main.screenshot({ path: '.audit/plugin-access-menu.png' }); await main.keyboard.press('Escape');
|
||||
await main.evaluate(() => document.documentElement.dataset.theme = 'light');
|
||||
await open.click(); await main.screenshot({ path: '.audit/plugin-access-menu-light.png' }); await main.keyboard.press('Escape');
|
||||
await main.evaluate(() => document.documentElement.dataset.theme = 'dark');
|
||||
await main.getByRole('button', { name: 'Commands', exact: true }).click();
|
||||
await main.getByRole('menuitem', { name: /Failed command/ }).click();
|
||||
await main.getByRole('alert').filter({ hasText: 'Command failed for test' }).waitFor();
|
||||
await main.getByRole('button', { name: 'Dismiss', exact: true }).click();
|
||||
await settings.goto(origin + '/?settingsWindow=true');
|
||||
await settings.getByRole('button', { name: 'Local Autocomplete', exact: true }).click();
|
||||
await settings.getByRole('textbox', { name: 'Model', exact: true }).fill('unsaved-model');
|
||||
assert.equal(await settings.locator('.mount-context').innerText(), 'settings');
|
||||
await settings.waitForTimeout(5500);
|
||||
assert.equal(await settings.getByRole('textbox', { name: 'Model', exact: true }).inputValue(), 'unsaved-model');
|
||||
assert.equal(await settings.evaluate(() => window.accessTest.mounts), 1);
|
||||
await settings.getByRole('button', { name: 'Save model', exact: true }).click();
|
||||
await main.waitForFunction(() => window.accessTest.settings === 1);
|
||||
await settings.screenshot({ path: '.audit/plugin-access-settings.png' });
|
||||
await settings.getByRole('button', { name: 'General', exact: true }).click();
|
||||
await settings.waitForFunction(() => window.accessTest.disposed === 1);
|
||||
await settings.getByRole('textbox', { name: 'Search settings' }).fill('Local');
|
||||
await settings.getByRole('textbox', { name: 'Model', exact: true }).waitFor();
|
||||
await settings.getByRole('textbox', { name: 'Search settings' }).fill('');
|
||||
await settings.getByRole('button', { name: 'Plug-ins', exact: true }).click();
|
||||
await settings.getByRole('switch', { name: 'Local Autocomplete', exact: true }).uncheck();
|
||||
await settings.getByRole('button', { name: 'Local Autocomplete', exact: true }).waitFor({ state: 'detached' });
|
||||
await main.getByRole('button', { name: 'Commands', exact: true }).waitFor({ state: 'detached' });
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('Plugin access smoke passed: launchers, dynamic tabs, keyboard focus, dialog, settings search, stable forms, cross-window settings, disable cleanup.');
|
||||
} catch (error) {
|
||||
await settings.screenshot({ path: '.audit/plugin-access-failure.png' });
|
||||
console.log(await settings.locator('body').innerText(), await settings.evaluate(() => window.accessTest), errors);
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,75 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { pluginAccess } from "../src/lib/plugins/access.ts";
|
||||
import { ExternalSession } from "../src/lib/plugins/externalSession.ts";
|
||||
import type { PluginApi, PluginCommand, PluginView } from "../src/lib/plugins/sdk.ts";
|
||||
|
||||
const view = (id: string, extra: Partial<PluginView> = {}): PluginView => ({ id, title: id, mount() {}, ...extra });
|
||||
const command = (id: string, extra: Partial<PluginCommand> = {}): PluginCommand => ({ id, title: id, run() {}, ...extra });
|
||||
|
||||
test("plugin access separates settings, launchers, and commands without reading titles", () => {
|
||||
const tools = pluginAccess("org.example.test", [command("open", { category: "open" }), command("configure")], [view("preferences", { settings: true }), view("tasks"), view("instance", { launcher: false })]);
|
||||
assert.deepEqual(tools.map(({ id, surface }) => [id, surface]), [["open", "open"], ["configure", "commands"], ["preferences", "settings"], ["tasks", "open"]]);
|
||||
});
|
||||
|
||||
test("installed RuneStone packages retain access before their next package update", () => {
|
||||
assert.equal(pluginAccess("runestone.local-autocomplete", [], [view("settings")])[0].surface, "settings");
|
||||
assert.deepEqual(pluginAccess("runestone.browser", [command("new-tab")], [view("tab-123")]).map(({ id, surface }) => [id, surface]), [["new-tab", "open"]]);
|
||||
assert.equal(pluginAccess("org.example.test", [], [view("settings")])[0].surface, "open");
|
||||
assert.equal(pluginAccess("runestone.local-autocomplete", [], [view("settings", { settings: false })])[0].surface, "open");
|
||||
assert.equal(pluginAccess("runestone.browser", [command("new-tab", { category: "action" })], [])[0].surface, "commands");
|
||||
});
|
||||
|
||||
test("settings listeners are removable and revoked before plugin cleanup", async () => {
|
||||
let api!: PluginApi, notify!: () => void;
|
||||
let received = 0, disposed = 0;
|
||||
const session = new ExternalSession("org.example.settings", {
|
||||
workspace: { list: async () => [], read: async () => "", write: async () => {} },
|
||||
assets: { read: async () => new Uint8Array() },
|
||||
settings: { read: async () => null, write: async () => {}, subscribe(listener) { notify = listener; return () => { disposed++; }; } },
|
||||
}, () => {}, () => {});
|
||||
await session.start({ activate(value) { api = value; } });
|
||||
const off = api.settings.subscribe!(() => { received++; });
|
||||
notify(); assert.equal(received, 1);
|
||||
await off(); await off(); assert.equal(disposed, 1);
|
||||
api.settings.subscribe!(() => { received++; });
|
||||
await session.stop(); notify();
|
||||
assert.equal(received, 1); assert.equal(disposed, 2);
|
||||
assert.throws(() => api.settings.subscribe!(() => {}), /disabled/);
|
||||
});
|
||||
|
||||
test("invalid access metadata fails registration", async () => {
|
||||
for (const activate of [
|
||||
(api: PluginApi) => api.registerCommand(command("invalid", { category: "unknown" as "open" })),
|
||||
(api: PluginApi) => api.registerView(view("invalid", { settings: "yes" as unknown as boolean })),
|
||||
(api: PluginApi) => api.registerView(view("invalid", { launcher: "yes" as unknown as boolean })),
|
||||
]) {
|
||||
const session = new ExternalSession("org.example.invalid", {
|
||||
workspace: { list: async () => [], read: async () => "", write: async () => {} },
|
||||
assets: { read: async () => new Uint8Array() }, settings: { read: async () => null, write: async () => {} },
|
||||
}, () => {}, () => {});
|
||||
await assert.rejects(session.start({ activate }), /category|boolean/);
|
||||
await session.stop();
|
||||
}
|
||||
});
|
||||
|
||||
test("settings windows permit model checks and cancellation", () => {
|
||||
const capability = JSON.parse(readFileSync(new URL("../src-tauri/capabilities/settings.json", import.meta.url), "utf8"));
|
||||
for (const permission of ["allow-completion-request", "allow-completion-cancel", "allow-plugins-data"]) assert(capability.permissions.includes(permission));
|
||||
});
|
||||
|
||||
test("view mount context distinguishes Settings from editor and dialog views", async () => {
|
||||
const surfaces: string[] = [];
|
||||
const session = new ExternalSession("org.example.context", {
|
||||
workspace: { list: async () => [], read: async () => "", write: async () => {} },
|
||||
assets: { read: async () => new Uint8Array() }, settings: { read: async () => null, write: async () => {} },
|
||||
}, () => {}, () => {});
|
||||
await session.start({ activate(api) { api.registerView(view("settings", { mount(_element, context) { surfaces.push(context!.surface); } })); } });
|
||||
const target = { replaceChildren() {} } as unknown as HTMLElement;
|
||||
const disposeView = await session.mount("settings", target);
|
||||
await disposeView();
|
||||
const disposeSettings = await session.mount("settings", target, undefined, "settings");
|
||||
await disposeSettings(); await session.stop();
|
||||
assert.deepEqual(surfaces, ["view", "settings"]);
|
||||
});
|
||||
@@ -7,10 +7,15 @@ const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 }, locale: 'en-US', timezoneId: 'America/Vancouver' });
|
||||
const page = await context.newPage();
|
||||
const settingsPage = await context.newPage();
|
||||
settingsPage.setDefaultTimeout(10000);
|
||||
await context.exposeBinding("settingsHostInvoke", (_source, command, args) =>
|
||||
page.evaluate(({ command, args }) => window.__TAURI_INTERNALS__.invoke(command, args), { command, args }));
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
settingsPage.on("pageerror", error => errors.push(error.message));
|
||||
const manifest = JSON.parse(readFileSync('fixtures/plugins/workspace-overview/plugin.json', 'utf8'));
|
||||
const pluginCode = readFileSync('fixtures/plugins/workspace-overview/main.js', 'utf8') + '\n// Browser cleanup probe\n';
|
||||
await page.context().addInitScript(({ manifest, pluginCode }) => {
|
||||
@@ -38,7 +43,10 @@ await page.context().addInitScript(({ manifest, pluginCode }) => {
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
if (location.search.includes("settingsWindow") && !command.startsWith("plugin:event|") && !command.startsWith("plugin:window|"))
|
||||
return window.settingsHostInvoke(command, args);
|
||||
calls.push({ command, args });
|
||||
if (command === "settings_open_window") return;
|
||||
if (command === "plugin:window|is_maximized") return false;
|
||||
if (command.startsWith("plugin:window|")) return null;
|
||||
if (command === "plugins_snapshot") return snapshot();
|
||||
@@ -117,10 +125,11 @@ async function quickOpen(name) {
|
||||
}
|
||||
|
||||
|
||||
const settingsDialog = page.getByRole('dialog', { name: 'Settings', exact: true });
|
||||
const settingsDialog = settingsPage.getByRole('dialog', { name: 'Settings', exact: true });
|
||||
const count = command => page.evaluate(command => window.__TEST__.calls.filter(call => call.command === command).length, command);
|
||||
async function settings() {
|
||||
await page.getByRole('button', { name: 'Settings (Ctrl+,)', exact: true }).click();
|
||||
await settingsPage.goto((process.env.SMOKE_URL || 'http://127.0.0.1:1420') + '/?settingsWindow=true');
|
||||
await settingsDialog.getByRole('button', { name: 'Plug-ins', exact: true }).click();
|
||||
}
|
||||
async function uninstall() { await settingsDialog.locator('.card').filter({ hasText: 'Workspace overview' }).getByRole('button', { name: 'Uninstall', exact: true }).click(); }
|
||||
@@ -131,13 +140,13 @@ try {
|
||||
assert.equal(await settingsDialog.getByRole('button', { name: 'Install from folder', exact: true }).count(), 0);
|
||||
assert.equal(await settingsDialog.getByRole('button', { name: 'Install from file', exact: true }).count(), 0);
|
||||
await settingsDialog.getByRole('button', { name: 'Install plugin ZIP', exact: true }).click();
|
||||
let review = page.getByRole('dialog', { name: 'Review plugin installation', exact: true });
|
||||
let review = settingsPage.getByRole('dialog', { name: 'Review plugin installation', exact: true });
|
||||
await review.getByText('Source: C:/Downloads/overview.zip', { exact: true }).waitFor();
|
||||
await review.getByRole('button', { name: 'Cancel', exact: true }).click();
|
||||
assert.equal(await count('plugins_install'), 0);
|
||||
const gitButton = settingsDialog.getByRole('button', { name: 'Install from Git link', exact: true });
|
||||
await gitButton.click();
|
||||
const gitDialog = page.getByRole('dialog', { name: 'Install from Git link', exact: true });
|
||||
const gitDialog = settingsPage.getByRole('dialog', { name: 'Install from Git link', exact: true });
|
||||
await gitDialog.getByLabel('Repository link', { exact: true }).fill('https://git.example/owner/plugin.git');
|
||||
await gitDialog.getByLabel('Release tag (optional)', { exact: true }).fill('missing');
|
||||
await gitDialog.getByLabel('Access token (optional)', { exact: true }).fill('test-token');
|
||||
@@ -156,8 +165,8 @@ try {
|
||||
assert(await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).isChecked());
|
||||
assert.equal(await settingsDialog.locator('time').getAttribute('datetime'), '2026-10-05T18:24:36.000Z');
|
||||
assert.match(await settingsDialog.locator('time').innerText(), /Oct 5, 2026.*11:24:36 AM PDT/);
|
||||
await page.screenshot({ path: '.audit/plugin-manager-installed.png' });
|
||||
await page.keyboard.press('Escape');
|
||||
await settingsPage.screenshot({ path: '.audit/plugin-manager-installed.png' });
|
||||
await settingsPage.keyboard.press('Escape');
|
||||
await page.getByRole('button', { name: 'Plugin commands and views', exact: true }).click();
|
||||
await page.getByRole('button', { name: /Show workspace overview/ }).click();
|
||||
const view = page.getByRole('dialog', { name: 'Workspace overview', exact: true });
|
||||
@@ -165,7 +174,7 @@ try {
|
||||
await view.getByRole('button', { name: 'Close plugin view', exact: true }).click();
|
||||
await settings();
|
||||
await uninstall();
|
||||
const confirmation = page.getByRole('dialog', { name: 'Uninstall Workspace overview?', exact: true });
|
||||
const confirmation = settingsPage.getByRole('dialog', { name: 'Uninstall Workspace overview?', exact: true });
|
||||
assert(await confirmation.getByRole('button', { name: 'Cancel', exact: true }).evaluate(el => el === document.activeElement));
|
||||
assert.equal(await confirmation.getByRole('button', { name: 'Continue', exact: true }).count(), 0);
|
||||
await confirmation.getByRole('button', { name: 'Cancel', exact: true }).click();
|
||||
@@ -173,27 +182,27 @@ try {
|
||||
assert(await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).isChecked());
|
||||
await uninstall();
|
||||
await confirmation.waitFor();
|
||||
await page.keyboard.press('Escape');
|
||||
await settingsPage.keyboard.press('Escape');
|
||||
assert(await settingsDialog.isVisible());
|
||||
assert(await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).isChecked());
|
||||
assert.equal(await count('plugins_remove'), 0);
|
||||
await uninstall();
|
||||
await confirmation.waitFor();
|
||||
await page.screenshot({ path: '.audit/plugin-uninstall-confirmation.png' });
|
||||
await settingsPage.screenshot({ path: '.audit/plugin-uninstall-confirmation.png' });
|
||||
await confirmation.getByRole('button', { name: 'Uninstall and delete files', exact: true }).click();
|
||||
await settingsDialog.getByText('No plugins installed.', { exact: true }).waitFor();
|
||||
assert.equal(await count('plugins_remove'), 1);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.cleaned), true);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.data.preserved), true);
|
||||
await page.keyboard.press('Escape');
|
||||
await settingsPage.keyboard.press('Escape');
|
||||
assert.equal(await page.getByRole('button', { name: 'Plugin commands and views', exact: true }).count(), 0);
|
||||
await page.setViewportSize({ width: 590, height: 820 });
|
||||
await settingsPage.setViewportSize({ width: 590, height: 820 });
|
||||
await settings();
|
||||
await page.screenshot({ path: '.audit/plugin-manager-narrow.png' });
|
||||
await settingsPage.screenshot({ path: '.audit/plugin-manager-narrow.png' });
|
||||
assert.equal(await settingsDialog.evaluate(element => element.scrollWidth > element.clientWidth), false);
|
||||
await gitButton.click();
|
||||
await gitDialog.getByLabel('Repository link', { exact: true }).fill('https://git.example/owner/plugin.git');
|
||||
await page.screenshot({ path: '.audit/plugin-git-narrow.png' });
|
||||
await settingsPage.screenshot({ path: '.audit/plugin-git-narrow.png' });
|
||||
assert.equal(await gitDialog.evaluate(element => element.scrollWidth > element.clientWidth), false);
|
||||
await gitDialog.getByRole('button', { name: 'Review release', exact: true }).click();
|
||||
await review.getByRole('button', { name: 'Install', exact: true }).click();
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
const page = await context.newPage();
|
||||
await context.exposeBinding("settingsHostInvoke", (_source, command, args) =>
|
||||
page.evaluate(({ command, args }) => window.__TAURI_INTERNALS__.invoke(command, args), { command, args }));
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
const pluginCode = `export function activate(api) {
|
||||
window.tabTest.api = api;
|
||||
const mount = (id, container) => {
|
||||
window.tabTest.mounts[id] = (window.tabTest.mounts[id] || 0) + 1;
|
||||
const input = document.createElement("input");
|
||||
input.setAttribute("aria-label", id + " state");
|
||||
container.append(input);
|
||||
return () => {
|
||||
window.tabTest.disposals[id] = (window.tabTest.disposals[id] || 0) + 1;
|
||||
input.remove();
|
||||
};
|
||||
};
|
||||
for (const [id, title, icon] of [["overview", "Overview", "puzzle"], ["browser", "Browser", "globe"]]) {
|
||||
api.registerView({ id, title, icon, placement: "editor", navigation: true, mount: container => mount(id, container) });
|
||||
}
|
||||
api.registerDocumentType({
|
||||
id: "board", title: "Board", icon: "kanban", extensions: ["board"],
|
||||
identify: (path, source) => ({ id: source }),
|
||||
mount: (container, document) => mount(document.id, container),
|
||||
});
|
||||
}`;
|
||||
await context.addInitScript(({ pluginCode }) => {
|
||||
window.isTauri = true;
|
||||
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false, autosaveSeconds: 5 }));
|
||||
const root = "C:\\plugin-tab-workspace";
|
||||
const files = new Map(["a.md", "b.md", "c.md", ...Array.from({ length: 14 }, (_, index) => `note-${index}.md`)].map(name => [name, `# ${name}\n\nOriginal text.\n`]));
|
||||
files.set("project.board", "project-board");
|
||||
const callbacks = new Map(), listeners = new Map();
|
||||
let sequence = 0, enabled = true;
|
||||
const manifest = { schemaVersion: 1, id: "test.tabs", name: "Tab fixtures", author: "Tests", description: "Test editor tabs.", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" };
|
||||
const emit = (event, payload) => {
|
||||
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
|
||||
};
|
||||
window.tabTest = { mounts: {}, disposals: {}, answer: "Cancel", prompts: 0, files };
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
if (location.search.includes("settingsWindow") && !command.startsWith("plugin:event|") && !command.startsWith("plugin:window|"))
|
||||
return window.settingsHostInvoke(command, args);
|
||||
if (command === "settings_open_window") return;
|
||||
if (command === "plugin:event|listen") {
|
||||
const ids = listeners.get(args.event) || []; ids.push(args.handler); listeners.set(args.event, ids); return args.handler;
|
||||
}
|
||||
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
|
||||
if (command === "plugin:window|is_maximized") return false;
|
||||
if (command.startsWith("plugin:window|")) return;
|
||||
if (command === "plugins_snapshot") return { root, plugins: [{ manifest, hash: "test", enabled, path: root, error: null, removal: false }] };
|
||||
if (command === "plugins_load") return pluginCode;
|
||||
if (command === "plugins_data") return "null";
|
||||
if (command === "plugins_release") return;
|
||||
if (command === "plugins_set_enabled") { enabled = args.enabled; emit("plugins-changed"); return; }
|
||||
if (command === "workspace_last_path") return location.search.includes("no-workspace") ? null : root;
|
||||
if (command === "workspace_open") return { root, name: "plugin-tab-workspace", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") { files.set(args.rel, args.contents); return; }
|
||||
if (command === "workspace_list") return args.rel ? [] : [...files.keys()].map(name => ({ name, rel_path: name, kind: "file" }));
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "plugin:dialog|message") { window.tabTest.prompts++; return window.tabTest.answer; }
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
}, { pluginCode });
|
||||
|
||||
const tab = name => page.getByRole("tab", { name, exact: true });
|
||||
const bar = page.getByRole("tablist", { name: "Working tabs" });
|
||||
const order = () => bar.getByRole("tab").evaluateAll(nodes => nodes.map(node => node.textContent.trim()));
|
||||
const settle = () => page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
|
||||
async function openFile(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await settle();
|
||||
}
|
||||
async function openView(name) {
|
||||
await page.getByRole("navigation", { name: "Plugin shortcuts" }).getByRole("button", { name, exact: true }).click();
|
||||
await tab(name).waitFor();
|
||||
}
|
||||
async function drag(from, to, side = "before", cancel) {
|
||||
const source = await tab(from).boundingBox(), target = await tab(to).boundingBox();
|
||||
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(side === "before" ? target.x + 2 : target.x + target.width - 2, target.y + target.height / 2, { steps: 10 });
|
||||
if (cancel === "escape") await page.keyboard.press("Escape");
|
||||
if (cancel === "outside") await page.mouse.move(target.x, target.y + 100);
|
||||
await page.mouse.up();
|
||||
await settle();
|
||||
}
|
||||
async function menu(name) {
|
||||
await tab(name).click({ button: "right" });
|
||||
await page.getByRole("menu", { name: "Tab actions" }).waitFor();
|
||||
}
|
||||
|
||||
try {
|
||||
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
await page.goto(url);
|
||||
await page.getByText("plugin-tab-workspace", { exact: true }).waitFor();
|
||||
await openFile("a.md");
|
||||
await openFile("b.md");
|
||||
await openView("Overview");
|
||||
await page.getByRole("textbox", { name: "overview state" }).fill("Keep this state");
|
||||
await openView("Browser");
|
||||
const siteIcon = "data:image/svg+xml;base64," + Buffer.from('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><rect width="16" height="16" rx="3" fill="#e35336"/></svg>').toString('base64');
|
||||
await page.evaluate(image => window.tabTest.api.updateViewIcon("browser", image), siteIcon);
|
||||
await tab("Browser").locator("img.tab-icon").waitFor();
|
||||
await page.waitForFunction(() => document.querySelector('.header img.tab-icon')?.naturalWidth === 16);
|
||||
assert.equal(await tab("Browser").locator("img").getAttribute("alt"), "");
|
||||
assert.equal(await tab("Browser").locator("img").getAttribute("draggable"), "false");
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
||||
await mkdir("output", { recursive: true });
|
||||
await page.locator(".header").screenshot({ path: `output/tab-site-icon-${theme}.png` });
|
||||
}
|
||||
await page.evaluate(() => window.tabTest.api.updateViewIcon("browser", "data:image/png;base64,aW1hZ2U="));
|
||||
await tab("Browser").locator("img").waitFor({ state: "detached" });
|
||||
assert.equal(await tab("Browser").locator("svg").count(), 1);
|
||||
await page.evaluate(image => window.tabTest.api.updateViewIcon("browser", image), siteIcon);
|
||||
await tab("Browser").locator("img").waitFor();
|
||||
await page.evaluate(() => window.tabTest.api.updateViewIcon("browser", null));
|
||||
await tab("Browser").locator("img").waitFor({ state: "detached" });
|
||||
assert.equal(await tab("Browser").locator("svg").count(), 1);
|
||||
console.log("PASS: site icons appear in both themes and missing or broken icons use the fallback");
|
||||
await openFile("project.board");
|
||||
await tab("project").waitFor();
|
||||
assert.equal(await page.locator(".header").getByRole("tablist").count(), 1);
|
||||
assert.deepEqual(await order(), ["a.md", "b.md", "Overview", "Browser", "project"]);
|
||||
await drag("Overview", "a.md");
|
||||
await drag("project", "b.md");
|
||||
await drag("a.md", "Browser", "after");
|
||||
const mixed = ["Overview", "project", "b.md", "Browser", "a.md"];
|
||||
assert.deepEqual(await order(), mixed);
|
||||
assert.equal(await tab("project").getAttribute("aria-selected"), "true");
|
||||
for (const cancel of ["escape", "outside"]) {
|
||||
await drag("Browser", "Overview", "before", cancel);
|
||||
assert.deepEqual(await order(), mixed);
|
||||
}
|
||||
await tab("Browser").press("Alt+Shift+Home");
|
||||
assert.equal((await order())[0], "Browser");
|
||||
await tab("Browser").press("ArrowRight");
|
||||
assert.equal(await tab("Overview").getAttribute("aria-selected"), "true");
|
||||
assert.equal(await page.getByRole("textbox", { name: "overview state" }).inputValue(), "Keep this state");
|
||||
await tab("Overview").press("ArrowRight");
|
||||
assert.equal(await tab("project").getAttribute("aria-selected"), "true");
|
||||
await page.evaluate(() => window.tabTest.api.updateViewTitle("browser", "Browser page"));
|
||||
await tab("Browser page").waitFor();
|
||||
assert.equal((await order())[0], "Browser page");
|
||||
assert.deepEqual(await page.evaluate(() => window.tabTest.mounts), { overview: 1, browser: 1, "project-board": 1 });
|
||||
assert.deepEqual(await page.evaluate(() => window.tabTest.disposals), {});
|
||||
assert.equal(await tab("project").getAttribute("aria-controls"), await page.getByRole("tabpanel", { name: "project" }).getAttribute("id"));
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
||||
await menu("Browser page");
|
||||
assert.equal(await page.getByRole("menuitem", { name: "Pin", exact: true }).count(), 1);
|
||||
await page.getByRole("menuitem", { name: "Move tab", exact: true }).click();
|
||||
await page.getByRole("menuitem", { name: "Move tab right", exact: true }).click();
|
||||
}
|
||||
console.log("PASS: mixed file, feature, and plugin document tabs move without remounting or changing selection");
|
||||
|
||||
await tab("Browser page").press("Alt+Shift+End");
|
||||
await tab("project").press("Alt+Shift+End");
|
||||
await tab("a.md").press("Alt+Shift+Home");
|
||||
await tab("Overview").press("Alt+Shift+Home");
|
||||
await tab("b.md").press("Alt+Shift+Home");
|
||||
await menu("b.md");
|
||||
await page.getByRole("menuitem", { name: "Pin", exact: true }).click();
|
||||
await tab("a.md").click();
|
||||
await page.locator(".cm-content").fill("Unsaved text");
|
||||
await tab("a.md •").waitFor();
|
||||
assert.deepEqual(await order(), ["b.md", "Overview", "a.md •", "Browser page", "project"]);
|
||||
await menu("Overview");
|
||||
await page.getByRole("menuitem", { name: "Close tabs after", exact: true }).click();
|
||||
await page.waitForFunction(() => window.tabTest.prompts === 1);
|
||||
assert.deepEqual(await order(), ["b.md", "Overview", "a.md •", "Browser page", "project"]);
|
||||
await page.evaluate(() => window.tabTest.answer = "Ok");
|
||||
await menu("Overview");
|
||||
await page.getByRole("menuitem", { name: "Close tabs after", exact: true }).click();
|
||||
await tab("project").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["b.md", "Overview"]);
|
||||
assert.equal(await tab("Overview").getAttribute("aria-selected"), "true");
|
||||
await menu("Overview");
|
||||
await page.getByRole("menuitem", { name: "Close all", exact: true }).click();
|
||||
await tab("Overview").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["b.md"]);
|
||||
assert.deepEqual(await page.evaluate(() => window.tabTest.disposals), { browser: 1, "project-board": 1, overview: 1 });
|
||||
console.log("PASS: mixed close actions follow visual order, preserve pins, and respect cancelled discards");
|
||||
|
||||
await openView("Overview");
|
||||
for (let index = 0; index < 14; index++) await openFile(`note-${index}.md`);
|
||||
await tab("Overview").press("Alt+Shift+Home");
|
||||
const source = await tab("Overview").boundingBox(), bounds = await bar.boundingBox();
|
||||
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2, { steps: 10 });
|
||||
await page.waitForFunction(() => {
|
||||
const bar = document.querySelector('[aria-label="Working tabs"]');
|
||||
return bar.scrollLeft >= bar.scrollWidth - bar.clientWidth - 2;
|
||||
});
|
||||
await page.mouse.up();
|
||||
await settle();
|
||||
assert.equal((await order()).at(-1), "Overview");
|
||||
await page.keyboard.press("Control+t");
|
||||
await tab("New tab").press("Alt+Shift+Home");
|
||||
await openFile("c.md");
|
||||
assert.equal((await order())[0], "c.md");
|
||||
const fileOrder = (await order()).filter(name => name !== "Overview");
|
||||
await page.keyboard.press("Control+,");
|
||||
const settingsPage = await context.newPage();
|
||||
settingsPage.on("pageerror", error => errors.push(error.message));
|
||||
await settingsPage.goto(url + '/?settingsWindow=true');
|
||||
await settingsPage.getByRole("button", { name: "Plug-ins", exact: true }).click();
|
||||
await settingsPage.getByRole("switch", { name: "Tab fixtures", exact: true }).click();
|
||||
await settingsPage.waitForFunction(() => document.getElementById("external-test.tabs")?.checked === false);
|
||||
await tab("Overview").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), fileOrder);
|
||||
console.log("PASS: plugin drag auto-scroll, empty-tab replacement, and plugin disable preserve the mixed order");
|
||||
await settingsPage.close();
|
||||
|
||||
await page.goto(`${url}?no-workspace`);
|
||||
await openView("Overview");
|
||||
await openView("Browser");
|
||||
await drag("Browser", "Overview");
|
||||
assert.deepEqual(await order(), ["Browser", "Overview"]);
|
||||
await page.setViewportSize({ width: 880, height: 700 });
|
||||
await mkdir(".audit", { recursive: true });
|
||||
await page.screenshot({ path: ".audit/plugin-tab-order.png" });
|
||||
await tab("Browser").click({ button: "middle" });
|
||||
assert.deepEqual(await order(), ["Overview"]);
|
||||
await page.getByRole("button", { name: "Close Overview", exact: true }).click();
|
||||
assert.equal(await page.getByRole("tab").count(), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: plugin tabs reorder and close without an open workspace");
|
||||
} catch (error) {
|
||||
await mkdir(".audit", { recursive: true });
|
||||
await page.screenshot({ path: ".audit/plugin-tab-order-failure.png" });
|
||||
console.error("Browser errors:", errors);
|
||||
throw error;
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
@@ -6,11 +6,15 @@ const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
await context.route('**/__settings-closed', route => route.fulfill({ contentType: 'text/html', body: '<!doctype html><title>Closed settings</title>' }));
|
||||
const page = await context.newPage();
|
||||
const settingsPage = await context.newPage();
|
||||
page.setDefaultTimeout(10000);
|
||||
settingsPage.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
settingsPage.on("pageerror", error => errors.push(error.message));
|
||||
await page.context().addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\smoke-workspace";
|
||||
@@ -32,6 +36,7 @@ await page.context().addInitScript(() => {
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
calls.push({ command, args });
|
||||
if (command === "settings_open_window") return;
|
||||
if (command === "plugin:event|listen") {
|
||||
const list = listeners.get(args.event) || []; list.push(args.handler); listeners.set(args.event, list); return args.handler;
|
||||
}
|
||||
@@ -83,16 +88,17 @@ async function quickOpen(name) {
|
||||
|
||||
const source = '# Formulas\n\n| A | B |\n| --- | --- |\n| 2 | =A2*3 |\n\nAfter.\n';
|
||||
const table = page.locator('.live-writer table');
|
||||
const dialog = page.getByRole('dialog', { name: 'Settings', exact: true });
|
||||
const dialog = settingsPage.getByRole('dialog', { name: 'Settings', exact: true });
|
||||
const switchFor = name => dialog.getByRole('switch', { name, exact: true });
|
||||
async function settings() {
|
||||
await page.getByRole('button', { name: 'Settings (Ctrl+,)', exact: true }).click();
|
||||
await settingsPage.goto((process.env.SMOKE_URL || 'http://127.0.0.1:1420') + '/?settingsWindow=true');
|
||||
await dialog.getByRole('button', { name: 'Plug-ins', exact: true }).click();
|
||||
}
|
||||
async function closeSettings() {
|
||||
await page.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
|
||||
await page.keyboard.press('Escape');
|
||||
await dialog.waitFor({ state: 'hidden' });
|
||||
await settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
|
||||
await settingsPage.goto((process.env.SMOKE_URL || 'http://127.0.0.1:1420') + '/__settings-closed');
|
||||
await page.bringToFront();
|
||||
}
|
||||
const count = command => page.evaluate(command => window.__TEST__.calls.filter(call => call.command === command).length, command);
|
||||
try {
|
||||
@@ -137,7 +143,7 @@ try {
|
||||
await settings();
|
||||
await switchFor('Terminal').uncheck();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === 'pty_close'));
|
||||
await page.screenshot({ path: '.audit/plugins-settings.png' });
|
||||
await settingsPage.screenshot({ path: '.audit/plugins-settings.png' });
|
||||
await closeSettings();
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
const opened = await count('pty_open');
|
||||
@@ -169,9 +175,9 @@ try {
|
||||
await settings();
|
||||
assert.equal(await dialog.getByRole('heading', { name: 'Bundled plugins' }).count(), 0);
|
||||
for (const name of ['Terminal', 'Table formulas']) {
|
||||
await page.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
|
||||
await dialog.locator('.card').filter({ has: page.getByRole('switch', { name, exact: true }) }).getByRole('button', { name: 'Uninstall', exact: true }).click();
|
||||
const confirmation = page.getByRole('dialog', { name: `Uninstall ${name}?`, exact: true });
|
||||
await settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
|
||||
await dialog.locator('.card').filter({ has: settingsPage.getByRole('switch', { name, exact: true }) }).getByRole('button', { name: 'Uninstall', exact: true }).click();
|
||||
const confirmation = settingsPage.getByRole('dialog', { name: `Uninstall ${name}?`, exact: true });
|
||||
await confirmation.getByRole('button', { name: 'Uninstall and delete files', exact: true }).click();
|
||||
await confirmation.waitFor({ state: 'hidden' });
|
||||
await switchFor(name).waitFor({ state: 'detached' });
|
||||
@@ -187,6 +193,8 @@ try {
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('Plugin smoke passed: formulas, source preservation, terminal shutdown, persistence, shortcuts, cross-window enable controls, removal, and no automatic restoration.');
|
||||
} catch (error) {
|
||||
await settingsPage.screenshot({ path: ".audit/plugins-settings-failure.png" });
|
||||
console.log("Settings page:", settingsPage.url(), await settingsPage.locator('body').innerText());
|
||||
await page.screenshot({ path: ".audit/plugins-failure.png" });
|
||||
console.log(await page.locator('.md-page').allTextContents());
|
||||
console.log(errors);
|
||||
|
||||
+39
-29
@@ -9,8 +9,10 @@ const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 800 } });
|
||||
const page = await context.newPage();
|
||||
const settingsPage = await context.newPage();
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
settingsPage.on("pageerror", error => errors.push(error.message));
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const disk = { "note.txt": "Original note" };
|
||||
@@ -32,8 +34,18 @@ await context.addInitScript(() => {
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
const settings = page.getByRole("dialog", { name: "Settings", exact: true });
|
||||
const settings = settingsPage.getByRole("dialog", { name: "Settings", exact: true });
|
||||
const trigger = page.getByRole("button", { name: "Settings (Ctrl+,)", exact: true });
|
||||
async function showSettings(shortcut = false) {
|
||||
if (shortcut) await page.keyboard.press("Control+,");
|
||||
else await trigger.click();
|
||||
await settingsPage.goto(`${url}/?settingsWindow=true`);
|
||||
await settings.waitFor();
|
||||
}
|
||||
async function closeSettings() {
|
||||
await settingsPage.goto("about:blank");
|
||||
await page.bringToFront();
|
||||
}
|
||||
const interval = settings.getByRole("spinbutton", { name: "Auto-save interval" });
|
||||
const enabled = settings.getByRole("switch", { name: "Auto-save", exact: true });
|
||||
async function changeSeconds(value) {
|
||||
@@ -51,15 +63,14 @@ try {
|
||||
await page.clock.install();
|
||||
await page.goto(url);
|
||||
await page.locator(".ws").filter({ hasText: "Notes" }).waitFor();
|
||||
await trigger.click();
|
||||
await showSettings();
|
||||
assert.equal(await interval.inputValue(), "5");
|
||||
assert(await enabled.isChecked());
|
||||
await changeSeconds(2);
|
||||
await settings.getByRole("status").filter({ hasText: "Changes saved." }).waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
assert(await trigger.evaluate(element => element === document.activeElement), "Closing restores focus");
|
||||
await closeSettings();
|
||||
await page.reload();
|
||||
await trigger.click();
|
||||
await showSettings();
|
||||
assert.equal(await interval.inputValue(), "2", "Interval survives reload");
|
||||
await changeSeconds(0);
|
||||
await settings.getByRole("alert").filter({ hasText: "whole number" }).waitFor();
|
||||
@@ -71,17 +82,17 @@ try {
|
||||
await settings.getByRole("textbox", { name: "Search settings" }).fill("no such setting");
|
||||
await settings.getByText("No settings found", { exact: true }).waitFor();
|
||||
await settings.getByRole("button", { name: "Clear search" }).click();
|
||||
await page.screenshot({ path: ".audit/settings-general.png" });
|
||||
await page.keyboard.press("Escape");
|
||||
await settingsPage.screenshot({ path: ".audit/settings-general.png" });
|
||||
await closeSettings();
|
||||
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("note.txt");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.txt" }).first().click();
|
||||
await page.locator(".monaco-editor textarea").waitFor();
|
||||
await page.clock.pauseAt(new Date(await page.evaluate(() => Date.now()) + 1000));
|
||||
await trigger.click();
|
||||
await showSettings();
|
||||
await changeSeconds(3);
|
||||
await page.keyboard.press("Escape");
|
||||
await closeSettings();
|
||||
await edit("Saved at three seconds");
|
||||
const before = await writes();
|
||||
await page.clock.runFor(2100);
|
||||
@@ -90,53 +101,52 @@ try {
|
||||
assert.equal(await writes(), before + 1, "New interval saves the dirty buffer");
|
||||
await page.clock.runFor(3100);
|
||||
assert.equal(await writes(), before + 1, "Clean files are not rewritten");
|
||||
await trigger.click();
|
||||
await showSettings();
|
||||
await enabled.uncheck();
|
||||
assert(await interval.isDisabled());
|
||||
await page.keyboard.press("Escape");
|
||||
await closeSettings();
|
||||
await edit("Manual save while auto-save is disabled");
|
||||
await page.clock.runFor(10000);
|
||||
assert.equal(await writes(), before + 1);
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(count => window.__TEST__.writes.length === count, before + 2);
|
||||
await page.locator(".monaco-editor textarea").focus();
|
||||
await page.keyboard.press("Control+,");
|
||||
await showSettings(true);
|
||||
await settings.waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
await closeSettings();
|
||||
await page.locator(".monaco-editor textarea").focus();
|
||||
await page.keyboard.press("F1");
|
||||
await page.getByRole("dialog", { name: "Help and about", exact: true }).waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
const other = await context.newPage();
|
||||
await other.goto(url);
|
||||
await other.getByRole("button", { name: "Settings (Ctrl+,)" }).click();
|
||||
await other.goto(`${url}/?settingsWindow=true`);
|
||||
assert.equal(await other.getByRole("spinbutton", { name: "Auto-save interval" }).inputValue(), "3");
|
||||
assert.equal(await other.getByRole("switch", { name: "Auto-save", exact: true }).isChecked(), false);
|
||||
await other.getByRole("button", { name: "Restore defaults" }).click();
|
||||
await page.waitForFunction(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveEnabled);
|
||||
await trigger.click();
|
||||
await showSettings();
|
||||
await enabled.waitFor();
|
||||
assert(await enabled.isChecked(), "Other windows receive changes");
|
||||
assert.equal(await interval.inputValue(), "5");
|
||||
await page.keyboard.press("Escape");
|
||||
await closeSettings();
|
||||
await edit("Auto-save enabled from another window");
|
||||
await page.clock.runFor(5100);
|
||||
assert.equal(await writes(), before + 3);
|
||||
await other.close();
|
||||
|
||||
await trigger.click();
|
||||
await page.evaluate(() => {
|
||||
await showSettings();
|
||||
await settingsPage.evaluate(() => {
|
||||
window.__SET_ITEM__ = Storage.prototype.setItem;
|
||||
Storage.prototype.setItem = () => { throw new Error("Storage unavailable"); };
|
||||
});
|
||||
await changeSeconds(7);
|
||||
await settings.getByRole("alert").filter({ hasText: "Could not save" }).waitFor();
|
||||
await page.evaluate(() => { Storage.prototype.setItem = window.__SET_ITEM__; });
|
||||
await page.keyboard.press("Escape");
|
||||
await trigger.click();
|
||||
await settingsPage.evaluate(() => { Storage.prototype.setItem = window.__SET_ITEM__; });
|
||||
await closeSettings();
|
||||
await showSettings();
|
||||
assert.equal(await interval.inputValue(), "5", "Failed writes preserve applied settings");
|
||||
await page.keyboard.press("Escape");
|
||||
await closeSettings();
|
||||
|
||||
await page.getByRole("button", { name: "Help and about (F1)" }).click();
|
||||
const help = page.getByRole("dialog", { name: "Help and about", exact: true });
|
||||
@@ -145,19 +155,19 @@ try {
|
||||
await page.screenshot({ path: ".audit/settings-help.png" });
|
||||
await page.keyboard.press("Escape");
|
||||
await page.keyboard.press("Control+b");
|
||||
await page.keyboard.press("Control+,");
|
||||
await showSettings(true);
|
||||
await settings.waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
await closeSettings();
|
||||
await page.keyboard.press("F1");
|
||||
await help.waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.setViewportSize({ width: 420, height: 650 });
|
||||
await page.keyboard.press("Control+,");
|
||||
await settingsPage.setViewportSize({ width: 540, height: 420 });
|
||||
await showSettings(true);
|
||||
await settings.waitFor();
|
||||
assert(await settings.evaluate(el => el.scrollWidth === el.clientWidth), "Narrow layout fits");
|
||||
await page.screenshot({ path: ".audit/settings-narrow.png" });
|
||||
await settingsPage.screenshot({ path: ".audit/settings-narrow.png" });
|
||||
for (let i = 0; i < 12; i++) {
|
||||
await page.keyboard.press("Tab");
|
||||
await settingsPage.keyboard.press("Tab");
|
||||
assert(await settings.evaluate(el => el.contains(document.activeElement)), "Focus stays in the modal");
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
// Run against pnpm dev. Native IPC is mocked; this does not test the operating system title bar.
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const origin = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
const errors = [];
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 760 } });
|
||||
const watch = page => page.on("pageerror", error => errors.push(error.message));
|
||||
try {
|
||||
const main = await context.newPage(); watch(main);
|
||||
await main.goto(origin);
|
||||
await main.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).click();
|
||||
assert.equal(await main.locator("dialog:modal").count(), 1, "Browser preview retains the settings dialog");
|
||||
const settings = await context.newPage(); watch(settings);
|
||||
await settings.goto(`${origin}/?settingsWindow=true`);
|
||||
await settings.getByRole("heading", { name: "General", exact: true }).waitFor();
|
||||
assert.equal(await settings.locator(".workbench").count(), 0);
|
||||
const interval = settings.getByRole("spinbutton", { name: "Auto-save interval" });
|
||||
await interval.fill("17"); await interval.press("Tab");
|
||||
await main.waitForFunction(() => document.querySelector("#autosave-seconds")?.value === "17");
|
||||
await main.getByRole("spinbutton", { name: "Auto-save interval" }).fill("29");
|
||||
await main.getByRole("spinbutton", { name: "Auto-save interval" }).press("Tab");
|
||||
await settings.waitForFunction(() => document.querySelector("#autosave-seconds")?.value === "29");
|
||||
await settings.reload();
|
||||
await settings.waitForFunction(() => document.querySelector("#autosave-seconds")?.value === "29");
|
||||
await interval.fill("301"); await interval.press("Tab");
|
||||
await settings.getByRole("alert").filter({ hasText: "Choose a whole number" }).waitFor();
|
||||
assert.equal(await settings.evaluate(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveSeconds), 29);
|
||||
await settings.evaluate(() => { Storage.prototype.setItem = () => { throw new Error("Storage full"); }; });
|
||||
await interval.fill("40"); await interval.press("Tab");
|
||||
await settings.getByRole("alert").filter({ hasText: "Could not save these settings" }).waitFor();
|
||||
assert.equal(await settings.evaluate(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveSeconds), 29);
|
||||
await settings.reload();
|
||||
await settings.getByRole("button", { name: "Plug-ins", exact: true }).click();
|
||||
await settings.getByRole("heading", { name: "Plug-ins", exact: true }).waitFor();
|
||||
await settings.getByRole("button", { name: "General", exact: true }).click();
|
||||
await mkdir(".audit", { recursive: true });
|
||||
await settings.screenshot({ path: ".audit/settings-window.png" });
|
||||
await settings.setViewportSize({ width: 540, height: 420 });
|
||||
assert.equal(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true);
|
||||
await settings.keyboard.press("Escape");
|
||||
await settings.waitForURL(`${origin}/`);
|
||||
|
||||
const desktop = await context.newPage(); watch(desktop);
|
||||
await desktop.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const callbacks = new Map();
|
||||
let sequence = 0;
|
||||
window.settingsTest = { opens: 0, fail: false, closes: 0 };
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "settings_open_window") {
|
||||
window.settingsTest.opens++;
|
||||
if (window.settingsTest.fail) throw new Error("Native window creation failed");
|
||||
await new Promise(resolve => setTimeout(resolve, 150));
|
||||
return;
|
||||
}
|
||||
if (command === "plugins_snapshot") return { root: "C:/plugins", plugins: [] };
|
||||
if (command === "workspace_last_path") return null;
|
||||
if (command === "plugin:event|listen") return args.handler;
|
||||
if (command === "plugin:event|unlisten") return;
|
||||
if (command === "plugin:window|close") { window.settingsTest.closes++; return; }
|
||||
throw new Error(`Unexpected IPC: ${command}`);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
});
|
||||
await desktop.goto(origin);
|
||||
await desktop.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).dblclick();
|
||||
assert.equal(await desktop.evaluate(() => window.settingsTest.opens), 1, "Rapid requests share the pending native open");
|
||||
assert.equal(await desktop.locator("dialog:modal").count(), 0, "Native open does not block the workbench");
|
||||
await desktop.waitForTimeout(180);
|
||||
await desktop.keyboard.press("Control+,");
|
||||
await desktop.waitForFunction(() => window.settingsTest.opens === 2);
|
||||
await desktop.waitForTimeout(180);
|
||||
await desktop.evaluate(() => { window.settingsTest.fail = true; });
|
||||
await desktop.keyboard.press("Control+,");
|
||||
await desktop.getByText(/Could not open settings: .*Native window creation failed/).waitFor();
|
||||
await desktop.goto(`${origin}/?settingsWindow=true`);
|
||||
await desktop.getByRole("heading", { name: "General", exact: true }).waitFor();
|
||||
await desktop.getByRole("button", { name: "Close settings", exact: true }).click();
|
||||
assert.equal(await desktop.evaluate(() => window.settingsTest.closes), 1);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("Settings window smoke passed: preview fallback, standalone layout, two-way save sync, persistence, failed saves, native open requests, and close.");
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,18 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { splitPane, removePane, paneBounds, containsPane } from "../src/lib/workspace/splitLayout.ts";
|
||||
|
||||
test("nested splits preserve the source and divide the requested pane", () => {
|
||||
const right = splitPane("a", "a", "b", "right");
|
||||
const nested = splitPane(right, "b", "c", "down");
|
||||
assert.deepEqual(paneBounds(nested), {
|
||||
a: { left: 0, top: 0, width: 50, height: 100 },
|
||||
b: { left: 50, top: 0, width: 50, height: 50 },
|
||||
c: { left: 50, top: 50, width: 50, height: 50 },
|
||||
});
|
||||
assert.equal(containsPane(nested, "c"), true);
|
||||
const closed = removePane(nested, "b")!;
|
||||
assert.deepEqual(paneBounds(closed).c, { left: 50, top: 0, width: 50, height: 100 });
|
||||
assert.equal(removePane(closed, "a"), "c");
|
||||
assert.equal(removePane("c", "c"), null);
|
||||
});
|
||||
@@ -34,7 +34,7 @@ await page.addInitScript(() => {
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const tab = name => page.getByRole("tab", { name, exact: true });
|
||||
const order = () => page.getByRole("tablist", { name: "Open files" }).getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path));
|
||||
const order = () => page.getByRole("tablist", { name: "Working tabs" }).getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path));
|
||||
const settle = () => page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
|
||||
async function open(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
@@ -100,7 +100,7 @@ try {
|
||||
console.log("PASS: empty tabs and middle-click close after reorder");
|
||||
|
||||
for (let i = 3; i < 16; i++) await open(`note-${String(i).padStart(2, "0")}.md`);
|
||||
const bar = page.getByRole("tablist", { name: "Open files" });
|
||||
const bar = page.getByRole("tablist", { name: "Working tabs" });
|
||||
assert.ok(await bar.evaluate(node => node.scrollLeft > 0));
|
||||
await tab("note-15.md").press("Alt+Shift+Home");
|
||||
assert.equal((await order())[0], "note-15.md");
|
||||
@@ -111,7 +111,7 @@ try {
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2, { steps: 10 });
|
||||
await page.waitForFunction(() => {
|
||||
const bar = document.querySelector('[aria-label="Open files"]');
|
||||
const bar = document.querySelector('[aria-label="Working tabs"]');
|
||||
return bar.scrollLeft >= bar.scrollWidth - bar.clientWidth - 2;
|
||||
});
|
||||
await page.mouse.up();
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { orderWorkbenchTabs } from "../src/lib/workspace/workbenchTabs.ts";
|
||||
import { tabsToClose } from "../src/lib/workspace/tabActions.ts";
|
||||
import { Documents } from "../src/lib/workspace/documents.ts";
|
||||
|
||||
test("mixed tabs retain their positions through title changes, closes, and new tabs", () => {
|
||||
const tabs = [
|
||||
{ id: "a", relPath: "a.md", name: "a.md", pinned: true },
|
||||
{ id: "b", relPath: "renamed.md", name: "renamed.md" },
|
||||
{ id: "plugin-a", relPath: "plugin:a", name: "New page title" },
|
||||
{ id: "plugin-b", relPath: "plugin:b", name: "Board" },
|
||||
];
|
||||
const ordered = orderWorkbenchTabs(tabs, ["plugin-a", "b", "a", "closed", "plugin-a"]);
|
||||
assert.deepEqual(ordered.map(tab => tab.id), ["plugin-a", "b", "a", "plugin-b"]);
|
||||
assert.equal(ordered[0].name, "New page title");
|
||||
assert.deepEqual(tabsToClose(ordered, "plugin:a", "after").map(tab => tab.id), ["b", "plugin-b"]);
|
||||
assert.deepEqual(tabsToClose(ordered, "renamed.md", "others").map(tab => tab.id), ["plugin-a", "plugin-b"]);
|
||||
assert.deepEqual(tabsToClose(ordered, "plugin:b", "all").map(tab => tab.id), ["plugin-a", "b", "plugin-b"]);
|
||||
});
|
||||
|
||||
test("replacing an empty or current document retains its tab position and creates a new buffer", async () => {
|
||||
const docs = new Documents({
|
||||
read: async path => path, write: async () => {}, image: async () => "",
|
||||
kind: () => "text", chrome: () => "Writing",
|
||||
}, () => {});
|
||||
docs.newTab();
|
||||
const emptyId = docs.active!.id;
|
||||
const order = ["plugin-a", emptyId, "plugin-b"];
|
||||
for (const rel_path of ["a.md", "b.md"]) {
|
||||
const previousBuffer = docs.active!.id;
|
||||
await docs.open({ rel_path, name: rel_path, kind: "file" }, "current");
|
||||
assert.notEqual(docs.active!.id, previousBuffer);
|
||||
assert.equal(docs.active!.tabId, emptyId);
|
||||
const tabs = [{ id: "plugin-a" }, { id: "plugin-b" }, { id: docs.active!.tabId! }];
|
||||
assert.deepEqual(orderWorkbenchTabs(tabs, order).map(tab => tab.id), order);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user