// Question(job575): does the actual generator reproduce #205's proposed rows // from current owning ledgers? Run with the unchanged served questions.js. const fs=require('fs'),path=require('path'),vm=require('vm'),assert=require('assert'); const root=__dirname; const paths=['research/centered-discrepancy-estimate.md','research/history/staging/xchan-at29-prereg.md','research/history/staging/attack-kstar-01-prereg.md','research/history/staging/var41-prereg.md','research/history/staging/shadow-prereg.md']; const ids=['Q-centered-discrepancy-estimate','Q-xchan-at29-prereg','Q-kstar-prereg','Q-var41','Q-shadow-prereg']; function rows(text){const m=new Map();for(const s of text.split('\n')){ let a=s.match(/^\| `([^`]+)` \|/),b=s.match(/^\| ([^|]+) \| `([^`]+)`/);let id=a?a[1]:b?b[2]:null; if(ids.includes(id)){let k=a?'id:'+id:b[1].trim()+':'+id;assert(!m.has(k));m.set(k,s);}} assert.equal(m.size,11);return m;} function generate(revised){let output;const C={ROOT:root,RESEARCH:path.join(root,'research'), historyMarkdown:paths.filter(s=>s.includes('/staging/')).map(s=>path.join(root,s)), bodyMarkdown:paths.filter(s=>!s.includes('/staging/')).map(s=>path.join(root,s)), rel:f=>path.relative(root,f),read:f=>fs.readFileSync(path.join(root,revised&&fs.existsSync(path.join(root,'revised-'+path.basename(f)))?'revised-'+path.basename(f):path.basename(f)),'utf8')}; const fakeFs={...fs,existsSync:f=>f===path.join(root,'TODO.md')?true:fs.existsSync(f), readFileSync:(f,...args)=>f===path.join(root,'TODO.md')?'**C. c\n**9. n\n**D. d\n**X. x\n**2. n\n':fs.readFileSync(f,...args), writeFileSync:(f,s)=>{assert.equal(f,path.join(root,'research','QUESTIONS.md'));output=s;}}; const mod={exports:{}};vm.runInNewContext(fs.readFileSync(path.join(root,'questions.js'),'utf8'),{module:mod,require:n=>n==='./corpus'?C:n==='fs'?fakeFs:require(n),console}); const summary=mod.exports.generate();assert.equal(summary.questions,5);return rows(output);} const target=rows(fs.readFileSync(path.join(root,'uploaded-QUESTIONS.md'),'utf8'));const current=generate(false),fixed=generate(true); const discrepancies=[...target].filter(([k,s])=>current.get(k)!==s).map(([k])=>k); assert.equal(discrepancies.length,7); assert.deepEqual(discrepancies.map(k=>k.split(':')[1]).sort(),['Q-kstar-prereg','Q-kstar-prereg','Q-shadow-prereg','Q-shadow-prereg','Q-var41','Q-var41','Q-var41'].sort()); let base=fs.readFileSync(path.join(root,'QUESTIONS.base.md'),'utf8'); const revised=base.split('\n').map(s=>{for(const [k,v] of rows(base)){if(v===s)return fixed.get(k);}return s;}).join('\n'); fs.writeFileSync(path.join(root,'QUESTIONS.with-source-fixes.md'),revised); fs.writeFileSync(path.join(root,'generator-check.json'),JSON.stringify({generator_unchanged:true,owning_notes:5,rows:11,discrepancies_with_205:discrepancies,explanation:'Five proposed index lines are not supported by their unchanged source ledgers; two existing shadow rows also differ from its unchanged OPEN source. Three revised source ledgers supply a durable regeneration.'},null,2)+'\n'); console.log(JSON.stringify({notes:5,rows:11,discrepancies:7}));