import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';import assert from 'node:assert/strict'; const [overlayTag,demoTag]=process.argv.slice(2);assert([overlayTag,demoTag].every(t=>/^[a-f0-9]{12}$/.test(t??'')));const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),overlay=path.join(run.root,'private/dossier-read-'+overlayTag),demo=path.join(run.root,'private/receipt-composition-'+demoTag),read=p=>JSON.parse(fs.readFileSync(p,'utf8')),hash=p=>crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex'),tests={}; for(const [name,base,file,count]of [['read_reuse',overlay,'dossier-read-result.json',30],['guards',demo,'dossier-guard-result.json',4],['demo',demo,'dossier-demo-result.json',12],['assets',demo,'dossier-assets.json',3]]){const p=path.join(base,file),r=read(p);assert(r.passed);assert.equal(r.checks.length,count);tests[name]={file:'private/'+path.basename(base)+'/'+file,sha256:hash(p),checks:count,result:r};} assert.equal(tests.read_reuse.result.before_sha256,tests.read_reuse.result.after_sha256);assert.equal(tests.read_reuse.result.financial_commands_repeated,0);assert.equal(tests.read_reuse.result.tables_checked,142); const files=['app/Modules/Purchasing/DossierController.php','app/Modules/Purchasing/WorkspaceNavigation.php','app/Shared/Context/ModuleNavigation.php','config/receipt_qa.php','routes/web.php','resources/views/purchasing-dossier.blade.php','public/purchasing-dossier.mjs'];for(const base of [overlay,demo])for(const f of files)assert.equal(hash(path.join(base,'app',f)),hash(f),f); const original=read(path.join(overlay,'state.json')).original_root,pins=[];for(const base of [original,demo]){const p={};for(const dir of ['bundle','economic','internal']){p[dir]=hash(path.join(base,dir,'manifest.json'));for(const [f,h]of Object.entries(read(path.join(base,dir,'manifest.json')).files))assert.equal(hash(path.join(base,dir,f)),h);}pins.push(p);}assert.deepEqual(pins[0],pins[1]);assert.deepEqual(pins[0],read('docs/proofs/purchasing-integrated-composition-20261103.json').pinned_native_manifests); const previous=['docs/proofs/purchasing-integrated-composition-20261103.json','docs/proofs/supplier-search-composition-20261103.json','docs/proofs/supplier-obligation-composition-20261103.json','docs/proofs/module-association-consolidation-summary-20261102.json'].map(file=>({file,sha256:hash(file)})),assoc=read(previous.at(-1).file);assert.equal(hash('app/Modules/Identity/Services/ModuleAssociationReview.php'),assoc.source_sha256);assert.equal(hash('app/Modules/Identity/Http/ModuleRecordsController.php'),assoc.controller_sha256);assert.equal(hash('packages/purchasing/current.json'),read(previous[0].file).preservation.installed_purchasing_sha256); const checks=Object.values(tests).reduce((n,t)=>n+t.checks,0);assert.equal(checks,49);const out='docs/proofs/purchasing-dossier-composition-20261103.json';assert(!fs.existsSync(out));fs.writeFileSync(out,JSON.stringify({date:new Date().toISOString(),increment:'SGF-PURCHASING-DOSSIER-QA-v1',passed:true,functional_code:true,checks,tests,sources:files.map(file=>({file,sha256:hash(file)})),pinned_native_manifests:pins[0],read_reuse:{source_regression:'purchasing-integrated-composition-20261103.json',original_application_preserved:true,new_application_and_sessions:true,all142_tables_and_sequences_unchanged:true,financial_commands_repeated:0},authority:{entry_right:'purchasing_requests.view',per_stage_rights:true,native_visibility:true,hidden_stages_have_no_counts_or_rows:true,history_excludes_hidden_stages_and_payloads:true,new_right_names:[],page_size:25,financial_page_scope:'source_invoice_window',view_revision_scope:'visible_pages_only'},demo:{port:8074,entry:'http://127.0.0.1:8074/qa/enter/requester?open=1',initial_main_operations:0,prepared_suppliers:3,approved_budget_minor:100000,locations:0},prior_proofs_preserved:previous,preservation:{installed_purchasing_sha256:hash('packages/purchasing/current.json'),target_database_connected:false,protected_six_records_changed:false,blocked_cache_cleared:false,previous_demo_data_written:false,public_rights_changed:false,publication:false,checkpoint:false},limitations:['Read dossier only: not a universal task queue, workflow readiness decision, approval or automatic execution.','Entry requires request view. Warehouse-only or invoice-only reviewers retain their own screens; dossier does not grant cross-stage rights.','Pagination of obligations is a25-invoice source window, not a global debt count. Empty page and inaccessible stage are distinct.','The regression read uses current application code against the original owned completed QA book, preserving its original profile/source identity. It does not clone or rewrite financial facts.','Only the new empty demonstration temporarily revokes/restores an existing QA grant; its final fingerprint is unchanged.','The extra supplier volume fixture remains8073;8074 starts with three prepared suppliers and the current paged selector.','Original native runtime pins are preserved; current schema provisioning and previous owner/runtime caveats are not converted into deployment evidence.','Visual review, sustained load and general deployment capability remain pending.'],visual_review_pending:true,deployment_capacity_validated:false},null,2)+'\n');console.log(JSON.stringify({output:out,checks,demo_port:8074}));