// Captures the wide Chat list/detail layout against a loopback fixture, never operator data. // PROBE_WIDTH=1280 PROBE_HEIGHT=800 node tool/chat_list_detail_probe.mjs import assert from 'node:assert/strict'; import { mkdir, mkdtemp, writeFile } from 'node:fs/promises'; import { once } from 'node:events'; import { tmpdir } from 'node:os'; import { join, resolve } from 'node:path'; import { startFixture } from './runs_probe_server.mjs'; import { launchChrome, waitForPort, waitForPage, connect, sleep } from './pipelines_probe_cdp_lib.mjs'; import { axNodes, enableSemantics, waitFor, capture } from './pipelines_probe_cdp_input.mjs'; const width = Number(process.env.PROBE_WIDTH ?? 1280); const height = Number(process.env.PROBE_HEIGHT ?? 800); const platform = process.env.PROBE_PLATFORM ?? 'cupertino'; const dark = process.env.PROBE_DARK === '1'; const messages = Array.from({ length: 6 }, (_, i) => ({ id: `m${i}`, role: i % 2 ? 'assistant' : 'user', parts: [{ id: `p${i}`, type: 'text', text: `Recorded fixture message ${i}.` }], })); const output = resolve(process.argv[3] ?? 'build/chat-list-detail'); await mkdir(output, { recursive: true }); const fixture = await startFixture({ root: resolve(process.argv[2]), chatMessages: messages }); const profile = await mkdtemp(join(tmpdir(), 'chat-list-detail-')); const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank'); const log = { width, height, platform, dark, checks: [], captures: [] }; let c; const named = async (pattern) => (await axNodes(c)).filter(n => pattern.test(n.name?.value ?? '')); const selectedChatRows = () => c.evaluate(`Array.from(document.querySelectorAll( '[aria-current="true"], [aria-selected="true"]' )).filter(e => (e.getAttribute('aria-label') || e.textContent || '').startsWith('Probe conversation')).length`); try { c = await connect((await waitForPage(await waitForPort(join(profile, 'DevToolsActivePort')))).webSocketDebuggerUrl); await c.send('Page.enable'); if (platform === 'material') await c.send('Emulation.setUserAgentOverride', { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36', platform: 'Win32', }); await c.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: dark ? 'dark' : 'light' }], }); await c.send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: false }); await c.send('Page.navigate', { url: fixture.url + '/chat' }); assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 30000)); await enableSemantics(c); assert.ok(await waitFor(async () => (await named(/Select a chat/)).length > 0, 30000), 'empty detail pane'); log.checks.push('empty pane beside list'); assert.equal(await selectedChatRows(), 0, 'no chat selected initially'); await sleep(500); await capture(c, output, log, 'list-empty-pane'); const row = (await named(/^Probe conversation/)).find(n => n.backendDOMNodeId); assert.ok(row, 'chat list row'); const { model } = await c.send('DOM.getBoxModel', { backendNodeId: row.backendDOMNodeId }); const [x1, y1, , , x3, y3] = model.content; await c.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: (x1 + x3) / 2, y: (y1 + y3) / 2, button: 'left', clickCount: 1 }); await c.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: (x1 + x3) / 2, y: (y1 + y3) / 2, button: 'left', clickCount: 1 }); await c.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: width - 5, y: height - 5 }); assert.ok(await waitFor(async () => (await named(/Recorded fixture message 5/)).length > 0, 30000), 'open chat transcript'); await sleep(800); // The rail, the list and the open chat are all on screen; nothing offers Back. for (const label of ['Pipelines', 'Runs', 'Settings']) { assert.ok((await named(new RegExp(`^${label}`))).length > 0, `rail ${label}`); } assert.ok((await named(/^Probe conversation/)).length > 0, 'list stays beside the chat'); assert.equal((await named(/^Back(\s|$)/)).length, 0, 'no Back in the two-pane layout'); log.path = await c.evaluate('location.pathname'); log.checks.push('rail, list and open chat visible together; no Back'); assert.equal(await selectedChatRows(), 1, 'open chat row stays selected after the pointer leaves'); log.checks.push('active chat row exposes persistent selected semantics'); await capture(c, output, log, 'list-open-chat'); await c.send('Page.reload'); assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 30000)); await enableSemantics(c); assert.ok(await waitFor(async () => (await named(/Recorded fixture message 5/)).length > 0, 30000), 'deep-linked chat reloads'); assert.ok(await waitFor(async () => await selectedChatRows() === 1, 30000), 'routed chat remains selected after reload'); log.checks.push('deep-linked chat selection survives reload'); console.log(JSON.stringify(log, null, 2)); } catch (error) { if (c) { await capture(c, output, log, 'failure'); await writeFile(join(output, 'failure-ax.json'), JSON.stringify(await axNodes(c), null, 2)); } throw error; } finally { await writeFile(join(output, 'result.json'), JSON.stringify(log, null, 2)); c?.close(); const exited = once(chrome, 'exit'); chrome.kill(); await exited; await fixture.close(); }