// blocksha.mjs — a fresh run against a tail's own record. // // node blocksha.mjs research/.js // // Answers, in the record's own terms: does the fresh run's normalized stdout hash to the recorded // out-sha256; if not, which normalized lines differ, and which figures the recorded block carries // that the fresh run does not produce (the figures the embed guard prints before it refuses). import fs from 'node:fs'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const T = require('./research/qc/tailfmt.js'); const [servedPath, freshPath] = process.argv.slice(2); if (!servedPath || !freshPath) { console.error('usage: node blocksha.mjs '); process.exit(2); } const served = fs.readFileSync(servedPath, 'utf8'); const fresh = fs.readFileSync(freshPath, 'utf8'); const fp = T.fingerprint(served); const recorded = T.normalize(T.outputTextRaw(served) ?? ''); const now = T.normalize(fresh); console.log(`served ${servedPath}`); console.log(` recorded out-sha256 ${fp['out-sha256']}`); console.log(` streams ${fp['streams'] || '(none)'} embedded ${fp['embedded'] || '(none)'}`); console.log(`fresh ${freshPath} (${fresh.length} bytes, ${fresh.split('\n').length} lines)`); console.log(` normalized ${T.sha(now)}`); console.log(` MATCH: ${T.sha(now) === fp['out-sha256']}`); console.log(''); const a = recorded.split('\n'); const b = now.split('\n'); console.log(`recorded block: ${a.length} normalized lines; fresh: ${b.length}`); let diff = 0; let shown = 0; for (let i = 0; i < Math.max(a.length, b.length); i++) { if (a[i] === b[i]) continue; diff++; if (shown < 12) { console.log(` line ${i + 1}\n recorded: ${String(a[i]).slice(0, 150)}\n fresh : ${String(b[i]).slice(0, 150)}`); shown++; } } console.log(` differing normalized lines: ${diff}`); console.log(''); const oldFigs = T.figures(a.join('\n')); const gone = [...oldFigs.keys()].filter((t) => !T.presentIn(t, now)); console.log(`figures in the recorded block: ${oldFigs.size}; not produced by this run: ${gone.length}`); for (const g of gone.slice(0, 40)) console.log(` ${g}`); const newFigs = T.figures(b.join('\n')); const added = [...newFigs.keys()].filter((t) => !T.presentIn(t, recorded)); console.log(`figures in the fresh run: ${newFigs.size}; not in the recorded block: ${added.length}`); for (const g of added.slice(0, 40)) console.log(` ${g}`);