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

15 lines
8.0 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-direct-cost-20261103.json';if(state.port!==55439||fs.existsSync(output))throw Error('Fresh owned consolidation required');
const names={actual_workflow:'ledger-6d0ea9e319e0/cost-workflow.json',defaults:'ledger-6d0ea9e319e0/cost-defaults.json',regression:'ledger-6c9ec47c310e/cost-cases.json',security:'ledger-6c9ec47c310e/cost-security.json',actual_http:'ledger-6c9ec47c310e/cost-http.json',http_final:'ledger-6c9ec47c310e/cost-http-final.json',ui_postcheck:'ledger-6c9ec47c310e/cost-ui-postcheck.json',concurrency:'ledger-5e566833f610/cost-race.json',team_http_and_forms:'ledger-6a73790314ce/cost-demo-http.json',team_preservation:'ledger-6a73790314ce/cost-demo-preservation.json',supplier_writer_compatibility:'ledger-a6f36429ef4f/ledger-cases.json',sales_compatibility:'ledger-7dabce07b0c3/cost-extension-sales-compatibility.json',native_uncomposed_refusal:'ledger-native-c5ff3a6aa5a3/cost-capability-refusal.json',cost_supplier_coexistence:'ledger-3eafd03c8c3a/cost-coexistence.json'};
const tests={},evidence=[];for(const [key,file]of Object.entries(names)){const p=path.join(state.root,'private',file),v=read(p);if(!v.passed)throw Error('Unsuccessful cost evidence '+key);tests[key]=v;evidence.push({file:'private/'+file,sha256:sha(p)});}
if(tests.regression.checks!==27||tests.security.checks!==10||tests.actual_http.checks!==51||tests.concurrency.workers!==6||tests.team_http_and_forms.checks!==22||tests.actual_workflow.debit_minor!==27500||tests.defaults.default_without_environment!==false||tests.cost_supplier_coexistence.debit_minor!==33500)throw Error('Expected authorised cost coverage missing');
const priorFiles=['docs/proofs/common-ledger-reports-20261103.json','docs/proofs/common-ledger-sales-receivable-20261103.json','docs/proofs/common-finance-bundle-20261103.json','docs/proofs/common-ledger-complete-cycle-20261102.json'];let preserved=0;for(const file of priorFiles){const prior=read(file);for(const f of prior.private_evidence??prior.evidence??[]){const p=path.resolve(state.root,f.file);if(!p.startsWith(path.resolve(state.root)+path.sep)||sha(p)!==f.sha256)throw Error('Previous valid artifact changed '+f.file);preserved++;}}
const approvedFile='private/ledger-cost-approved-scope.md',approved=sha(path.join(state.root,approvedFile)),expected=read(priorFiles[0]).next_scope.sha256;if(approved!==expected)throw Error('Approved scope does not match presented proposal');evidence.push({file:approvedFile,sha256:approved});
const packages=[];for(const [tag,pin,count]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!==count)throw Error('Frozen package mismatch');for(const f of m.files)if(sha(path.join(root,f.file))!==f.sha256)throw Error('Frozen runtime changed');packages.push({files:count,manifest_sha256:pin,all_hashes_preserved:true,cost_extension_not_installed:true});}
const sources=['AGENTS.md','config/cost_ledger.php','app/Shared/Testing/TestingDatabaseGuard.php','app/Modules/Workshop/DirectCosts.php','app/Modules/Purchasing/SupplierPayables.php','app/Modules/Accounting/GeneralLedger.php','app/Modules/Accounting/GeneralLedgerController.php','app/Modules/Accounting/CostLedgerController.php','app/Modules/Accounting/CostLedgerSource.php','packages/general-ledger/bootstrap.php','packages/general-ledger/README.md',...['LedgerSchema','CycleSchema','CostSchema','PayableJournal','LedgerCycle','LedgerSales','LedgerReports','ReportsWorkspace'].map(n=>'packages/general-ledger/src/'+n+'.php'),'packages/general-ledger/ui/reports.php','resources/views/accounting/general-ledger.blade.php','resources/views/accounting/cost-ledger.blade.php','resources/views/accounting/cost-demo-entry.blade.php','routes/web.php','scripts/payable-history-sgf-proof.php','scripts/ledger-run.mjs','scripts/ledger-sales-proof.php','scripts/ledger-cycle-native-proof.php',...fs.readdirSync('scripts').filter(n=>n.startsWith('ledger-cost-')).map(n=>'scripts/'+n),'scripts/archive-ledger-cost-scope.mjs','scripts/summarize-ledger-cost.mjs','docs/GENERAL_LEDGER_DIRECT_COST_SCOPE.md','docs/GENERAL_LEDGER_DIRECT_COST_DELIVERY.md','docs/GENERAL_LEDGER_DIRECT_COST_CORRECTION_SCOPE.md','README.md','docs/PRODUCT_DEMO.md','docs/SGF_MODULE_FLOW_PREPARATION.md'];let php=0,js=0;
for(const file of sources){if(file.endsWith('.blade.php')||(!file.endsWith('.php')&&!file.endsWith('.mjs')))continue;const isPhp=file.endsWith('.php'),r=spawnSync(isPhp?'C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe':process.execPath,[isPhp?'-l':'--check',file],{encoding:'utf8',windowsHide:true});if(r.status!==0)throw Error('Syntax failed '+file);isPhp?php++:js++;}
for(const cwd of [process.cwd(),path.resolve('../compras')])if(spawnSync('git',['diff','--check'],{cwd,encoding:'utf8',windowsHide:true}).status!==0)throw Error('Diff check failed '+cwd);
const demo=read(path.join(state.root,'private/ledger-6a73790314ce/cost-demo.json')),r=await fetch(demo.url,{signal:AbortSignal.timeout(5000)});if(!r.ok||!(await r.text()).includes('data-cost-demo="'+demo.tag+'"'))throw Error('Team cost demo unavailable');
const result={increment:'COMMON-LEDGER-DIRECT-COST-SIM-v1',consolidated_at_utc:new Date().toISOString(),authorization:{answer:'Autorizar o ciclo sintético proposto',scope_archive_matches_presented_proposal:true,approved_scope_sha256:approved},status:'implemented_and_tested_with_explicit_limits',functional_code:true,synthetic_only:true,tests,evidence,previous_proofs:priorFiles.map(file=>({file,sha256:sha(file)})),previous_private_artifacts_verified:preserved,frozen_native_packages:packages,sources:sources.map(file=>({file,sha256:sha(file)})),quality:{syntax:{php_files:php,javascript_files:js},git_diff_check_both_repositories:true,new_dependencies:false,sgf_phpstan_pint:'not_installed_not_run',native_application_code_unchanged_previous_quality_not_repeated:true},rights:{distinct_ledger_rights:7,ledger_grants_per_standard_cost_fixture:9,existing_cost_and_technical_rights_only:true,real_or_public_grants:0,mixed_supplier_fixture_additional_existing_qa_rights_only:true},source:{actual_workshop_and_cost_workflows:true,known_selected_direct_cost_minor:27500,full_cost_or_margin:false,automatic_outbox_processing:false,identity_stable_per_order_and_selected_perimeter:true,correction_of_already_posted_cost:false},team_demo:demo,preservation:{six_pending_records_untouched:true,blocked_cache_not_cleared:true,existing_demos_not_reset:true,source_history_outbox_preserved:true,existing_valid_proofs_preserved:true,unrelated_work_preserved:true,destination_package_unchanged:true},next_scope:{file:'docs/GENERAL_LEDGER_DIRECT_COST_CORRECTION_SCOPE.md',sha256:sha('docs/GENERAL_LEDGER_DIRECT_COST_CORRECTION_SCOPE.md'),status:'proposal_only_requires_explicit_authorization',implemented:false},limits:{visual_review_pending:true,actual_browser:false,large_volume_load_not_measured:true,deployment_capacity_validated:false,new_indexes:false,all_six_modules_operational_composition:false,real_chart_or_cost_policy:false,stock_valuation_or_posting:false,payroll_or_industrial_cost_posting:false,real_financial_operations:false,cost_correction_or_revaluation:false,reopening:false,destination_migrations_or_grants:false,publication:false,purchasing_activation:false,acceptance_presumed:false,checkpoint:false}};
fs.writeFileSync(output,JSON.stringify(result,null,2)+'\n');console.log(JSON.stringify({output,regression_checks:27,security_checks:10,http_checks:51,workers:6,team_checks:22,supplier_assertions:74,mixed_book_minor:33500,previous_artifacts_verified:preserved,syntax:result.quality.syntax,demo:demo.url}));