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 -14
View File
@@ -1,11 +1,16 @@
// Run the browser smoke tests in tests/smoke/. See docs/development.md#browser-smoke-tests.
//
// pnpm smoke [filter...] [--list] [--jobs N] [--timeout seconds] [--no-serve]
// pnpm smoke [filter...] [--list] [--jobs N] [--timeout seconds] [--retries N] [--no-serve]
//
// A filter selects the tests whose path contains it, for example `tabs` or `tables/drag`.
// After the parallel run, the runner runs each failed test again, one at a time (--retries, default 1).
// A test that passes on a retry counts as "flaky". The summary lists it, but the run does not fail.
// A test declares what it needs on a line near the top:
// // @requires plugin:terminal plugin:table-formulas repo:RuneStone_Git/dist electron
// The runner skips a test, with the reason, when a requirement is missing.
// A test that fails because of a known app defect states it near the top:
// // @known-issue <the defect>
// It still runs. A failure counts as "known". A pass counts as a failure, so remove the stale line.
import { spawn } from "node:child_process";
import { createWriteStream, existsSync } from "node:fs";
import { mkdir, readdir, readFile } from "node:fs/promises";
@@ -33,6 +38,7 @@ const list = flag("--list");
const serve = !flag("--no-serve");
const jobs = Math.max(1, Number(option("--jobs", "4")));
const timeoutMs = Math.max(10, Number(option("--timeout", "180"))) * 1000;
const retries = Math.max(0, Number(option("--retries", "1")));
const filters = args;
const env = { ...process.env, SMOKE_URL: process.env.SMOKE_URL || "http://127.0.0.1:1420" };
@@ -48,9 +54,12 @@ async function findTests(dir) {
return result.sort();
}
async function requirements(file) {
async function header(file) {
const head = (await readFile(file, "utf8")).split("\n").slice(0, 10).join("\n");
return head.match(/@requires\s+([^\n]+)/)?.[1].trim().split(/\s+/) ?? [];
return {
needs: head.match(/@requires\s+([^\r\n]+)/)?.[1].trim().split(/\s+/) ?? [],
knownIssue: head.match(/@known-issue\s+([^\r\n]+)/)?.[1].trim(),
};
}
function missing(requirement) {
@@ -115,9 +124,9 @@ async function startServer() {
throw new Error(`The dev server did not start at ${env.SMOKE_URL}.`);
}
function run(file) {
function run(file, knownIssue, logSuffix = "") {
const name = path.relative(smokeRoot, file).replace(/\\/g, "/").replace(/\.smoke\.mjs$/, "");
const log = path.join(logRoot, name.replaceAll("/", "__") + ".log");
const log = path.join(logRoot, name.replaceAll("/", "__") + logSuffix + ".log");
const started = Date.now();
return new Promise(resolve => {
const out = createWriteStream(log);
@@ -129,8 +138,9 @@ function run(file) {
clearTimeout(timer);
out.end();
const seconds = ((Date.now() - started) / 1000).toFixed(1);
const status = code === 0 ? "pass" : Date.now() - started >= timeoutMs ? "timeout" : "fail";
resolve({ name, status, detail: `${seconds}s`, log });
let status = code === 0 ? "pass" : Date.now() - started >= timeoutMs ? "timeout" : "fail";
if (knownIssue) status = status === "pass" ? "unexpected-pass" : "known";
resolve({ name, status, detail: status === "known" ? knownIssue : `${seconds}s`, log });
});
});
}
@@ -146,9 +156,9 @@ if (!tests.length) {
const plan = [];
for (const file of tests) {
const needs = await requirements(file);
const { needs, knownIssue } = await header(file);
const reasons = needs.map(missing).filter(Boolean);
plan.push({ file, needs, reasons });
plan.push({ file, needs, reasons, knownIssue });
}
if (list) {
@@ -178,14 +188,21 @@ for (const item of plan.filter(item => item.reasons.length)) {
}
async function worker() {
while (queue.length) {
const { file } = queue.shift();
const result = await run(file);
const { file, knownIssue } = queue.shift();
const result = { ...await run(file, knownIssue), file };
results.push(result);
console.log(`${result.status.padEnd(7)} ${result.name} (${result.detail})`);
}
}
try {
await Promise.all(Array.from({ length: Math.min(jobs, queue.length || 1) }, worker));
for (let attempt = 1; attempt <= retries; attempt++) {
for (const result of results.filter(item => ["fail", "timeout"].includes(item.status))) {
const retry = await run(result.file, undefined, `.retry${attempt}`);
console.log(`retry ${retry.name}: ${retry.status} (${retry.detail})`);
if (retry.status === "pass") result.status = "flaky";
}
}
} finally {
server?.kill();
}
@@ -193,7 +210,9 @@ try {
const count = status => results.filter(result => result.status === status).length;
console.log("");
for (const result of results.filter(item => item.status !== "pass").sort((a, b) => a.name.localeCompare(b.name))) {
console.log(`${result.status.padEnd(7)} ${result.name}: ${result.status === "skip" ? result.detail : path.relative(root, result.log)}`);
const detail = ["skip", "known"].includes(result.status) ? result.detail : path.relative(root, result.log);
console.log(`${result.status.padEnd(7)} ${result.name}: ${detail}`);
}
console.log(`\n${count("pass")} passed, ${count("fail") + count("timeout")} failed, ${count("skip")} skipped. Logs: ${path.relative(root, logRoot)}`);
process.exitCode = count("fail") + count("timeout") ? 1 : 0;
const failed = count("fail") + count("timeout") + count("unexpected-pass");
console.log(`\n${count("pass")} passed, ${count("flaky")} flaky, ${failed} failed, ${count("known")} known issues, ${count("skip")} skipped. Logs: ${path.relative(root, logRoot)}`);
process.exitCode = failed ? 1 : 0;