'use strict'; // Lightweight record check, not a sieve or a new shadow measurement. // Usage: node verify-registry.js SOURCE_DIRECTORY OUTPUT_DIRECTORY // SOURCE_DIRECTORY: served shadow-prereg.md, shadow-buchstab.md, QUESTIONS.md, // and research/qc/questions.js saved as questions.js. import fs from 'node:fs'; import path from 'node:path'; import vm from 'node:vm'; import assert from 'node:assert/strict'; import crypto from 'node:crypto'; const [srcDir, outDir] = process.argv.slice(2); if (!srcDir || !outDir) throw Error('Supply source and output directories'); fs.mkdirSync(outDir, {recursive:true}); const read = name => fs.readFileSync(path.join(srcDir, name), 'utf8'); const hash = s => crypto.createHash('sha256').update(s).digest('hex'); const prereg = read('shadow-prereg.md'); const scored = read('shadow-buchstab.md'); const index = read('QUESTIONS.md'); const generator = read('questions.js'); const id = 'Q-shadow-prereg'; const verdict = 'Scored in shadow-buchstab.md: SHAPE-ONLY under the original y >= 997 rule; D3 passes in the reported ten clusters but D1 fails near y = 1000 at 1.49 times the 0.011 tolerance. Later finite-y normalisation and counting-floor corrections do not promote this verdict. The pair-Buchstab identification remains conjectural; the pre-registration body is preserved.'; const blockRE = //; const block = prereg.match(blockRE); assert(block); assert(block[1].includes('id: ' + id)); assert(block[1].includes('status: OPEN\n')); const amendedBlock = block[0].replace('status: OPEN\n', 'status: ANSWERED\n') .replace(/^verdict:.*$/m, 'verdict: ' + verdict); const revised = prereg.replace(block[0], amendedBlock); assert.equal(prereg.replace(block[0], ''), revised.replace(amendedBlock, '')); assert(prereg.includes('y ≥ 997')); assert(prereg.includes('tol = 0.011')); assert(scored.includes('**SHAPE-ONLY, not DERIVED**')); assert(scored.includes('**10 of 10 PASS**')); const residual = 0.85004 - 0.83365; assert(residual - 0.00001 > 0.011); // even allowing both displayed rounding errors const score = (d1,d2,d3) => !d3 ? 'MISS' : d1 && d2 ? 'DERIVED' : 'SHAPE-ONLY'; assert.equal(score(false, false, true), 'SHAPE-ONLY'); assert.equal(score(false, true, true), 'SHAPE-ONLY'); // D2 dispute is immaterial // Run the unchanged project generator on a one-note fixture. Inject only the // corpus/filesystem adapters; no project code is edited or fetched recursively. function generateFixture(note) { let output; const notePath = '/fixture/research/history/staging/shadow-prereg.md'; const C = {ROOT:'/fixture', RESEARCH:'/fixture/research', historyMarkdown:[notePath], bodyMarkdown:[], read: p => {assert.equal(p,notePath); return note;}, rel: p => p.replace('/fixture/',''), norm: s => s.trim()}; const fixtureFS = {existsSync: () => false, writeFileSync: (p,s) => {assert.equal(p,'/fixture/research/QUESTIONS.md'); output=s;}}; const mod = {exports:{}}; const sandbox = {module:mod, require: name => { if (name==='fs') return fixtureFS; if (name==='path') return path; if (name==='./corpus') return C; throw Error('Unexpected dependency: '+name); }}; vm.runInNewContext(generator,sandbox,{timeout:1000,filename:'questions.js'}); const stats=mod.exports.generate(); assert.equal(stats.questions,1); assert.equal(mod.exports.ledger().findings.length,0); return output.split('\n').filter(line=>line.includes('`'+id+'`')); } const oldRows=generateFixture(prereg), newRows=generateFixture(revised); assert.equal(oldRows.length,2); assert.equal(newRows.length,2); let amended=index; oldRows.forEach((row,i)=>{ assert.equal(amended.split('\n').filter(l=>l===row).length,1); amended=amended.replace(row,newRows[i]); }); const originalLines=index.split('\n'), amendedLines=amended.split('\n'); assert.equal(originalLines.length,amendedLines.length); assert.equal(originalLines.filter((line,i)=>line!==amendedLines[i]).length,2); fs.writeFileSync(path.join(outDir,'shadow-prereg.md'),revised); fs.writeFileSync(path.join(outDir,'QUESTIONS.md'),amended); const result={scope:'Record audit only; no new sieve measurements or proof', checks:{original_rule_retained:true,prereg_body_byte_identical:true, d1_residual:Number(residual.toFixed(5)),d1_tolerance:0.011, d1_tolerance_multiple:Number((residual/0.011).toFixed(2)), score_regardless_of_d2:'SHAPE-ONLY',unchanged_project_generator_used:true, fixture_ledger_findings:0,generated_index_rows_changed:2, all_other_index_lines_unchanged:true}, source_sha256:Object.fromEntries(['shadow-prereg.md','shadow-buchstab.md','QUESTIONS.md','questions.js'].map(n=>[n,hash(read(n))])), output_sha256:{'shadow-prereg.md':hash(revised),'QUESTIONS.md':hash(amended)}}; const resultJSON=JSON.stringify(result,null,2)+'\n'; fs.writeFileSync(path.join(outDir,'verification.json'),resultJSON); process.stdout.write(resultJSON);