Files
SGF/scripts/summarize-ledger-industrial-correction.mjs
2026-11-04 09:37:20 +02:00

14 lines
9.4 KiB
JavaScript

import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';import {spawnSync} from 'node:child_process';
const read=p=>JSON.parse(fs.readFileSync(p,'utf8').replace(/^\uFEFF/,'')),sha=p=>crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex'),state=read('C:/laragon/data/sgf-tempo/run/modular-regression-current.json'),output='docs/proofs/common-ledger-industrial-correction-20261103.json';if(state.port!==55439||fs.existsSync(output))throw Error('Fresh isolated industrial correction consolidation required');
const names={actual_owner_setup:'ledger-a3c69acf5a50/industrial-correction-fixture.json',actual_industrial_pair:'ledger-a3c69acf5a50/industrial-correction-workflow.json',regression:'ledger-a3c69acf5a50/industrial-correction-cases.json',security:'ledger-a3c69acf5a50/industrial-correction-security.json',fully_eligible_foreign_contexts:'ledger-d55f5fc71dcb/industrial-correction-deep-scope.json',actual_http:'ledger-d55f5fc71dcb/industrial-correction-http.json',three_pair_domains:'ledger-d55f5fc71dcb/industrial-correction-coexistence.json',joint_workflow:'ledger-d55f5fc71dcb/composition-workflow.json',joint_final:'ledger-d55f5fc71dcb/industrial-correction-final.json',concurrency:'ledger-5b49607829f9/industrial-correction-race.json',concurrency_final:'ledger-5b49607829f9/industrial-correction-final.json',team_http_forms:'ledger-61b694d72ae4/industrial-correction-demo-http.json',team_before:'ledger-61b694d72ae4/industrial-correction-demo-preservation.json',team_after:'ledger-61b694d72ae4/industrial-correction-demo-post.json',old8058_preservation:'ledger-072ef8124ab4/industrial-demo-after-correction.json'};const tests={},evidence=[];for(const [name,file]of Object.entries(names)){const p=path.join(state.root,'private',file),v=read(p);if(!v.passed)throw Error('Incomplete final correction evidence '+name);tests[name]=v;evidence.push({file:'private/'+file,sha256:sha(p)});}
if(tests.regression.checks!==31||tests.security.checks!==7||tests.fully_eligible_foreign_contexts.checks!==4||tests.actual_http.checks!==51||tests.three_pair_domains.checks!==6||tests.joint_workflow.combined_checks!==33||tests.team_http_forms.checks!==23||tests.concurrency.workers!==6||tests.joint_final.gross_minor!==872500||tests.joint_final.industrial_closing_minor!==182000||!tests.team_after.source_original_outbox_rights_exact)throw Error('Expected industrial correction coverage missing');
// Correct an inherited label in the public view; the original private proof remains byte-for-byte preserved.
delete tests.security.four_live_rights_revalidated;tests.security.capture_rights_revalidated=['industrial_costs.view','general_ledger.view','general_ledger.correct_prepare'];tests.security.post_right_revocation_covered_in_main_regression=true;tests.team_http_forms.initial_industrial_journals=tests.team_http_forms.initial_journals;delete tests.team_http_forms.initial_journals;tests.team_http_forms.initial_company_journals=2;
const priorFiles=['docs/proofs/sgf-payable-report-capture-20261103.json','docs/proofs/common-ledger-industrial-20261103.json','docs/proofs/common-ledger-composition-20261103.json','docs/proofs/common-ledger-direct-cost-correction-20261103.json','docs/proofs/common-ledger-direct-cost-20261103.json','docs/proofs/common-ledger-sales-receivable-20261103.json','docs/proofs/common-ledger-complete-cycle-20261102.json'];const prior=[];let preserved=0;for(const file of priorFiles){const old=read(file);for(const e of old.private_evidence??old.evidence??[]){const p=path.resolve(state.root,e.file);if(!p.startsWith(path.resolve(state.root)+path.sep)||sha(p)!==e.sha256)throw Error('Previously valid artifact changed '+e.file);preserved++;}prior.push({file,sha256:sha(file),private_artifacts_preserved:true});}
const archive='private/ledger-industrial-correction-approved-scope.md',approvedHash=sha(path.join(state.root,archive));if(approvedHash!==read(priorFiles[0]).next_scope.sha256)throw Error('Scope differs from approved presented proposal');evidence.push({file:archive,sha256:approvedHash});const frozen=[];for(const [tag,pin,n]of [['760a92655dc1','6a507ea7d708a12a8e526e4c610696d8db84079d18aede470237b65505630e7e',25],['b06aa4315783','cbc4ddbea15f5e396c92bc2e664b973138551928980f334bcf3eb0cf097cacb1',30]]){const root=path.join(state.root,'private/finance-bundle-'+tag),m=read(path.join(root,'manifest.json'));if(sha(path.join(root,'manifest.json'))!==pin||m.files.length!==n)throw Error('Frozen bundle changed');for(const f of m.files)if(sha(path.join(root,f.file))!==f.sha256)throw Error('Frozen runtime changed');frozen.push({files:n,manifest_sha256:pin,all_bytes_preserved:true});}
const files=['AGENTS.md','config/industrial_ledger.php','app/Modules/Accounting/IndustrialLedgerSource.php','app/Modules/Accounting/GeneralLedger.php','packages/general-ledger/bootstrap.php','packages/general-ledger/README.md',...['IndustrialCorrectionSchema','PayableJournal','LedgerCycle'].map(n=>'packages/general-ledger/src/'+n+'.php'),'packages/general-ledger/ui/cycle.php','resources/views/accounting/industrial-ledger.blade.php','resources/views/accounting/industrial-correction.blade.php','resources/views/accounting/industrial-correction-demo-entry.blade.php','resources/views/accounting/general-ledger.blade.php','resources/views/accounting/cost-ledger.blade.php','scripts/payable-history-sgf-proof.php','scripts/ledger-cost-proof.php','scripts/ledger-industrial-proof.php','scripts/ledger-cost-http-entry.php','scripts/ledger-composition-workflow.php','scripts/ledger-run.mjs',...fs.readdirSync('scripts').filter(n=>n.startsWith('ledger-industrial-correction-')).map(n=>'scripts/'+n),'scripts/summarize-ledger-industrial-correction.mjs','docs/GENERAL_LEDGER_INDUSTRIAL_CORRECTION_SCOPE.md','docs/GENERAL_LEDGER_INDUSTRIAL_CORRECTION_DELIVERY.md','docs/GENERAL_LEDGER_INDUSTRIAL_DELIVERY.md','README.md','docs/PRODUCT_DEMO.md','docs/SGF_MODULE_FLOW_PREPARATION.md','docs/integration/sgf-flow-plan.json'];let php=0,js=0;for(const file of files){if(file.endsWith('.blade.php')||(!file.endsWith('.php')&&!file.endsWith('.mjs')))continue;const p=file.endsWith('.php'),r=spawnSync(p?'C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe':process.execPath,[p?'-l':'--check',file],{windowsHide:true,encoding:'utf8'});if(r.status!==0)throw Error('Syntax failed '+file);p?php++:js++;}for(const cwd of [process.cwd(),path.resolve('../compras')])if(spawnSync('git',['diff','--check'],{cwd,windowsHide:true,encoding:'utf8'}).status!==0)throw Error('Diff check failed');
const team=read(path.join(state.root,'private/ledger-61b694d72ae4/cost-demo.json'));for(const [url,tag]of [[team.url,team.tag],['http://127.0.0.1:8058/qa/cost-demo','072ef8124ab4'],['http://127.0.0.1:8057/qa/cost-demo','fe42e1169ce6']]){const r=await fetch(url,{signal:AbortSignal.timeout(15000)});if(!r.ok||!(await r.text()).includes('data-cost-demo="'+tag+'"'))throw Error('Expected preserved demo unavailable');}
const graphFile='docs/proofs/module-flow-industrial-correction-update-20261103.json',graph=read(graphFile);if(!graph.checks.mandatory_dependency_graph_acyclic||graph.preservation.database_connections!==0)throw Error('Invalid static inventory');
const result={increment:'COMMON-LEDGER-INDUSTRIAL-CORRECTION-SIM-v1',consolidated_at_utc:new Date().toISOString(),authorization:{answer:'Autorizar a correcção industrial sintética proposta',approved_scope_archive_sha256:approvedHash,matches_presented_proposal:true},functional_code:true,synthetic_only:true,status:'implemented_and_tested_with_limits',targeted_checks:155,form_vm_checks:5,concurrency_workers:6,tests,private_evidence:evidence,metadata_notes:['The inherited four_live_rights_revalidated label was replaced with the exact three capture rights in the public view; correct_post revocation is tested in the main regression. Original private evidence is unmodified.','Team initial_industrial_journals is1; the initial company book contains2 journals.'],previous_manifests:prior,previous_private_artifacts_verified:preserved,frozen_bundles:frozen,quality:{syntax:{php,js},diff_check_both_repositories:true,unrelated_suites_not_repeated:true},source_files:files.map(file=>({file,sha256:sha(file)})),static_inventory:{file:graphFile,sha256:sha(graphFile),modules:6,stages:13,sources:33,mandatory_cycles:0,database_connections:0,operational_validation:false},team_demo:team,observed_result:{industrial_journals:3,industrial_lines:6,industrial_gross_minor:542000,industrial_closing_minor:182000,residual_exact:'300',residual_not_posted:true,joint_journals:11,joint_lines:23,joint_gross_minor:872500,joint_closures:1,client_balance_minor:40000,direct_cost_balance_minor:29500,supplier_balance_minor:6000},preservation:{old8058_flag_off_and_schema_absent:true,old8058_source_outbox_rights_and_three_provider_packet_exact:true,six_pending_records_untouched:true,blocked_cache_untouched:true,prior_demos_not_reset:true,unrelated_work_preserved:true,credentials_private:true,destination_unchanged:true},limits:{visual_review_pending:true,actual_browser:false,large_volume_benchmarks:false,deployment_capacity_validated:false,all_six_modules_operationally_complete:false,additional_correction_chains:false,closed_period_correction_or_reopening:false,stock_valuation_payroll_or_residual_posting:false,new_payments_or_receipts:false,destination_migrations_or_grants:false,purchasing_activation:false,publication:false,checkpoint:false,acceptance_presumed:false}};
fs.writeFileSync(output,JSON.stringify(result,null,2)+'\n');console.log(JSON.stringify({output,checks:155,workers:6,previous_artifacts_verified:preserved,syntax:result.quality.syntax,demo:team.url}));