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
+118 -155
View File
@@ -1,158 +1,121 @@
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
import { createRequire } from "node:module";
// Inline note title rename: tabs and tree, undo of contents, Enter/Tab/Escape, validation, collisions, tab switches mid-rename, and reload.
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 page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
page.setDefaultTimeout(10000);
const errors = [];
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
page.on("pageerror", error => errors.push(error.message));
await page.addInitScript(() => {
window.isTauri = true;
const root = "C:\\smoke-workspace";
const files = new Map([
["notes/welcome.md", "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n"],
["notes/second.md", "# Second note\n"],
["src/hello.py", "print('hello')\n"],
]);
const callbacks = new Map();
const listeners = new Map();
let sequence = 0;
const 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 = {}) => {
calls.push({ command, args });
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 root;
if (command === "workspace_open") return { root, name: "smoke-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") {
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
files.set(args.rel, args.contents); emit("workspace-event", { root, kind: "modify", paths: [args.rel] }); return;
}
if (command === "workspace_list") {
const prefix = args.rel ? args.rel + "/" : "";
const entries = new Map();
for (const path of files.keys()) {
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
const tail = path.slice(prefix.length); const name = tail.split("/")[0];
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
}
return [...entries.values()];
}
if (command === "workspace_create") { if (files.has(args.rel)) throw new Error("exists"); files.set(args.rel, ""); return; }
if (command === "workspace_rename") {
if (window.__TEST__.delayRename) await new Promise(resolve => { window.__TEST__.resumeRename = resolve; });
if (!files.has(args.from)) throw new Error("File is missing");
if (files.has(args.to)) throw new Error("A file with that name already exists");
files.set(args.to, files.get(args.from)); files.delete(args.from); return;
}
if (command === "workspace_search") return [];
if (command === "pty_profiles") return [{ id: "powershell", title: "PowerShell", kind: "powershell" }];
if (command === "pty_open") {
const data = [...new TextEncoder().encode("READY 🪨\r\n\x1b[6n")];
emit("pty-data", { id: args.id, data: data.slice(0, 8) });
emit("pty-data", { id: args.id, data: data.slice(8) });
await new Promise(resolve => setTimeout(resolve, 50));
return;
}
if (command.startsWith("pty_")) return;
if (command === "plugin:dialog|message") return "Cancel";
throw new Error(`Unhandled IPC: ${command}`);
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("tree/renameTitle", async ({ page }) => {
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
await mockTauri(page, {
commands: test => {
const ws = test.workspace({
root: "C:\\smoke-workspace",
files: {
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
"notes/second.md": "# Second note\n",
"src/hello.py": "print('hello')\n",
},
});
const files = ws.files;
Object.assign(test, { files, root: ws.root });
return {
...ws,
workspace_write: ({ rel, contents, expected }) => {
if (expected !== undefined && files.get(rel) !== expected) throw new Error("Save blocked: file changed on disk");
files.set(rel, contents);
test.emit("workspace-event", { root: ws.root, kind: "modify", paths: [rel] });
},
workspace_rename: async ({ from, to }) => {
if (test.delayRename) await new Promise(resolve => { test.resumeRename = resolve; });
if (!files.has(from)) throw new Error("File is missing");
if (files.has(to)) throw new Error("A file with that name already exists");
files.set(to, files.get(from));
files.delete(from);
},
};
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
window.__TEST__ = { files, calls, emit, root };
});
async function openNote(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 page.getByRole("button", { name: "Rename note", exact: true }).waitFor();
}
const title = page.getByRole("button", { name: "Rename note", exact: true });
const input = page.getByRole("textbox", { name: "Note filename", exact: true });
const writer = page.getByRole("textbox", { name: "Writing editor", exact: true });
async function editTitle(value) { await title.click(); await input.fill(value); }
const renamed = name => page.waitForFunction(expected => document.querySelector(".breadcrumb")?.textContent === expected, name);
try {
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
await page.getByText("smoke-workspace", { exact: true }).waitFor();
await openNote("welcome.md");
const original = await page.evaluate(() => window.__TEST__.files.get("notes/welcome.md"));
await writer.click();
await page.keyboard.press("Control+End");
await page.keyboard.type("Unsaved text");
await editTitle("Release 1.2");
await input.press("Enter");
await renamed("notes/Release 1.2.md");
assert.equal(await page.evaluate(() => window.__TEST__.files.has("notes/welcome.md")), false);
await page.getByRole("tab", { name: /Release 1\.2\.md/ }).waitFor();
await page.locator('.tree').getByText("notes", { exact: true }).click();
await page.locator('.tree').getByText("Release 1.2", { exact: true }).waitFor();
await writer.click();
await page.keyboard.press("Control+z");
await page.keyboard.press("Control+s");
await page.waitForFunction(text => window.__TEST__.files.get("notes/Release 1.2.md") === text, original);
await page.keyboard.press("Control+y");
await page.keyboard.press("Control+s");
await page.waitForFunction(text => window.__TEST__.files.get("notes/Release 1.2.md") === text, original + "Unsaved text");
await editTitle("Cancelled");
await input.press("Escape");
await renamed("notes/Release 1.2.md");
assert.equal(await input.isVisible(), false);
// Keyboard activation and filename errors stay outside Markdown editing.
await title.focus(); await title.press("Enter");
await input.fill(" "); await input.press("Enter");
await page.getByRole("alert").filter({ hasText: "Name is empty" }).waitFor();
await input.fill("folder/note"); await input.press("Enter");
await page.getByRole("alert").filter({ hasText: "path separator" }).waitFor();
await input.fill("second"); await input.press("Enter");
await page.getByRole("alert").filter({ hasText: "already exists" }).waitFor();
assert.equal(await input.inputValue(), "second");
assert.equal(await page.evaluate(() => window.__TEST__.files.get("notes/second.md")), "# Second note\n");
await input.fill("Renamed.md"); await input.press("Tab");
await renamed("notes/Renamed.md");
await page.mouse.move(10, 10);
await page.screenshot({ path: ".audit/rename-title.png" });
// A pending rename belongs to its original document even if the tab changes.
await page.evaluate(() => { window.__TEST__.delayRename = true; });
await editTitle("Background"); await input.press("Enter");
await page.waitForFunction(() => !!window.__TEST__.resumeRename);
await page.locator('.tree').getByText("second", { exact: true }).click();
await renamed("notes/second.md");
await page.evaluate(() => { window.__TEST__.resumeRename(); window.__TEST__.delayRename = false; });
await page.getByRole("tab", { name: "Background.md", exact: true }).waitFor();
await renamed("notes/second.md");
await page.getByRole("tab", { name: "Background.md", exact: true }).click();
await renamed("notes/Background.md");
// Disk reload after rename must not restore the old displayed title.
await page.evaluate(() => {
window.__TEST__.files.set("notes/Background.md", "Reloaded\n");
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "modify", paths: ["notes/Background.md"] });
});
await page.waitForFunction(() => document.querySelector(".cm-line")?.textContent === "Reloaded");
assert.ok((await title.innerText()).startsWith("Background"));
assert.deepEqual(errors, []);
console.log("PASS: inline filename rename, folder/extension preservation, tabs/tree, contents and undo, Enter/blur/Escape, validation/collisions, tab switching during rename, and reload (mocked desktop IPC).");
} catch (error) {
console.error("Browser errors:", errors);
console.error("Visible text:", (await page.locator("body").innerText()).slice(0, 3000));
await page.screenshot({ path: ".audit/rename-title-failure.png" });
throw error;
} finally { await browser.close(); }
const output = await outputDir("tree/renameTitle");
const title = page.getByRole("button", { name: "Rename note", exact: true });
const input = page.getByRole("textbox", { name: "Note filename", exact: true });
const writer = page.getByRole("textbox", { name: "Writing editor", exact: true });
// Empty names and path separators share one message (src/lib/workspace/renamePath.ts:56-57, used by Workbench.svelte:958).
const invalidName = "Enter a document name without a leading dot or reserved filename characters.";
async function openNote(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 title.waitFor();
}
async function editTitle(value) { await title.click(); await input.fill(value); }
const renamed = name => page.waitForFunction(expected => document.querySelector(".breadcrumb")?.textContent === expected, name);
try {
await page.goto(smokeUrl);
await page.getByText("smoke-workspace", { exact: true }).waitFor();
await openNote("welcome.md");
const original = await page.evaluate(() => window.__TEST__.files.get("notes/welcome.md"));
await writer.click();
await page.keyboard.press("Control+End");
await page.keyboard.type("Unsaved text");
await editTitle("Release 1.2");
await input.press("Enter");
await renamed("notes/Release 1.2.md");
assert.equal(await page.evaluate(() => window.__TEST__.files.has("notes/welcome.md")), false);
await page.getByRole("tab", { name: /Release 1\.2\.md/ }).waitFor();
await page.locator(".tree").getByText("notes", { exact: true }).click();
await page.locator(".tree").getByText("Release 1.2", { exact: true }).waitFor();
await writer.click();
await page.keyboard.press("Control+z");
await page.keyboard.press("Control+s");
await page.waitForFunction(text => window.__TEST__.files.get("notes/Release 1.2.md") === text, original);
await page.keyboard.press("Control+y");
await page.keyboard.press("Control+s");
await page.waitForFunction(text => window.__TEST__.files.get("notes/Release 1.2.md") === text, original + "Unsaved text");
await editTitle("Cancelled");
await input.press("Escape");
await renamed("notes/Release 1.2.md");
assert.equal(await input.isVisible(), false);
// Keyboard activation and filename errors stay outside Markdown editing.
await title.focus(); await title.press("Enter");
await input.fill(" "); await input.press("Enter");
await page.getByRole("alert").filter({ hasText: invalidName }).waitFor();
await input.fill("folder/note"); await input.press("Enter");
await page.getByRole("alert").filter({ hasText: invalidName }).waitFor();
await page.waitForFunction(() => !document.querySelector(".note-title-input[aria-busy]"));
assert.equal(await page.evaluate(() => window.__TEST__.calls.some(call => call.command === "workspace_rename" && call.args.to.includes("folder"))), false);
await input.fill("second"); await input.press("Enter");
await page.getByRole("alert").filter({ hasText: "already exists" }).waitFor();
assert.equal(await input.inputValue(), "second");
assert.equal(await page.evaluate(() => window.__TEST__.files.get("notes/second.md")), "# Second note\n");
await input.fill("Renamed.md"); await input.press("Tab");
await renamed("notes/Renamed.md");
await page.mouse.move(10, 10);
await page.screenshot({ path: path.join(output, "rename-title.png") });
// A pending rename belongs to its original document even if the tab changes.
await page.evaluate(() => { window.__TEST__.delayRename = true; });
await editTitle("Background"); await input.press("Enter");
await page.waitForFunction(() => !!window.__TEST__.resumeRename);
// A plain tree click replaces the current tab (src/lib/layout/Workbench.svelte:1347), so open the other note in a new tab.
await page.locator('[data-tree-rel="notes/second.md"]').click({ button: "right" });
await page.getByRole("menuitem", { name: "Open in new tab", exact: true }).click();
await renamed("notes/second.md");
await page.evaluate(() => { window.__TEST__.resumeRename(); window.__TEST__.delayRename = false; });
await page.getByRole("tab", { name: "Background.md", exact: true }).waitFor();
await renamed("notes/second.md");
await page.getByRole("tab", { name: "Background.md", exact: true }).click();
await renamed("notes/Background.md");
// Disk reload after rename must not restore the old displayed title.
await page.evaluate(() => {
window.__TEST__.files.set("notes/Background.md", "Reloaded\n");
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "modify", paths: ["notes/Background.md"] });
});
await page.waitForFunction(() => document.querySelector(".cm-line")?.textContent === "Reloaded");
assert.ok((await title.innerText()).startsWith("Background"));
} catch (error) {
console.error("Visible text:", (await page.locator("body").innerText()).slice(0, 3000));
await page.screenshot({ path: path.join(output, "rename-title-failure.png") });
throw error;
}
});