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
+95 -117
View File
@@ -1,17 +1,9 @@
import { createRequire } from "node:module";
// The last tab becomes a new tab, compact tab widths, site icons, mixed file and plugin tabs, close actions, plugin disable, and secondary windows.
// @known-issue Without a workspace, plugin tabs cannot be dragged to reorder: they are native-draggable but get no drag data (Workbench.svelte workingTabDragData).
import assert from "node:assert/strict";
import { mkdir } from "node:fs/promises";
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, settle as settleFrames, smokeUrl } from "../_harness/index.mjs";
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: 1440, height: 1000 } });
const page = await context.newPage();
await context.exposeBinding("settingsHostInvoke", (_source, command, args) =>
page.evaluate(({ command, args }) => window.__TAURI_INTERNALS__.invoke(command, args), { command, args }));
page.setDefaultTimeout(10000);
const errors = [];
page.on("pageerror", error => errors.push(error.message));
const pluginCode = `export function activate(api) {
window.tabTest.api = api;
const mount = (id, container) => {
@@ -33,90 +25,84 @@ const pluginCode = `export function activate(api) {
mount: (container, document) => mount(document.id, container),
});
}`;
await context.addInitScript(({ pluginCode }) => {
window.isTauri = true;
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false, autosaveSeconds: 5 }));
const root = "C:\\plugin-tab-workspace";
const files = new Map(["a.md", "b.md", "c.md", ...Array.from({ length: 14 }, (_, index) => `note-${index}.md`)].map(name => [name, `# ${name}\n\nOriginal text.\n`]));
files.set("project.board", "project-board");
const callbacks = new Map(), listeners = new Map();
let sequence = 0, enabled = true;
const manifest = { schemaVersion: 1, id: "test.tabs", name: "Tab fixtures", author: "Tests", description: "Test editor tabs.", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" };
const emit = async (event, payload) => {
await Promise.all((listeners.get(event) || []).map(id => callbacks.get(id)?.({ event, id, payload })));
};
window.tabTest = { mounts: {}, disposals: {}, answer: "Cancel", prompts: 0, closeRequests: 0, destroys: 0, files };
const label = location.search.includes("secondary") ? "workspace-2" : "main";
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label }, currentWebview: { label } },
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
unregisterCallback: id => callbacks.delete(id),
invoke: async (command, args = {}) => {
if (location.search.includes("settingsWindow") && !command.startsWith("plugin:event|") && !command.startsWith("plugin:window|"))
return window.settingsHostInvoke(command, args);
if (command === "settings_open_window") return;
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") { callbacks.delete(args.eventId); return; }
if (command === "plugin:window|is_maximized") return false;
if (command === "plugin:window|close") {
window.tabTest.closeRequests++;
await emit("tauri://close-requested");
return;
}
if (command === "plugin:window|destroy") { window.tabTest.destroys++; return; }
if (command.startsWith("plugin:window|")) return;
if (command === "plugins_snapshot") return { root, plugins: [{ manifest, hash: "test", enabled, path: root, error: null, removal: false }] };
if (command === "plugins_load") return pluginCode;
if (command === "plugins_data") return "null";
if (command === "plugins_release") return;
if (command === "plugins_set_enabled") { enabled = args.enabled; emit("plugins-changed"); return; }
if (command === "workspace_last_path") return location.search.includes("no-workspace") ? null : root;
if (command === "workspace_open") return { root, name: "plugin-tab-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") { files.set(args.rel, args.contents); return; }
if (command === "workspace_list") return args.rel ? [] : [...files.keys()].map(name => ({ name, rel_path: name, kind: "file" }));
if (command === "workspace_search") return [];
if (command === "plugin:dialog|message") { window.tabTest.prompts++; return window.tabTest.answer; }
throw new Error(`Unhandled IPC: ${command}`);
// `?secondary` loads a secondary window. `?settingsWindow` loads the settings window, which sends its commands to the main page.
function windowRoles(context) {
return context.addInitScript(() => {
const internals = window.__TAURI_INTERNALS__;
if (location.search.includes("secondary")) internals.metadata = { currentWindow: { label: "workspace-2" }, currentWebview: { label: "workspace-2" } };
if (!location.search.includes("settingsWindow")) return;
const { invoke } = internals;
internals.invoke = (command, args = {}) => command.startsWith("plugin:event|") || command.startsWith("plugin:window|")
? invoke(command, args)
: window.settingsHostInvoke(command, args);
});
}
await runSmoke("tabs/lastTabAndSiteIcons", async ({ browser }) => {
const output = await outputDir("tabs/lastTabAndSiteIcons");
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
await mockTauri(context, {
state: { pluginCode },
commands: test => {
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false, autosaveSeconds: 5 }));
const root = "C:\\plugin-tab-workspace";
const files = Object.fromEntries(["a.md", "b.md", "c.md", ...Array.from({ length: 14 }, (_, index) => `note-${index}.md`)].map(name => [name, `# ${name}\n\nOriginal text.\n`]));
files["project.board"] = "project-board";
const manifest = { schemaVersion: 1, id: "test.tabs", name: "Tab fixtures", author: "Tests", description: "Test editor tabs.", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" };
let enabled = true;
window.tabTest = { mounts: {}, disposals: {}, answer: "Cancel", prompts: 0, closeRequests: 0, destroys: 0 };
const workspace = test.workspace({ root, files });
return {
...workspace,
workspace_last_path: () => location.search.includes("no-workspace") ? null : root,
settings_open_window: () => null,
"plugin:window|is_maximized": () => false,
"plugin:window|close": () => { window.tabTest.closeRequests++; test.emit("tauri://close-requested"); },
"plugin:window|destroy": () => { window.tabTest.destroys++; },
"plugin:dialog|message": () => { window.tabTest.prompts++; return window.tabTest.answer; },
plugins_snapshot: () => ({ root, plugins: [{ manifest, hash: "test", enabled, path: root, error: null, removal: false }] }),
plugins_load: () => test.state.pluginCode,
plugins_release: () => null,
plugins_set_enabled: args => { enabled = args.enabled; test.emit("plugins-changed"); },
};
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
}, { pluginCode });
});
await windowRoles(context);
const page = await openPage(context);
const pages = [page];
await context.exposeBinding("settingsHostInvoke", (_source, command, args) =>
page.evaluate(({ command, args }) => window.__TAURI_INTERNALS__.invoke(command, args), { command, args }));
const tab = name => page.getByRole("tab", { name, exact: true });
const bar = page.getByRole("tablist", { name: "Working tabs" });
const order = () => bar.getByRole("tab").evaluateAll(nodes => nodes.map(node => node.textContent.trim()));
const settle = () => settleFrames(page);
async function openFile(name) {
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 settle();
}
async function openView(name) {
await page.getByRole("navigation", { name: "Plugin shortcuts" }).getByRole("button", { name, exact: true }).click();
await tab(name).waitFor();
}
async function drag(from, to, side = "before", cancel) {
const source = await tab(from).boundingBox(), target = await tab(to).boundingBox();
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
await page.mouse.down();
await page.mouse.move(side === "before" ? target.x + 2 : target.x + target.width - 2, target.y + target.height / 2, { steps: 10 });
if (cancel === "escape") await page.keyboard.press("Escape");
if (cancel === "outside") await page.mouse.move(target.x, target.y + 100);
await page.mouse.up();
await settle();
}
async function menu(name) {
await tab(name).click({ button: "right" });
await page.getByRole("menu", { name: "Tab actions" }).waitFor();
}
const tab = name => page.getByRole("tab", { name, exact: true });
const bar = page.getByRole("tablist", { name: "Working tabs" });
const order = () => bar.getByRole("tab").evaluateAll(nodes => nodes.map(node => node.textContent.trim()));
const settle = () => page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
async function openFile(name) {
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 settle();
}
async function openView(name) {
await page.getByRole("navigation", { name: "Plugin shortcuts" }).getByRole("button", { name, exact: true }).click();
await tab(name).waitFor();
}
async function drag(from, to, side = "before", cancel) {
const source = await tab(from).boundingBox(), target = await tab(to).boundingBox();
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
await page.mouse.down();
await page.mouse.move(side === "before" ? target.x + 2 : target.x + target.width - 2, target.y + target.height / 2, { steps: 10 });
if (cancel === "escape") await page.keyboard.press("Escape");
if (cancel === "outside") await page.mouse.move(target.x, target.y + 100);
await page.mouse.up();
await settle();
}
async function menu(name) {
await tab(name).click({ button: "right" });
await page.getByRole("menu", { name: "Tab actions" }).waitFor();
}
try {
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
await page.goto(url);
await page.goto(smokeUrl);
await page.getByText("plugin-tab-workspace", { exact: true }).waitFor();
await tab("New tab").waitFor();
for (const close of ["button", "middle", "shortcut", "all"]) {
@@ -165,8 +151,7 @@ try {
await plus.focus();
await page.locator('[role="tooltip"]:popover-open').filter({ hasText: "New tab (Ctrl T)" }).waitFor();
await page.keyboard.press("Escape");
await mkdir(".audit", { recursive: true });
await page.locator(".header").screenshot({ path: `.audit/compact-tabs-${width}-${theme}.png` });
await page.locator(".header").screenshot({ path: path.join(output, `compact-tabs-${width}-${theme}.png`) });
}
}
await menu("note-0.md");
@@ -187,8 +172,7 @@ try {
assert.equal(await tab("Browser").locator("img").getAttribute("draggable"), "false");
for (const theme of ["dark", "light"]) {
await page.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
await mkdir("output", { recursive: true });
await page.locator(".header").screenshot({ path: `output/tab-site-icon-${theme}.png` });
await page.locator(".header").screenshot({ path: path.join(output, `site-icon-${theme}.png`) });
}
await page.evaluate(() => window.tabTest.api.updateViewIcon("browser", "data:image/png;base64,aW1hZ2U="));
await tab("Browser").locator("img").waitFor({ state: "detached" });
@@ -274,6 +258,9 @@ try {
const bar = document.querySelector('[aria-label="Working tabs"]');
return bar.scrollLeft >= bar.scrollWidth - bar.clientWidth - 2;
});
// Native drag needs a fresh pointer event after the strip scrolls beneath it, as in tabs/order.
await page.mouse.move(bounds.x + bounds.width - 4, source.y + source.height / 2);
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2);
await page.mouse.up();
await settle();
assert.equal((await order()).at(-1), "Overview");
@@ -283,9 +270,9 @@ try {
assert.equal((await order())[0], "c.md");
const fileOrder = (await order()).filter(name => name !== "Overview");
await page.keyboard.press("Control+,");
const settingsPage = await context.newPage();
settingsPage.on("pageerror", error => errors.push(error.message));
await settingsPage.goto(url + '/?settingsWindow=true');
const settingsPage = await openPage(context);
pages.push(settingsPage);
await settingsPage.goto(smokeUrl + '/?settingsWindow=true');
await settingsPage.getByRole("button", { name: "Plug-ins", exact: true }).click();
await settingsPage.getByRole("switch", { name: "Tab fixtures", exact: true }).click();
await settingsPage.waitForFunction(() => document.getElementById("external-test.tabs")?.checked === false);
@@ -294,7 +281,7 @@ try {
console.log("PASS: plugin drag auto-scroll, empty-tab replacement, and plugin disable preserve the mixed order");
await settingsPage.close();
await page.goto(`${url}?no-workspace`);
await page.goto(`${smokeUrl}?no-workspace`);
await tab("New tab").waitFor();
await openView("Overview");
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
@@ -302,17 +289,16 @@ try {
await drag("Browser", "Overview");
assert.deepEqual(await order(), ["Browser", "Overview"]);
await page.setViewportSize({ width: 880, height: 700 });
await mkdir(".audit", { recursive: true });
await page.screenshot({ path: ".audit/plugin-tab-order.png" });
await page.screenshot({ path: path.join(output, "plugin-tab-order.png") });
await tab("Browser").click({ button: "middle" });
assert.deepEqual(await order(), ["Overview"]);
await page.getByRole("button", { name: "Close Overview", exact: true }).click();
await tab("New tab").waitFor();
assert.deepEqual(await order(), ["New tab"]);
assert.deepEqual(errors, []);
assert.deepEqual(pages.flatMap(page => page.errors), []);
console.log("PASS: plugin tabs reorder and close without an open workspace");
for (const close of ["button", "middle", "shortcut", "all", "plugin", "dirty"]) {
await page.goto(`${url}?secondary`);
await page.goto(`${smokeUrl}?secondary`);
await tab("New tab").waitFor();
if (close === "plugin") {
await openView("Overview");
@@ -326,8 +312,7 @@ try {
await page.waitForFunction(() => window.tabTest.prompts === 1);
assert.equal(await page.evaluate(() => window.tabTest.destroys), 0);
assert.match(await page.locator(".cm-content").innerText(), /Keep these unsaved edits/);
await mkdir(".audit", { recursive: true });
await page.screenshot({ path: ".audit/secondary-last-tab-cancel.png" });
await page.screenshot({ path: path.join(output, "secondary-last-tab-cancel.png") });
await page.evaluate(() => window.tabTest.answer = "Ok");
await page.keyboard.press("Control+w");
} else if (close === "button") {
@@ -345,13 +330,6 @@ try {
await page.waitForFunction(() => window.tabTest.destroys === 1);
assert.equal(await page.evaluate(() => window.tabTest.closeRequests), close === "dirty" ? 2 : 1);
}
assert.deepEqual(errors, []);
assert.deepEqual(pages.flatMap(page => page.errors), []);
console.log("PASS: secondary windows close through the window guard for the last empty, document, or plugin tab; Cancel preserves unsaved edits");
} catch (error) {
await mkdir(".audit", { recursive: true });
await page.screenshot({ path: ".audit/plugin-tab-order-failure.png" });
console.error("Browser errors:", errors);
throw error;
} finally {
await browser.close();
}
});