diff options
Diffstat (limited to 'test/web/catalog_ui.mjs')
| -rw-r--r-- | test/web/catalog_ui.mjs | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/test/web/catalog_ui.mjs b/test/web/catalog_ui.mjs index 6120a51..eed6c0a 100644 --- a/test/web/catalog_ui.mjs +++ b/test/web/catalog_ui.mjs @@ -11,8 +11,8 @@ const binary = path.resolve(process.argv[2] || 'zig-out/bin/9web'); const work = await fs.mkdtemp(path.join(os.tmpdir(), '9web-ui-')); const children = [], exceptions = [], pending = new Map(); let socket, serial = 0; -function start(command, args) { - const p = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'] }); +function start(command, args, env = process.env) { + const p = spawn(command, args, { env, stdio: ['ignore', 'pipe', 'pipe'] }); p.output = ''; p.stdout.on('data', b => { p.output += b; }); p.stderr.on('data', b => { p.output += b; }); p.on('error', e => { p.output += e.message; }); children.push(p); return p; } @@ -47,9 +47,15 @@ async function readySites() { await wait(() => evaluate(`document.querySelectorA try { const root = path.join(work, 'public'); await fs.mkdir(root); await fs.writeFile(path.join(root, 'index.html'), '<h1>Fixture</h1>'); + await fs.writeFile(path.join(work, 'large.txt'), 'x'.repeat(180000)); const dashboard = await port(), sitePort = await port(), debugPort = await port(); - await fs.writeFile(path.join(work, 'config.json'), JSON.stringify({ sites: [{ name: 'fixture', title: 'Fixture notes', cwd: work, root, port: sitePort, build: ['sh', '-c', 'echo integrated-build'], inputs: ['public/index.html'] }] })); - const web = start(binary, ['--listen', `127.0.0.1:${dashboard}`, '--catalog', path.join(work, 'config.json'), '--catalog-socket', path.join(work, 'catalog.sock'), '--state-dir', path.join(work, 'state')]); + const runtime = path.join(work, 'runtime'); + await fs.mkdir(path.join(runtime, '9p'), { recursive: true }); + start(path.resolve('zig-out/bin/9proc-demo'), ['--unix', path.join(runtime, '9p', 'fixture')]); + await wait(() => fs.stat(path.join(runtime, '9p', 'fixture')), '9P fixture posted'); + await fs.writeFile(path.join(work, 'config.json'), JSON.stringify({ filesystem: '/', sites: [{ name: 'fixture', title: 'Fixture notes', cwd: work, root, port: sitePort, build: ['sh', '-c', 'echo integrated-build'], inputs: ['public/index.html'] }] })); + const startWeb = () => start(path.resolve('zig-out/bin/9ns'), ['--mntgen', '--', binary, '--listen', `127.0.0.1:${dashboard}`, '--catalog', path.join(work, 'config.json'), '--catalog-socket', path.join(work, 'catalog.sock'), '--state-dir', path.join(work, 'state')], { ...process.env, XDG_RUNTIME_DIR: runtime }); + const web = startWeb(); const url = `http://127.0.0.1:${dashboard}`; await wait(async () => (await fetch(url)).ok, 'server ready'); assert.equal((await (await fetch(url + '/_cloud9/config.json')).json()).catalog, true); @@ -69,11 +75,35 @@ try { await cdp('Page.navigate', { url }); await wait(() => evaluate(`document.getElementById('status')?.textContent.includes('entries')`), 'files loaded'); assert.equal(await evaluate(`document.querySelectorAll('header').length`), 1); + assert.equal(await evaluate(`document.querySelector('#sidebar')`), null); assert.equal(await evaluate(`document.querySelector('.brand').textContent`), '9web'); assert.equal(await evaluate(`document.querySelector('footer').textContent`), 'served by 9web'); assert.equal(await evaluate(`document.title`), '/ — 9web'); + assert.equal(await evaluate(`Boolean(document.querySelector('#entries a[data-path="/etc"]'))`), true); assert.equal(await evaluate(`getComputedStyle(document.documentElement).backgroundColor`), 'rgb(255, 255, 255)'); assert.equal(await evaluate(`document.getElementById('view-files').getAttribute('aria-current')`), 'page'); + // Browse a real mounted 9P tree, including finite zero-stat-length files. + async function browse(path) { + await evaluate(`document.getElementById('path').value = ${JSON.stringify(path)}; document.getElementById('path-form').requestSubmit()`); + await wait(() => evaluate(`document.getElementById('status').textContent === 'File loaded.' || document.getElementById('status').textContent.includes('entries')`), 'mounted path loaded'); + } + await browse('/mnt/9p/fixture/build'); + assert.equal(await evaluate(`Boolean(document.querySelector('#entries a[data-path="/mnt/9p/fixture/build/zig_version"]'))`), true); + await browse('/mnt/9p/fixture/runtime/pid'); + assert.match(await evaluate(`document.getElementById('editor').value`), /^\d+/); + await browse('/mnt/9p/fixture/runtime/ctl'); + assert.equal(await evaluate(`document.getElementById('editor').value`), ''); + await browse(path.join(work, 'large.txt')); + assert.equal(await evaluate(`document.getElementById('editor').value.length`), 180000, 'full-msize browser reads across several frames'); + await browse('/_9web/sites/fixture'); + await click('#entries a[data-path="/_9web/sites/fixture/events"][data-follow]'); + await wait(() => evaluate(`document.getElementById('stream').textContent.includes('revision')`), 'direct follow of blocking events'); + assert.equal(await evaluate(`document.getElementById('go').disabled`), false, 'stream does not block navigation'); + await click('#follow'); + assert.equal(await evaluate(`document.getElementById('status').textContent`), 'Stream stopped.'); + await browse('/'); + await fs.mkdir('.zig-cache/catalog-ui', { recursive: true }); + await fs.writeFile('.zig-cache/catalog-ui/files.png', Buffer.from((await cdp('Page.captureScreenshot', { format: 'png' })).data, 'base64')); await view('sites'); await readySites(); assert.equal(await evaluate(`document.title`), 'sites — 9web'); assert.equal(await evaluate(`document.querySelector('#sites-entries .site-name').href`), `http://127.0.0.1:${sitePort}/`); @@ -130,8 +160,18 @@ try { assert.match(competitor.output, /address already in use/); web.kill('SIGTERM'); await once(web, 'exit'); await fs.unlink(path.join(work, 'catalog.sock')); - start(binary, ['--listen', `127.0.0.1:${dashboard}`, '--catalog', path.join(work, 'config.json'), '--catalog-socket', path.join(work, 'catalog.sock'), '--state-dir', path.join(work, 'state')]); + startWeb(); await wait(async () => (await fetch(url)).ok && (await fetch(`http://127.0.0.1:${sitePort}`)).ok, 'immediate restart with recent HTTP traffic'); + // Opt-in, read-only smoke navigation against an installed workstation. + if (process.env.NINE_WEB_LIVE) { + for (const pathname of ['/mnt/9p', '/mnt/9p/agents', '/mnt/9p/agents/codex/history', '/mnt/9p/zmx/daybreak/command', '/mnt/9p/zmx/daybreak/cwd', '/usr/bin']) { + await cdp('Page.navigate', { url: process.env.NINE_WEB_LIVE + pathname }); + await wait(() => evaluate(`document.getElementById('path')?.value === ${JSON.stringify(pathname)} && (document.getElementById('status').textContent === 'File loaded.' || document.getElementById('status').textContent.includes('entries'))`), 'live navigation: ' + pathname, 30000).catch(async error => { + throw new Error(error.message + ': ' + await evaluate(`document.getElementById('status')?.textContent`)); + }); + console.log('live browser navigation passed:', pathname); + } + } console.log('catalog_ui: shared shell/style, tab history, file/log navigation, build control, focus, dirty edits and mobile layout passed'); } catch (e) { for (const child of children) console.error(child.output.slice(-5000)); @@ -141,5 +181,5 @@ try { for (const p of children.reverse()) { if (p.exitCode === null) { p.kill('SIGTERM'); await Promise.race([once(p, 'exit'), new Promise(r => setTimeout(r, 3000))]); if (p.exitCode === null) p.kill('SIGKILL'); } } - await fs.rm(work, { recursive: true, force: true }); + await fs.rm(work, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 }); } |
