test(e2e): add playwright harness and test stack

- test(e2e): add playwright harness and test stack
- test(e2e): add core flow
- fix(ui): preserve same-origin browser form submissions
- fix(ui): offer reload inside stale edit dialogs
- test(e2e): add persona session and accessibility suites
- test(e2e): preserve per-run artifacts and clean pulled images
- test(e2e): verify import and audit state across navigation
- test(e2e): tighten verification helpers and persona checks
- test(e2e): bound response body reads of the browser observer
- test: recover review compatibility assertions
- test: stabilize audit and user flow assertions
This commit is contained in:
bryanpedini committed 2026-11-19 15:46:12 +01:00
1 parent a7ba01fc77
commit 57a005c19f
48 files changed
+6239 -6

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2026 Bryan Joshua Pedini
import { spawn } from 'node:child_process';
import { HarnessError } from './errors';
export interface ProcResult {
code: number | null;
signal: string | null;
stdout: string;
stderr: string;
durationMs: number;
}
export interface ProcOptions {
input?: string | Buffer;
timeoutMs?: number;
env?: NodeJS.ProcessEnv;
}
export function run(command: string, args: readonly string[], opts: ProcOptions = {}): Promise<ProcResult> {
const timeoutMs = opts.timeoutMs ?? 120_000;
const started = Date.now();
return new Promise((resolve, reject) => {
let child;
try {
child = spawn(command, [...args], { env: opts.env ?? process.env, stdio: ['pipe', 'pipe', 'pipe'] });
} catch (e) {
reject(new HarnessError('spawn', `cannot start ${command}: ${(e as Error).message}`));
return;
}
const out: Buffer[] = [];
const err: Buffer[] = [];
let timedOut = false;
const timer = setTimeout(() => {
timedOut = true;
child.kill('SIGKILL');
}, timeoutMs);
child.stdout.on('data', (b: Buffer) => out.push(b));
child.stderr.on('data', (b: Buffer) => err.push(b));
child.on('error', (e) => {
clearTimeout(timer);
reject(new HarnessError('spawn', `cannot start ${command}: ${e.message}`));
});
child.on('close', (code, signal) => {
clearTimeout(timer);
const result: ProcResult = {
code,
signal,
stdout: Buffer.concat(out).toString('utf8'),
stderr: Buffer.concat(err).toString('utf8'),
durationMs: Date.now() - started,
};
if (timedOut) {
reject(new HarnessError('timeout', `${command} ${args.slice(0, 4).join(' ')} did not finish within ${timeoutMs} ms`, result));
return;
}
resolve(result);
});
child.stdin.on('error', () => undefined);
if (opts.input !== undefined) child.stdin.end(opts.input);
else child.stdin.end();
});
}
export async function runOk(command: string, args: readonly string[], opts: ProcOptions = {}): Promise<ProcResult> {
const r = await run(command, args, opts);
if (r.code !== 0) {
throw new HarnessError('infrastructure', `${command} ${args.join(' ')} exited with ${r.code}: ${r.stderr.trim().slice(-2000)}`, r);
}
return r;
}
export function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
export async function pollUntil<T>(what: string, fn: () => Promise<T | undefined | null | false>, timeoutMs = 30_000, intervalMs = 250): Promise<T> {
const deadline = Date.now() + timeoutMs;
let lastError: unknown;
for (;;) {
try {
const v = await fn();
if (v !== undefined && v !== null && v !== false) return v as T;
} catch (e) {
lastError = e;
}
if (Date.now() > deadline) {
throw new HarnessError('timeout', `${what} did not happen within ${timeoutMs} ms${lastError ? `: ${(lastError as Error).message}` : ''}`);
}
await sleep(intervalMs);
}
}