8476cfd740
Register the landed PipelinesScreen at /pipelines through AppSession, with an honest first-connection gate, a native reconnect banner that retains the open list and detail, and an in-place refresh on reconnect. Move the shared connection chrome out of RunsDestination so both destinations use one implementation and one wording. Add destination, registration and reconnect coverage plus an isolated loopback Chrome probe that drives the real runPipelinesApp() composition.
237 lines
9.1 KiB
JavaScript
237 lines
9.1 KiB
JavaScript
// Real-Chrome acceptance for the Pipelines destination in the normal app.
|
|
//
|
|
// The bundle is `tool/pipelines_wiring_probe_entry.dart`, i.e. the same
|
|
// composition as main; the isolated loopback fixture answers the protocol.
|
|
// Both native hosts are exercised by changing the browser platform user agent.
|
|
//
|
|
// Usage: node tool/pipelines_wiring_probe.mjs <build-dir> <capture-dir>
|
|
import { execFile } from 'node:child_process';
|
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join, resolve } from 'node:path';
|
|
import { promisify } from 'node:util';
|
|
|
|
import {
|
|
connect,
|
|
launchChrome,
|
|
sleep,
|
|
waitForPage,
|
|
waitForPort,
|
|
} from './pipelines_probe_cdp_lib.mjs';
|
|
import {
|
|
assertName,
|
|
axNodes,
|
|
capture,
|
|
click,
|
|
enableSemantics,
|
|
waitFor,
|
|
} from './pipelines_probe_cdp_input.mjs';
|
|
import { startWiringFixture } from './pipelines_wiring_probe_server.mjs';
|
|
|
|
const CHROME =
|
|
process.env.CHROME_PATH ??
|
|
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
|
const buildDir = resolve(process.argv[2] ?? 'build/wiring_web');
|
|
const captureDir = resolve(process.argv[3] ?? 'p1-wire-captures');
|
|
const fixture = await startWiringFixture({ root: buildDir, refuse: true });
|
|
await mkdir(captureDir, { recursive: true });
|
|
const profile = join(tmpdir(), `pipelines-wiring-chrome-${process.pid}`);
|
|
const chrome = launchChrome(CHROME, profile, 'about:blank');
|
|
let connection;
|
|
const log = { url: fixture.url, captures: [], checks: [], states: [] };
|
|
|
|
const semanticText = () =>
|
|
connection.evaluate(`(() => {
|
|
const chunks = [];
|
|
for (const el of document.querySelectorAll('flt-semantics')) {
|
|
const label = el.getAttribute('aria-label');
|
|
if (label) chunks.push(label);
|
|
if (!el.children.length && el.innerText) chunks.push(el.innerText);
|
|
}
|
|
if (document.body?.innerText) chunks.push(document.body.innerText);
|
|
return [...new Set(chunks)].join('\\n');
|
|
})()`);
|
|
|
|
const assertBody = async (text) => {
|
|
const ok = await waitFor(
|
|
async () => (await semanticText()).includes(text),
|
|
12000,
|
|
);
|
|
if (!ok) {
|
|
throw new Error(`Missing text ${JSON.stringify(text)}:\n${(await semanticText()).slice(0, 3000)}`);
|
|
}
|
|
log.checks.push(`text: ${text}`);
|
|
};
|
|
|
|
const noBody = async (text) => {
|
|
if ((await semanticText()).includes(text)) {
|
|
throw new Error(`Unexpected text ${JSON.stringify(text)}`);
|
|
}
|
|
log.checks.push(`absent: ${text}`);
|
|
};
|
|
|
|
const state = async () => fixture.state();
|
|
|
|
const waitForState = async (check, label) => {
|
|
const value = await waitFor(async () => {
|
|
const current = await state();
|
|
return check(current) ? current : false;
|
|
}, 12000);
|
|
if (!value) throw new Error(`Timed out waiting for ${label}: ${JSON.stringify(await state())}`);
|
|
log.states.push({ label, ...value });
|
|
return value;
|
|
};
|
|
|
|
const ocr = async (path) => {
|
|
const { stdout } = await promisify(execFile)('tesseract', [path, 'stdout']);
|
|
return stdout;
|
|
};
|
|
|
|
const assertOcr = async (name, text) => {
|
|
const read = await ocr(join(captureDir, `${name}.png`));
|
|
if (!read.toLowerCase().includes(text.toLowerCase())) {
|
|
throw new Error(`OCR of ${name} lacks ${JSON.stringify(text)}:\n${read.slice(0, 3000)}`);
|
|
}
|
|
log.checks.push(`ocr ${name}: ${text}`);
|
|
};
|
|
|
|
const navigate = async (url) => {
|
|
await connection.send('Page.navigate', { url });
|
|
await waitFor(
|
|
() => connection.evaluate("document.querySelector('flutter-view') !== null"),
|
|
20000,
|
|
);
|
|
await sleep(1200);
|
|
await enableSemantics(connection);
|
|
};
|
|
|
|
try {
|
|
const devtoolsPort = await waitForPort(join(profile, 'DevToolsActivePort'));
|
|
const target = await waitForPage(devtoolsPort);
|
|
connection = await connect(target.webSocketDebuggerUrl);
|
|
await connection.send('Page.enable');
|
|
await connection.send('Runtime.enable');
|
|
await connection.send('DOM.enable');
|
|
await connection.send('Accessibility.enable');
|
|
await connection.send('Emulation.setDeviceMetricsOverride', {
|
|
width: 1200,
|
|
height: 900,
|
|
deviceScaleFactor: 1,
|
|
mobile: false,
|
|
});
|
|
|
|
// Material host: Linux platform, light mode.
|
|
await connection.send('Emulation.setUserAgentOverride', {
|
|
userAgent:
|
|
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 ' +
|
|
'(KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
|
|
platform: 'Linux x86_64',
|
|
});
|
|
await navigate(`${fixture.url}/pipelines`);
|
|
|
|
// The first connection is refused: the honest gate must appear and nothing
|
|
// may be requested while there is no socket.
|
|
await assertBody('Pipelines server unavailable');
|
|
const initial = await state();
|
|
if (initial.listPipelines !== 0 || initial.listRuns !== 0 || initial.getPipeline !== 0) {
|
|
throw new Error(`Premature requests before connection: ${JSON.stringify(initial)}`);
|
|
}
|
|
log.checks.push('no requests before first connection');
|
|
await capture(connection, captureDir, log, '01-gate-refused-material');
|
|
await assertOcr('01-gate-refused-material', 'Pipelines server unavailable');
|
|
|
|
await fetch(`${fixture.url}/fixture/accept`, { method: 'POST' });
|
|
await click(connection, 'Retry');
|
|
await assertName(connection, 'Release verification', 'real pipeline row', log);
|
|
await assertName(connection, 'Nightly documentation', 'second real row', log);
|
|
await noBody('Pipelines — Not implemented');
|
|
const loaded = await waitForState(
|
|
(value) => value.listPipelines >= 1 && value.listRuns >= 1,
|
|
'pipeline list after retry',
|
|
);
|
|
log.checks.push('shell lists real rows');
|
|
await capture(connection, captureDir, log, '02-list-material');
|
|
await assertOcr('02-list-material', 'Release verification');
|
|
|
|
await click(connection, 'Release verification');
|
|
await assertName(connection, 'Content hash', 'real pipeline detail', log);
|
|
await capture(connection, captureDir, log, '03-detail-material');
|
|
await assertOcr('03-detail-material', 'sha256:fixture-3-v3');
|
|
|
|
await click(connection, 'Source');
|
|
await capture(connection, captureDir, log, '04-source-material');
|
|
await assertOcr('04-source-material', 'name: Release verification');
|
|
await assertOcr('04-source-material', 'type: model');
|
|
await click(connection, 'Summary');
|
|
await assertName(connection, 'Content hash', 'summary restored', log);
|
|
|
|
// A drop keeps the open detail visible and, once the socket returns, the
|
|
// same list and detail are re-read without remounting or losing selection.
|
|
await fetch(`${fixture.url}/fixture/refuse`, { method: 'POST' });
|
|
await assertBody('Reconnecting to Pipelines…');
|
|
await assertName(connection, 'Content hash', 'detail retained after drop', log);
|
|
if ((await connection.evaluate('location.pathname')) !== '/pipelines') {
|
|
throw new Error(`Drop moved the route to ${await connection.evaluate('location.pathname')}`);
|
|
}
|
|
await capture(connection, captureDir, log, '05-drop-detail-retained-material');
|
|
|
|
await fetch(`${fixture.url}/fixture/accept`, { method: 'POST' });
|
|
await click(connection, 'Retry');
|
|
await waitForState(
|
|
(value) =>
|
|
value.listPipelines > loaded.listPipelines &&
|
|
value.getPipeline > loaded.getPipeline,
|
|
'reconnect reload of list and open detail',
|
|
);
|
|
await assertName(connection, 'Content hash', 'detail refreshed in place', log);
|
|
await noBody('Pipelines server unavailable');
|
|
await capture(connection, captureDir, log, '06-reconnect-detail-refreshed-material');
|
|
|
|
// Cupertino host: macOS platform, dark appearance.
|
|
await connection.send('Emulation.setUserAgentOverride', {
|
|
userAgent:
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 ' +
|
|
'(KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
|
|
platform: 'MacIntel',
|
|
});
|
|
await connection.send('Emulation.setEmulatedMedia', {
|
|
features: [{ name: 'prefers-color-scheme', value: 'dark' }],
|
|
});
|
|
await navigate(`${fixture.url}/pipelines`);
|
|
await assertName(connection, 'Release verification', 'cupertino dark row', log);
|
|
await noBody('Pipelines — Not implemented');
|
|
await capture(connection, captureDir, log, '07-list-cupertino-dark');
|
|
await assertOcr('07-list-cupertino-dark', 'Release verification');
|
|
|
|
await click(connection, 'Release verification');
|
|
await assertName(connection, 'Content hash', 'cupertino dark detail', log);
|
|
await capture(connection, captureDir, log, '08-detail-cupertino-dark');
|
|
await assertOcr('08-detail-cupertino-dark', 'Content hash');
|
|
|
|
await click(connection, 'Source');
|
|
await capture(connection, captureDir, log, '09-source-cupertino-dark');
|
|
await assertOcr('09-source-cupertino-dark', 'name: Release verification');
|
|
await assertOcr('09-source-cupertino-dark', 'type: model');
|
|
|
|
const final = await state();
|
|
if (final.connections < 1) throw new Error('No shared socket');
|
|
log.checks.push('both native hosts rendered real rows, detail and source');
|
|
log.final = final;
|
|
} catch (error) {
|
|
log.error = String(error?.stack ?? error);
|
|
try {
|
|
log.failureAx = (await axNodes(connection))
|
|
.filter((node) => node.name?.value)
|
|
.map((node) => `${node.role?.value}: ${node.name.value}`)
|
|
.slice(0, 120);
|
|
} catch {
|
|
// The browser may already be gone; the error itself is still recorded.
|
|
}
|
|
process.exitCode = 1;
|
|
} finally {
|
|
await writeFile(join(captureDir, 'probe.json'), JSON.stringify(log, null, 2));
|
|
connection?.close();
|
|
chrome.kill('SIGTERM');
|
|
await fixture.close();
|
|
}
|