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=f=>JSON.parse(fs.readFileSync(f,'utf8').replace(/^\uFEFF/,'')),hash=f=>crypto.createHash('sha256').update(fs.readFileSync(f)).digest('hex'); const tests={};for(const [name,base,file,count]of [['workflow',qa,'order-result.json',28],['guards',qa,'order-guards.json',3],['demonstration',demo,'order-demo-smoke.json',9],['assets',demo,'order-demo-assets.json',3]]){const result=read(path.join(base,file));assert(result.passed);assert.equal(Array.isArray(result.checks)?result.checks.length:result.checks,count);tests[name]={file:'private/'+path.basename(base)+'/'+file,sha256:hash(path.join(base,file)),checks:count,result};}const ui='docs/proofs/order-home-20261103.json',u=read(ui);assert(u.passed&&u.checks===6);tests.navigation={file:ui,sha256:hash(ui),checks:6,result:u};assert.equal(Object.values(tests).reduce((n,t)=>n+t.checks,0),49); const files=['app/Modules/Purchasing/OrderController.php','app/Modules/Purchasing/ReceiptRuntime.php','app/Modules/Purchasing/ReceiptController.php','config/receipt_qa.php','routes/web.php','app/Shared/Context/ModuleNavigation.php','app/Modules/Identity/Services/IdentityWorkflow.php','resources/js/PurchasingHome.jsx','resources/views/order-workspace.blade.php','public/order-workspace.mjs','scripts/order-native-setup.php','scripts/order-host-setup.php','scripts/order-composition-proof.php','scripts/order-guard-proof.php','scripts/order-demo-smoke.php','scripts/receipt-composition-run.mjs','scripts/receipt-composition-http.php'];const sources=files.map(file=>({file,sha256:hash(file)}));for(const base of [qa,demo])for(const file of files.filter(f=>!f.startsWith('scripts/')))assert.equal(hash(path.join(base,'app',file)),hash(file)); const bundled={};for(const base of [qa,demo]){const bundle=read(path.join(base,'bundle/manifest.json'));for(const [file,pin]of Object.entries(bundle.files))assert.equal(hash(path.join(base,'bundle',file)),pin);const economic=read(path.join(base,'economic/manifest.json'));for(const [file,pin]of Object.entries(economic.files)){assert.equal(hash(path.join(base,'economic',file)),pin);assert.equal(hash(path.join('../compras/packages/purchasing/src',file)),pin);}bundled[path.basename(base)]={native_manifest_sha256:hash(path.join(base,'bundle/manifest.json')),economic_manifest_sha256:hash(path.join(base,'economic/manifest.json')),purchase_workflow_original_sha256:bundle.originals['app/Services/PurchaseWorkflow.php'],receipt_workflow_original_sha256:bundle.originals['app/Services/ReceiptWorkflow.php']};}assert.deepEqual(Object.values(bundled)[0],Object.values(bundled)[1]); const previous=read('docs/proofs/receipt-composition-20261103.json');assert.equal(hash('packages/purchasing/current.json'),previous.preservation.installed_purchasing_pointer_sha256);const old=path.join(run.root,'private/receipt-composition-304b80f5a05f/bundle');assert.equal(hash(path.join(old,'manifest.json')),previous.native_workflow.namespace_only_bundle_manifest_sha256);for(const [file,pin]of Object.entries(read(path.join(old,'manifest.json')).files))assert.equal(hash(path.join(old,file)),pin);const association=read('docs/proofs/module-association-consolidation-summary-20261102.json');assert.equal(hash('app/Modules/Identity/Services/ModuleAssociationReview.php'),association.source_sha256);assert.equal(hash('app/Modules/Identity/Http/ModuleRecordsController.php'),association.controller_sha256); const prior=['docs/proofs/receipt-composition-20261103.json','docs/proofs/module-association-consolidation-summary-20261102.json','docs/proofs/requisition-composition-20261103.json','docs/proofs/common-ledger-stock-valuation-20261103.json'].map(file=>({file,sha256:hash(file)})),out='docs/proofs/order-composition-20261103.json';assert(!fs.existsSync(out));fs.writeFileSync(out,JSON.stringify({date:new Date().toISOString(),increment:'SGF-ORDER-TO-RECEIPT-QA-v1',functional_code:true,passed:true,checks:49,tests,sources,bundled,approved_source_created_by_native_select_and_distinct_decide:true,qa_rights:['purchasing_orders.view','purchasing_orders.issue'],demo:{url:'http://127.0.0.1:8065/qa/enter/actor?open=1',warehouse_url:'http://127.0.0.1:8065/qa/enter/validator?open=1',review_url:'http://127.0.0.1:8065/qa/enter/issuer?open=1',initial_orders:0,initial_receipts:0,initial_movements:0,initial_commitments:0,initial_reserved_minor:10000,port:8065},prior_proofs_preserved:prior,preservation:{installed_purchasing_sha256:hash('packages/purchasing/current.json'),previous_receipt_demo_manifest_sha256:hash(path.join(old,'manifest.json')),protected_six_records_changed:false,blocked_cache_cleared:false,existing_demos_written:false,real_rights_changed:false,purchasing_activated_at_destination:false,publication:false,checkpoint:false},diagnostics:{initial_attempt_preserved:true,reason:'ProposalComparison requires original ProposalScoring/QuotationPricing; those exact files are now pinned and loaded separately from the unchanged installed module.'},limitations:['Entry is an already approved native synthetic award, not yet a supplier-selection/award interface in SGF.','No implicit bridge or duplicated budget between SGF requisitions and native awards; the selected source budget alone receives the commitment.','Original native snapshot retains legacy budget_checked=false alongside its actual budget_control evidence.','One-unit100MZN/zero-tax selected scenario; no real tax or commercial policy validation.','New QA roles own their databases; installation/owner-runtime separation and long-lived worker deployment remain unvalidated.','No publication, purchasing destination activation, financial settlement, accounting or change of protected real associations.','Visual review, sustained load and deployment capacity remain separate.'],visual_review_pending:true,deployment_capacity_validated:false},null,2)+'\n');console.log(JSON.stringify({output:out,checks:49,demo_port:8065}));