a44f31b989
Read-only Pipelines screen for the Flutter client: - list_pipelines and list_runs with a last-run join, plus get_pipeline with an explicit version (0 = latest); no mutation requests. - Name, run-presence, last-run-status and schedule filters; six sort orders; clear filters; truthful loading, empty and error states. - Detail Summary, selectable Source and version history with selection and return to latest. - Sequenced list/detail requests so stale replies cannot replace a newer selection or open a cleared one; refresh keeps the selected pipeline and version. - Material controls on Android/desktop and Cupertino on iOS; a per-label segmented tab row at narrow widths and scaled text, with the native control kept wherever an equal share fits. - Fixture probe entry and Chrome scripts for the rendered evidence; widget tests cover filters, sorting, formatting, sequencing, layout and the tab row. Graph rendering remains P2: the Graph tab states that it is pending and exposes a host hook. PipelinesScreen is not yet registered in the shell. Evidence and limits: app/notes/P1.md.
128 lines
3.9 KiB
JavaScript
128 lines
3.9 KiB
JavaScript
// Chrome DevTools connection and fixture-server helpers for the Pipelines P1
|
|
// probe. No live server or operator data is involved.
|
|
import { spawn } from "node:child_process";
|
|
import { createServer } from "node:http";
|
|
import { readFile, stat } from "node:fs/promises";
|
|
import { extname, join, normalize } from "node:path";
|
|
|
|
export const sleep = (ms) =>
|
|
new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
|
const MIME = {
|
|
".html": "text/html; charset=utf-8",
|
|
".js": "text/javascript; charset=utf-8",
|
|
".mjs": "text/javascript; charset=utf-8",
|
|
".css": "text/css; charset=utf-8",
|
|
".json": "application/json",
|
|
".png": "image/png",
|
|
".jpg": "image/jpeg",
|
|
".svg": "image/svg+xml",
|
|
".ttf": "font/ttf",
|
|
".otf": "font/otf",
|
|
".wasm": "application/wasm",
|
|
".map": "application/json",
|
|
};
|
|
|
|
export async function startServer(buildDir) {
|
|
const root = normalize(buildDir);
|
|
const server = createServer(async (request, response) => {
|
|
try {
|
|
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
let file = normalize(join(root, decodeURIComponent(url.pathname)));
|
|
if (!file.startsWith(root)) throw new Error("outside build");
|
|
let info = await stat(file).catch(() => null);
|
|
if (!info || info.isDirectory()) {
|
|
file = join(root, "index.html");
|
|
info = await stat(file);
|
|
}
|
|
response.writeHead(200, {
|
|
"content-type": MIME[extname(file)] ?? "application/octet-stream",
|
|
"cache-control": "no-store",
|
|
});
|
|
response.end(await readFile(file));
|
|
} catch {
|
|
response.writeHead(404).end("not found");
|
|
}
|
|
});
|
|
await new Promise((done) => server.listen(0, "127.0.0.1", done));
|
|
return { server, url: `http://127.0.0.1:${server.address().port}/` };
|
|
}
|
|
|
|
export function launchChrome(chromePath, profile, url) {
|
|
return spawn(
|
|
chromePath,
|
|
[
|
|
"--headless=new",
|
|
"--remote-debugging-port=0",
|
|
`--user-data-dir=${profile}`,
|
|
"--no-first-run",
|
|
"--no-default-browser-check",
|
|
"--disable-background-networking",
|
|
"--disable-sync",
|
|
"--hide-scrollbars",
|
|
"--force-device-scale-factor=1",
|
|
"--window-size=1200,900",
|
|
url,
|
|
],
|
|
{ stdio: "ignore" },
|
|
);
|
|
}
|
|
|
|
export async function waitForPort(file) {
|
|
for (let attempt = 0; attempt < 200; attempt++) {
|
|
const text = await readFile(file, "utf8").catch(() => "");
|
|
if (text) return text.split("\n")[0].trim();
|
|
await sleep(100);
|
|
}
|
|
throw new Error("Chrome DevTools did not start");
|
|
}
|
|
|
|
export async function waitForPage(devtoolsPort) {
|
|
for (let attempt = 0; attempt < 100; attempt++) {
|
|
const targets = await fetch(
|
|
`http://127.0.0.1:${devtoolsPort}/json/list`,
|
|
).then((response) => response.json());
|
|
const page = targets.find((target) => target.type === "page");
|
|
if (page) return page;
|
|
await sleep(100);
|
|
}
|
|
throw new Error("No page target");
|
|
}
|
|
|
|
export async function connect(webSocketUrl) {
|
|
const socket = new WebSocket(webSocketUrl);
|
|
await new Promise((done, fail) => {
|
|
socket.addEventListener("open", done, { once: true });
|
|
socket.addEventListener("error", fail, { once: true });
|
|
});
|
|
let nextId = 1;
|
|
const pending = new Map();
|
|
socket.addEventListener("message", (event) => {
|
|
const message = JSON.parse(event.data);
|
|
if (!message.id) return;
|
|
const entry = pending.get(message.id);
|
|
if (!entry) return;
|
|
pending.delete(message.id);
|
|
if (message.error) entry.reject(new Error(message.error.message));
|
|
else entry.resolve(message.result);
|
|
});
|
|
const send = (method, params = {}) =>
|
|
new Promise((resolve, reject) => {
|
|
const id = nextId++;
|
|
pending.set(id, { resolve, reject });
|
|
socket.send(JSON.stringify({ id, method, params }));
|
|
});
|
|
return {
|
|
send,
|
|
close: () => socket.close(),
|
|
evaluate: async (expression) => {
|
|
const result = await send("Runtime.evaluate", {
|
|
expression,
|
|
awaitPromise: true,
|
|
returnByValue: true,
|
|
});
|
|
return result.result?.value;
|
|
},
|
|
};
|
|
}
|