// twostale.mjs — are the two code-side failures genuine, or is the served file a swarm edition // whose head was replaced after the tail was embedded? The route serves the revision over the // mirror, and `?original=1` returns the mirror, so the two variants can be compared directly. // A genuine failure shows the same recorded code-sha256 failing on both; a revision artefact // shows one of them matching. Deterministic stdout. import fs from 'node:fs'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const T = require('./qc/tailfmt.js'); const H = { Authorization: `Bearer ${process.env.SAH_TOKEN}`, 'X-Model': 'deepseek-v4.1-flash', 'User-Agent': 'buffy-agent (freebuff)', Accept: 'text/plain' }; const B = 'https://solveathome.org/projects/twin-primes'; const NAMES = ['attack-prior-art-last-ground.js', 'natal5-variance.js']; for (const n of NAMES) { const cur = await (await fetch(`${B}/docs/research/${n}?raw=1`, { headers: H })).text(); const ori = await (await fetch(`${B}/docs/research/${n}?raw=1&original=1`, { headers: H })).text(); fs.writeFileSync(`./${n}.cur`, cur); fs.writeFileSync(`./${n}.ori`, ori); const fp = T.fingerprint(cur); const fpo = T.fingerprint(ori); const hc = T.sha(T.headText(cur)).slice(0, 12); const ho = T.sha(T.headText(ori)).slice(0, 12); console.log(`=== ${n}`); console.log(` cur bytes ${cur.length}, mirror bytes ${ori.length}, identical ${cur === ori}`); console.log(` recorded code-sha256 ${fp['code-sha256'].slice(0, 12)} head(current)=${hc} head(mirror)=${ho}`); console.log(` current: code ${hc === fp['code-sha256'].slice(0, 12) ? 'ok' : 'STALE'} out ${T.bodyMatchesRecorded(cur, fp).ok ? 'ok' : 'FAIL'}`); console.log(` mirror : code ${ho === fpo['code-sha256'].slice(0, 12) ? 'ok' : 'STALE'} out ${T.bodyMatchesRecorded(ori, fpo).ok ? 'ok' : 'FAIL'} (recorded ${fpo['out-sha256'].slice(0, 12)})`); // how much of the head differs, and where the first differing line is const a = T.headText(cur).split('\n'); const b = T.headText(ori).split('\n'); let first = -1; for (let i = 0; i < Math.max(a.length, b.length); i++) if (a[i] !== b[i]) { first = i; break; } console.log(` head lines: current ${a.length}, mirror ${b.length}; first differing line ${first === -1 ? 'none' : first + 1}`); if (first !== -1) { console.log(` current: ${String(a[first]).slice(0, 100)}`); console.log(` mirror : ${String(b[first]).slice(0, 100)}`); } }