Files
doormilxpress_astryx/scripts/owliver-baseline.mjs
2026-08-20 18:18:10 +05:30

54 lines
1.9 KiB
JavaScript

/**
* Writes the Owliver behaviour baseline.
*
* node scripts/owliver-baseline.mjs # report drift, write nothing
* node scripts/owliver-baseline.mjs --write # (re)generate the snapshot
*
* The snapshot is the existing product's behaviour, recorded before the Agent
* layer was built and asserted by `skill-check.mjs` on every run afterwards.
*
* Regenerating is a deliberate act with a reason attached. A baseline rewritten
* to make a red check go green records the regression instead of catching it,
* which is worse than having no baseline at all — it converts a caught bug into
* a documented one.
*/
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
import { dirname } from 'node:path';
import { createServer } from 'vite';
import { BASELINE_PATH, captureBaseline } from './owliver-capture.mjs';
const ROOT = process.cwd();
const server = await createServer({
root: ROOT,
server: { middlewareMode: true },
appType: 'custom',
logLevel: 'error',
});
const captured = await captureBaseline(server);
await server.close();
const serialized = `${JSON.stringify(captured, null, 2)}\n`;
if (process.argv.includes('--write')) {
mkdirSync(dirname(BASELINE_PATH), { recursive: true });
writeFileSync(BASELINE_PATH, serialized);
const pages = Object.keys(captured.contexts).length;
console.log(`Baseline written — ${pages} contexts, ${captured.skillIds.length} skills, ${Object.keys(captured.routes).length} routes.`);
process.exit(0);
}
if (!existsSync(BASELINE_PATH)) {
console.error('No baseline recorded. Run `node scripts/owliver-baseline.mjs --write`.');
process.exit(1);
}
if (readFileSync(BASELINE_PATH, 'utf8') === serialized) {
console.log('Owliver behaviour matches the baseline.');
process.exit(0);
}
console.error('Owliver behaviour has DRIFTED from the baseline. Run `npm test` for the per-page detail.');
process.exit(1);