web: prepare the client workstream for feature parity
Adds the area map (web/AGENTS.md), the parity acceptance checklist (web/PARITY.md, one row per Android feature), and a zero-dependency browser verification harness: test/browser.mjs drives the installed Chrome over the DevTools protocol, and test/ui-smoke.mjs serves the page, connects it through its own /connect proxy, and captures the rendered pipeline list, a pipeline detail and a run detail as PNGs. This closes the spike's 'rendered page not verified' gap (29 pipelines rendered, three captures) and gives review stages real UI evidence without a phone or an npm install. Hosting is unchanged: serve.mjs stays alongside the Pipelines server and proxies /connect.
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
# The web client — working map
|
||||
|
||||
Read this before touching `web/`. This is the browser client for the Pipelines
|
||||
server. Its target is **feature parity with the Android app** (`android/`), not a
|
||||
reimplementation of it: same features, the same wire protocol, the same words,
|
||||
rendered for a browser. `web/PARITY.md` is the acceptance checklist; that file,
|
||||
not this one, decides whether a feature is done.
|
||||
|
||||
## What it is
|
||||
|
||||
- **Browser-native** (plain ES modules in the browser). Deliberately **no
|
||||
framework and no runtime dependency** — no React/Vue/Svelte, no bundler
|
||||
required. Keep it that way unless a concrete feature cannot be built without
|
||||
one, and say why in the item's note.
|
||||
- **Simple but beautiful**: hand-written CSS (`styles.css`), the app's dark
|
||||
palette and spacing, real attention to hierarchy and detail. "Simple" is about
|
||||
the stack, never about the finish.
|
||||
- **Trusted LAN/VPN only.** The server has no authentication; the page stores
|
||||
nothing but the server URL in `localStorage`. Never bake in a server address,
|
||||
never store secrets, never expose the API to an untrusted network.
|
||||
|
||||
## Layout
|
||||
|
||||
| File | Android counterpart | Notes |
|
||||
| --- | --- | --- |
|
||||
| `src/protocol.js` | `data/protocol/Message.kt` | message type constants, `#success`/`#failure` |
|
||||
| `src/serverUrl.js` | `data/transport/ServerUrl.kt` | `validateServerUrl`, `resolveArtifactUrl` |
|
||||
| `src/client.js` | `data/transport/PipelinesClient.kt` | one reused socket, id matching, timeout, backoff. **DOM-free** |
|
||||
| `src/repository.js` | `data/PipelinesRepository.kt` | typed request builders |
|
||||
| `src/app.js` | `ui/**` | the DOM UI. Grow it toward `PARITY.md` |
|
||||
| `index.html`, `styles.css` | — | shell + styling |
|
||||
| `serve.mjs` | — | static server + `/connect` proxy |
|
||||
| `test/*.test.mjs` | `app/src/test/**` | `node --test`, no server needed |
|
||||
| `test/smoke.mjs` | — | protocol smoke against a live server |
|
||||
| `test/browser.mjs` | — | zero-dep Chrome DevTools driver |
|
||||
| `test/ui-smoke.mjs` | UI review captures | live browser check + screenshots |
|
||||
|
||||
Keep `client.js` DOM-free: the smoke tests and the page must drive the **same**
|
||||
transport module.
|
||||
|
||||
## Build and run
|
||||
|
||||
```sh
|
||||
cd web
|
||||
node serve.mjs # http://127.0.0.1:8090/ (proxies /connect -> 127.0.0.1:8080)
|
||||
node serve.mjs --port 8091 --pipelines 127.0.0.1:8080
|
||||
```
|
||||
|
||||
There is no build step and nothing to compile. `node serve.mjs` is the whole
|
||||
"install".
|
||||
|
||||
## Test
|
||||
|
||||
```sh
|
||||
cd web
|
||||
node --test test/ # unit tests, no server
|
||||
PIPELINES_WS_URL=ws://127.0.0.1:8080/connect node test/smoke.mjs # protocol, live
|
||||
node test/ui-smoke.mjs --out /path/to/run/artifacts # browser, live, screenshots
|
||||
```
|
||||
|
||||
`ui-smoke.mjs` starts `serve.mjs`, launches the installed Chrome headless, drives
|
||||
the real page and writes PNGs into `--out`. **That is the UI evidence**: a review
|
||||
stage must run it (or an extension of it) and report the capture paths, not
|
||||
describe what it thinks would render. Set `CHROME_PATH` if Chrome is not at the
|
||||
default macOS location.
|
||||
|
||||
## Why the page connects through `serve.mjs`, not the server directly
|
||||
|
||||
`internal/server/websocket.go` calls `websocket.Accept(w, r, nil)`, which rejects
|
||||
an upgrade whose `Origin` host does not match the request `Host`. A page served
|
||||
from port 8090 opening `ws://HOST:8080/connect` is refused with **403**. The
|
||||
static server therefore also proxies `/connect` (dropping `Origin`), so the page
|
||||
and the socket are one origin. **Do not "fix" this by relaxing the server's Origin
|
||||
check** — that check is the only thing standing between a random web page and an
|
||||
unauthenticated control API. Keep the proxy.
|
||||
|
||||
The web server is spawned alongside the Pipelines server; it is not part of the
|
||||
Go binary and needs no server change.
|
||||
|
||||
## Rules
|
||||
|
||||
- One small, independently verifiable change per item; keep the diff tight.
|
||||
- Match the Android app's wording and behaviour; where the browser genuinely
|
||||
cannot match (local notifications need HTTPS, deep links become URL routes),
|
||||
say so in the parity row rather than inventing a difference.
|
||||
- Every new user-visible state needs a capture from `ui-smoke.mjs`.
|
||||
- Do not edit `android/` from this workstream.
|
||||
- Update `web/PARITY.md` in the same commit when a row's status changes.
|
||||
- `node --check` every file you touch; `node --test test/` must stay green.
|
||||
@@ -0,0 +1,90 @@
|
||||
# Web client — parity checklist
|
||||
|
||||
The browser client's acceptance gate. **The target is the Android app's feature
|
||||
set** (`android/`), rendered for the web. A row is only `done` when the feature
|
||||
works in the browser against a live server **and** a review stage captured the
|
||||
rendered result through `test/ui-smoke.mjs` (or an extension of it). A green unit
|
||||
test, or a code change without a capture, is `partial` at best.
|
||||
|
||||
Status legend: `todo` · `partial` (some of it works) · `done` (working + captured).
|
||||
|
||||
## Transport and connection
|
||||
| # | Feature (Android counterpart) | Protocol | Status |
|
||||
| --- | --- | --- | --- |
|
||||
| T1 | Server-URL entry + validation rules (`data/transport/ServerUrl.kt`) | — | done |
|
||||
| T2 | One reused socket, id matching, request timeout, not-connected guard (`PipelinesClient.kt`) | — | done |
|
||||
| T3 | Connect / disconnect / manual reconnect | `ping` | partial (connect works; no reconnect UI) |
|
||||
| T4 | Backoff recovery + foreground reconnect after sleep/blur (`ConnectionRecovery.kt`, `ForegroundReconnector.kt`) | — | todo |
|
||||
| T5 | Connection banner + live badge; build/protocol mismatch warning | `pong` build/protocol | todo |
|
||||
| T6 | Artifact URL resolution against the configured server (`resolveArtifactUrl`) | `GET /artifacts/…` | done (URL only) |
|
||||
|
||||
## Pipelines
|
||||
| # | Feature | Protocol | Status |
|
||||
| --- | --- | --- | --- |
|
||||
| P1 | Pipeline list | `list_pipelines` | partial (list + count only) |
|
||||
| P2 | Filter + sort (status/name/updated) | client-side | todo |
|
||||
| P3 | Pipeline detail: stages, graph, versions, last run, content hash | `get_pipeline` | todo |
|
||||
| P4 | Templates gallery + template detail | `list_templates` | todo |
|
||||
| P5 | Create pipeline from a template (validate then submit) | `validate`, `submit` | todo |
|
||||
| P6 | Workflow graph rendering (nodes, edges, stage panes) | `get_pipeline` | todo |
|
||||
|
||||
## Runs
|
||||
| # | Feature | Protocol | Status |
|
||||
| --- | --- | --- | --- |
|
||||
| R1 | Run history list with status roll-up | `list_runs` | partial (list only) |
|
||||
| R2 | Filter by status, sort, "needs you" markers | client-side | todo |
|
||||
| R3 | Run detail: run fields, steps/visits, targets, sessions | `get_run` | partial (fields + steps) |
|
||||
| R4 | Summary tab incl. collapsible **Changes** viewer (raw + rendered diff) | `get_run` file changes | todo |
|
||||
| R5 | Graph tab (per-stage panes, verdicts) | `get_run` | todo |
|
||||
| R6 | Input / Output field sections per stage | `get_run` | todo |
|
||||
| R7 | Timeline | `get_run` | todo |
|
||||
| R8 | Artifacts gallery + full-screen viewer (images inline, others download/open) | `GET /artifacts/…` | todo |
|
||||
| R9 | Session export link (read-only `session.html`) | `GET /artifacts/…` | todo |
|
||||
| R10 | Live run updates: subscribe/unsubscribe + event fold | `subscribe`, `unsubscribe`, `run_event` | todo |
|
||||
| R11 | Human decision sheet: prompt, options, feedback | `decide_run` | todo |
|
||||
| R12 | Cancel run | `cancel_run` | todo |
|
||||
| R13 | Retry failed stage (resume) / restart from start | `retry_run` | todo |
|
||||
| R14 | Rename a run | `set_run_title` | todo |
|
||||
| R15 | Attention / "Needs you" surface: counts, open, individual dismiss, clear all | derived from `list_runs` + run events | todo |
|
||||
|
||||
## Search
|
||||
| # | Feature | Protocol | Status |
|
||||
| --- | --- | --- | --- |
|
||||
| S1 | Omni-search across pipelines, versions, runs, steps, fields, artifacts | `search` | todo |
|
||||
| S2 | Result routing (open the pipeline, run, stage, artifact) | — | todo |
|
||||
|
||||
## Chat
|
||||
| # | Feature | Protocol | Status |
|
||||
| --- | --- | --- | --- |
|
||||
| C1 | Session list (operator sessions, closed grouped as history) | `chat_sessions` | todo |
|
||||
| C2 | Create a chat (directory picker) | `chat_directories`, `chat_create` | todo |
|
||||
| C3 | Open / close / reopen a session | `chat_close`, `chat_reopen` | todo |
|
||||
| C4 | History with paging / "load older" | `chat_messages` | todo |
|
||||
| C5 | Live transcript: user/assistant text, one reply = one turn | `chat_subscribe`, `chat_event` | todo |
|
||||
| C6 | Reasoning block + tool calls with name/input for the whole lifecycle | `chat_event` | todo |
|
||||
| C7 | Markdown rendering + code blocks | — | todo |
|
||||
| C8 | Composer: send, stop, attachments, draft | `chat_prompt`, `chat_interrupt` | todo |
|
||||
| C9 | Slash commands | client-side | todo |
|
||||
| C10 | Permission/approval cards (allow once/always/reject) | `chat_permission`, `chat_reply` | todo |
|
||||
| C11 | Background tasks bar: running shells only, capped + scrollable, bounded output page | `chat_shells`, `chat_shell_output` | todo |
|
||||
| C12 | Human-decision notices inside chat + dismiss | `chat_event` | todo |
|
||||
| C13 | Local rename/hide, seen state, persistence to `localStorage` | client-side | todo |
|
||||
| C14 | Scroll behaviour: follow newest, "jump to newest", restored position | client-side | todo |
|
||||
|
||||
## Settings, layout, platform
|
||||
| # | Feature | Protocol | Status |
|
||||
| --- | --- | --- | --- |
|
||||
| L1 | Settings: server URL, workspace | — | todo |
|
||||
| L2 | Wide layout: left rail + two panes | client-side | todo |
|
||||
| L3 | Narrow layout: bottom section strip + bottom navigation | client-side | todo |
|
||||
| L4 | Responsive switch by viewport width (no hardcoded device) | `WindowSize.kt` analogue | todo |
|
||||
| L5 | Notifications for failed/waiting runs (browser Notification API; HTTPS/localhost only) | derived | todo |
|
||||
| L6 | Deep links to a run (`pipelines://run/…` analogue → URL route) | — | todo |
|
||||
| L7 | Accessibility: focus order, labels, keyboard operation | — | todo |
|
||||
|
||||
## Deliberately out of scope
|
||||
- **Operator-only transport** — `inspect_resource`, `reconcile_resource`,
|
||||
`inspect_resource_pool`, `configure_resource_pool` are loopback-only and must
|
||||
not be exposed by a browser client.
|
||||
- **Device/ADB features** — the Android app's device work is the UI reviewer's
|
||||
lease-based work, not a client feature.
|
||||
+22
-10
@@ -42,6 +42,10 @@ format, server-URL rules and reply matching here mirror
|
||||
| `serve.mjs` | — | zero-dep static server |
|
||||
| `test/*.test.mjs` | `app/src/test/**` | `node --test` |
|
||||
| `test/smoke.mjs` | — | live end-to-end against a running server |
|
||||
| `test/browser.mjs` | — | zero-dependency Chrome DevTools driver |
|
||||
| `test/ui-smoke.mjs` | UI review captures | live browser check; writes screenshots |
|
||||
| `PARITY.md` | `android/` feature set | the acceptance checklist |
|
||||
| `AGENTS.md` | `android/AGENTS.md` | the area map for this workstream |
|
||||
|
||||
`client.js` is DOM-free on purpose, so the smoke test drives the **same**
|
||||
transport module the page uses.
|
||||
@@ -125,17 +129,25 @@ server (`ws://100.85.25.33:8080/connect`):
|
||||
- `PIPELINES_WS_URL=ws://100.85.25.33:8090/connect node test/smoke.mjs` →
|
||||
**SMOKE PASS (6 checks)** — a full request/reply session over the tunnel.
|
||||
|
||||
**Not verified:** the rendered page itself. No desktop browser was connected to
|
||||
this session, so the DOM UI was not opened, clicked or screenshotted. `app.js`
|
||||
parses and its data path is exercised through the shared `client`/`repository`/
|
||||
`serverUrl` modules, but its rendering and event wiring are unproven. Also
|
||||
unverified: `wss://`/TLS (no TLS server was available) and multiple concurrent
|
||||
**Not verified:** `wss://`/TLS (no TLS server was available) and multiple concurrent
|
||||
browser tabs.
|
||||
|
||||
### Rendered-page verification (2026-10-19)
|
||||
|
||||
The gap above is closed: `node test/ui-smoke.mjs` launches the installed Chrome
|
||||
headless through the zero-dependency DevTools driver (`test/browser.mjs`), serves
|
||||
the page, connects it through the proxy, and captures what actually rendered.
|
||||
Against the live server it rendered **29 pipelines**, opened a pipeline detail and
|
||||
a run detail, and wrote three PNGs. Flow: web → connect → pipeline list → pipeline
|
||||
detail → Runs tab → run detail, all with real clicks.
|
||||
|
||||
```sh
|
||||
cd web
|
||||
node test/ui-smoke.mjs --out /tmp/web-ui # needs a running Pipelines server
|
||||
```
|
||||
|
||||
## Next step
|
||||
|
||||
Before committing to a route, open `http://127.0.0.1:8090/` in a browser, connect
|
||||
to the running server, and confirm the list/detail flow. If Route A is chosen
|
||||
instead, the `data/`-layer mapping in the table above is the port checklist; the
|
||||
Android-API friction lives in the artifact viewer, navigation, lifecycle and
|
||||
`SharedPreferences` touchpoints (`android/README.md` documents them).
|
||||
Feature parity with the Android app is tracked in **`PARITY.md`**; that table is
|
||||
the acceptance gate (a row is only `done` with a captured browser E2E). Work is
|
||||
planned as small items, one per row or tight group of rows.
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@
|
||||
"scripts": {
|
||||
"serve": "node serve.mjs",
|
||||
"test": "node --test test/",
|
||||
"smoke": "node test/smoke.mjs"
|
||||
"smoke": "node test/smoke.mjs",
|
||||
"ui": "node test/ui-smoke.mjs"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,302 @@
|
||||
// A zero-dependency Chrome DevTools Protocol driver for verifying the web client
|
||||
// in a real browser.
|
||||
//
|
||||
// It launches the installed Google Chrome in headless mode and talks to it over
|
||||
// the DevTools WebSocket, using only Node's built-in `fetch` and global
|
||||
// `WebSocket` (Node 22+). There is deliberately no npm dependency: the UI
|
||||
// verification a pipeline stage runs must work from a clean checkout with no
|
||||
// install step and no network.
|
||||
//
|
||||
// Usage:
|
||||
// const browser = await launchChrome(); // { port, close() }
|
||||
// const page = await browser.openPage(url); // navigate + await load
|
||||
// await page.fill("#url", "ws://127.0.0.1:8090/connect");
|
||||
// await page.click("#connectBtn");
|
||||
// await page.waitForSelector(".row-title");
|
||||
// await page.screenshot("/path/to/out.png");
|
||||
// await page.close(); await browser.close();
|
||||
//
|
||||
// Chrome path: CHROME_PATH, else the macOS app bundle, else `google-chrome`.
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
const CHROME_CANDIDATES = [
|
||||
process.env.CHROME_PATH,
|
||||
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
||||
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
||||
"/usr/bin/google-chrome",
|
||||
"/usr/bin/chromium",
|
||||
].filter(Boolean);
|
||||
|
||||
async function resolveChrome() {
|
||||
for (const candidate of CHROME_CANDIDATES) {
|
||||
try {
|
||||
await readFile(candidate);
|
||||
return candidate;
|
||||
} catch {
|
||||
// try the next candidate
|
||||
}
|
||||
}
|
||||
throw new Error(
|
||||
"no Chrome/Chromium found; set CHROME_PATH to a browser binary to run UI verification",
|
||||
);
|
||||
}
|
||||
|
||||
/** Poll `check` until it returns a truthy value or the timeout elapses. */
|
||||
export async function eventually(check, { timeout = 20000, interval = 100, what = "condition" } = {}) {
|
||||
const deadline = Date.now() + timeout;
|
||||
let lastError = null;
|
||||
while (Date.now() < deadline) {
|
||||
try {
|
||||
const value = await check();
|
||||
if (value) return value;
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, interval));
|
||||
}
|
||||
throw new Error(`timed out waiting for ${what}${lastError ? `: ${lastError.message}` : ""}`);
|
||||
}
|
||||
|
||||
/** One CDP connection: id-matched commands plus method listeners. */
|
||||
class Cdp {
|
||||
constructor(ws) {
|
||||
this.ws = ws;
|
||||
this.nextId = 0;
|
||||
this.pending = new Map();
|
||||
this.listeners = new Map();
|
||||
ws.addEventListener("message", (event) => {
|
||||
const message = JSON.parse(event.data);
|
||||
if (message.id != null) {
|
||||
const entry = this.pending.get(message.id);
|
||||
this.pending.delete(message.id);
|
||||
if (!entry) return;
|
||||
if (message.error) entry.reject(new Error(`${message.error.message}`));
|
||||
else entry.resolve(message.result ?? {});
|
||||
return;
|
||||
}
|
||||
for (const listener of this.listeners.get(message.method) ?? []) listener(message);
|
||||
});
|
||||
}
|
||||
|
||||
opened() {
|
||||
if (this.ws.readyState === 1) return Promise.resolve();
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.addEventListener("open", () => resolve(), { once: true });
|
||||
this.ws.addEventListener("error", () => reject(new Error("devtools websocket failed")), {
|
||||
once: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
on(method, listener) {
|
||||
const list = this.listeners.get(method) ?? [];
|
||||
list.push(listener);
|
||||
this.listeners.set(method, list);
|
||||
}
|
||||
|
||||
send(method, params = {}, sessionId) {
|
||||
const id = ++this.nextId;
|
||||
const frame = { id, method, params };
|
||||
if (sessionId) frame.sessionId = sessionId;
|
||||
return new Promise((resolve, reject) => {
|
||||
this.pending.set(id, { resolve, reject });
|
||||
this.ws.send(JSON.stringify(frame));
|
||||
});
|
||||
}
|
||||
|
||||
close() {
|
||||
try {
|
||||
this.ws.close();
|
||||
} catch {
|
||||
// already gone
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch headless Chrome with a fresh profile and remote debugging on an
|
||||
* ephemeral port (read back from the profile's `DevToolsActivePort`).
|
||||
*/
|
||||
export async function launchChrome({ width = 1440, height = 900, chromePath } = {}) {
|
||||
const chrome = chromePath ?? (await resolveChrome());
|
||||
const profile = await mkdtemp(join(tmpdir(), "pipelines-web-cdp-"));
|
||||
const child = spawn(
|
||||
chrome,
|
||||
[
|
||||
"--headless=new",
|
||||
"--disable-gpu",
|
||||
"--no-first-run",
|
||||
"--no-default-browser-check",
|
||||
"--disable-extensions",
|
||||
"--hide-scrollbars",
|
||||
"--mute-audio",
|
||||
`--user-data-dir=${profile}`,
|
||||
"--remote-debugging-port=0",
|
||||
`--window-size=${width},${height}`,
|
||||
"about:blank",
|
||||
],
|
||||
{ stdio: ["ignore", "ignore", "pipe"] },
|
||||
);
|
||||
let stderr = "";
|
||||
child.stderr.on("data", (chunk) => {
|
||||
stderr += chunk.toString();
|
||||
});
|
||||
|
||||
const port = await eventually(
|
||||
async () => {
|
||||
if (child.exitCode != null) {
|
||||
throw new Error(`chrome exited early (${child.exitCode}): ${stderr.trim().slice(-400)}`);
|
||||
}
|
||||
const text = await readFile(join(profile, "DevToolsActivePort"), "utf8").catch(() => "");
|
||||
const first = text.split("\n")[0]?.trim();
|
||||
return first ? Number(first) : 0;
|
||||
},
|
||||
{ what: "chrome devtools port", timeout: 30000 },
|
||||
);
|
||||
|
||||
let cdp = null;
|
||||
const openCdp = async () => {
|
||||
if (cdp) return cdp;
|
||||
const version = await (await fetch(`http://127.0.0.1:${port}/json/version`)).json();
|
||||
const ws = new WebSocket(version.webSocketDebuggerUrl);
|
||||
cdp = new Cdp(ws);
|
||||
await cdp.opened();
|
||||
return cdp;
|
||||
};
|
||||
|
||||
return {
|
||||
port,
|
||||
chrome,
|
||||
async openPage(url, { width: w = width, height: h = height } = {}) {
|
||||
const conn = await openCdp();
|
||||
const { targetId } = await conn.send("Target.createTarget", { url: "about:blank" });
|
||||
const { sessionId } = await conn.send("Target.attachToTarget", { targetId, flatten: true });
|
||||
const session = (method, params) => conn.send(method, params, sessionId);
|
||||
await session("Page.enable");
|
||||
await session("Runtime.enable");
|
||||
await session("Emulation.setDeviceMetricsOverride", {
|
||||
width: w,
|
||||
height: h,
|
||||
deviceScaleFactor: 1,
|
||||
mobile: false,
|
||||
});
|
||||
|
||||
const api = {
|
||||
targetId,
|
||||
async evaluate(expression) {
|
||||
const result = await session("Runtime.evaluate", {
|
||||
expression,
|
||||
awaitPromise: true,
|
||||
returnByValue: true,
|
||||
});
|
||||
if (result.exceptionDetails) {
|
||||
const text =
|
||||
result.exceptionDetails.exception?.description ??
|
||||
result.exceptionDetails.text ??
|
||||
"evaluation failed";
|
||||
throw new Error(text);
|
||||
}
|
||||
return result.result?.value;
|
||||
},
|
||||
async goto(nextUrl) {
|
||||
await session("Page.navigate", { url: nextUrl });
|
||||
await eventually(
|
||||
async () => (await api.evaluate("document.readyState")) === "complete",
|
||||
{ what: `load of ${nextUrl}` },
|
||||
);
|
||||
},
|
||||
/** Set an input's value and fire input/change so the app sees it. */
|
||||
async fill(selector, value) {
|
||||
const ok = await api.evaluate(`(() => {
|
||||
const el = document.querySelector(${JSON.stringify(selector)});
|
||||
if (!el) return false;
|
||||
el.focus();
|
||||
el.value = ${JSON.stringify(value)};
|
||||
el.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
el.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
return true;
|
||||
})()`);
|
||||
if (!ok) throw new Error(`fill: no element for ${selector}`);
|
||||
},
|
||||
async rect(selector) {
|
||||
return api.evaluate(`(() => {
|
||||
const el = document.querySelector(${JSON.stringify(selector)});
|
||||
if (!el) return null;
|
||||
el.scrollIntoView({ block: "center", inline: "center" });
|
||||
const r = el.getBoundingClientRect();
|
||||
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
||||
})()`);
|
||||
},
|
||||
/** A real mouse click at the element's centre. */
|
||||
async click(selector) {
|
||||
const point = await api.rect(selector);
|
||||
if (!point) throw new Error(`click: no element for ${selector}`);
|
||||
const base = { x: point.x, y: point.y, button: "left", clickCount: 1 };
|
||||
await session("Input.dispatchMouseEvent", { type: "mouseMoved", x: point.x, y: point.y });
|
||||
await session("Input.dispatchMouseEvent", { type: "mousePressed", ...base });
|
||||
await session("Input.dispatchMouseEvent", { type: "mouseReleased", ...base });
|
||||
},
|
||||
/** Click the first element matching `selector` whose text contains `text`. */
|
||||
async clickText(selector, text) {
|
||||
const found = await api.evaluate(`(() => {
|
||||
const wanted = ${JSON.stringify(text)};
|
||||
const all = [...document.querySelectorAll(${JSON.stringify(selector)})];
|
||||
const el = all.find((node) => (node.textContent ?? "").includes(wanted));
|
||||
if (!el) return false;
|
||||
el.scrollIntoView({ block: "center" });
|
||||
el.setAttribute("data-test-click", "1");
|
||||
return true;
|
||||
})()`);
|
||||
if (!found) throw new Error(`clickText: no ${selector} containing ${JSON.stringify(text)}`);
|
||||
await api.click("[data-test-click='1']");
|
||||
await api.evaluate(
|
||||
`document.querySelector("[data-test-click='1']")?.removeAttribute("data-test-click")`,
|
||||
);
|
||||
},
|
||||
async waitForSelector(selector, { timeout = 20000 } = {}) {
|
||||
return eventually(() => api.evaluate(`!!document.querySelector(${JSON.stringify(selector)})`), {
|
||||
timeout,
|
||||
what: selector,
|
||||
});
|
||||
},
|
||||
async waitForText(text, { timeout = 20000 } = {}) {
|
||||
return eventually(
|
||||
() => api.evaluate(`document.body.innerText.includes(${JSON.stringify(text)})`),
|
||||
{ timeout, what: `text ${JSON.stringify(text)}` },
|
||||
);
|
||||
},
|
||||
async text() {
|
||||
return api.evaluate("document.body.innerText");
|
||||
},
|
||||
async screenshot(path) {
|
||||
const { data } = await session("Page.captureScreenshot", { format: "png" });
|
||||
await writeFile(path, Buffer.from(data, "base64"));
|
||||
return path;
|
||||
},
|
||||
async close() {
|
||||
await conn.send("Target.closeTarget", { targetId }).catch(() => {});
|
||||
},
|
||||
};
|
||||
|
||||
if (url) await api.goto(url);
|
||||
return api;
|
||||
},
|
||||
async close() {
|
||||
try {
|
||||
await fetch(`http://127.0.0.1:${port}/json/close/${""}`).catch(() => {});
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
cdp?.close();
|
||||
child.kill("SIGTERM");
|
||||
await eventually(async () => child.exitCode != null || child.signalCode != null, {
|
||||
timeout: 5000,
|
||||
what: "chrome exit",
|
||||
}).catch(() => {});
|
||||
await rm(profile, { recursive: true, force: true }).catch(() => {});
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
// Live browser check for the web client: serve the page, open it in headless
|
||||
// Chrome, connect to a running Pipelines server through the page's own proxy,
|
||||
// and capture what actually rendered.
|
||||
//
|
||||
// node test/ui-smoke.mjs [--port 8091] [--pipelines 127.0.0.1:8080] [--out DIR]
|
||||
//
|
||||
// This is the UI evidence a review stage produces: real screenshots of the
|
||||
// rendered client, not a claim. It needs a running Pipelines server (the live one
|
||||
// or a scratch one) and the installed Chrome; it has no npm dependencies.
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdir, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { eventually, launchChrome } from "./browser.mjs";
|
||||
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
|
||||
function flag(argv, name, fallback) {
|
||||
const i = argv.indexOf(name);
|
||||
return i !== -1 && argv[i + 1] ? argv[i + 1] : fallback;
|
||||
}
|
||||
|
||||
const port = Number(flag(process.argv, "--port", process.env.WEB_UI_PORT ?? 8091));
|
||||
const pipelines = flag(process.argv, "--pipelines", process.env.PIPELINES_TARGET ?? "127.0.0.1:8080");
|
||||
const out = resolve(
|
||||
flag(process.argv, "--out", process.env.WEB_UI_OUT ?? join(tmpdir(), "pipelines-web-ui")),
|
||||
);
|
||||
|
||||
const shots = [];
|
||||
let serve = null;
|
||||
let browser = null;
|
||||
let page = null;
|
||||
let failed = false;
|
||||
|
||||
function step(label) {
|
||||
console.log(`• ${label}`);
|
||||
}
|
||||
|
||||
try {
|
||||
await mkdir(out, { recursive: true });
|
||||
|
||||
step(`serving web/ on 127.0.0.1:${port} (proxy /connect -> ${pipelines})`);
|
||||
serve = spawn(process.execPath, ["serve.mjs", "--port", String(port), "--pipelines", pipelines], {
|
||||
cwd: ROOT,
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
});
|
||||
let serveLog = "";
|
||||
serve.stdout.on("data", (chunk) => (serveLog += chunk.toString()));
|
||||
serve.stderr.on("data", (chunk) => (serveLog += chunk.toString()));
|
||||
await eventually(
|
||||
async () => {
|
||||
if (serve.exitCode != null) throw new Error(`serve.mjs exited: ${serveLog.trim().slice(-300)}`);
|
||||
const res = await fetch(`http://127.0.0.1:${port}/`).catch(() => null);
|
||||
return res?.ok;
|
||||
},
|
||||
{ what: "the page to be served" },
|
||||
);
|
||||
|
||||
step("launching headless Chrome");
|
||||
browser = await launchChrome({ width: 1440, height: 900 });
|
||||
page = await browser.openPage(`http://127.0.0.1:${port}/`);
|
||||
|
||||
step("connecting the page to the server through its own proxy");
|
||||
await page.fill("#url", `ws://127.0.0.1:${port}/connect`);
|
||||
await page.click("#connectBtn");
|
||||
await page.waitForSelector(".row-title", { timeout: 25000 });
|
||||
await page.waitForText("connected", { timeout: 25000 });
|
||||
const pipelineCount = await page.evaluate(
|
||||
`document.querySelectorAll(".list button.row").length`,
|
||||
);
|
||||
if (!pipelineCount) throw new Error("connected but no pipelines rendered");
|
||||
|
||||
shots.push(await page.screenshot(`${out}/01-pipelines.png`));
|
||||
console.log(` pipelines rendered: ${pipelineCount}`);
|
||||
|
||||
step("opening a pipeline detail");
|
||||
await page.click(".list button.row");
|
||||
await page.waitForSelector(".detail h2");
|
||||
shots.push(await page.screenshot(`${out}/02-pipeline-detail.png`));
|
||||
|
||||
step("switching to Runs and opening a run detail");
|
||||
await page.clickText("nav.tabs button.tab", "Runs");
|
||||
await page.waitForSelector(".list button.row", { timeout: 25000 });
|
||||
await page.click(".list button.row");
|
||||
await page.waitForSelector(".detail h2", { timeout: 25000 });
|
||||
shots.push(await page.screenshot(`${out}/03-run-detail.png`));
|
||||
|
||||
console.log("\nUI SMOKE PASS");
|
||||
for (const shot of shots) console.log(` ${shot}`);
|
||||
} catch (error) {
|
||||
failed = true;
|
||||
console.error(`\nUI SMOKE FAIL: ${error.message}`);
|
||||
if (page) {
|
||||
try {
|
||||
shots.push(await page.screenshot(`${out}/failure.png`));
|
||||
console.error(` failure capture: ${shots.at(-1)}`);
|
||||
console.error((await page.text()).split("\n").slice(0, 25).join("\n"));
|
||||
} catch {
|
||||
// the page may be gone; the error above is the real signal
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await page?.close().catch(() => {});
|
||||
await browser?.close().catch(() => {});
|
||||
serve?.kill("SIGTERM");
|
||||
await eventually(async () => serve?.exitCode != null, { timeout: 5000, what: "serve exit" }).catch(
|
||||
() => {},
|
||||
);
|
||||
if (!failed) await rm(`${out}/failure.png`, { force: true }).catch(() => {});
|
||||
}
|
||||
|
||||
process.exit(failed ? 1 : 0);
|
||||
Reference in New Issue
Block a user