Move the smoke tests onto the shared harness

Each smoke test now uses tests/smoke/_harness/ for Playwright, the Tauri
IPC mock, the in-memory workspace, and output folders, instead of its
own copy. The tests keep their interactions and assertions. Mock
handlers that the app never calls are gone.

- Split the four mixed regression scripts into 18 feature tests.
- Update tests that broke when the app changed on purpose. Each update
  cites the app source that shows the new behavior.
- Mark two real app defects with @known-issue: the settings window
  controls are 1px shorter than the main window controls, and plugin
  tabs cannot be reordered by dragging without a workspace.
- Merge three palette unit tests into one table-driven test.
- The native tests load Playwright through the harness and read
  NATIVE_CDP_URL, with their old variable names as fallbacks.
- A failed smoke test saves a screenshot and prints the console errors.
- The runner runs failed tests once more, alone, and reports a test
  that then passes as flaky.

Result: 89 passed, 1 flaky, 2 known issues, 0 failed. Before, 45 of 78
passed.
This commit is contained in:
Knotty Wyvern
2026-10-27 20:58:55 -07:00
parent c66ea1ce83
commit 69f90df571
109 changed files with 5920 additions and 7915 deletions
+111 -125
View File
@@ -1,129 +1,115 @@
import { createRequire } from "node:module";
// Full-app plug-ins: compact header, navigation, dynamic and restored tabs, dialogs, settings forms across windows, and disable cleanup.
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);
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("plugins/access", async ({ browser }) => {
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
await mockTauri(context, {
commands: test => {
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'; } });
}`,
};
// Settings and the enabled state live in localStorage, so both windows of the context share them.
window.addEventListener("storage", event => {
if (event.key?.startsWith("settings:")) test.emit("plugin-settings-changed", event.key.slice(9));
if (event.key === "disabled") test.emit("plugins-changed", {});
});
return {
browser_connect: () => "test-session",
workspace_last_path: () => null,
plugins_snapshot: () => ({ 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 })) }),
plugins_load: ({ id }) => modules[id],
plugins_data: ({ id, value }) => {
if (value !== null) { localStorage.setItem("settings:" + id, value); test.emit("plugin-settings-changed", id); }
return localStorage.getItem("settings:" + id) || "null";
},
plugins_set_enabled: ({ enabled }) => { if (!enabled) localStorage.setItem("disabled", "true"); test.emit("plugins-changed", {}); },
plugins_release: () => null,
"plugin:window|is_maximized": () => false,
};
},
};
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` });
const output = await outputDir("plugins/access");
const main = await openPage(context), settings = await openPage(context);
const external = page => page.evaluate(() => performance.getEntriesByType("resource").find(entry => new URL(entry.name).pathname === "/src/lib/plugins/external.ts").name);
try {
await main.goto(smokeUrl);
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();
const module = await external(main);
await main.evaluate(async module => {
const { closePluginEditor, pluginTabState, pluginView, restorePluginTab } = await import(module);
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");
}, module);
await main.getByText("Task content", { exact: true }).waitFor();
await main.evaluate(async module => { await (await import(module)).runPluginCommand("org.example.browser", "new-tab"); }, module);
await main.getByText("Browser content", { exact: true }).waitFor();
await main.evaluate(async module => { (await import(module)).openPluginView("org.example.tasks", "dialog"); }, module);
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: path.join(output, `plugin-access-${theme}.png`) });
}
await settings.goto(smokeUrl + "/?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: path.join(output, "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([...main.errors, ...settings.errors], []);
} catch (error) {
await settings.screenshot({ path: path.join(output, "plugin-access-failure.png") });
console.log(await settings.locator("body").innerText(), await settings.evaluate(() => window.accessTest), [...main.errors, ...settings.errors]);
throw error;
}
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(); }
console.log("Plugin access smoke passed: compact header, navigation, dynamic tabs, dialog, settings search, stable forms, cross-window settings, disable cleanup.");
});