import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';import assert from 'node:assert/strict'; const [qaTag,demoTag]=process.argv.slice(2);assert([qaTag,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')),qa=path.join(run.root,'private/receipt-composition-'+qaTag),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 [['documents',qa,'supplier-documents-result.json',28],['integration',qa,'supplier-documents-integration.json',9],['guards',demo,'supplier-documents-guards.json',4],['demo',demo,'supplier-documents-demo.json',8],['assets',demo,'supplier-documents-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};} const files=['app/Modules/Purchasing/SupplierDocumentsController.php','app/Modules/Purchasing/SupplierDocumentFiles.php','app/Modules/Purchasing/SupplierController.php','app/Modules/Purchasing/SupplierAccess.php','config/receipt_qa.php','routes/web.php','public/supplier-workspace.mjs','public/supplier-documents.mjs'];for(const base of [qa,demo])for(const f of files)assert.equal(hash(path.join(base,'app',f)),hash(f),f); const pins=[];for(const base of [qa,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/receipt-workspace-completion-20261103.json').pinned_native_manifests); const previous=['docs/proofs/receipt-workspace-completion-20261103.json','docs/proofs/purchasing-dossier-composition-20261103.json','docs/proofs/supplier-search-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 count=Object.values(tests).reduce((n,t)=>n+t.checks,0);assert.equal(count,52);const out='docs/proofs/supplier-documents-composition-20261103.json';assert(!fs.existsSync(out));fs.writeFileSync(out,JSON.stringify({date:new Date().toISOString(),increment:'SGF-SUPPLIER-DOCUMENTS-QA-v1',passed:true,functional_code:true,checks:count,tests,sources:files.map(file=>({file,sha256:hash(file)})),pinned_native_manifests:pins[0],authority:{original_document_controller:true,private_qa_storage:true,source_company_unit_checked:true,existing_rights:['purchasing_suppliers.view','purchasing_suppliers.prepare'],new_right_names:[],upload_invalidates_review:true,independent_review_reopens_sourcing:true,automatic_quote:false},regression:{transport_documents:2,native_volume_documents:14,documents_and_files:16,staged_files:0,concurrency_statuses:[200,201],prior_successful_checks_preserved:17,resumed_after_download_adapter_fix:11,source_request_setup_minor:100,attachment_creates_budget_reservation:false},demo:{port:8076,entry:'http://127.0.0.1:8076/qa/enter/actor?open=1',reviewer:'http://127.0.0.1:8076/qa/enter/issuer?open=1',initial_documents:0,initial_main_requests:0,prepared_suppliers:3,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:['Positive binary fixture is PNG. Allowed PDF/JPEG rules are original native rules, not a new full-format reader regression.','Validation does not certify authenticity, fiscal validity or universally required document types.','Ordinary rollback compensation is tested. If commit outcome cannot be verified, files are retained; crash-orphan reconciliation and retention/quota maintenance are not declared delivered.','Preview sequence values may advance and empty private staging directories may remain; staged file count is zero.','Same key is idempotent; another key is another explicit upload intent. The original mechanism does not perform global content-hash deduplication.','Fourteen native-controller volume uploads are fixture preparation, not14 independent HTTP transport confirmations.','Native schema provisioning remains current while runtime is pinned; general installation/least-privilege deployment is not validated.','Visual review, sustained load and storage capacity remain pending.'],visual_review_pending:true,deployment_capacity_validated:false},null,2)+'\n');console.log(JSON.stringify({output:out,checks:count,demo_port:8076}));