Files
SGF/scripts/summarize-receipt-composition.mjs
T
2026-11-04 09:37:20 +02:00

13 lines
7.2 KiB
JavaScript

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 state=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),root=path.join(state.root,'private/receipt-composition-'+qaTag),demo=path.join(state.root,'private/receipt-composition-'+demoTag),hash=f=>crypto.createHash('sha256').update(fs.readFileSync(f)).digest('hex'),read=f=>JSON.parse(fs.readFileSync(f,'utf8').replace(/^\uFEFF/,''));
const tests={};for(const [name,base,file,count]of [['workflow',root,'result.json',30],['concurrency_recovery',root,'extra.json',10],['origin_audit',root,'origin.json',6],['runtime_contract',root,'runtime-contract.json',4],['demonstration',demo,'demo-smoke.json',9],['compiled_assets',demo,'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/receipt-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),68);
assert.deepEqual(read(path.join(root,'partial-accepted.json')),tests.workflow.result.checks.slice(0,21));assert.deepEqual(read(path.join(root,'complete-accepted.json')),tests.workflow.result.checks.slice(0,29));
const files=['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/receipt-workspace.blade.php','public/receipt-workspace.mjs','scripts/build-receipt-runtime.php','scripts/receipt-composition-run.mjs','scripts/receipt-composition-proof.php','scripts/receipt-composition-extra.php','scripts/receipt-origin-proof.php','scripts/receipt-runtime-contract.php','scripts/receipt-composition-http.php','scripts/receipt-native-setup.php','scripts/receipt-native-extra.php','scripts/receipt-demo-smoke.php'];
const sources=files.map(file=>({file,sha256:hash(file)}));for(const base of [root,demo])for(const file of files.filter(f=>!f.startsWith('scripts/')))assert.equal(hash(path.join(base,'app',file)),hash(file));
const parallelSourceChanges=[];const bundle=read(path.join(demo,'bundle/manifest.json'));assert.equal(hash(path.join(root,'bundle/manifest.json')),hash(path.join(demo,'bundle/manifest.json')));for(const [file,pin]of Object.entries(bundle.files)){assert.equal(hash(path.join(demo,'bundle',file)),pin);const native=file.startsWith('app/')?path.join('../compras',file):path.join('../compras/vendor/laravel/fortify/src',file.slice(8));if(hash(native)!==bundle.originals[file]){assert.equal(file,'app/Http/Controllers/GoodsReceiptController.php');parallelSourceChanges.push({file,archived_sha256:bundle.originals[file],current_sha256:hash(native),used_by_adapter:false,preserved_without_changes:true});}}
const writer='packages/inventory-write/releases/0.1.0/manifest.json';for(const base of [root,demo])assert.equal(hash(path.join(base,'app',writer)),'f0b99e591f9a4df135e685f64ceffad77bed259222debe0f34c20f95e3cad800');
const prior=['docs/proofs/requisition-composition-20261103.json','docs/proofs/stock-period-batches-20261103.json','docs/proofs/stock-prefix-stream-20261103.json','docs/proofs/module-association-consolidation-summary-20261102.json','docs/proofs/common-ledger-stock-valuation-20261103.json'].map(file=>({file,sha256:hash(file)}));const association=read(prior[3].file);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 old=read(prior[4].file),oldDemo=path.join(state.root,'private/stock-ledger-cf1b85f9a040/bundle');assert.equal(hash(path.join(oldDemo,'manifest.json')),old.demo.pinned_common_manifest_sha256);for(const [file,pin]of Object.entries(read(path.join(oldDemo,'manifest.json')).files))assert.equal(hash(path.join(oldDemo,file)),pin);const pointer=read('packages/purchasing/current.json');assert.equal(pointer.version,'0.1.1');
const out='docs/proofs/receipt-composition-20261103.json';assert(!fs.existsSync(out));fs.writeFileSync(out,JSON.stringify({date:new Date().toISOString(),increment:'SGF-RECEIPT-WORKFLOW-QA-v1',functional_code:true,passed:true,checks:68,tests,sources,native_workflow:{original_source:'../compras/app/Services/ReceiptWorkflow.php',original_sha256:bundle.originals['app/Services/ReceiptWorkflow.php'],namespace_only_bundle_manifest_sha256:hash(path.join(demo,'bundle/manifest.json')),files_verified:Object.keys(bundle.files).length,business_rules_reimplemented:false,parallel_source_changes:parallelSourceChanges,writer_manifest_sha256:'f0b99e591f9a4df135e685f64ceffad77bed259222debe0f34c20f95e3cad800'},demo:{url:'http://127.0.0.1:8064/qa/enter/actor?open=1',reader_url:'http://127.0.0.1:8064/qa/enter/validator?open=1',issuer_url:'http://127.0.0.1:8064/qa/enter/issuer?open=1',initial_receipts:0,initial_movements:0,port:8064,synthetic_only:true},qa_rights:['purchasing_receipts.view','purchasing_receipts.confirm'],prior_proofs_preserved:prior,preservation:{installed_purchasing_pointer_sha256:hash('packages/purchasing/current.json'),old_stock_demo_manifest_sha256:hash(path.join(oldDemo,'manifest.json')),protected_six_records_changed:false,blocked_cache_cleared:false,real_rights_changed:false,existing_demos_written:false,destination_migrated:false,purchasing_activated_at_destination:false,publication:false,checkpoint:false},selected_evidence_reuse:{first_21:hash(path.join(root,'partial-accepted.json')),first_29:hash(path.join(root,'complete-accepted.json')),failed_attempts_preserved:true,causes:['Foreign warehouse was rejected422 by the original tenant validator; harness initially expected403.','Final assertion used supplier_invoices instead of the native invoices table.'],accepted_tests_not_repeated:true},limitations:['Explicit local QA identity/order/warehouse binding; no automatic tenant/company/unit equivalence.','Original source is packaged with namespace-only adaptation to coexist with SGF models; one bundle version per process. No general installation or long-lived Octane worker validation.','Host authority is held in a read/lock transaction; all receipt, movement and origin audit writes commit together in the native transaction. Host database has no receipt business copy.','New QA roles own their databases; deployment owner/runtime separation is not validated.','Order and receipt history are server-paginated; stock selector currently exposes at most100 source items and this is not a full catalogue search interface.','No new invoice, payment, accounting recognition, real fiscal emission, stock-cost composition or review of real associations.','No browser visual review, sustained load or deployment capacity evidence.'],deployment_capacity_validated:false,visual_review_pending:true},null,2)+'\n');console.log(JSON.stringify({output:out,passed:true,checks:68,demo_port:8064}));