Move the tests from scripts/ to tests/ by feature
Unit tests go to tests/unit/<area>/, browser smoke tests to tests/smoke/<area>/, and tests against a running desktop app to tests/native/. Files named after dates, work passes, or Kanban cards get feature names, for example editorOctober12 -> editor/footnotes. scripts/ keeps the build, release, and package tools. Plugin repositories import scripts/packagePlugin.mjs, and the Terminal smoke test imports scripts/pluginMocks.mjs, which now re-exports the harness copy. The unit tests get their own type check (tests/tsconfig.json) with Node types. pnpm check runs it after the app check. Add @types/node and fix the three test mocks that it reported.
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
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("org.example.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'); } });
|
||||
}`,
|
||||
"org.example.browser": `export function activate(api) {
|
||||
api.registerCommand({ id: 'new-tab', title: 'New browser tab', category: 'open', 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', launch() { api.openView('default-board'); }, mount(container) { container.textContent = 'Task content'; } });
|
||||
api.registerView({ id: 'default-board', title: 'Default board', launcher: false, placement: 'editor', mount(container) { container.textContent = 'Default board content'; } });
|
||||
window.taskTestApi = api;
|
||||
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 === 'browser_connect') return 'test-session';
|
||||
if (command === 'browser_stop') 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);
|
||||
await main.getByRole('navigation', { name: 'Plugin shortcuts' }).getByRole('button', { name: 'All tasks', exact: true }).waitFor();
|
||||
assert.equal(await main.getByRole('button', { name: 'Open tab or view', exact: true }).count(), 0);
|
||||
assert.equal(await main.getByRole('button', { name: 'Commands', exact: true }).count(), 1);
|
||||
await main.getByRole('navigation', { name: 'Plugin shortcuts' }).getByRole('button', { name: 'All tasks', exact: true }).click();
|
||||
await main.getByText('Default board content', { exact: true }).waitFor();
|
||||
await main.evaluate(() => window.taskTestApi.openView('tasks'));
|
||||
await main.getByText('Task content', { exact: true }).waitFor();
|
||||
await main.evaluate(async () => {
|
||||
const { closePluginEditor, pluginTabState, pluginView, restorePluginTab } = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
||||
let view;
|
||||
const off = pluginView.subscribe(value => { view = value; }); off();
|
||||
const transfer = pluginTabState(view);
|
||||
closePluginEditor(view.key);
|
||||
if (!await restorePluginTab(transfer)) throw Error('Tab restore failed');
|
||||
});
|
||||
await main.getByText('Task content', { exact: true }).waitFor();
|
||||
await main.evaluate(async () => {
|
||||
const { runPluginCommand } = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
||||
await runPluginCommand('org.example.browser', 'new-tab');
|
||||
});
|
||||
await main.getByText('Browser content', { exact: true }).waitFor();
|
||||
await main.evaluate(async () => {
|
||||
const { openPluginView } = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
||||
openPluginView('org.example.tasks', 'dialog');
|
||||
});
|
||||
await main.getByRole('dialog', { name: 'Task summary' }).waitFor();
|
||||
await main.keyboard.press('Escape');
|
||||
for (const theme of ['dark', 'light']) {
|
||||
await main.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
||||
await main.screenshot({ path: `.audit/plugin-access-${theme}.png` });
|
||||
}
|
||||
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: compact header, navigation, dynamic tabs, 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,52 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile, mkdir } from 'node:fs/promises';
|
||||
import { createRequire } from 'node:module';
|
||||
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();
|
||||
const url = process.env.SMOKE_URL || 'http://127.0.0.1:1420';
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await mkdir('.audit/menu-audit', { recursive: true });
|
||||
await page.route('**/__choice-audit__', route => route.fulfill({ contentType: 'text/html', body: '<link rel="stylesheet" href="/src/lib/theme/tokens.css"><link rel="stylesheet" href="/src/lib/ui/menu.css"><style>dialog{inset:0;margin:0;max-width:none;max-height:none;width:100%;height:100%;box-sizing:border-box;background:var(--rs-bg);color:var(--rs-text);padding:0;border:0}</style><dialog><main></main></dialog>' }));
|
||||
await page.route('**/__autocomplete__/*.mjs', async route => {
|
||||
const name = new URL(route.request().url()).pathname.split('/').pop();
|
||||
assert.ok(['main.mjs', 'engine.mjs'].includes(name));
|
||||
await route.fulfill({ contentType: 'application/javascript', body: await readFile(new URL(`../../../../RuneStone_LocalAutocomplete/src/${name}`, import.meta.url), 'utf8') });
|
||||
});
|
||||
try {
|
||||
for (const theme of ['light', 'dark']) for (const width of [1100, 390]) {
|
||||
await page.setViewportSize({ width, height: 850 });
|
||||
await page.goto(url + '/__choice-audit__');
|
||||
await page.evaluate(async theme => {
|
||||
document.documentElement.dataset.theme = theme;
|
||||
const { showActionMenu } = await import('/src/lib/ui/managedActionMenu.ts');
|
||||
const { activate } = await import('/__autocomplete__/main.mjs');
|
||||
let view;
|
||||
window.choiceAudit = { saved: null };
|
||||
await activate({ ui: { showActionMenu }, completion: { version: 1, transport() {}, invalidate() {}, registerProvider() { return () => {}; }, registerInput() { return { dispose() {}, request() {} }; } },
|
||||
settings: { read: async () => ({}), write: async value => { window.choiceAudit.saved = value; } },
|
||||
onDispose() {}, registerCommand() {}, registerView(value) { view = value; } });
|
||||
document.querySelector('dialog').showModal();
|
||||
window.choiceAudit.dispose = view.mount(document.querySelector('main'), { surface: 'settings' });
|
||||
}, theme);
|
||||
const trigger = page.getByRole('button', { name: 'Server type', exact: true });
|
||||
await trigger.click();
|
||||
const menu = page.getByRole('menu', { name: 'Server type', exact: true });
|
||||
assert.equal(await menu.evaluate(node => !!node.closest('dialog[open]')), true);
|
||||
await page.keyboard.press('End');
|
||||
assert.equal(await page.getByRole('menuitemradio', { name: 'Ollama', exact: true }).evaluate(node => node === document.activeElement), true);
|
||||
await page.screenshot({ path: `.audit/menu-audit/autocomplete-${theme}-${width}.png` });
|
||||
await page.keyboard.press('Enter');
|
||||
assert.match(await trigger.innerText(), /Ollama/);
|
||||
await page.getByRole('button', { name: 'Save settings', exact: true }).click();
|
||||
await page.waitForFunction(() => window.choiceAudit.saved?.adapter === 'ollama');
|
||||
await trigger.click(); await page.keyboard.press('Escape');
|
||||
assert.equal(await trigger.evaluate(node => node === document.activeElement), true);
|
||||
await trigger.click(); await page.evaluate(() => window.choiceAudit.dispose());
|
||||
assert.equal(await page.locator('.rs-menu').count(), 0);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('PASS: Local Autocomplete shared choices, modal input, saved adapter, focus return, and cleanup in both themes at 1100/390px.');
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,238 @@
|
||||
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
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 }, 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 }) => {
|
||||
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 = [];
|
||||
let installed = [];
|
||||
let removalPrepared = false;
|
||||
const data = { preserved: true };
|
||||
const path = "C:\\AppData\\RuneStone\\plugins\\" + manifest.id;
|
||||
const snapshot = () => ({ root: "C:\\AppData\\RuneStone\\plugins", plugins: installed });
|
||||
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 = {}) => {
|
||||
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();
|
||||
if (command === "plugins_choose") return [{ token: 'candidate', source: 'C:/Downloads/overview.zip', manifest, error: null }];
|
||||
if (command === "plugins_from_git") {
|
||||
if (args.tag === 'missing') throw new Error('Release not found. Publish a release with one plugin ZIP.');
|
||||
return [{ token: 'git-candidate', source: args.url + ' @ ' + (args.tag || 'v1.0.0'), manifest, error: null }];
|
||||
}
|
||||
if (command === "plugins_cancel") { removalPrepared = false; return; }
|
||||
if (command === "plugins_install") {
|
||||
const previous = installed[0];
|
||||
installed = [{ manifest, hash: 'reviewed-hash', enabled: previous ? previous.enabled : args.enabled, installedAt: Date.parse('2026-10-05T18:24:36Z'), path, error: null, removal: false }];
|
||||
emit('plugins-changed', null); return [{ name: manifest.name, error: null }];
|
||||
}
|
||||
if (command === "plugins_set_enabled") {
|
||||
installed[0].enabled = args.enabled;
|
||||
emit('plugins-changed', null); return;
|
||||
}
|
||||
if (command === "plugins_load") { window.__TEST__.cleaned = false; window.__TEST__.released = false; return pluginCode.replace('export function activate(api) {', 'export function activate(api) { api.onDispose(() => { window.__TEST__.cleaned = true; });'); }
|
||||
if (command === "plugins_release") { window.__TEST__.released = true; return; }
|
||||
if (command === "plugins_data") return JSON.stringify(data);
|
||||
if (command === "plugins_reveal") return;
|
||||
if (command === "plugins_prepare_remove") { removalPrepared = true; return { token: 'remove-plan', plugin: installed[0] }; }
|
||||
if (command === "plugins_remove") {
|
||||
if (!removalPrepared) throw Error('Missing removal plan');
|
||||
removalPrepared = false;
|
||||
installed[0].enabled = false; emit('plugins-changed', null);
|
||||
for (let i=0; i<100 && !window.__TEST__.released; i++) await new Promise(resolve => setTimeout(resolve, 50));
|
||||
if (!window.__TEST__.cleaned || !window.__TEST__.released) throw Error('Cleanup was not acknowledged');
|
||||
installed = []; emit('plugins-changed', null); return;
|
||||
}
|
||||
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_profiles") return [{ id: "powershell", title: "PowerShell", kind: "powershell" }];
|
||||
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, data };
|
||||
}, { manifest, pluginCode });
|
||||
|
||||
async function quickOpen(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 page.locator('.live-writer').waitFor();
|
||||
}
|
||||
|
||||
|
||||
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(); }
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420');
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await settings();
|
||||
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 = 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 = 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');
|
||||
await gitDialog.getByRole('button', { name: 'Review release', exact: true }).click();
|
||||
await gitDialog.getByRole('alert').getByText(/Release not found/).waitFor();
|
||||
assert.equal(await gitDialog.getByLabel('Access token (optional)', { exact: true }).inputValue(), '');
|
||||
await gitDialog.getByLabel('Release tag (optional)', { exact: true }).fill('v1.0.0');
|
||||
await gitDialog.getByRole('button', { name: 'Review release', exact: true }).click();
|
||||
await review.getByText('Source: https://git.example/owner/plugin.git @ v1.0.0', { exact: true }).waitFor();
|
||||
await review.getByRole('button', { name: 'Cancel', exact: true }).click();
|
||||
assert.equal(await count('plugins_install'), 0);
|
||||
assert(await gitButton.evaluate(element => element === document.activeElement));
|
||||
await settingsDialog.getByRole('button', { name: 'Install plugin ZIP', exact: true }).click();
|
||||
await review.getByRole('button', { name: 'Install and enable', exact: true }).click();
|
||||
await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).waitFor();
|
||||
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 settingsPage.screenshot({ path: '.audit/plugin-manager-installed.png' });
|
||||
await settingsPage.keyboard.press('Escape');
|
||||
await page.getByRole('button', { name: 'Commands', exact: true }).click();
|
||||
await page.getByRole('menuitem', { name: /Show workspace overview/ }).click();
|
||||
const view = page.getByRole('dialog', { name: 'Workspace overview', exact: true });
|
||||
await view.getByText(/files and folders in this workspace/).waitFor();
|
||||
await view.getByRole('button', { name: 'Close plugin view', exact: true }).click();
|
||||
await settings();
|
||||
await settingsDialog.getByRole('button', { name: 'Install plugin ZIP', exact: true }).click();
|
||||
await review.getByText(/Update .* → .*Settings and enabled state stay the same/).waitFor();
|
||||
assert.equal(await review.getByRole('button', { name: 'Install and enable', exact: true }).count(), 0);
|
||||
for (const mode of ['dark', 'light']) {
|
||||
await settingsPage.evaluate(async mode => {
|
||||
const { saveAppearance } = await import('/src/lib/theme/appearance.ts');
|
||||
saveAppearance({ theme: 'default', mode });
|
||||
}, mode);
|
||||
for (const width of [1440, 590]) {
|
||||
await settingsPage.setViewportSize({ width, height: width === 590 ? 820 : 1000 });
|
||||
await settingsPage.screenshot({ path: `.audit/plugin-update-review-${mode}-${width}.png` });
|
||||
assert.equal(await review.evaluate(element => element.scrollWidth > element.clientWidth), false);
|
||||
}
|
||||
}
|
||||
await review.getByRole('button', { name: 'Apply packages', exact: true }).click();
|
||||
assert(await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).isChecked());
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.data.preserved), true);
|
||||
assert.equal(await count('plugins_remove'), 0);
|
||||
await settingsPage.setViewportSize({ width: 1440, height: 1000 });
|
||||
await uninstall();
|
||||
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();
|
||||
assert.equal(await count('plugins_remove'), 0);
|
||||
assert(await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).isChecked());
|
||||
await uninstall();
|
||||
await confirmation.waitFor();
|
||||
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 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 settingsPage.keyboard.press('Escape');
|
||||
assert.equal(await page.getByRole('button', { name: 'Plugin commands and views', exact: true }).count(), 0);
|
||||
await settingsPage.setViewportSize({ width: 590, height: 820 });
|
||||
await settings();
|
||||
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 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();
|
||||
await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).waitFor();
|
||||
assert.equal(await settingsDialog.getByRole('switch', { name: 'Workspace overview', exact: true }).isChecked(), false);
|
||||
assert.equal(await count('plugins_from_git'), 3);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('External plugin smoke passed: ZIP and Git-link review, download errors, token clearing, disabled installation, code loading, cancellation, focus, cleanup, and uninstall.');
|
||||
} catch (error) {
|
||||
console.log('Main page:', await page.locator('body').innerText());
|
||||
console.log('Page errors:', errors);
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,202 @@
|
||||
import { mockFeaturePlugins } from "../_harness/pluginMocks.mjs";
|
||||
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
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";
|
||||
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 === "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;
|
||||
}
|
||||
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_profiles") return [{ id: "powershell", title: "PowerShell", kind: "powershell" }];
|
||||
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 };
|
||||
});
|
||||
await mockFeaturePlugins(page.context());
|
||||
|
||||
|
||||
async function quickOpen(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 page.locator('.live-writer').waitFor();
|
||||
}
|
||||
|
||||
const source = '# Formulas\n\n| A | B |\n| --- | --- |\n| 2 | =A2*3 |\n\nAfter.\n';
|
||||
const table = page.locator('.live-writer table');
|
||||
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 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 {
|
||||
await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420');
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await page.evaluate(text => window.__TEST__.files.set('formulas.md', text), source);
|
||||
await quickOpen('formulas.md');
|
||||
await table.waitFor();
|
||||
assert.equal(await table.locator('.md-table-formula').innerText(), '6');
|
||||
await settings();
|
||||
await switchFor('Table formulas').uncheck();
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => !document.querySelector('.md-table-formula'));
|
||||
assert.match(await table.innerText(), /=A2\*3/);
|
||||
assert.equal(await page.locator('.table-formula-tools').count(), 0);
|
||||
await table.locator('td').last().click();
|
||||
await page.locator('.writer-cell-editor').fill('=A2*4');
|
||||
await page.keyboard.press('Enter');
|
||||
await settings();
|
||||
await switchFor('Table formulas').check();
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => document.querySelector('.md-table-formula')?.textContent === '8');
|
||||
await page.getByRole('group', { name: 'Document view', exact: true }).getByRole('button', { pressed: true }).press('ArrowRight');
|
||||
const preview = page.locator('.md-page table').first();
|
||||
await preview.locator('.md-table-formula').waitFor();
|
||||
await settings();
|
||||
await switchFor('Table formulas').uncheck();
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => !document.querySelector('.md-page .md-table-formula'));
|
||||
assert.match(await preview.innerText(), /=A2\*4/);
|
||||
await settings();
|
||||
await switchFor('Table formulas').check();
|
||||
await closeSettings();
|
||||
await preview.locator('.md-table-formula').waitFor();
|
||||
assert.equal(await preview.locator('.md-table-formula').innerText(), '8');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('formulas.md').includes('=A2*4'));
|
||||
assert(!await page.evaluate(() => window.__TEST__.files.get('formulas.md').includes('>8<')));
|
||||
|
||||
await page.getByRole('button', { name: 'Terminal', exact: true }).click();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === 'pty_open'));
|
||||
await settings();
|
||||
await switchFor('Terminal').uncheck();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === 'pty_close'));
|
||||
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');
|
||||
await page.keyboard.press('Control+j');
|
||||
assert.equal(await count('pty_open'), opened);
|
||||
await page.reload();
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
await settings();
|
||||
assert(!await switchFor('Terminal').isChecked());
|
||||
|
||||
const standalone = await page.context().newPage();
|
||||
await standalone.goto((process.env.SMOKE_URL || 'http://127.0.0.1:1420') + '?terminalWindow=C%3A%5Csmoke-workspace');
|
||||
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
|
||||
await switchFor('Terminal').check();
|
||||
await standalone.locator('.xterm').waitFor();
|
||||
await standalone.waitForFunction(() => window.__TEST__.calls.some(call => call.command === 'pty_open'));
|
||||
await switchFor('Terminal').uncheck();
|
||||
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
|
||||
await standalone.waitForFunction(() => window.__TEST__.calls.some(call => call.command === 'pty_close'));
|
||||
await standalone.close();
|
||||
await switchFor('Terminal').check();
|
||||
await closeSettings();
|
||||
await page.getByRole('button', { name: 'Terminal', exact: true }).click();
|
||||
await page.locator('.xterm').waitFor();
|
||||
await page.evaluate(text => window.__TEST__.files.set('formulas.md', text.replace('=A2*3', '=A2*4')), source);
|
||||
await page.getByRole('button', { name: 'Terminal', exact: true }).focus();
|
||||
await quickOpen('formulas.md');
|
||||
await settings();
|
||||
assert.equal(await dialog.getByRole('heading', { name: 'Bundled plugins' }).count(), 0);
|
||||
for (const name of ['Terminal', 'Table formulas']) {
|
||||
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' });
|
||||
}
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => !document.querySelector('.md-table-formula') && !document.querySelector('.xterm'));
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
assert.match(await table.innerText(), /=A2\*4/);
|
||||
await page.reload();
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await settings();
|
||||
await dialog.getByText('No plugins installed.', { exact: true }).waitFor();
|
||||
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);
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
Reference in New Issue
Block a user