// verify-revised.mjs — what a reviewer should check about a re-embed. // // node verify-revised.mjs research/.served.js research/.revised.js // // The document decomposes into the record's own three parts, so compare those rather than line // numbers (a banner that gains the `body-lines` and `streams` fields shifts every index): // head — must differ only in the lines this revision is for; // block — the pasted output; a re-embed rewrites it from a fresh run, so its raw timing // figures legitimately move. The check is that `normalize` maps the two to the same // text, which is exactly the claim `out-sha256` makes; // readings — prose; must be untouched. 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, revisedPath] = process.argv.slice(2); if (!servedPath || !revisedPath) { console.error('usage: node verify-revised.mjs '); process.exit(2); } const served = fs.readFileSync(servedPath, 'utf8'); const revised = fs.readFileSync(revisedPath, 'utf8'); const fpS = T.fingerprint(served); const fpR = T.fingerprint(revised); console.log(`served ${servedPath} sha256 ${T.sha(served).slice(0, 16)}`); console.log(` code-sha256 ${fpS['code-sha256']} out-sha256 ${fpS['out-sha256']}`); console.log(`revised ${revisedPath} sha256 ${T.sha(revised).slice(0, 16)}`); const codeOk = fpR['code-sha256'] === T.sha(T.headText(revised)); const bodyOk = T.bodyMatchesRecorded(revised, fpR).ok; console.log(` code-sha256 ${fpR['code-sha256']} ${codeOk ? 'code side ok' : 'code side STALE'}`); console.log(` out-sha256 ${fpR['out-sha256']} ${bodyOk ? 'out side ok' : 'out side FAIL'}`); console.log(` out-sha256 unchanged from served: ${fpS['out-sha256'] === fpR['out-sha256']}`); // head: line-by-line, with the banner header lines excluded by pattern (they are the record's // own fields, and the revision is expected to add fields the 2026-08-20 migration introduced) const bannerLine = (l) => /^\/\/\s{3}[a-z-]+:\s/.test(l.trimStart()) || /^\/\/\s+(node|embedded|elapsed|invocation|code-sha256|out-sha256|body-lines|streams|inputs|forced):/.test(l); const headLines = (t) => T.headText(t).split('\n').filter((l) => !bannerLine(l)); const hs = headLines(served); const hr = headLines(revised); const headDiffs = []; for (let i = 0; i < Math.max(hs.length, hr.length); i++) if (hs[i] !== hr[i]) headDiffs.push({ line: i + 1, served: hs[i] ?? '(absent)', revised: hr[i] ?? '(absent)' }); console.log(''); console.log(`HEAD (banner fields excluded): ${headDiffs.length} differing line(s)`); for (const d of headDiffs.slice(0, 10)) { console.log(` line ${d.line}`); console.log(` served : ${String(d.served).slice(0, 130)}`); console.log(` revised: ${String(d.revised).slice(0, 130)}`); } // block: normalized texts must be identical const bS = T.normalize(T.outputTextRaw(served) ?? ''); const bR = T.normalize(T.outputTextRaw(revised) ?? ''); console.log(''); console.log(`BLOCK: normalize(served) === normalize(revised): ${bS === bR} (sha ${T.sha(bS).slice(0, 16)} vs ${T.sha(bR).slice(0, 16)})`); if (bS !== bR) { const a = bS.split('\n'); const b = bR.split('\n'); let shown = 0; for (let i = 0; i < Math.max(a.length, b.length) && shown < 8; i++) if (a[i] !== b[i]) { console.log(` line ${i + 1}: served ${JSON.stringify(a[i])} | revised ${JSON.stringify(b[i])}`); shown++; } } // readings: prose, untouched const rS = T.readingsText(served) ?? ''; const rR = T.readingsText(revised) ?? ''; console.log(''); console.log(`READINGS: identical: ${rS === rR} (${rS.split('\n').length} lines)`); console.log(''); console.log(codeOk && bodyOk && fpS['out-sha256'] === fpR['out-sha256'] && bS === bR && rS === rR ? 'VERDICT: clean re-embed — provenance repaired, no result and no reading changed' : 'VERDICT: needs reading (something other than the banner moved)');