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
+33 -49
View File
@@ -1,51 +1,36 @@
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
import { createRequire } from "node:module";
// Custom window controls: maximize, restore, minimize, the terminal close guard, the keyboard tooltip, and the header at 1400 and 880 px.
// @requires plugin:terminal plugin:table-formulas
import assert from "node:assert/strict";
import { readFile } 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 page = await browser.newPage({ viewport: { width: 1400, height: 900 } });
const errors = [];
page.on("pageerror", error => errors.push(error.message));
await page.addInitScript(() => {
window.isTauri = true;
const callbacks = new Map(), listeners = new Map();
let sequence = 0;
const state = { maximized: false, confirm: "Cancel", calls: [] };
const emit = (event, payload) => {
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
};
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 = {}) => {
state.calls.push(command);
if (command === "plugin:event|listen") {
const list = listeners.get(args.event) || []; list.push(args.handler); listeners.set(args.event, list); return args.handler;
}
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
if (command === "workspace_last_path") return null;
if (command === "plugin:window|is_maximized") return state.maximized;
if (command === "plugin:window|toggle_maximize") { state.maximized = !state.maximized; emit("tauri://resize", { width: 1400, height: 900 }); return; }
if (command === "plugin:window|minimize" || command === "plugin:window|destroy") return;
if (command === "plugin:window|close") { emit("tauri://close-requested"); return; }
if (command === "plugin:dialog|message") return state.confirm;
throw new Error(`Unhandled IPC: ${command}`);
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
window.__TEST__ = { state, emit };
});
try {
const config = JSON.parse(await readFile(new URL("../../../src-tauri/tauri.conf.json", import.meta.url), "utf8"));
import path from "node:path";
import { mockTauri, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
import { mockFeaturePlugins } from "../_harness/pluginMocks.mjs";
await runSmoke("layout/windowControls", async ({ page }) => {
const output = await outputDir("layout/windowControls");
await mockTauri(page, {
state: { maximized: false, confirm: "Cancel" },
commands: test => ({
workspace_last_path: () => null,
"plugin:window|is_maximized": () => test.state.maximized,
"plugin:window|toggle_maximize": () => { test.state.maximized = !test.state.maximized; test.emit("tauri://resize", { width: 1400, height: 900 }); },
"plugin:window|minimize": () => {},
"plugin:window|destroy": () => {},
"plugin:window|close": () => { test.emit("tauri://close-requested"); },
"plugin:dialog|message": () => test.state.confirm,
}),
});
// The Terminal button belongs to the terminal plug-in (src/lib/layout/Workbench.svelte:1305).
await mockFeaturePlugins(page);
const called = command => page.evaluate(command => window.__TEST__.calls.some(call => call.command === command), command);
const config = JSON.parse(await readFile(path.join(repoRoot, "src-tauri/tauri.conf.json"), "utf8"));
assert.equal(config.app.windows[0].decorations, false);
const capability = JSON.parse(await readFile(new URL("../../../src-tauri/capabilities/default.json", import.meta.url), "utf8"));
const capability = JSON.parse(await readFile(path.join(repoRoot, "src-tauri/capabilities/default.json"), "utf8"));
for (const permission of ["close", "minimize", "toggle-maximize", "start-dragging"]) {
assert.ok(capability.permissions.includes(`core:window:allow-${permission}`));
}
await page.goto(process.env.SMOKE_URL || "http://localhost:1420");
await page.goto(smokeUrl);
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 }).click();
@@ -54,17 +39,17 @@ try {
await page.evaluate(() => { window.__TEST__.state.maximized = true; window.__TEST__.emit("tauri://resize", { width: 1920, height: 1080 }); });
await page.getByRole("button", { name: "Restore window", exact: true }).waitFor();
await page.getByRole("button", { name: "Minimize window", exact: true }).click();
assert.ok(await page.evaluate(() => window.__TEST__.state.calls.includes("plugin:window|minimize")));
assert.ok(await called("plugin:window|minimize"));
await page.getByRole("button", { name: "Close window", exact: true }).focus();
await page.getByRole("tooltip", { name: "Close window", exact: true }).waitFor();
// Opening the terminal engages the existing close guard; cancellation must not destroy the window.
await page.getByRole("button", { name: "Terminal", exact: true }).click();
await page.getByRole("button", { name: "Close window", exact: true }).click();
await page.waitForFunction(() => window.__TEST__.state.calls.includes("plugin:dialog|message"));
assert.equal(await page.evaluate(() => window.__TEST__.state.calls.includes("plugin:window|destroy")), false);
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === "plugin:dialog|message"));
assert.equal(await called("plugin:window|destroy"), false);
await page.evaluate(() => window.__TEST__.state.confirm = "Ok");
await page.getByRole("button", { name: "Close window", exact: true }).click();
await page.waitForFunction(() => window.__TEST__.state.calls.includes("plugin:window|destroy"));
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === "plugin:window|destroy"));
await page.getByRole("button", { name: "Terminal", exact: true }).click();
for (const width of [1400, 880]) {
await page.setViewportSize({ width, height: 900 });
@@ -77,8 +62,7 @@ try {
assert.equal(layout.top, 0);
assert.ok(layout.fits);
assert.ok(layout.drag >= 40);
await page.screenshot({ path: `.audit/window-controls-${width}.png` });
await page.screenshot({ path: path.join(output, `window-controls-${width}.png`) });
}
assert.deepEqual(errors, []);
console.log("Window controls smoke passed: actions, restore state, close guard, keyboard tooltip, and 1400/880px layouts.");
} finally { await browser.close(); }
}, { viewport: { width: 1400, height: 900 }, timeout: 30000 });