import { createRequire } from 'node:module'; import assert from 'node:assert/strict'; import { mkdir, writeFile } 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 context = await browser.newContext({ viewport: { width: 1280, height: 850 } }); const page = await context.newPage(); page.setDefaultTimeout(10000); const errors = []; page.on('pageerror', error => errors.push(error.message)); await context.addInitScript(() => { window.isTauri = true; const root = 'C:\\navigation-check'; const folders = new Set(['Untitled', 'Parent', 'Empty']); const files = new Map([['note.md', '# Note'], ['Parent/existing.md', '# Existing']]); const state = { folders, files, calls: [] }; window.__NAVIGATION_CHECK__ = state; let sequence = 0; window.__TAURI_INTERNALS__ = { metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } }, transformCallback: () => ++sequence, unregisterCallback: () => {}, invoke: async (command, args = {}) => { state.calls.push({ command, args }); if (command === 'plugins_snapshot') return { root: 'C:/plugins', plugins: [] }; if (command === 'workspace_last_path') return state.noWorkspace ? null : root; if (command === 'workspace_open') return { root, name: 'navigation-check', watch_mode: 'native' }; if (command === 'workspace_read') { if (!files.has(args.rel)) throw new Error('Missing file'); return files.get(args.rel); } if (command === 'workspace_write') { files.set(args.rel, args.contents); return; } if (command === 'workspace_list') { const prefix = args.rel ? args.rel + '/' : ''; return [...[...folders].filter(path => path.startsWith(prefix) && !path.slice(prefix.length).includes('/')).map(path => ({ name: path.slice(prefix.length), rel_path: path, kind: 'folder' })), ...[...files.keys()].filter(path => path.startsWith(prefix) && !path.slice(prefix.length).includes('/') && !path.startsWith('.runestone/')).map(path => ({ name: path.slice(prefix.length), rel_path: path, kind: 'file' }))]; } if (command === 'workspace_create') { if (folders.has(args.rel) || files.has(args.rel)) throw new Error('Destination exists'); if (args.kind === 'folder') folders.add(args.rel); else files.set(args.rel, ''); return; } if (command === 'workspace_rename') { if (folders.has(args.to) || files.has(args.to)) throw new Error('Destination exists'); if (folders.delete(args.from)) folders.add(args.to); else { files.set(args.to, files.get(args.from)); files.delete(args.from); } return; } if (command === 'plugin:event|listen') return ++sequence; if (command === 'plugin:window|is_maximized') return false; if (command === 'workspace_recent' || command === 'workspace_search') return []; return null; }, }; window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} }; }); const output = '.audit/todo-navigation'; await mkdir(output, { recursive: true }); const row = path => page.locator(`[data-tree-rel="${path}"]`); const input = () => page.locator('.tree input'); const folderAction = () => page.getByRole('menuitem', { name: 'New folder', exact: true }); async function checkRename(name) { await input().waitFor(); await page.waitForFunction(() => document.activeElement?.matches('.tree input')); const state = await input().evaluate(node => ({ name: node.value, start: node.selectionStart, end: node.selectionEnd })); assert.deepEqual(state, { name, start: 0, end: name.length }); assert.equal(await page.getByRole('dialog').count(), 0, 'New folder uses inline rename'); } async function setMode(mode) { await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode); } try { await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:5194'); await row('Untitled').waitFor(); const welcome = page.locator('.welcome-actions'); await welcome.waitFor(); await welcome.getByRole('button', { name: 'Open browser', exact: true }).waitFor(); assert.deepEqual(await welcome.locator('button').allTextContents().then(values => values.map(value => value.replace(/Ctrl [NOP]/g, '').trim())), ['New file', 'New note', 'Find file', 'Open folder', 'Open browser']); const firstRow = welcome.locator('.welcome-row').first(); assert.equal(await firstRow.locator('button').count(), 3); const tops = await firstRow.locator('button').evaluateAll(nodes => nodes.map(node => node.getBoundingClientRect().top)); assert.ok(tops.every(top => top === tops[0]), 'Wide layout has three actions in the first row'); await welcome.getByRole('button', { name: /^New file/ }).focus(); for (const name of ['New note', 'Find file', 'Open folder', 'Open browser']) { await page.keyboard.press('Tab'); assert.ok((await page.evaluate(() => document.activeElement.textContent)).includes(name), `Tab reaches ${name} in order`); } for (const mode of ['dark', 'light']) { await setMode(mode); await welcome.getByRole('button', { name: /^New file/ }).focus(); await page.screenshot({ path: `${output}/splash-${mode}.png` }); await page.setViewportSize({ width: 850, height: 650 }); await page.screenshot({ path: `${output}/splash-${mode}-narrow.png` }); assert.ok(await welcome.locator('button').evaluateAll(nodes => nodes.every(node => { const rect = node.getBoundingClientRect(); return rect.left >= 0 && rect.right <= innerWidth; })), 'Narrow splash controls fit'); await page.setViewportSize({ width: 1280, height: 850 }); } await page.getByRole('navigation', { name: 'Workspace files' }).click({ button: 'right', position: { x: 80, y: 320 } }); await folderAction().focus(); await page.keyboard.press('Enter'); await checkRename('untitled 2'); await input().fill('Created folder'); await input().press('Enter'); await row('Created folder').waitFor(); await row('Parent').click(); await row('Parent').click(); assert.equal(await row('Parent').getAttribute('aria-expanded'), 'false'); await row('Parent').click({ button: 'right' }); await folderAction().click(); await checkRename('untitled'); assert.equal(await row('Parent').getAttribute('aria-expanded'), 'true', 'Cached collapsed parent opens for rename'); await input().press('Escape'); await row('Parent/untitled').waitFor(); for (const mode of ['dark', 'light']) { await setMode(mode); await row('Parent').click({ button: 'right' }); await folderAction().click(); const expected = mode === 'dark' ? 'untitled 2' : 'untitled 3'; await checkRename(expected); await page.screenshot({ path: `${output}/new-folder-${mode}.png` }); await page.setViewportSize({ width: 850, height: 650 }); await page.screenshot({ path: `${output}/new-folder-${mode}-narrow.png` }); await input().press('Escape'); await page.setViewportSize({ width: 1280, height: 850 }); } await row('Empty').click({ button: 'right' }); await folderAction().click(); await checkRename('untitled'); await input().fill('First folder'); await input().press('Enter'); await row('Empty/First folder').waitFor(); assert.equal(await page.evaluate(() => window.__NAVIGATION_CHECK__.folders.has('Empty/First folder')), true); const emptyPage = await context.newPage(); await emptyPage.addInitScript(() => { window.__NAVIGATION_CHECK__.noWorkspace = true; }); await emptyPage.goto(process.env.SMOKE_URL || 'http://127.0.0.1:5194'); await emptyPage.locator('.welcome-actions').waitFor(); await emptyPage.locator('.welcome-actions').getByRole('button', { name: 'Open browser', exact: true }).waitFor(); assert.deepEqual(await emptyPage.locator('.welcome-actions button').allTextContents().then(values => values.map(value => value.replace(/Ctrl O/g, '').trim())), ['Open folder', 'Open browser']); await emptyPage.screenshot({ path: `${output}/splash-no-workspace.png` }); await emptyPage.close(); assert.deepEqual(errors, []); await writeFile(`${output}/checks.json`, JSON.stringify({ passed: true, checks: ['Case-insensitive root name collision', 'Selected inline name and no dialog', 'Enter saves rename', 'Escape retains created folder', 'Collapsed cached parent opens', 'Empty parent', 'Repeated unique names', 'Splash order and three-column maximum', 'Keyboard tab order', 'No workspace actions', 'Dark/light wide/narrow screenshots'], errors }, null, 2)); console.log(`Navigation checks passed. Evidence: ${output}`); } finally { await browser.close(); }