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

12 lines
7.5 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-reports-20261103.json';if(state.port!==55439||fs.existsSync(output))throw Error('Fresh owned consolidation required');
const names={sgf_seed:'ledger-217b04d4fc64/ledger-reports-seed.json',native_seed:'ledger-native-9be03d75ee37/ledger-reports-seed.json',sgf_service:'ledger-217b04d4fc64/ledger-reports-cases.json',native_service:'ledger-native-9be03d75ee37/ledger-reports-cases.json',sgf_http:'ledger-217b04d4fc64/ledger-reports-http.json',native_http:'ledger-native-9be03d75ee37/ledger-reports-http.json',sgf_isolation:'ledger-217b04d4fc64/ledger-reports-isolation.json',native_isolation:'ledger-native-9be03d75ee37/ledger-reports-isolation.json',actual_sales_cycle:'ledger-7dabce07b0c3/ledger-reports-reconcile.json',actual_mixed_sources:'ledger-7a94f1f4fe7d/ledger-reports-reconcile.json',actual_native_complete_cycle:'ledger-native-717011443eb8/ledger-reports-reconcile.json',packaged_runtime:'ledger-native-be2ea10293ea/ledger-reports-package.json',packaged_report_after_capability_guard:'ledger-native-be2ea10293ea/ledger-reports-reconcile.json',frozen_previous_package_refusal:'ledger-native-be2ea10293ea/ledger-reports-old-package-postcheck.json',team_readiness:'ledger-reports-demo-readiness.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 report evidence '+key);tests[key]=v;evidence.push({file:'private/'+file,sha256:sha(p)});}
if(tests.sgf_service.checks!==21||tests.native_service.checks!==21||tests.sgf_http.checks!==21||tests.native_http.checks!==20||tests.sgf_isolation.checks!==8||tests.native_isolation.checks!==8||tests.actual_sales_cycle.debit_minor!==240000||tests.actual_mixed_sources.debit_minor!==106000||tests.actual_native_complete_cycle.debit_minor!==22000)throw Error('Expected report coverage missing');
const priorPaths=['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 priorPaths){const p=read(file);for(const f of p.private_evidence??p.evidence??[]){const absolute=path.resolve(state.root,f.file);if(!absolute.startsWith(path.resolve(state.root)+path.sep)||sha(absolute)!==f.sha256)throw Error('Previous valid evidence changed '+f.file);preserved++;}}
const artifact=read(path.join(state.root,'finance-bundle-latest.json'));if(artifact.tag!=='b06aa4315783'||artifact.manifest_sha256!==tests.packaged_runtime.pinned_manifest_sha256)throw Error('Report package mismatch');const verifyArtifact=(root,pin)=>{if(sha(path.join(root,'manifest.json'))!==pin)throw Error('Pinned manifest changed');const m=read(path.join(root,'manifest.json'));for(const f of m.files)if(sha(path.join(root,f.file))!==f.sha256)throw Error('Pinned file changed');return m.files.length;};const newFiles=verifyArtifact(artifact.root,artifact.manifest_sha256),oldFiles=verifyArtifact(path.join(state.root,'private/finance-bundle-760a92655dc1'),'6a507ea7d708a12a8e526e4c610696d8db84079d18aede470237b65505630e7e');if(newFiles!==30||oldFiles!==25)throw Error('Unexpected package contents');
const sources=['packages/general-ledger/bootstrap.php','packages/general-ledger/README.md','packages/general-ledger/src/PayableJournal.php','packages/general-ledger/src/LedgerReports.php','packages/general-ledger/src/ReportsWorkspace.php','packages/general-ledger/ui/reports.php','packages/general-ledger/ui/cycle.php','app/Modules/Accounting/GeneralLedger.php','app/Modules/Accounting/GeneralLedgerController.php','resources/views/accounting/general-ledger.blade.php','routes/web.php','../compras/app/Services/GeneralLedger.php','../compras/app/Http/Controllers/GeneralLedgerController.php','../compras/routes/web.php','scripts/ledger-proof.php','scripts/ledger-sales-proof.php','scripts/ledger-http-entry.php','scripts/ledger-cycle-native-proof.php',...fs.readdirSync('scripts').filter(n=>n.startsWith('ledger-reports-')).map(n=>'scripts/'+n),'scripts/summarize-ledger-reports.mjs','docs/GENERAL_LEDGER_REPORTS_DELIVERY.md','docs/GENERAL_LEDGER_DIRECT_COST_SCOPE.md','README.md','docs/PRODUCT_DEMO.md','docs/SGF_MODULE_FLOW_PREPARATION.md','../compras/docs/relatorios-contabilisticos-ensaio.md','../compras/docs/desenvolvimento.md','../compras/docs/orientacoes-continuidade.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');
const result={increment:'COMMON-LEDGER-REPORTS-SIM-v1',consolidated_at_utc:new Date().toISOString(),functional_code:true,read_only_capability:true,new_business_effect_types:0,new_rights:0,new_dependencies:false,tests,evidence,previous_proofs:priorPaths.map(file=>({file,sha256:sha(file)})),previous_private_artifacts_verified:preserved,distribution:{new_artifact:{files:newFiles,manifest_sha256:artifact.manifest_sha256,qa_only:true,runtime_and_ui_from_package_proven:true},previous_artifact:{files:oldFiles,all_pinned_hashes_preserved:true},destination_package_replaced:false},quality:{syntax:{php_files:php,javascript_files:js},native_phpstan:{passed:true,level:7,errors:0,files:['app/Services/GeneralLedger.php','app/Http/Controllers/GeneralLedgerController.php'],single_canonical_autoload:true,private_cache:true},native_pint:{passed:true,same_two_files:true},sgf_phpstan_pint:'not_installed_not_run',git_diff_check_both:true},sources:sources.map(file=>({file,sha256:sha(file)})),scope:{posted_journals_only:true,dates_inclusive:true,page_sizes:[25,100],server_side_aggregation:true,running_balance_before_pagination:true,trial_balance_report_queries:3,authorization_and_schema_queries_additional:true,missing_capability_or_schema_status:503},preservation:{six_pending_records_untouched:true,blocked_cache_not_cleared:true,existing_demos_not_reset:true,existing_valid_proofs_preserved:true,unrelated_work_preserved:true,real_or_public_rights_unchanged:true},next_scope:{file:'docs/GENERAL_LEDGER_DIRECT_COST_SCOPE.md',sha256:sha('docs/GENERAL_LEDGER_DIRECT_COST_SCOPE.md'),status:'proposal_only_requires_explicit_authorization',implemented:false},limits:{visual_review_pending:true,browser_automation:false,deployment_capacity_validated:false,new_large_volume_benchmarks:false,new_indexes:false,legal_financial_statements:false,stock_cost_payroll_accounting:false,real_operations:false,destination_migrations:false,publishing:false,purchasing_activation:false,checkpoint:false,acceptance_presumed:false}};
fs.writeFileSync(output,JSON.stringify(result,null,2)+'\n');console.log(JSON.stringify({output,service_checks:tests.sgf_service.checks+tests.native_service.checks,http_checks:tests.sgf_http.checks+tests.native_http.checks,isolation_checks:16,reconciliation_checks:18,packaged_checks:tests.packaged_runtime.checks,previous_artifacts_verified:preserved,syntax:result.quality.syntax}));