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,'receipt-documents-result.json',28],['additional',qa,'receipt-documents-extra.json',6],['guards',demo,'receipt-documents-guards.json',4],['demo',demo,'receipt-documents-demo.json',8],['assets',demo,'receipt-documents-assets.json',3],['ui',demo,'receipt-documents-ui.json',9]]){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/ReceiptDocumentsController.php','app/Modules/Purchasing/SupplierDocumentFiles.php','app/Modules/Purchasing/ReceiptController.php','app/Modules/Purchasing/DossierController.php','config/receipt_qa.php','routes/web.php','public/receipt-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/supplier-documents-composition-20261103.json').pinned_native_manifests); const previous=['docs/proofs/supplier-documents-composition-20261103.json','docs/proofs/receipt-workspace-completion-20261103.json','docs/proofs/purchasing-dossier-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,58);const out='docs/proofs/receipt-documents-composition-20261103.json';assert(!fs.existsSync(out));fs.writeFileSync(out,JSON.stringify({date:new Date().toISOString(),increment:'SGF-RECEIPT-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_service:'ReceiptDocuments::add',original_download_controller:true,private_qa_storage:true,source_company_unit_checked:true,existing_rights:['purchasing_receipts.view','purchasing_receipts.confirm'],new_right_names:[],canonical_document_reused_by_receipt_type_hash:true,quantity_or_quality_decision_changed:false},regression:{transport_documents:1,native_volume_documents:15,documents_and_files:16,staged_files:0,concurrency_statuses:[200,201],receipt_quantity_milli:1000,physical_movements:1,source_workflow_setup_only:true,successful_prefix_reused:true,dossier_test_corrected_for_profile_and_history_page:true,other_module_test_expected403_for_warehouse:true},demo:{port:8077,entry:'http://127.0.0.1:8077/qa/enter/actor?open=1',warehouse:'http://127.0.0.1:8077/qa/enter/validator?open=1',initial_documents:0,initial_receipts:0,initial_main_requests:0,prepared_suppliers:3},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; PDF/JPEG rules remain native, without a new full-format reader regression.','A document is evidence, not authentication, fiscal certification or a decision accepting quantities/quality.','Deduplication is within one receipt and document type by SHA; it is not global deduplication. Separate explicit intents may each have an audit event for the same canonical document.','Ordinary rollback compensation is tested. An uncertain commit retains evidence; crash-orphan reconciliation, retention, quotas and sustained storage load are pending.','Fifteen original-service uploads are volume fixture preparation, not15 HTTP transport confirmations.','The final physical assertion after resumed read checks verifies one receipt and one1000milli movement; no all-table before/after fingerprint is claimed for the full command run.','DOM simulation checks component logic, not browser rendering, accessibility or visual acceptance.','Native schema provisioning is current while runtime is pinned. General installation and least-privilege deployment are not validated.','Visual review, sustained load and deployment capacity remain pending.'],visual_review_pending:true,deployment_capacity_validated:false},null,2)+'\n');console.log(JSON.stringify({output:out,checks:count,demo_port:8077}));