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
+22 -87
View File
@@ -1,81 +1,20 @@
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
import { createRequire } from "node:module";
// Writer text menu on empty and whitespace lines: submenus, disabled actions, links, the file picker, keyboard focus, both themes, a narrow window, and the IDE.
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 === "spelling_menu_install") 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 };
});
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
try {
await mkdir('output/round4-editor-menu', { recursive: true });
await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:5187');
await runSmoke("editor/emptyMenu", async ({ page }) => {
await mockTauri(page, {
commands: test => test.workspace({
root: "C:\\smoke-workspace",
files: {
"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 output = await outputDir("editor/emptyMenu");
await page.goto(smokeUrl);
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');
@@ -99,14 +38,14 @@ try {
for (const label of ['Add link','Add external link','Format','Paragraph','Insert','Paste','Paste as plain text','Select all']) assert.equal(await menu().getByRole('menuitem', {name:label,exact:true}).count(),1,label);
assert.equal(await menu().getByRole('menuitem',{name:'Cut',exact:true}).isDisabled(),true);
assert.equal(await menu().getByRole('menuitem',{name:'Copy',exact:true}).isDisabled(),true);
await page.screenshot({path:`output/round4-editor-menu/empty-${theme}.png`});
await page.screenshot({path:`${output}/empty-${theme}.png`});
await menu().getByRole('menuitem',{name:'Format',exact:true}).focus();
await page.keyboard.press('ArrowRight');
const format = page.getByRole('menu',{name:'Format',exact:true});
for (const label of ['Bold','Italic','Strikethrough','Highlight','Code','Math','Comment','Clear formatting']) assert.equal(await format.getByRole('menuitem',{name:label,exact:true}).count(),1);
await page.keyboard.press('End');
assert.equal(await page.getByRole('menuitem',{name:'Comment',exact:true}).evaluate(el=>el===document.activeElement),true);
await page.screenshot({path:`output/round4-editor-menu/format-${theme}.png`});
await page.screenshot({path:`${output}/format-${theme}.png`});
await page.keyboard.press('ArrowLeft');
await page.keyboard.press('Escape');
assert.equal(await page.locator('.cm-content').evaluate(el=>el===document.activeElement),true);
@@ -116,7 +55,7 @@ try {
assert.equal(await source(),'###### ');
await setSource(''); await openKeyboard();
await menu().getByRole('menuitem',{name:'Insert',exact:true}).click();
await page.screenshot({path:`output/round4-editor-menu/insert-${theme}.png`});
await page.screenshot({path:`${output}/insert-${theme}.png`});
await page.getByRole('menu',{name:'Insert',exact:true}).getByRole('menuitem',{name:'Code block',exact:true}).click();
assert.match(await source(),/^```\nCode\n```/);
await setSource(''); await openKeyboard();
@@ -131,7 +70,7 @@ try {
await setSource(''); await openKeyboard();
await menu().getByRole('menuitem',{name:'Add link',exact:true}).click();
await page.getByRole('textbox',{name:'Find a file'}).fill('second');
await page.screenshot({path:`output/round4-editor-menu/workspace-picker-${theme}.png`});
await page.screenshot({path:`${output}/workspace-picker-${theme}.png`});
await page.keyboard.press('Enter');
await page.getByRole('dialog').waitFor({state:'detached'});
assert.equal(await source(),'[[/notes/second.md]]');
@@ -151,7 +90,7 @@ try {
await page.locator('.cm-scroller').click({button:'right',position:{x:60,y:180}});
await menu().waitFor();
const box = await menu().boundingBox(); assert.ok(box.x>=8 && box.y>=8 && box.x+box.width<=552 && box.y+box.height<=412);
await page.screenshot({path:`output/round4-editor-menu/narrow-${theme}.png`});
await page.screenshot({path:`${output}/narrow-${theme}.png`});
await page.keyboard.press('Escape');
await page.setViewportSize({width:1440,height:1000});
await page.getByRole('button',{name:'Show outline',exact:true}).click();
@@ -172,10 +111,6 @@ try {
await page.getByRole('textbox',{name:'Find a file'}).fill('second');
await page.keyboard.press('Enter');
await page.getByRole('dialog').waitFor({state:'detached'});
await page.screenshot({path:'output/round4-editor-menu/ide-links.png'});
assert.deepEqual(errors,[]);
await page.screenshot({path:`${output}/ide-links.png`});
console.log('PASS: empty and whitespace Writer menus, full submenus, disabled actions, links, picker, selection, keyboard focus, two themes, narrow viewport and IDE.');
} catch(error) {
await page.screenshot({path:'output/round4-editor-menu/failure.png'});
console.error('Browser errors:',errors); throw error;
} finally { await browser.close(); }
});