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
+113 -111
View File
@@ -1,10 +1,8 @@
import { createRequire } from "node:module";
// Tab sessions: restore after a normal close, missing files, cancelled closes, plugin documents, and plugin tab transfers between windows and workspaces.
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 context = await browser.newContext({ viewport: { width: 1400, height: 900 } });
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
const pluginCode = `export function activate(api) {
let state = "Board state";
api.registerView({ id: "board", title: "Board", icon: "kanban", placement: "editor", navigation: true,
@@ -20,122 +18,129 @@ const pluginCode = `export function activate(api) {
mount(container) { container.textContent = "Saved board document"; return () => { container.textContent = ""; }; }
});
}`;
await context.addInitScript(({ pluginCode }) => {
window.isTauri = true;
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false }));
const params = new URLSearchParams(location.search);
const root = params.has("other") ? "C:\\other-lifecycle" : params.has("plugins") ? "C:\\plugins-lifecycle" : "C:\\document-lifecycle";
const files = new Map(["a.md", "b.md", "c.md"].map(name => [name, `# ${name}\n\nSaved text.\n`]));
files.set("saved.board", "board document");
if (params.has("missing")) files.delete("a.md");
let sequence = 0;
const callbacks = new Map(), listeners = new Map();
const emit = async event => { for (const id of listeners.get(event) || []) await callbacks.get(id)?.({ event, id, payload: null }); };
window.lifecycle = { answer: "Cancel", close: () => emit("tauri://close-requested"), root, transfer: null };
const manifest = { schemaVersion: 1, id: "test.lifecycle", name: "Lifecycle", author: "Tests", description: "Tab fixture", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" };
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
transformCallback: fn => { const id = ++sequence; callbacks.set(id, fn); 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") return;
if (command.startsWith("plugin:window|")) return;
if (command === "plugin:dialog|message") return window.lifecycle.answer;
if (command === "workspace_last_path") return root;
if (command === "workspace_open") return { root, name: "Lifecycle", watch_mode: "native" };
if (command === "workspace_open_window") { window.lifecycle.transfer = args.transfer; return; }
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("Missing file"); return files.get(args.rel); }
if (command === "workspace_list") return args.rel ? [] : [...files.keys()].map(name => ({ name, rel_path: name, kind: "file" }));
if (command === "workspace_search") return [];
if (command === "plugins_snapshot") return { root, plugins: params.has("disabled") ? [] : [{ manifest, hash: "test", enabled: true, path: root, error: null, removal: false }] };
if (command === "plugins_load") return pluginCode;
if (command === "plugins_data") return "null";
if (command === "plugins_release") return;
throw new Error(`Unhandled IPC: ${command}`);
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
}, { pluginCode });
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
const errors = [];
const dragSources = new Map();
const tab = (page, name) => page.getByRole("tab", { name, exact: true });
const bar = page => page.getByRole("tablist", { name: "Working tabs" });
async function create(query = "") {
const page = await context.newPage(); page.setDefaultTimeout(15000);
page.on("pageerror", error => errors.push(error.message));
await page.goto(url + query); await page.getByRole("tab").first().waitFor(); return page;
}
async function open(page, name) {
await page.bringToFront(); await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
await tab(page, name === "saved.board" ? "saved" : name).waitFor();
}
async function openBoard(page) {
await page.getByRole("navigation", { name: "Plugin shortcuts" }).getByRole("button", { name: "Board", exact: true }).click();
await page.getByRole("textbox", { name: "Board state" }).waitFor();
}
async function pin(page, name) {
await tab(page, name).click({ button: "right" }); await page.getByRole("menuitem", { name: "Pin", exact: true }).click();
}
async function start(page, name) {
const data = await tab(page, name).evaluate(node => {
assertDraggable(node);
function assertDraggable(node) { if (node.getAttribute("draggable") !== "true") throw new Error("The tab must support native transfer."); }
const transfer = new DataTransfer(); node.dispatchEvent(new DragEvent("dragstart", { bubbles: true, dataTransfer: transfer }));
return transfer.getData("application/x-runestone-tab");
// `window.requestClose()` sends the native close request and waits for the async close guard, which the harness emit does not await.
function closeRequests(target) {
return target.addInitScript(() => {
const internals = window.__TAURI_INTERNALS__;
const { transformCallback, invoke } = internals;
const callbacks = new Map(), handlers = [];
internals.transformCallback = (callback, once) => { const id = transformCallback(callback, once); callbacks.set(id, callback); return id; };
internals.invoke = (command, args = {}) => {
if (command === "plugin:event|listen" && args.event === "tauri://close-requested") handlers.push(args.handler);
return invoke(command, args);
};
window.requestClose = async () => {
for (const id of handlers) await callbacks.get(id)?.({ event: "tauri://close-requested", id, payload: null });
};
});
dragSources.set(data, { page, name });
return data;
}
async function drop(page, data) {
await bar(page).evaluate((node, data) => {
const transfer = new DataTransfer(); transfer.setData("application/x-runestone-tab", data);
const options = { bubbles: true, cancelable: true, clientX: node.getBoundingClientRect().left, dataTransfer: transfer };
node.dispatchEvent(new DragEvent("dragover", options)); node.dispatchEvent(new DragEvent("drop", options));
}, data);
const source = dragSources.get(data);
if (source) {
await tab(source.page, source.name).evaluateAll(nodes => nodes[0]?.dispatchEvent(new DragEvent("dragend", { bubbles: true })));
await runSmoke("tabs/lifecycle", async ({ browser }) => {
const output = await outputDir("tabs/lifecycle");
const context = await browser.newContext({ viewport: { width: 1400, height: 900 } });
await mockTauri(context, {
state: { pluginCode },
commands: test => {
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false }));
const params = new URLSearchParams(location.search);
const root = params.has("other") ? "C:\\other-lifecycle" : params.has("plugins") ? "C:\\plugins-lifecycle" : "C:\\document-lifecycle";
const files = Object.fromEntries(["a.md", "b.md", "c.md"].map(name => [name, `# ${name}\n\nSaved text.\n`]));
files["saved.board"] = "board document";
if (params.has("missing")) delete files["a.md"];
const manifest = { schemaVersion: 1, id: "test.lifecycle", name: "Lifecycle", author: "Tests", description: "Tab fixture", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" };
Object.assign(test, { answer: "Cancel", root, transfer: null });
return {
...test.workspace({ root, name: "Lifecycle", files }),
"plugin:window|is_maximized": () => false,
"plugin:window|destroy": () => null,
"plugin:dialog|message": () => test.answer,
workspace_open_window: ({ transfer }) => { test.transfer = transfer; },
plugins_snapshot: () => ({ root, plugins: params.has("disabled") ? [] : [{ manifest, hash: "test", enabled: true, path: root, error: null, removal: false }] }),
plugins_load: () => test.state.pluginCode,
};
},
});
await closeRequests(context);
const pages = [];
const dragSources = new Map();
const tab = (page, name) => page.getByRole("tab", { name, exact: true });
const bar = page => page.getByRole("tablist", { name: "Working tabs" });
const session = page => page.evaluate(() => JSON.parse(localStorage.getItem(`runestone.document-session.${encodeURIComponent(window.__TEST__.root)}`)));
async function create(query = "") {
const page = await openPage(context, { timeout: 15000 });
pages.push(page);
await page.goto(smokeUrl + query); await page.getByRole("tab").first().waitFor(); return page;
}
}
async function screenshots(page, prefix) {
await mkdir("output/tab-lifecycle", { recursive: true });
for (const mode of ["dark", "light"]) {
await page.evaluate(async mode => { const { applyAppearance } = await import("/src/lib/theme/appearance.ts"); await applyAppearance({ theme: "default", mode }); }, mode);
await page.screenshot({ path: `output/tab-lifecycle/${prefix}-${mode}.png` });
async function open(page, name) {
await page.bringToFront(); await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
await tab(page, name === "saved.board" ? "saved" : name).waitFor();
}
await page.setViewportSize({ width: 700, height: 700 });
await page.screenshot({ path: `output/tab-lifecycle/${prefix}-narrow.png` });
await page.setViewportSize({ width: 1400, height: 900 });
}
try {
async function openBoard(page) {
await page.getByRole("navigation", { name: "Plugin shortcuts" }).getByRole("button", { name: "Board", exact: true }).click();
await page.getByRole("textbox", { name: "Board state" }).waitFor();
}
async function pin(page, name) {
await tab(page, name).click({ button: "right" }); await page.getByRole("menuitem", { name: "Pin", exact: true }).click();
}
async function start(page, name) {
const data = await tab(page, name).evaluate(node => {
if (node.getAttribute("draggable") !== "true") throw new Error("The tab must support native transfer.");
const transfer = new DataTransfer(); node.dispatchEvent(new DragEvent("dragstart", { bubbles: true, dataTransfer: transfer }));
return transfer.getData("application/x-runestone-tab");
});
dragSources.set(data, { page, name });
return data;
}
async function drop(page, data) {
await bar(page).evaluate((node, data) => {
const transfer = new DataTransfer(); transfer.setData("application/x-runestone-tab", data);
const options = { bubbles: true, cancelable: true, clientX: node.getBoundingClientRect().left, dataTransfer: transfer };
node.dispatchEvent(new DragEvent("dragover", options)); node.dispatchEvent(new DragEvent("drop", options));
}, data);
const source = dragSources.get(data);
if (source) {
await tab(source.page, source.name).evaluateAll(nodes => nodes[0]?.dispatchEvent(new DragEvent("dragend", { bubbles: true })));
}
}
async function screenshots(page, prefix) {
for (const mode of ["dark", "light"]) {
await page.evaluate(async mode => { const { applyAppearance } = await import("/src/lib/theme/appearance.ts"); await applyAppearance({ theme: "default", mode }); }, mode);
await page.screenshot({ path: path.join(output, `${prefix}-${mode}.png`) });
}
await page.setViewportSize({ width: 700, height: 700 });
await page.screenshot({ path: path.join(output, `${prefix}-narrow.png`) });
await page.setViewportSize({ width: 1400, height: 900 });
}
const page = await create();
for (const name of ["a.md", "b.md", "c.md"]) await open(page, name);
await tab(page, "c.md").focus(); await page.keyboard.press("Alt+Shift+ArrowLeft"); await page.keyboard.press("Alt+Shift+ArrowLeft");
await pin(page, "b.md"); await tab(page, "b.md").click();
await page.evaluate(() => window.lifecycle.close());
const session = await page.evaluate(() => JSON.parse(localStorage.getItem(`runestone.document-session.${encodeURIComponent(window.lifecycle.root)}`)));
assert.deepEqual(session.documents.map(item => item.path), ["c.md", "a.md", "b.md"]);
assert.equal(session.activePath, "b.md"); assert.equal(session.documents[2].pinned, true);
assert.ok(!JSON.stringify(session).includes("Saved text"));
await page.goto(url + "?missing"); await tab(page, "b.md").waitFor();
await page.evaluate(() => window.requestClose());
const saved = await session(page);
assert.deepEqual(saved.documents.map(item => item.path), ["c.md", "a.md", "b.md"]);
assert.equal(saved.activePath, "b.md"); assert.equal(saved.documents[2].pinned, true);
assert.ok(!JSON.stringify(saved).includes("Saved text"));
await page.goto(smokeUrl + "?missing"); await tab(page, "b.md").waitFor();
assert.deepEqual(await bar(page).getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path)), ["c.md", "b.md"]);
assert.equal(await tab(page, "b.md").getAttribute("aria-selected"), "true");
await tab(page, "b.md").click({ button: "right" }); await page.getByRole("menuitem", { name: "Unpin", exact: true }).waitFor(); await page.keyboard.press("Escape");
await screenshots(page, "restored-documents");
await page.locator(".cm-content").fill("Unsaved draft");
await page.evaluate(() => window.lifecycle.close());
assert.deepEqual(await page.evaluate(() => JSON.parse(localStorage.getItem(`runestone.document-session.${encodeURIComponent(window.lifecycle.root)}`))), session);
await page.evaluate(() => { window.lifecycle.answer = "Ok"; return window.lifecycle.close(); });
await page.evaluate(() => window.requestClose());
assert.deepEqual(await session(page), saved);
await page.evaluate(() => { window.__TEST__.answer = "Ok"; return window.requestClose(); });
page.on("dialog", dialog => dialog.accept());
await page.reload(); await tab(page, "b.md").waitFor();
assert.match(await page.locator(".cm-content").innerText(), /Saved text/);
await open(page, "saved.board"); await page.getByText("Saved board document", { exact: true }).waitFor();
await page.evaluate(() => window.lifecycle.close()); await page.reload();
await page.evaluate(() => window.requestClose()); await page.reload();
await tab(page, "saved").waitFor(); await page.getByText("Saved board document", { exact: true }).waitFor();
console.log("PASS: normal-close restore, order, active tab, pins, missing files, canceled close, disk-only restore, and plugin documents");
const source = await create("?plugins"), target = await create("?plugins"), other = await create("?other"), disabled = await create("?plugins&disabled");
assert.equal(await tab(other, "New tab").count(), 1);
await openBoard(source); await source.getByRole("textbox", { name: "Board state" }).fill("Transferred board state"); await pin(source, "Board");
@@ -154,14 +159,11 @@ try {
assert.equal(await target.getByRole("textbox", { name: "Board state" }).inputValue(), "Destination state"); assert.equal(await tab(source, "Board").count(), 1);
await tab(source, "Board").evaluate(node => node.dispatchEvent(new DragEvent("dragend", { bubbles: true })));
await tab(source, "Board").click({ button: "right" }); await source.getByRole("menuitem", { name: "Open in new window", exact: true }).click();
const token = await source.evaluate(() => window.lifecycle.transfer); assert.ok(token);
const token = await source.evaluate(() => window.__TEST__.transfer); assert.ok(token);
const detached = await create(`?plugins&tabTransfer=${token}`); await detached.getByRole("textbox", { name: "Board state" }).waitFor();
await tab(source, "Board").waitFor({ state: "detached" });
data = await start(detached, "Board"); await drop(source, data); await tab(detached, "Board").waitFor({ state: "detached" });
assert.equal(await source.getByRole("textbox", { name: "Board state" }).inputValue(), "Transferred board state");
assert.deepEqual(errors, []);
console.log("PASS: normal-close restore, order, active tab, pins, missing files, workspace isolation, canceled close, disk-only restore, plugin documents, plugin join, duplicate protection, disabled plugin, and tear-out return");
} catch (reason) {
for (const page of context.pages()) console.error(page.url(), (await page.locator("body").innerText()).slice(-1000));
throw reason;
} finally { await browser.close(); }
assert.deepEqual(pages.flatMap(page => page.errors), []);
console.log("PASS: workspace isolation, plugin join, duplicate protection, disabled plugin, and tear-out return");
});