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

12 lines
5.1 KiB
JavaScript

import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';import assert from 'node:assert/strict';
const state=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),root=path.join(state.root,'private/stock-prefix-248a2edca17f'),hash=f=>crypto.createHash('sha256').update(fs.readFileSync(f)).digest('hex'),read=f=>JSON.parse(fs.readFileSync(f)),out='docs/proofs/stock-prefix-stream-20261103.json';assert(!fs.existsSync(out));
const selectedFile=path.join(root,'prefix-review-safe.json'),contextFile=path.join(root,'prefix-context-current.json'),planFile=path.join(root,'prefix-plan.json'),selected=read(selectedFile),context=read(contextFile),plans=read(planFile);assert(selected.passed&&context.passed&&plans.passed);assert.equal(selected.checks.length,43);assert.equal(context.checks.length,5);
const old=read('docs/proofs/common-ledger-stock-valuation-20261103.json'),reference=read(path.join(root,'settings.json')).reference;assert.equal(reference.source_sha256,old.sources.find(s=>s.file==='packages/general-ledger/src/StockValuation.php').sha256);assert.equal(hash(path.join(root,'StockValuationBaseline.php')),reference.baseline_sha256);
const median=a=>[...a].sort((a,b)=>a-b)[Math.floor(a.length/2)];const metrics=selected.metrics.map(m=>{const row={prefix_records:m.prefix_records};for(const variant of ['before','after']){const samples=m.samples[variant];assert(samples.every(s=>s.digest===m.samples.before[0].digest));row[variant]={median_ms:median(samples.map(s=>s.elapsed_ms)),queries:[...new Set(samples.map(s=>s.queries))],max_incremental_peak_php_bytes:Math.max(...samples.map(s=>s.incremental_peak_php_bytes)),max_result_rows:Math.max(...samples.map(s=>s.max_result_rows)),evidence_bytes:samples[0].evidence_bytes,samples};}assert(row.after.max_result_rows<=500);return row;});
const proof=f=>({file:'private/stock-prefix-248a2edca17f/'+path.basename(f),sha256:hash(f)});
const sourceFiles=['packages/general-ledger/src/StockValuation.php','scripts/stock-prefix-proof.php','scripts/stock-prefix-context.php','scripts/stock-prefix-plan.php','scripts/stock-prefix-run.mjs'];const sources=sourceFiles.map(file=>({file,sha256:hash(file)}));
const priorFiles=['docs/proofs/common-ledger-stock-valuation-20261103.json','docs/proofs/module-association-consolidation-summary-20261102.json','docs/proofs/requisition-composition-20261103.json'];const preserved=priorFiles.map(file=>({file,sha256:hash(file)}));const association=read(priorFiles[1]);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 demo=path.join(state.root,'private/stock-ledger-cf1b85f9a040/bundle'),bundle=read(path.join(demo,'manifest.json'));for(const [file,pin]of Object.entries(bundle.files))assert.equal(hash(path.join(demo,file)),pin);assert.equal(hash(path.join(demo,'manifest.json')),old.demo.pinned_common_manifest_sha256);
const nodes=p=>{const list=[];const visit=n=>{list.push({type:n['Node Type'],join:n['Join Type']??null,relation:n['Relation Name']??null,index:n['Index Name']??null,estimated_rows:n['Plan Rows']});for(const child of n.Plans??[])visit(child);};visit(p[0].Plan);return list;};
fs.writeFileSync(out,JSON.stringify({date:new Date().toISOString(),increment:'STOCK-PRIOR-STREAM-v1',functional_code:true,passed:true,checks:48,tests:{metadata:{...proof(selectedFile),checks:43,result:selected},transaction:{...proof(contextFile),checks:5,result:context},plan:{...proof(planFile),explain_only:true,comparison:Object.fromEntries(Object.entries(plans.plans).map(([k,v])=>[k,nodes(v)]))}},metrics,reference:{original_source_sha256:reference.source_sha256,private_baseline_sha256:reference.baseline_sha256},sources,prior_proofs_preserved:preserved,preservation:{frozen_demo_bundle_sha256:hash(path.join(demo,'manifest.json')),existing_three_posted_snapshots_byte_equivalent:true,no_existing_record_or_grant_changed:true,no_indices_added:true,new_financial_effects:0,blocked_cache_cleared:false,publication:false,purchasing_activation:false},limitations:['Metadata-only infrastructure fixture; not1000/5000/10000 validated stock movements or a full-page/period load test.','Three warm samples in alternating order, equal read-only repeatable-read transactions. Peak PHP memory excludes PostgreSQL and process RSS.','The deployed/frozen demonstration bundle is preserved, not upgraded by this source change.','Long prefixes use an explicit summary format with all-reference digest and first25 references; accepted three-movement snapshots remain exact.','Total work and query count grow with prefix size; full-page/period batching and deployment capacity remain unvalidated.'],diagnostics_preserved:{partial_instrumentation_run:'prefix-review-selected',cancelled_read_only_text_join_run:'prefix-review-types',other_intermediate_results_kept:true}},null,2));console.log(JSON.stringify({output:out,checks:48,metrics:metrics.map(m=>({prefix:m.prefix_records,before_ms:m.before.median_ms,after_ms:m.after.median_ms,after_peak_bytes:m.after.max_incremental_peak_php_bytes}))}));