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
+41 -54
View File
@@ -1,21 +1,20 @@
// Run against pnpm dev. Native IPC is mocked; this does not test the operating system title bar.
import { createRequire } from "node:module";
// Settings window: browser preview fallback, standalone layout, two-way save sync, failed saves, native open requests, and close. The OS title bar is not tested.
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 errors = [];
const context = await browser.newContext({ viewport: { width: 1100, height: 760 } });
const watch = page => page.on("pageerror", error => errors.push(error.message));
try {
const main = await context.newPage(); watch(main);
await main.goto(origin);
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("settings/window", async ({ browser }) => {
const output = await outputDir("settings/window");
const context = await browser.newContext({ viewport: { width: 1100, height: 760 } });
const autosaveSeconds = page => page.evaluate(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveSeconds);
// The main window and settings run as browser previews, without the Tauri mock.
const main = await openPage(context);
await main.goto(smokeUrl);
await main.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).click();
assert.equal(await main.locator("dialog:modal").count(), 1, "Browser preview retains the settings dialog");
const settings = await context.newPage(); watch(settings);
await settings.goto(`${origin}/?settingsWindow=true`);
const settings = await openPage(context);
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
await settings.getByRole("heading", { name: "General", exact: true }).waitFor();
assert.equal(await settings.locator(".workbench").count(), 0);
const interval = settings.getByRole("spinbutton", { name: "Auto-save interval" });
@@ -28,65 +27,53 @@ try {
await settings.waitForFunction(() => document.querySelector("#autosave-seconds")?.value === "29");
await interval.fill("301"); await interval.press("Tab");
await settings.getByRole("alert").filter({ hasText: "Choose a whole number" }).waitFor();
assert.equal(await settings.evaluate(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveSeconds), 29);
assert.equal(await autosaveSeconds(settings), 29);
await settings.evaluate(() => { Storage.prototype.setItem = () => { throw new Error("Storage full"); }; });
await interval.fill("40"); await interval.press("Tab");
await settings.getByRole("alert").filter({ hasText: "Could not save these settings" }).waitFor();
assert.equal(await settings.evaluate(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveSeconds), 29);
assert.equal(await autosaveSeconds(settings), 29);
await settings.reload();
await settings.getByRole("button", { name: "Plug-ins", exact: true }).click();
await settings.getByRole("heading", { name: "Plug-ins", exact: true }).waitFor();
await settings.getByRole("button", { name: "General", exact: true }).click();
await mkdir(".audit", { recursive: true });
await settings.screenshot({ path: ".audit/settings-window.png" });
await settings.screenshot({ path: path.join(output, "settings-window.png") });
await settings.setViewportSize({ width: 540, height: 420 });
assert.equal(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true);
await settings.keyboard.press("Escape");
await settings.waitForURL(`${origin}/`);
await settings.waitForURL(`${smokeUrl}/`);
const desktop = await context.newPage(); watch(desktop);
await desktop.addInitScript(() => {
window.isTauri = true;
const callbacks = new Map();
let sequence = 0;
window.settingsTest = { opens: 0, fail: false, closes: 0 };
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 === "settings_open_window") {
window.settingsTest.opens++;
if (window.settingsTest.fail) throw new Error("Native window creation failed");
await new Promise(resolve => setTimeout(resolve, 150));
return;
}
if (command === "plugins_snapshot") return { root: "C:/plugins", plugins: [] };
if (command === "workspace_last_path") return null;
if (command === "plugin:event|listen") return args.handler;
if (command === "plugin:event|unlisten") return;
if (command === "plugin:window|is_maximized") return false;
if (command === "plugin:window|close") { window.settingsTest.closes++; return; }
throw new Error(`Unexpected IPC: ${command}`);
// A desktop window with the Tauri mock opens settings in a native window.
const desktop = await openPage(context);
await mockTauri(desktop, {
state: { opens: 0, fail: false, closes: 0 },
commands: test => ({
settings_open_window: async () => {
test.state.opens++;
if (test.state.fail) throw new Error("Native window creation failed");
await new Promise(resolve => setTimeout(resolve, 150));
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
workspace_last_path: () => null,
"plugin:window|is_maximized": () => false,
"plugin:window|close": () => { test.state.closes++; },
}),
});
await desktop.goto(origin);
const desktopState = () => desktop.evaluate(() => window.__TEST__.state);
await desktop.goto(smokeUrl);
await desktop.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).dblclick();
assert.equal(await desktop.evaluate(() => window.settingsTest.opens), 1, "Rapid requests share the pending native open");
assert.equal((await desktopState()).opens, 1, "Rapid requests share the pending native open");
assert.equal(await desktop.locator("dialog:modal").count(), 0, "Native open does not block the workbench");
await desktop.waitForTimeout(180);
await desktop.keyboard.press("Control+,");
await desktop.waitForFunction(() => window.settingsTest.opens === 2);
await desktop.waitForFunction(() => window.__TEST__.state.opens === 2);
await desktop.waitForTimeout(180);
await desktop.evaluate(() => { window.settingsTest.fail = true; });
await desktop.evaluate(() => { window.__TEST__.state.fail = true; });
await desktop.keyboard.press("Control+,");
await desktop.getByText(/Could not open settings: .*Native window creation failed/).waitFor();
await desktop.goto(`${origin}/?settingsWindow=true`);
await desktop.goto(`${smokeUrl}/?settingsWindow=true`);
await desktop.getByRole("heading", { name: "General", exact: true }).waitFor();
await desktop.getByRole("button", { name: "Close window", exact: true }).click();
assert.equal(await desktop.evaluate(() => window.settingsTest.closes), 1);
assert.deepEqual(errors, []);
assert.equal((await desktopState()).closes, 1);
assert.deepEqual([main, settings, desktop].flatMap(page => page.errors), []);
console.log("Settings window smoke passed: preview fallback, standalone layout, two-way save sync, persistence, failed saves, native open requests, and close.");
} finally { await browser.close(); }
});