// What a run reports: the step it is at, how many of each kind of request // it made, and the first thing that differs, which ends it. In a // compatibility run (`--area`, compat.mjs), a difference is kept and the // check goes on: lib/areas.mjs counts a check with one as failed. import { writeFileSync } from 'node:fs' import { AREA, SEED, TALLY } from './args.mjs' import { logs, shutdown } from './processes.mjs' /// The step the run is at, which `differ` names. export const run = { step: 0 } /// How many of each kind of request went, `{ok, error}` by kind. export const counts = {} export const count = (kind, ok) => { counts[kind] ??= { ok: 0, error: 0 } counts[kind][ok ? 'ok' : 'error'] += 1 } // The tally, by kind in order, written with `--tally` as the run ends; a // port a kind names (as in a did:web of a harness service, or the server's // metrics port) is ``, as it is drawn fresh each run. if (TALLY) { process.on('exit', () => { const tally = {} for (const [kind, n] of Object.entries(counts)) { const k = kind.replace(/(:|%3A|%253A|_PORT )\d{2,5}\b/g, '$1') tally[k] ??= { ok: 0, error: 0 } tally[k].ok += n.ok tally[k].error += n.error } writeFileSync(TALLY, `${JSON.stringify(Object.fromEntries(Object.entries(tally).sort(([a], [b]) => a.localeCompare(b))), null, 1)}\n`) }) } /// What spec/COMPAT.md lets an implementation other than Monolith have, /// which it made use of in this run, by name, how often. export const allowed = {} export const allow = (name) => void (allowed[name] = (allowed[name] ?? 0) + 1) /// In a compatibility run, the differences found since lib/areas.mjs last /// took them, each as `differ` prints it. export const found = [] /// Say what differs, with the request and both answers, and stop; in a /// compatibility run, keep it, and go on. export async function differ(what, request, theirs, ours, note) { if (AREA) return void found.push({ step: run.step, what, note: note ?? null, request, reference: theirs, server: ours }) console.error(`\nstep ${run.step} (seed ${SEED}): ${what} differs${note ? `: ${note}` : ''}`) // Span attributes hold BigInts, which JSON does not. const show = (v) => JSON.stringify(v, (_, x) => (typeof x === 'bigint' ? `${x}n` : x), 2) console.error('request:', show(request)) console.error('reference:', show(theirs)) console.error('server:', show(ours)) console.error(logs()) await shutdown(1) }