11 lines
6.6 KiB
JavaScript
11 lines
6.6 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'),root=path.join(state.root,'private/report-profile-b7f7d0c1c2c2'),output='docs/proofs/sgf-payable-report-capture-20261103.json';if(state.port!==55439||fs.existsSync(output))throw Error('Fresh isolated report consolidation required');
|
|
const names={clone:'clone.json',initial_profile:'profile-before.json',statistics_only:'profile-analyze.json',baseline_analyzed:'profile-analyzed.json',optimized_final:'profile-final.json',query_plan:'profile-plan.json',regression:'profile-cases.json',http:'profile-http.json',live_command:'profile-command-probe.json',preservation:'profile-preservation.json'},tests={},evidence=[];for(const [key,file]of Object.entries(names)){const p=path.join(root,file),v=read(p);if(!v.passed)throw Error('Incomplete report capture evidence '+key);tests[key]=v;evidence.push({file:path.relative(state.root,p).replaceAll('\\','/'),sha256:sha(p)});}if(tests.regression.checks!==22||tests.http.checks!==17||tests.optimized_final.report.totals.count!==10000||!tests.live_command.same_key_replayed||!tests.preservation.clone_matches_valid_original_business_fingerprint||sha(path.join(root,'baseline.php'))!==tests.clone.baseline_sha256)throw Error('Missing expected regression or archived baseline');
|
|
for(const key of ['totals','known_positions','positions_sha256','windows'])if(JSON.stringify(tests.baseline_analyzed.report[key])!==JSON.stringify(tests.optimized_final.report[key])||JSON.stringify(tests.initial_profile.report[key])!==JSON.stringify(tests.optimized_final.report[key]))throw Error('Financial report content changed');
|
|
const priorFiles=['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/sgf-payable-report-20261102.json','docs/proofs/sgf-payable-paged-read-20261102.json'];let preserved=0;const prior=[];for(const file of priorFiles){const v=read(file);for(const e of v.private_evidence??v.evidence??[]){const p=path.resolve(state.root,e.file);if(!p.startsWith(path.resolve(state.root)+path.sep)||sha(p)!==e.sha256)throw Error('Valid earlier artifact changed '+e.file);preserved++;}prior.push({file,sha256:sha(file),private_artifacts_preserved:true});}
|
|
const frozen=[];for(const [tag,pin,n]of [['760a92655dc1','6a507ea7d708a12a8e526e4c610696d8db84079d18aede470237b65505630e7e',25],['b06aa4315783','cbc4ddbea15f5e396c92bc2e664b973138551928980f334bcf3eb0cf097cacb1',30]]){const r=path.join(state.root,'private/finance-bundle-'+tag),m=read(path.join(r,'manifest.json'));if(sha(path.join(r,'manifest.json'))!==pin||m.files.length!==n)throw Error('Frozen bundle changed');for(const f of m.files)if(sha(path.join(r,f.file))!==f.sha256)throw Error('Frozen runtime changed');frozen.push({files:n,manifest_sha256:pin,preserved:true});}
|
|
const files=['packages/payables/src/HistoricalCapture.php','packages/payables/src/Payables.php','packages/payables/bootstrap.php','app/Modules/Purchasing/SupplierHistoryReceipts.php','app/Modules/Purchasing/SupplierPayables.php','scripts/payable-history-sgf-proof.php','scripts/payable-report-profile-clone.mjs','scripts/payable-report-profile.php','scripts/payable-report-capture-cases.php','scripts/payable-report-capture-http.mjs','scripts/summarize-payable-report-capture.mjs','docs/SGF_PAYABLE_REPORT_CAPTURE_DELIVERY.md','docs/GENERAL_LEDGER_INDUSTRIAL_CORRECTION_SCOPE.md','README.md','docs/SGF_MODULE_FLOW_PREPARATION.md'];let php=0,js=0;for(const file of files){if(!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');
|
|
for(const [url,tag]of [['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('Prior demo unavailable');}
|
|
const result={increment:'SGF-PAYABLE-REPORT-CAPTURE-REUSE-v1',consolidated_at_utc:new Date().toISOString(),functional_optimization:true,synthetic_only:true,tests,targeted_checks:39,additional_live_command_probe:true,private_evidence:evidence,archived_baseline:{file:path.relative(state.root,path.join(root,'baseline.php')).replaceAll('\\','/'),sha256:sha(path.join(root,'baseline.php'))},previous_manifests:prior,previous_private_artifacts_verified:preserved,frozen_bundles:frozen,observed_comparison:{records:10000,windows:100,window_size:100,before_ms:tests.baseline_analyzed.time_ms,after_ms:tests.optimized_final.time_ms,queries_before:tests.baseline_analyzed.queries,queries_after:tests.optimized_final.queries,heap_peak_before:tests.baseline_analyzed.heap_peak_bytes,heap_peak_after:tests.optimized_final.heap_peak_bytes,totals_and_content_hash_identical:true,statistics_effect_separate:true,new_indexes:0},quality:{syntax:{php,js},diff_check_both_repositories:true,unrelated_suites_not_repeated:true},source_files:files.map(file=>({file,sha256:sha(file)})),preservation:{six_pending_records_untouched:true,blocked_cache_untouched:true,prior_demos_not_reset:true,previous_evidence_preserved:true,destination_data_and_statistics_unchanged:true,real_or_public_grants:0,unrelated_work_preserved:true,credentials_private:true},limits:{remaining_report_bottleneck:true,one_valid_sample_per_condition:true,local_activity_not_controlled:true,visual_review_pending:true,sustained_load_validated:false,deployment_capacity_validated:false,source_history_live_sgf_link:false,purchasing_activation:false,publication:false,checkpoint:false,acceptance_presumed:false},next_scope:{file:'docs/GENERAL_LEDGER_INDUSTRIAL_CORRECTION_SCOPE.md',sha256:sha('docs/GENERAL_LEDGER_INDUSTRIAL_CORRECTION_SCOPE.md'),status:'proposal_only_authorization_required'}};
|
|
fs.writeFileSync(output,JSON.stringify(result,null,2)+'\n');console.log(JSON.stringify({output,checks:39,previous_artifacts_verified:preserved,syntax:result.quality.syntax,before_ms:result.observed_comparison.before_ms,after_ms:result.observed_comparison.after_ms}));
|