okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221apps/host: the owner's UI and the Node App Host0b3299a01

main
2.1 KiB55 linesraw
1#!/usr/bin/env node
2/**
3 * Runs every recorded flow and reports which ones fail.
4 *
5 *   node scripts/flows.mjs            all flows
6 *   node scripts/flows.mjs chat rail  only these
7 *
8 * Why this exists: two flows silently stopped testing anything — one waited for
9 * a button the completed setup screen correctly no longer shows, the other kept
10 * a CSS class that had been renamed. Both looked like regressions when they were
11 * finally run, and neither had been exercised in weeks. A suite nobody runs is
12 * not a suite, so the whole set is one command now.
13 */
14import { execFile } from 'node:child_process';
15import { readFileSync } from 'node:fs';
16import { promisify } from 'node:util';
17
18const run = promisify(execFile);
19const ROOT = new URL('..', import.meta.url).pathname;
20
21const source = readFileSync(`${ROOT}scripts/flow.mjs`, 'utf8');
22const all = [...new Set([...source.matchAll(/flow === '([a-z]+)'/g)].map((m) => m[1]))].sort();
23const wanted = process.argv.slice(2).filter((a) => !a.startsWith('-'));
24const flows = wanted.length ? wanted.filter((f) => all.includes(f)) : all;
25
26if (wanted.length && flows.length !== wanted.length) {
27  const unknown = wanted.filter((f) => !all.includes(f));
28  console.error(`Unknown flow(s): ${unknown.join(', ')}`);
29  console.error(`Available: ${all.join(', ')}`);
30  process.exit(2);
31}
32
33const failed = [];
34for (const flow of flows) {
35  process.stdout.write(`${flow.padEnd(16)} `);
36  try {
37    const { stdout } = await run('node', ['scripts/flow.mjs', flow], { cwd: ROOT, timeout: 180_000 });
38    const last = stdout.trim().split('\n').filter(Boolean).pop() ?? '';
39    console.log(last.slice(0, 78));
40  } catch (err) {
41    const out = `${err.stdout ?? ''}${err.stderr ?? ''}`;
42    const reason = /Timeout .*exceeded/.test(out)
43      ? 'timed out waiting for something that is not there'
44      : (out.trim().split('\n').filter(Boolean).pop() ?? 'failed').slice(0, 78);
45    console.log(`FAIL — ${reason}`);
46    failed.push(flow);
47  }
48}
49
50console.log(
51  failed.length
52    ? `\nflows: ${failed.length} of ${flows.length} failed — ${failed.join(', ')}`
53    : `\nflows: all ${flows.length} passed`,
54);
55process.exit(failed.length ? 1 : 0);