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
+59 -82
View File
@@ -1,71 +1,48 @@
import { createRequire } from "node:module";
// Link context menus in the Writer, Reading, IDE, and table cells: browser and workspace actions, Edit link with undo, keyboard use, narrow windows, bookmarks, rename, and move.
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(15000);
const errors = [];
page.on("pageerror", error => errors.push(error.message));
await mkdir(".audit", { recursive: true });
await page.addInitScript(() => {
window.isTauri = true;
const root = "C:\\tab-menu-workspace";
const files = new Map(["a.md", "b.md", "c.md", "d.md"].map(name => [name, `# ${name}\n\nOriginal text.\n\n\`\`\`js\nconst answer = 42;\n\`\`\`\n\n| Name | Value |\n| --- | --- |\n| Alpha | One |\n`]));
files.set("a.md", "# Links\n\nSelected reading text.\n\n[Web label](https://example.com/path)\n\n[[b.md|Workspace note]]\n\n| Link | Note |\n| --- | --- |\n| [Cell web](https://example.com/cell) | [[b.md\\|Cell note]] |\n");
files.set("sample.txt", "const answer = 42;\n");
window.tabMenuTest = { prompts: [], answer: "Cancel", revealed: null, clipboard: null, opened: null, app: null, windows: [] };
Object.defineProperty(navigator, "clipboard", { value: { writeText: async text => { window.tabMenuTest.clipboard = text; } } });
window.tabMenuTest.files = files;
let sequence = 0;
const callbacks = new Map(), listeners = new Map();
window.spellingTest = { commands: [], emit: payload => callbacks.get(listeners.get("spelling-menu"))?.({ event: "spelling-menu", id: 1, payload }) };
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
transformCallback: callback => { callbacks.set(++sequence, callback); return sequence; }, unregisterCallback: id => callbacks.delete(id),
invoke: async (command, args = {}) => {
if (command === "plugin:event|listen") { listeners.set(args.event, args.handler); return ++sequence; }
if (command === "plugin:event|unlisten") return;
if (command.startsWith("spelling_menu_")) { window.spellingTest.commands.push({ method: command, ...args }); return; }
if (command === "spelling_suggestions") return { language: "en-US", words: ["Corrected"], misspelled: args.word === "Original" };
if (command === "workspace_last_path") return root;
if (command === "workspace_open") return { root, name: "tab-menu-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_list") return [...(!args.rel ? [{ name: "notes", rel_path: "notes", kind: "folder" }] : []), ...[...files.keys()].filter(path => path.split("/").slice(0, -1).join("/") === (args.rel || "")).map(path => ({ name: path.split("/").at(-1), rel_path: path, kind: "file" }))];
if (command === "workspace_search") { window.tabMenuTest.searched = args.query; return []; }
if (command === "plugin:opener|open_url") { window.tabMenuTest.opened = args.url; return; }
if (command === "workspace_open_default") { window.tabMenuTest.app = args.rel; return; }
if (command === "workspace_open_window") { window.tabMenuTest.windows.push(args); return; }
if (command === "workspace_write") { files.set(args.rel, args.contents); return; }
if (command === "workspace_rename") { files.set(args.to, files.get(args.from)); files.delete(args.from); return; }
if (command === "workspace_abs_path") return `${root}\\${args.rel}`;
if (command === "workspace_reveal") { window.tabMenuTest.revealed = args.rel; return; }
if (command === "plugin:dialog|message") { window.tabMenuTest.prompts.push(args.message); return window.tabMenuTest.answer; }
throw new Error(`Unhandled IPC: ${command}`);
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
});
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
const menu = name => page.getByRole('menu', { name, exact: true });
const item = name => page.getByRole('menuitem', { name, exact: true });
const output = '.audit/editor-link-menus';
await mkdir(output, { recursive: true });
const dismiss = async () => { await page.keyboard.press('Escape'); await page.locator('.rs-menu').waitFor({ state: 'detached' }); };
const report = [];
async function writerMenu(target='Web label') {
await page.locator('.cm-content').getByText('Selected reading text.', { exact: true }).click();
await page.locator('.cm-content').getByText(target, { exact: true }).click({ button: 'right' });
await menu('Markdown text actions').waitFor();
}
try {
await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420');
await runSmoke("links/linkMenus", async ({ page }) => {
const output = await outputDir("links/linkMenus");
await mockTauri(page, {
commands: test => {
const note = name => `# ${name}\n\nOriginal text.\n\n\`\`\`js\nconst answer = 42;\n\`\`\`\n\n| Name | Value |\n| --- | --- |\n| Alpha | One |\n`;
const files = Object.fromEntries(["b.md", "c.md", "d.md"].map(name => [name, note(name)]));
// Enter in a table cell moves to the next row, and adds one after the last row (src/lib/editor/tableControls.ts:278-285).
// The second row keeps each link edit a single undo step.
files["a.md"] = "# Links\n\nSelected reading text.\n\n[Web label](https://example.com/path)\n\n[[b.md|Workspace note]]\n\n| Link | Note |\n| --- | --- |\n| [Cell web](https://example.com/cell) | [[b.md\\|Cell note]] |\n| Plain | Row |\n";
files["sample.txt"] = "const answer = 42;\n";
const workspace = test.workspace({ root: "C:\\tab-menu-workspace", folders: ["notes"], files });
Object.assign(test, { files: workspace.files, clipboard: null, opened: null, app: null, revealed: null, searched: null, windows: [] });
Object.defineProperty(navigator, "clipboard", { value: { writeText: async text => { test.clipboard = text; } } });
return {
...workspace,
workspace_search: args => { test.searched = args.query; return []; },
workspace_rename: args => { workspace.files.set(args.to, workspace.files.get(args.from)); workspace.files.delete(args.from); },
workspace_reveal: args => { test.revealed = args.rel; },
workspace_open_default: args => { test.app = args.rel; },
workspace_open_window: args => { test.windows.push(args); },
"plugin:opener|open_url": args => { test.opened = args.url; },
spelling_menu_install: () => {},
};
},
});
const menu = name => page.getByRole('menu', { name, exact: true });
const item = name => page.getByRole('menuitem', { name, exact: true });
const dismiss = async () => { await page.keyboard.press('Escape'); await page.locator('.rs-menu').waitFor({ state: 'detached' }); };
const report = [];
async function writerMenu(target='Web label') {
await page.locator('.cm-content').getByText('Selected reading text.', { exact: true }).click();
await page.locator('.cm-content').getByText(target, { exact: true }).click({ button: 'right' });
await menu('Markdown text actions').waitFor();
}
await page.goto(smokeUrl);
await page.locator('[data-tree-rel="a.md"]').click();
await page.locator('.cm-content').waitFor();
await page.evaluate(async () => {
const { pluginHost } = await import('/src/lib/plugins/registry.ts');
pluginHost.register('link-smoke', 'browser', { open: async target => { window.tabMenuTest.browser = target; return true; }, mountSettings: () => () => {}, mountBookmarks: () => () => {} });
pluginHost.register('link-smoke', 'browser', { open: async target => { window.__TEST__.browser = target; return true; }, mountSettings: () => () => {}, mountBookmarks: () => () => {} });
});
for (const theme of ['dark', 'light']) {
await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({theme:'default', mode}); }, theme);
@@ -73,11 +50,11 @@ try {
for (const label of ['Open link in app browser', 'Open link in default browser', 'Copy URL', 'Edit link']) assert.equal(await item(label).count(), 1);
await page.screenshot({ path: `${output}/writer-link-${theme}.png` });
await item('Copy URL').click();
await page.waitForFunction(() => window.tabMenuTest.clipboard === 'https://example.com/path');
await page.waitForFunction(() => window.__TEST__.clipboard === 'https://example.com/path');
await writerMenu(); await item('Open link in default browser').click();
await page.waitForFunction(() => window.tabMenuTest.opened === 'https://example.com/path');
await page.waitForFunction(() => window.__TEST__.opened === 'https://example.com/path');
await writerMenu(); await item('Open link in app browser').click();
await page.waitForFunction(() => window.tabMenuTest.browser === 'https://example.com/path');
await page.waitForFunction(() => window.__TEST__.browser === 'https://example.com/path');
await writerMenu(); await item('Edit link').click();
assert.equal(await page.evaluate(async () => { const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js'); const v = EditorView.findFromDOM(document.querySelector('.cm-content')); return v.state.sliceDoc(v.state.selection.main.from, v.state.selection.main.to); }), 'https://example.com/path');
await page.screenshot({ path: `${output}/edit-url-${theme}.png` });
@@ -98,8 +75,8 @@ try {
await page.getByRole('button',{name:'Files',exact:true}).click(); await page.getByRole('button',{name:'Show outline',exact:true}).click();
await writerMenu('Workspace note');
await item('Copy path').focus(); await page.keyboard.press('ArrowRight'); await item('Workspace path').click();
await page.waitForFunction(() => window.tabMenuTest.clipboard === 'b.md');
await writerMenu('Workspace note'); await item('Show in system explorer').click(); await page.waitForFunction(() => window.tabMenuTest.revealed === 'b.md');
await page.waitForFunction(() => window.__TEST__.clipboard === 'b.md');
await writerMenu('Workspace note'); await item('Show in system explorer').click(); await page.waitForFunction(() => window.__TEST__.revealed === 'b.md');
await writerMenu('Workspace note'); await item('Reveal file in navigation').click();
await page.waitForFunction(() => document.activeElement?.getAttribute('data-tree-rel') === 'b.md');
await page.getByRole('group', { name: 'Document view', exact: true }).hover(); await page.getByRole('button', { name:'Read', exact:true }).click();
@@ -110,13 +87,13 @@ try {
await page.keyboard.press('End'); assert.match(await page.evaluate(() => document.activeElement.textContent), /^Search for/);
await page.screenshot({ path: `${output}/reading-selection-${theme}.png` });
await page.keyboard.press('Home'); await page.keyboard.press('Enter');
await page.waitForFunction(() => window.tabMenuTest.clipboard === 'Selected reading text.');
await page.waitForFunction(() => window.__TEST__.clipboard === 'Selected reading text.');
await page.keyboard.press('Shift+F10');
await page.getByRole('menuitem', {name:/^Search for/}).click();
await page.waitForFunction(() => window.tabMenuTest.searched === 'Selected reading text.');
await page.waitForFunction(() => window.__TEST__.searched === 'Selected reading text.');
await page.evaluate(() => getSelection().removeAllRanges());
await reading.getByRole('link',{name:'Web label'}).click({button:'right'});
await item('Copy URL').click(); await page.waitForFunction(() => window.tabMenuTest.clipboard === 'https://example.com/path');
await item('Copy URL').click(); await page.waitForFunction(() => window.__TEST__.clipboard === 'https://example.com/path');
await page.getByRole('button', { name: 'Search', exact: true }).click();
await page.getByRole('button', { name: 'Hide outline', exact: true }).click();
await page.setViewportSize({ width: 560, height: 620 });
@@ -143,7 +120,7 @@ try {
await item('Edit link').waitFor();
await page.screenshot({path:`${output}/table-link-${theme}.png`});
await item('Copy URL').click();
await page.waitForFunction(() => window.tabMenuTest.clipboard === 'https://example.com/cell');
await page.waitForFunction(() => window.__TEST__.clipboard === 'https://example.com/cell');
await cellLink.click({button:'right'}); await item('Edit link').click();
const sourceCell = page.locator('.writer-table .is-source-editing .writer-cell-editor');
await sourceCell.waitFor();
@@ -182,28 +159,28 @@ try {
report.push({theme,passed:['Writer and IDE edit URL selection','browser destinations','workspace file actions','Reader copy/search/link actions','inline table web/wiki link edits and undo','table source Escape and keyboard menu','keyboard focus return','narrow viewport'],nativeDesktop:'not tested'});
}
await writerMenu('Workspace note'); await item('Open in new window').click();
await page.waitForFunction(() => window.tabMenuTest.windows.length === 1);
await page.evaluate(() => { const {transfer}=window.tabMenuTest.windows[0]; dispatchEvent(new StorageEvent('storage',{key:`runestone.tab-transfer.${transfer}.accepted`,newValue:'true'})); });
await page.waitForFunction(() => window.__TEST__.windows.length === 1);
await page.evaluate(() => { const {transfer}=window.__TEST__.windows[0]; dispatchEvent(new StorageEvent('storage',{key:`runestone.tab-transfer.${transfer}.accepted`,newValue:'true'})); });
assert.equal(await page.getByRole('tab',{name:/b.md/}).count(),1,'Opening a linked document in a new window keeps the source tab');
await page.locator('[data-tree-rel="a.md"]').click();
await writerMenu('Workspace note'); await item('Bookmark').click();
await page.waitForFunction(() => JSON.parse(window.tabMenuTest.files.get('.runestone/marks.json') || '{}').bookmarks?.includes('b.md'));
await page.waitForFunction(() => JSON.parse(window.__TEST__.files.get('.runestone/marks.json') || '{}').bookmarks?.includes('b.md'));
await writerMenu('Workspace note'); await item('Copy path').focus(); await page.keyboard.press('ArrowRight'); await item('System path').click();
await page.waitForFunction(() => window.tabMenuTest.clipboard.endsWith('\\b.md'));
await page.waitForFunction(() => window.__TEST__.clipboard.endsWith('\\b.md'));
await page.getByRole('group', { name: 'Document view', exact: true }).hover(); await page.getByRole('button', { name:'Read', exact:true }).click();
const readerWorkspaceMenu = async () => { await page.locator('.reading').getByRole('link',{name:'Workspace note'}).click({button:'right'}); };
await readerWorkspaceMenu(); await item('Open in default app').click();
await page.waitForFunction(() => window.tabMenuTest.app === 'b.md');
await page.waitForFunction(() => window.__TEST__.app === 'b.md');
await readerWorkspaceMenu(); await item('Rename…').click();
await page.getByLabel('New file name').fill('renamed.md'); await page.getByRole('button',{name:'Continue',exact:true}).click();
await page.waitForFunction(() => window.tabMenuTest.files.has('renamed.md') && !window.tabMenuTest.files.has('b.md'));
assert.equal(await page.evaluate(() => JSON.parse(window.tabMenuTest.files.get('.runestone/marks.json')).bookmarks.includes('renamed.md')),true);
await page.waitForFunction(() => window.__TEST__.files.has('renamed.md') && !window.__TEST__.files.has('b.md'));
assert.equal(await page.evaluate(() => JSON.parse(window.__TEST__.files.get('.runestone/marks.json')).bookmarks.includes('renamed.md')),true);
await page.getByRole('group', { name: 'Document view', exact: true }).hover(); await page.getByRole('button', { name:'Edit', exact:true }).click();
await page.locator('.cm-content').evaluate(async node => { const {EditorView}=await import('/node_modules/@codemirror/view/dist/index.js'); const view=EditorView.findFromDOM(node); const from=view.state.doc.toString().indexOf('b.md'); view.dispatch({changes:{from,to:from+4,insert:'renamed.md'}}); });
await page.getByRole('group', { name: 'Document view', exact: true }).hover(); await page.getByRole('button', { name:'Read', exact:true }).click();
await readerWorkspaceMenu(); await item('Move file to…').click();
await page.getByLabel('Move file to (workspace path, including filename)').fill('notes/moved.md'); await page.getByRole('button',{name:'Continue',exact:true}).click();
await page.waitForFunction(() => window.tabMenuTest.files.has('notes/moved.md') && !window.tabMenuTest.files.has('renamed.md'));
assert.equal(await page.evaluate(() => JSON.parse(window.tabMenuTest.files.get('.runestone/marks.json')).bookmarks.includes('notes/moved.md')),true);
assert.deepEqual(errors,[]); console.log(JSON.stringify(report,null,2));
} catch(error) { await page.screenshot({path:`${output}/failure.png`}); console.log(await page.locator('.rs-menu').allTextContents()); throw error; } finally { await browser.close(); }
await page.waitForFunction(() => window.__TEST__.files.has('notes/moved.md') && !window.__TEST__.files.has('renamed.md'));
assert.equal(await page.evaluate(() => JSON.parse(window.__TEST__.files.get('.runestone/marks.json')).bookmarks.includes('notes/moved.md')),true);
console.log(JSON.stringify(report,null,2));
}, { timeout: 15000 });