// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation. import { createRequire } from "node:module"; 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_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}`); }, }; window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) }; window.__TEST__ = { files, calls, emit, root }; }); const row = rel => page.locator(`[data-tree-rel="${rel}"]`); const selected = () => page.locator('[role="treeitem"][aria-selected="true"]').evaluateAll(rows => rows.map(row => row.dataset.treeRel)); try { await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420'); await row('notes').waitFor(); await row('notes').click(); await row('notes/second.md').waitFor(); assert.deepEqual(await selected(), ['notes']); await row('notes/second.md').click({ modifiers: ['Control'] }); await row('src').click({ modifiers: ['Control'] }); assert.deepEqual(await selected(), ['notes', 'notes/second.md', 'src']); assert.equal(await row('src').getAttribute('aria-expanded'), 'false'); assert.equal(await page.getByRole('tab').count(), 0); await row('notes').click({ modifiers: ['Control'] }); assert.deepEqual(await selected(), ['notes/second.md', 'src']); assert.equal(await row('notes').getAttribute('aria-expanded'), 'true'); await row('notes/second.md').click({ modifiers: ['Shift'] }); assert.deepEqual(await selected(), ['notes', 'notes/second.md']); await row('src').click({ modifiers: ['Shift'] }); assert.deepEqual(await selected(), ['notes', 'notes/second.md', 'notes/welcome.md', 'src']); await page.keyboard.press('F2'); assert.equal(await page.locator('.tree .rename').count(), 0); await row('notes/welcome.md').click({ modifiers: ['Shift'] }); assert.deepEqual(await selected(), ['notes', 'notes/second.md', 'notes/welcome.md']); await row('notes/second.md').click(); assert.deepEqual(await selected(), ['notes/second.md']); await page.getByRole('tab', { name: /second/ }).waitFor(); await row('notes/second.md').click({ modifiers: ['Control'] }); assert.deepEqual(await selected(), []); await row('src').click({ modifiers: ['Control'] }); await row('notes').click({ modifiers: ['Control'] }); await row('notes').click({ modifiers: ['Control'] }); await page.keyboard.press('F2'); assert.equal(await page.locator('.tree .rename').inputValue(), 'src'); await page.keyboard.press('Escape'); await row('notes/second.md').click({ modifiers: ['Shift'] }); assert.deepEqual(await selected(), ['notes/second.md', 'notes/welcome.md', 'src']); const colors = await page.locator('.tree .row.selected').evaluateAll(rows => rows.map(row => getComputedStyle(row).backgroundColor)); assert.equal(new Set(colors).size, 1); await page.screenshot({ path: '.audit/tree-selection.png' }); await page.getByRole('button', { name: 'Collapse all', exact: true }).click(); assert.deepEqual(await selected(), ['src']); await row('notes').click({ modifiers: ['Shift'] }); assert.deepEqual(await selected(), ['notes', 'src']); await row('notes').click({ modifiers: ['Control'] }); await row('notes').click({ modifiers: ['Shift', 'Control'] }); assert.deepEqual(await selected(), ['notes', 'src']); assert.deepEqual(errors, []); console.log('Tree selection browser checks passed.'); } finally { await browser.close(); }