import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';import assert from 'node:assert/strict'; const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),root=path.join(run.root,'private/receipt-composition-cc50a276c10c'),s=JSON.parse(fs.readFileSync(path.join(root,'state.json'))),read=p=>JSON.parse(fs.readFileSync(p,'utf8')),hash=p=>crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex');assert(s.singleInstallation&&s.tag==='cc50a276c10c'); if(process.argv.includes('--handoffs-final')){ const previous='docs/proofs/purchasing-completion-final-20261104.json',result=read(previous),handoffFile=path.join(root,'completion-handoffs-result.json'),handoffs=read(handoffFile);assert(result.passed&&handoffs.passed&&handoffs.checks.length===3&&handoffs.business_commands===0); const allowed=['public/purchasing-focus.mjs','public/request-workspace.mjs'];assert.deepEqual(handoffs.sources.map(x=>x.file).sort(),allowed.slice().sort()); for(const source of result.sources){const replacement=handoffs.sources.find(x=>x.file===source.file);if(replacement)source.sha256=replacement.sha256;assert.equal(source.sha256,hash(source.file),source.file);assert.equal(source.sha256,hash(path.join(s.app,source.file)),source.file);} result.checks+=3;result.tests.handoffs={file:'private/receipt-composition-cc50a276c10c/completion-handoffs-result.json',sha256:hash(handoffFile),checks:3,result:handoffs};result.previous_final_preserved={file:previous,sha256:hash(previous)};result.limits.push('Three additional read-only UI checks cover the final explicit function handoffs from request and receipt; the completed business commands were not replayed.'); const out='docs/proofs/purchasing-completion-final-20261104-r2.json';assert(!fs.existsSync(out));fs.writeFileSync(out,JSON.stringify(result,null,2)+'\n');console.log(JSON.stringify({output:out,checks:result.checks,entry:result.installation.entry}));process.exit(0); } if(process.argv.includes('--final')){ const initial='docs/proofs/purchasing-completion-20261104.json',result=read(initial),stockFile=path.join(root,'completion-stock-result.json'),stock=read(stockFile);assert(result.passed&&stock.passed&&stock.checks.length===1);for(const source of result.sources)assert.equal(source.sha256,hash(source.file)); const final='docs/proofs/purchasing-completion-final-20261104.json';assert(!fs.existsSync(final));result.checks+=stock.checks.length;result.tests.stock={file:'private/receipt-composition-cc50a276c10c/completion-stock-result.json',sha256:hash(stockFile),checks:1,result:stock};result.criteria.C06.stock_observation=true;result.initial_summary_preserved={file:initial,sha256:hash(initial)};result.final_summary=true;fs.writeFileSync(final,JSON.stringify(result,null,2)+'\n');console.log(JSON.stringify({output:final,checks:result.checks,entry:result.installation.entry}));process.exit(0); } const tests={};for(const [name,file,count]of [['flow','completion-flow-result.json',13],['reads','completion-read-result.json',22],['client','completion-client-result.json',10],['canonical','completion-data-result.json',12],['preservation','completion-preservation-result.json',2]]){const p=path.join(root,file),r=read(p);assert(r.passed);assert.equal(r.checks.length,count);tests[name]={file:'private/receipt-composition-cc50a276c10c/'+file,sha256:hash(p),checks:count,result:r};} const files=['app/Modules/Purchasing/PurchasingEntry.php','resources/views/purchasing-entry.blade.php','resources/views/purchasing-workspace.blade.php','resources/views/partials/purchasing-navigation.blade.php','resources/views/supplier-workspace.blade.php','resources/js/PurchasingHome.jsx',...['purchasing-exit','purchasing-board','purchasing-presenter','purchasing-focus','request-workspace','sourcing-workspace','order-workspace','receipt-workspace','supplier-workspace','supplier-invoice-workspace','supplier-obligation-workspace','obligation-evidence'].map(n=>'public/'+n+'.mjs')];for(const file of files)assert.equal(hash(file),hash(path.join(s.app,file)),file); const baseline=path.join(run.root,'private/receipt-composition-73a9188da342/app'),authorities=['app/Modules/Purchasing/ReceiptRuntime.php','app/Modules/Purchasing/RequestController.php','app/Modules/Purchasing/SupplierController.php','app/Modules/Purchasing/SourcingController.php','app/Modules/Purchasing/OrderController.php','app/Modules/Purchasing/ReceiptController.php','app/Modules/Purchasing/InvoiceController.php','app/Modules/Purchasing/ObligationController.php','packages/payables/src/Payables.php','resources/js/context-transition.js','app/Shared/Context/ModuleNavigation.php'];for(const file of authorities){assert.equal(hash(file),hash(path.join(baseline,file)),file);assert.equal(hash(file),hash(path.join(s.app,file)),file);} const previous=['docs/proofs/stock-period-report-20261103.json','docs/proofs/purchasing-integrated-composition-20261103.json','docs/proofs/module-association-consolidation-summary-20261102.json'].map(file=>({file,sha256:hash(file)})),assoc=read(previous[2].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 criteria=Object.fromEntries(['C01','C02','C03','C04','C05','C06','C07','C08','C09','C10'].map(id=>[id,{passed:true,definition:'docs/PURCHASING_COMPLETION.md'}]));const pins={};for(const dir of ['bundle','economic','internal'])pins[dir]=hash(path.join(root,dir,'manifest.json'));assert.deepEqual(pins,read(previous[0].file).pinned_native_manifests); const manifest='public/build/manifest.json',entry=read(manifest)['resources/js/app.jsx'].file;assert.equal(hash(manifest),hash(path.join(s.app,manifest)));assert.equal(hash('public/build/'+entry),hash(path.join(s.app,'public/build',entry))); const out='docs/proofs/purchasing-completion-20261104.json';assert(!fs.existsSync(out));fs.writeFileSync(out,JSON.stringify({date:'2026-11-04',increment:'SGF-PURCHASING-SINGLE-INSTALLATION-COMPLETE-v1',passed:true,checks:59,criteria,installation:{id:s.tag,entry:'http://127.0.0.1:8085/compras',port:8085,reuses_existing_application_and_books:true,new_database:false,new_role:false,new_port:false,new_demonstration:false},tests,sources:files.map(file=>({file,sha256:hash(file)})),unchanged_business_authority:authorities.map(file=>({file,sha256:hash(file)})),pinned_native_manifests:pins,pre_navigation_flow_sources:read(path.join(root,'completion-flow-source-pins.json')),build:{manifest_sha256:hash(manifest),entry_sha256:hash('public/build/'+entry)},prior_proofs_preserved:previous,preservation:{installed_purchasing_sha256:hash('packages/purchasing/current.json'),protected_six_records_changed:false,blocked_cache_cleared:false,other_demo_instances_changed:false,target_database_connected:false,new_public_or_real_rights:false,permission_grants_unchanged:true,host_budget_unchanged:true,activation_of_candidates:false,publication:false,checkpoint:false},functional_scope:'Existing local synthetic purchasing acquisition from new supplier and requisition through independently recognised payable. One persistent installation, normal native workflows and UI modules, no replay of completed commands.',limits:['The main path uses actual workspace modules/forms and HTTP on8085 with a simulated DOM, not a browser visual/accessibility acceptance.','After the successful business flow, document-retention navigation and exit guards were improved;22 read/entry checks and10 client checks cover those changes without repeating the business operations.','The final SQL check is READ ONLY and checks canonical state, distinct identities, unique effects and audit. An initial verifier used the wrong evaluation-table name; corrected to the existing proposal_evaluations without replaying any command.','The initial host/native database dumps and code-update backups are private and excluded from the repository. Backup extraction comparison proves permissions and host-budget rows unchanged; no restore was executed.','8085 is now the continuing working installation with a completed100MZN example, superseding its earlier empty-demo state. Other demos and their historical proofs are preserved.','Real operations, payments, accounting of this new origin, fiscal issuance, historical responsibility migration, deployment and publication remain outside this completion.','Visual review, sustained load, deployment capability and full operating-system restart have not been validated. The start command was checked against the already running installation and does not provision a new one.'],acceptance_presumed:false},null,2)+'\n');console.log(JSON.stringify({output:out,criteria:Object.keys(criteria).length,checks:59,entry:'http://127.0.0.1:8085/compras'}));