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
+58 -69
View File
@@ -1,67 +1,56 @@
// Run against pnpm dev with PLAYWRIGHT_MODULE and CHROME_PATH if needed.
import { createRequire } from "node:module";
import { mkdirSync, readFileSync } from "node:fs";
// General settings: auto-save timers, manual saves, persistence, cross-window updates, validation, storage failure, help, search, focus, narrow layout.
import { readFileSync } from "node:fs";
import assert from "node:assert/strict";
const require = createRequire(import.meta.url);
const { version } = JSON.parse(readFileSync(new URL("../../../package.json", import.meta.url), "utf8"));
mkdirSync(".audit", { recursive: true });
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" };
const writes = [];
window.__TEST__ = { disk, writes };
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
transformCallback: () => 1, unregisterCallback: () => {},
invoke: async (command, args = {}) => {
if (command === "plugins_snapshot") return { root: "D:\\AppData\\RuneStone\\plugins", plugins: [] };
if (command === "workspace_last_path") return "D:\\Notes";
if (command === "workspace_open") return { root: "D:\\Notes", name: "Notes", watch_mode: "native" };
if (command === "workspace_list") return args.rel ? [] : [{ name: "note.txt", rel_path: "note.txt", kind: "file" }];
if (command === "workspace_read") { if (args.rel in disk) return disk[args.rel]; throw "Missing file"; }
if (command === "workspace_write") { disk[args.rel] = args.contents; writes.push(args); return; }
return null;
import path from "node:path";
import { mockTauri, openPage, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
const { version } = JSON.parse(readFileSync(path.join(repoRoot, "package.json"), "utf8"));
await runSmoke("settings/general", async ({ browser }) => {
const output = await outputDir("settings/general");
const context = await browser.newContext({ viewport: { width: 1100, height: 800 } });
await mockTauri(context, {
state: { writes: [] },
commands: test => {
const workspace = test.workspace({ root: "D:\\Notes", files: { "note.txt": "Original note" } });
return {
...workspace,
workspace_write: args => { workspace.workspace_write(args); test.state.writes.push(args); },
plugins_snapshot: () => ({ root: "D:\\AppData\\RuneStone\\plugins", plugins: [] }),
settings_open_window: () => null,
};
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
});
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
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) {
await interval.fill(String(value));
await interval.press("Tab");
}
async function edit(value) {
await page.evaluate(async text => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected).setValue(text);
}, value);
}
const writes = () => page.evaluate(() => window.__TEST__.writes.length);
try {
});
const page = await openPage(context);
const settingsPage = await openPage(context);
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(`${smokeUrl}/?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) {
await interval.fill(String(value));
await interval.press("Tab");
}
async function edit(value) {
await page.evaluate(async text => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected).setValue(text);
}, value);
}
const writes = () => page.evaluate(() => window.__TEST__.state.writes.length);
await page.clock.install();
await page.goto(url);
await page.goto(smokeUrl);
await page.locator(".ws").filter({ hasText: "Notes" }).waitFor();
await showSettings();
assert.equal(await interval.inputValue(), "5");
@@ -82,7 +71,7 @@ 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 settingsPage.screenshot({ path: ".audit/settings-general.png" });
await settingsPage.screenshot({ path: path.join(output, "general.png") });
await closeSettings();
await page.keyboard.press("Control+p");
@@ -109,7 +98,7 @@ try {
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.waitForFunction(count => window.__TEST__.state.writes.length === count, before + 2);
await page.locator(".monaco-editor textarea").focus();
await showSettings(true);
await settings.waitFor();
@@ -119,8 +108,8 @@ try {
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}/?settingsWindow=true`);
const other = await openPage(context);
await other.goto(`${smokeUrl}/?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();
@@ -152,7 +141,7 @@ try {
const help = page.getByRole("dialog", { name: "Help and about", exact: true });
await help.getByRole("heading", { name: "RuneStone", exact: true }).waitFor();
await help.getByText(`Version ${version}`, { exact: false }).waitFor();
await page.screenshot({ path: ".audit/settings-help.png" });
await page.screenshot({ path: path.join(output, "help.png") });
await page.keyboard.press("Escape");
await page.keyboard.press("Control+b");
await showSettings(true);
@@ -165,11 +154,11 @@ try {
await showSettings(true);
await settings.waitFor();
assert(await settings.evaluate(el => el.scrollWidth === el.clientWidth), "Narrow layout fits");
await settingsPage.screenshot({ path: ".audit/settings-narrow.png" });
await settingsPage.screenshot({ path: path.join(output, "narrow.png") });
for (let i = 0; i < 12; i++) {
await settingsPage.keyboard.press("Tab");
assert(await settings.evaluate(el => el.contains(document.activeElement)), "Focus stays in the modal");
}
assert.deepEqual(errors, []);
assert.deepEqual([...page.errors, ...settingsPage.errors], []);
console.log("Settings smoke passed: timer changes, disabled auto-save, manual saves, persistence, cross-window updates, validation, storage failure, help, search, focus, shortcuts, and narrow layout.");
} finally { await browser.close(); }
});