// Local static fixture only: real view + modal controller, no RuntimeSocket/server/providers. // node web/test/schedules-browser.mjs /approved/temp/capture-directory import assert from 'node:assert/strict'; import { createServer } from 'node:http'; import { readFile, mkdir, writeFile } from 'node:fs/promises'; import { fileURLToPath } from 'node:url'; import { resolve, extname } from 'node:path'; import { createHash } from 'node:crypto'; import { launchChrome, eventually } from './browser.mjs'; const root = fileURLToPath(new URL('../', import.meta.url)); const out = process.argv[2]; if (!out) throw new Error('Pass an approved capture directory.'); await mkdir(out, { recursive: true }); const fixture = `

Research

`; const server = createServer(async (req, res) => { try { if (req.url === '/') { res.setHeader('Content-Type', 'text/html'); res.end(fixture); return; } const path = resolve(root, `.${new URL(req.url, 'http://fixture').pathname}`); if (!path.startsWith(root)) { res.writeHead(403); res.end(); return; } res.setHeader('Content-Type', ({ '.js': 'text/javascript', '.css': 'text/css' })[extname(path)] ?? 'text/plain'); res.end(await readFile(path)); } catch { res.writeHead(404); res.end(); } }); await new Promise(resolve => server.listen(0, '127.0.0.1', resolve)); let browser; const manifest = []; try { browser = await launchChrome({ width: 1100, height: 900 }); const page = await browser.openPage(`http://127.0.0.1:${server.address().port}/`); await page.waitForText('No schedules yet'); const capture = async name => { const path = resolve(out, `${name}.png`); await page.screenshot(path); manifest.push({ path, sha256: createHash('sha256').update(await readFile(path)).digest('hex') }); }; const noOverflow = async () => assert.equal(await page.evaluate('document.documentElement.scrollWidth <= innerWidth'), true); await capture('schedule-empty-1100'); await page.evaluate('seed()'); await page.waitForText('Battery news'); assert.equal(await page.evaluate('document.querySelectorAll(".schedule-card").length'), 2); await capture('schedule-two-1100'); await page.clickText('[data-schedule-id="2"] button', 'Edit'); await capture('schedule-clock-editor-1100'); await noOverflow(); assert.equal(await page.evaluate('document.querySelector("[name=mode]").value'), 'clock'); await page.clickText('.schedule-panel button', 'Cancel'); await page.clickText('[data-schedule-id="1"] button', 'Edit'); await page.fill('[name="prompt"]', 'AI draft remains here'); assert.equal(await page.evaluate('document.activeElement.name'), 'prompt'); await page.evaluate('rt.renderContent()'); assert.equal(await page.evaluate('document.querySelector("[name=prompt]").value'), 'AI draft remains here'); assert.equal(await page.evaluate('document.activeElement.name'), 'prompt'); await page.evaluate('window.refuse=true'); await page.clickText('.schedule-panel button', 'Save schedule'); await page.waitForText('409 revision conflict'); assert.equal(await page.evaluate('document.querySelector("[name=prompt]").value'), 'AI draft remains here'); await capture('schedule-conflict-1100'); await page.evaluate('window.refuse=false'); await page.clickText('.schedule-panel button', 'Save schedule'); await eventually(() => page.evaluate('!rt.modal.isOpen("schedule-editor")')); assert.equal(await page.evaluate('records[1].input.prompt'), 'Research battery advances'); assert.equal(await page.evaluate('records[0].input.count'), 2); await page.clickText('[data-schedule-id="1"] button', 'Pause'); await eventually(() => page.evaluate('!records[0].enabled')); await capture('schedule-paused-1100'); await page.clickText('[data-schedule-id="1"] button', 'Delete'); assert.equal(await page.evaluate('calls.delete'), 0); await capture('schedule-delete-confirm-1100'); await page.clickText('.schedule-confirm button', 'Keep schedule'); assert.equal(await page.evaluate('document.activeElement.textContent'), 'Delete'); await page.clickText('[data-schedule-id="1"] button', 'Delete'); await page.clickText('.schedule-confirm button', 'Delete schedule'); await eventually(() => page.evaluate('records.length===1 && !rt.modal.isOpen("schedule-delete")')); assert.equal(await page.evaluate('records[0].id'), 2); await page.evaluate('seed()'); await page.resize(390, 844); await capture('schedule-two-390'); await noOverflow(); await page.click('.schedule-add'); await page.fill('[name="name"]', 'Third independent topic'); await page.fill('[name="prompt"]', 'Mobile draft'); await page.click('.schedule-advanced summary'); await page.fill('[name="otherInput"]', 'null'); await page.clickText('.schedule-panel button', 'Save schedule'); await page.waitForText('Other input must be a JSON object'); assert.equal(await page.evaluate('document.querySelector("[name=prompt]").value'), 'Mobile draft'); await capture('schedule-invalid-json-390'); await page.fill('[name="otherInput"]', '{"count":3}'); await page.clickText('.schedule-panel button', 'Save schedule'); await eventually(() => page.evaluate('records.length===3 && !rt.modal.isOpen("schedule-editor")')); await page.clickText('[data-schedule-id="3"] button', 'Edit'); await capture('schedule-editor-390'); await noOverflow(); await page.click('.schedule-advanced summary'); await page.fill('[name="model"]', 'provider/model'); assert.equal(await page.evaluate('document.activeElement.name'), 'model'); await capture('schedule-advanced-390'); await noOverflow(); await page.clickText('.schedule-panel button', 'Cancel'); assert.equal(await page.evaluate('document.activeElement.textContent'), 'Edit'); await page.evaluate('holdRead=true;view.clearScheduleCache();rt.renderContent()'); await page.waitForText('Loading schedules'); await capture('schedule-loading-390'); await page.evaluate('holdRead=false;releaseRead()'); await page.waitForText('Third independent topic'); await page.evaluate('unsupported=true;view.clearScheduleCache();rt.renderContent()'); await page.waitForText('old server'); await capture('schedule-old-server-390'); await page.evaluate('unsupported=false'); await page.clickText('.schedule-section button', 'Retry'); await page.waitForText('Third independent topic'); await page.close(); await writeFile(resolve(out, 'manifest.json'), JSON.stringify(manifest, null, 2)); console.log(JSON.stringify({ checks: 'passed', captures: manifest }, null, 2)); } finally { await browser?.close(); await new Promise(resolve => server.close(resolve)); }