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
+51 -62
View File
@@ -1,68 +1,55 @@
// Run against pnpm dev with PLAYWRIGHT_MODULE and CHROME_PATH if needed.
import { createRequire } from "node:module";
import { mkdirSync, readFileSync } from "node:fs";
// Settings window title bar: scoped permissions, drag regions, minimize, maximize, restore, close, Escape, focus, errors, themes, and the browser fallback.
import { readFileSync } from "node:fs";
import assert from "node:assert/strict";
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 url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
mkdirSync(".audit", { recursive: true });
const settingsCapability = JSON.parse(readFileSync(new URL("../../../src-tauri/capabilities/settings.json", import.meta.url), "utf8"));
assert.deepEqual(settingsCapability.windows, ["settings-main", "settings-workspace-*"]);
for (const action of ["close", "minimize", "toggle-maximize", "start-dragging"]) {
assert(settingsCapability.permissions.includes(`core:window:allow-${action}`));
}
const errors = [];
try {
import path from "node:path";
import { mockTauri, openPage, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("settings/titlebar", async ({ browser }) => {
const settingsCapability = JSON.parse(readFileSync(path.join(repoRoot, "src-tauri/capabilities/settings.json"), "utf8"));
assert.deepEqual(settingsCapability.windows, ["settings-main", "settings-workspace-*"]);
for (const action of ["close", "minimize", "toggle-maximize", "start-dragging"]) {
assert(settingsCapability.permissions.includes(`core:window:allow-${action}`));
}
const output = await outputDir("settings/titlebar");
const context = await browser.newContext({ viewport: { width: 920, height: 650 } });
await context.addInitScript(() => {
window.isTauri = true;
const callbacks = new Map();
const listeners = new Map();
window.__TEST__ = { calls: [], maximized: false, fail: "", resize: () => callbacks.get(listeners.get("tauri://resize"))?.({ payload: {} }) };
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: "settings-main" }, currentWebview: { label: "settings-main" } },
transformCallback: callback => { const id = callbacks.size + 1; callbacks.set(id, callback); return id; },
unregisterCallback: id => callbacks.delete(id),
invoke: async (command, args = {}) => {
window.__TEST__.calls.push(command);
if (window.__TEST__.fail === command) throw new Error("Window action failed");
if (command === "plugins_snapshot") return { root: "D:\\SettingsTest\\plugins", plugins: [] };
if (command === "plugin:event|listen") { listeners.set(args.event, args.handler); return args.handler; }
if (command === "plugin:window|is_maximized") return window.__TEST__.maximized;
if (command === "plugin:window|toggle_maximize") window.__TEST__.maximized = !window.__TEST__.maximized;
return null;
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
await mockTauri(context, {
label: "settings-main",
state: { maximized: false, failMinimize: false },
commands: test => ({
plugins_snapshot: () => ({ root: "D:\\SettingsTest\\plugins", plugins: [] }),
"plugin:window|is_maximized": () => test.state.maximized,
"plugin:window|toggle_maximize": () => { test.state.maximized = !test.state.maximized; },
"plugin:window|minimize": () => { if (test.state.failMinimize) throw new Error("Window action failed"); },
"plugin:window|close": () => null,
}),
});
const page = await context.newPage();
page.on("pageerror", error => errors.push(error.message));
page.setDefaultTimeout(5000);
await page.goto(`${url}/?settingsWindow=true`);
const page = await openPage(context, { timeout: 5000 });
await page.goto(`${smokeUrl}/?settingsWindow=true`);
const dialog = page.getByRole("dialog", { name: "Settings", exact: true });
await dialog.waitFor();
assert.equal(await dialog.getByRole("button", { name: /^Close/ }).count(), 1);
assert(await dialog.locator("header[data-tauri-drag-region] h1[data-tauri-drag-region]").isVisible());
assert.equal(await dialog.locator(".window-controls [data-tauri-drag-region]").count(), 0);
const calls = () => page.evaluate(() => window.__TEST__.calls);
await page.getByRole("button", { name: "Minimize window", exact: true }).click();
const calls = () => page.evaluate(() => window.__TEST__.calls.map(call => call.command));
const closes = async () => (await calls()).filter(command => command === "plugin:window|close").length;
const button = name => page.getByRole("button", { name, exact: true });
await button("Minimize window").click();
assert((await calls()).includes("plugin:window|minimize"));
await page.getByRole("button", { name: "Maximize window", exact: true }).click();
await page.getByRole("button", { name: "Restore window", exact: true }).waitFor();
await page.getByRole("button", { name: "Restore window", exact: true }).focus();
await button("Maximize window").click();
await button("Restore window").waitFor();
await button("Restore window").focus();
await page.keyboard.press("Enter");
await page.getByRole("button", { name: "Maximize window", exact: true }).waitFor();
await page.evaluate(() => { window.__TEST__.maximized = true; window.__TEST__.resize(); });
await page.getByRole("button", { name: "Restore window", exact: true }).waitFor();
await page.getByRole("button", { name: "Close window", exact: true }).focus();
await button("Maximize window").waitFor();
await page.evaluate(() => { window.__TEST__.state.maximized = true; window.__TEST__.emit("tauri://resize", {}); });
await button("Restore window").waitFor();
await button("Close window").focus();
await page.getByRole("tooltip", { name: "Close window", exact: true }).waitFor();
await page.keyboard.press("Space");
const beforeEscape = (await calls()).filter(command => command === "plugin:window|close").length;
const beforeEscape = await closes();
assert.equal(beforeEscape, 1);
await page.getByRole("textbox", { name: "Search settings" }).focus();
await page.keyboard.press("Escape");
assert.equal((await calls()).filter(command => command === "plugin:window|close").length, beforeEscape + 1);
assert.equal(await closes(), beforeEscape + 1);
await page.mouse.move(400, 180);
for (const theme of ["dark", "light"]) {
await page.evaluate(value => document.documentElement.setAttribute("data-theme", value), theme);
@@ -70,27 +57,29 @@ try {
await page.setViewportSize(size);
assert(await dialog.evaluate(element => element.scrollWidth === element.clientWidth));
for (const label of ["Minimize window", "Restore window", "Close window"]) {
const button = dialog.getByRole("button", { name: label, exact: true });
const bounds = await button.boundingBox();
const control = dialog.getByRole("button", { name: label, exact: true });
const bounds = await control.boundingBox();
assert(bounds.x >= 0 && bounds.x + bounds.width <= size.width && bounds.height >= 28);
assert.notEqual(await button.evaluate(element => getComputedStyle(element).borderTopLeftRadius), "0px");
assert.notEqual(await control.evaluate(element => getComputedStyle(element).borderTopLeftRadius), "0px");
}
await page.screenshot({ path: `.audit/settings-window-${theme}-${size.width}.png` });
await page.screenshot({ path: path.join(output, `${theme}-${size.width}.png`) });
}
}
await page.evaluate(() => { window.__TEST__.fail = "plugin:window|minimize"; });
await page.getByRole("button", { name: "Minimize window", exact: true }).click();
await page.evaluate(() => { window.__TEST__.state.failMinimize = true; });
await button("Minimize window").click();
await dialog.getByRole("alert").filter({ hasText: "Window action failed" }).waitFor();
await page.evaluate(() => { window.__TEST__.fail = ""; });
await page.getByRole("button", { name: "Minimize window", exact: true }).focus();
await page.evaluate(() => { window.__TEST__.state.failMinimize = false; });
await button("Minimize window").focus();
await page.keyboard.press("Shift+Tab");
assert.equal(await page.evaluate(() => document.activeElement?.textContent), "Restore defaults");
await page.keyboard.press("Tab");
assert.equal(await page.evaluate(() => document.activeElement?.getAttribute("aria-label")), "Minimize window");
const web = await browser.newPage();
await web.goto(`${url}/?settingsWindow=true`);
// Without the Tauri mock, the page is a plain browser preview.
const web = await openPage(browser);
await web.goto(`${smokeUrl}/?settingsWindow=true`);
await web.getByRole("button", { name: "Close settings", exact: true }).waitFor();
assert.equal(await web.getByRole("group", { name: "Window controls" }).count(), 0);
assert.deepEqual(errors, []);
assert.deepEqual(page.errors, []);
console.log("Settings window smoke passed: scoped permissions, drag regions, minimize, maximize, restore, resize, close, Escape, keyboard focus, tooltips, errors, both themes, narrow layout, and browser fallback.");
} finally { await browser.close(); }
});