Files
pipelines/app/tool/list_detail_consistency_probe.mjs
T

93 lines
5.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Shared pane geometry and selected rows, against isolated loopback fixtures.
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 { startWiringFixture } from './pipelines_wiring_probe_server.mjs';
import { launchChrome, waitForPort, waitForPage, connect, sleep } from './pipelines_probe_cdp_lib.mjs';
import { axNodes, enableSemantics, waitFor, capture, clickAt } from './pipelines_probe_cdp_input.mjs';
const platform = process.env.PROBE_PLATFORM ?? 'material';
const width = Number(process.env.PROBE_WIDTH ?? 1280);
const dark = process.env.PROBE_DARK === '1';
const output = resolve(process.argv[3] ?? `build/list-detail-${platform}`);
await mkdir(output, { recursive: true });
const root = resolve(process.argv[2]);
const runs = await startFixture({ root, chatMessages: [], chatSessions: [
{ id: 'ses_probechat', title: 'First fixture chat', backend: 'opencode', starred:true, model: 'claude-opus', directory:'/srv/probe', updated_at:Date.now()-180000, mode: 'auto', mode_name: 'Auto' },
{ id: 'ses_secondchat', title: 'Second fixture chat', backend: 'claude', starred:true, model: 'claude-opus', directory:'/srv/probe', updated_at:Date.now()-180000, mode: 'auto', mode_name: 'Auto' },
] });
const pipelines = await startWiringFixture({ root });
const profile = await mkdtemp(join(tmpdir(), 'list-detail-consistency-'));
const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank');
const log = { platform, width, dark, checks: [], captures: [], panes: [] };
let c;
const geometry = () => c.evaluate(`(() => {
const box = id => { const r = document.querySelector('[flt-semantics-identifier="' + id + '"]')?.getBoundingClientRect(); return r && {x:r.x,width:r.width}; };
return {list:box('list-detail-list'),body:box('list-detail-body')};
})()`);
const selected = async titles => (await c.evaluate(`Array.from(document.querySelector('[flt-semantics-identifier="list-detail-list"]').querySelectorAll('[aria-current="true"], [aria-selected="true"]')).map(e => e.getAttribute('aria-label') || e.textContent || '')`)).filter(name => titles.some(title => name.includes(title)));
async function open(title) {
const node = await waitFor(async () => {
const nodes = await axNodes(c);
return nodes.find(n => n.name?.value === title && n.role?.value === 'StaticText' && n.backendDOMNodeId)
?? nodes.find(n => n.name?.value?.includes(title) && n.backendDOMNodeId);
}, 12000);
assert.ok(node, title);
const { model } = await c.send('DOM.getBoxModel', { backendNodeId: node.backendDOMNodeId });
const [x1,y1,,,x3,y3] = model.content;
await clickAt(c, (x1+x3)/2, (y1+y3)/2);
await c.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: width-5, y: 895 });
}
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.setDeviceMetricsOverride', { width, height: 900, deviceScaleFactor: 1, mobile: false });
await c.send('Emulation.setEmulatedMedia', { features: [{ name:'prefers-color-scheme',value:dark?'dark':'light' }] });
for (const [destination, fixture, titles] of [
['pipelines', pipelines, ['Release verification', 'Nightly documentation']],
['runs', runs, ['Fixture live run', 'Fixture failing run']],
['chat', runs, ['First fixture chat', 'Second fixture chat']],
]) {
await c.send('Page.navigate', { url: fixture.url + '/' + destination });
assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"),30000));
await enableSemantics(c);
assert.ok(await waitFor(async () => (await geometry()).list,30000));
const before = await geometry();
assert.ok(before.body.width>=width*0.5-1 && before.body.width<=width*0.6+1, 'body gets at least half the full window, targeting sixty percent');
assert.ok(before.body.width>before.list.width,'body takes priority over list');
assert.deepEqual(await selected(titles), []);
for (let i=0;i<titles.length;i++) {
await open(titles[i]);
assert.ok(await waitFor(async () => (await selected(titles)).some(name => name.includes(titles[i])),12000), `${destination} selected ${titles[i]}`);
assert.equal((await selected(titles)).length,1,'only the active row is selected');
const bounds = await geometry();
assert.equal(bounds.body.width,before.body.width,'body width is stable during selection');
assert.equal(bounds.list.width,before.list.width,'selection does not resize panes');
log.panes.push({destination,title:titles[i],...bounds});
await sleep(300);
await capture(c,output,log,`${destination}-selected-${i+1}`);
}
log.checks.push(`${destination}: list remains visible, selection moves, body gets 50–60% of full window`);
}
assert.ok(log.panes.every(p => Math.abs(p.list.width-log.panes[0].list.width)<1),'identical pane widths across destinations');
assert.ok(log.panes.every(p => Math.abs(p.body.width-log.panes[0].body.width)<1),'identical body widths across destinations');
log.checks.push('all three destinations share the same body-priority pane widths');
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 Promise.all([runs.close(),pipelines.close()]);
}