// Run unchanged served generator against all owners of precisely fifteen ids. const fs=require('fs'),path=require('path'),vm=require('vm'),assert=require('assert'),crypto=require('crypto'); const root=__dirname,read=n=>fs.readFileSync(path.join(root,n),'utf8'); const selected=JSON.parse(read('selection.json')), inputs=JSON.parse(read('owner-inputs.json')); const ids=new Set(selected.map(r=>r.id)); assert.equal(ids.size,15); const files=Object.keys(inputs).map(f=>path.join(root,'research',f));assert.equal(files.length,22); const C={ROOT:root,RESEARCH:path.join(root,'research'),bodyMarkdown:files.filter(f=>!f.includes('/history/')), historyMarkdown:files.filter(f=>f.includes('/history/')),rel:f=>path.relative(root,f), read:f=>inputs[path.relative(path.join(root,'research'),f)]}; let generated; const fakeFs={...fs,existsSync:f=>f===path.join(root,'TODO.md')?false:fs.existsSync(f), writeFileSync:(f,s)=>{assert.equal(f,path.join(root,'research','QUESTIONS.md'));generated=s;}}; const mod={exports:{}}; vm.runInNewContext(read('qc-questions.js'),{module:mod,require:n=>n==='./corpus'?C:n==='fs'?fakeFs:require(n),console}); const summary=mod.exports.generate();assert.equal(summary.questions,15);assert.equal(summary.notes,22);assert.equal(summary.unindexed,0); function rows(text){const out=new Map();for(const l of text.split('\n')){ if(!l.startsWith('| '))continue;const m=l.match(/`(Q-[A-Za-z0-9-]+)`/);if(!m||!ids.has(m[1]))continue; const key=(l.startsWith('| `')?'id:':'todo:')+m[1];assert(!out.has(key));out.set(key,l); }return out;} const original=read('QUESTIONS.md'), old=rows(original),next=rows(generated);console.log("row counts",old.size,next.size);assert.equal(old.size,30);assert.equal(next.size,30); const changed=[];for(const [k,v] of old){assert(next.has(k));if(next.get(k)!==v)changed.push(k);} assert.deepEqual(changed.sort(),['id:Q-global-factor-signs','todo:Q-global-factor-signs']); const documents=Object.fromEntries(Object.entries(inputs).map(([f,s])=>[f,crypto.createHash('sha256').update(s).digest('hex')])); const output={scope:'Document synchronization only. No mathematical revalidation or full corpus QC.', selected_rows:15,owner_documents:22,index_occurrences:30,changed_occurrences:changed, rows:selected.map(r=>({row:r.row,id:r.id,owners:r.paths.length,index_matches_owners:![...changed].some(k=>k.endsWith(':'+r.id))})), source_hashes:documents,generator_sha256:crypto.createHash('sha256').update(read('qc-questions.js')).digest('hex')}; fs.writeFileSync(path.join(root,'comparison.json'),JSON.stringify(output,null,2)+'\n'); console.log(JSON.stringify({rows:15,owners:22,occurrences:30,stale_rows:1,current_rows:14}));