Files
SGF/scripts/summarize-native-payable-page.mjs
T
2026-11-04 09:37:20 +02:00

55 lines
5.9 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import crypto from 'node:crypto';
const read = p => JSON.parse(fs.readFileSync(p, 'utf8').replace(/^\uFEFF/, ''));
const hash = p => crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex');
const state = read('C:/laragon/data/sgf-tempo/run/modular-regression-current.json');
if (state.port !== 55439) throw Error('Isolated regression cluster required');
const root = path.join(state.root, 'private/payable-history-bf3c4eba3d11');
const checksRoot = path.join(state.root, 'private/stock-receipt-5b28d5dfd6a9');
const evidence = [];
const record = p => { evidence.push({ file: path.relative(state.root, p).replaceAll('\\', '/'), sha256: hash(p) }); return p; };
const http = read(record(path.join(root, 'native-page-http.json')));
const preservation = read(record(path.join(root, 'native-page-post.json')));
const concurrency = read(record(path.join(checksRoot, 'native-page-concurrency.json')));
const query_shape = read(record(path.join(checksRoot, 'native-page-query.json')));
const analysis = read(record(path.join(checksRoot, 'native-payable-page-phpstan.json')));
if (!http.passed || !preservation.original_source_stock_and_budget_unchanged || !preservation.one_obligation || preservation.new_paged_read_default !== false || !concurrency.reader_completed_before_writer_release || !concurrency.uncommitted_audit_not_observed || analysis.errors !== 0) throw Error('Evidence incomplete');
const attrs = s => Object.fromEntries([...s.matchAll(/(\w+)="([^"]*)"/g)].map(m => [m[1], m[2]]));
function cases(file) {
const xml = fs.readFileSync(record(file), 'utf8');
return [...xml.matchAll(/<testcase\b[^>]*\/>|<testcase\b[^>]*>[\s\S]*?<\/testcase>/g)].map(m => ({ ...attrs(m[0].match(/^<testcase\b[^>]*>/)[0]), passed: !/<(?:failure|error|skipped)\b/.test(m[0]) }));
}
const feature = cases(path.join(checksRoot, 'native-payable-page-1793646797175-junit.xml'));
if (feature.length !== 9 || feature.some(c => !c.passed)) throw Error('Feature tests incomplete');
const compat = new Map();
for (const tag of ['1d076320ce39', '3732cd3cf3c7']) for (const c of cases(path.join(state.root, `private/stock-receipt-${tag}/native-payable-compat-junit.xml`))) if (c.passed) compat.set(c.name, c);
if (compat.size !== 26) throw Error('Compatibility tests incomplete');
const measurements = [];
for (const volume of [1000, 5000, 10000]) {
const strategies = {};
for (const strategy of ['legacy', 'page25', 'page100', 'invoice']) strategies[strategy] = read(record(path.join(root, `native-bench-${volume}-${strategy}.json`)));
const old = strategies.legacy;
for (const size of [25, 100]) {
const current = strategies[`page${size}`];
if (old.document_fingerprints[size] !== current.document_fingerprints[size] || current.documents !== size || current.indices_added || old.indices_added) throw Error('Page parity failed');
}
if (old.original_position_fingerprint !== strategies.invoice.original_position_fingerprint || strategies.invoice.original_balance_minor !== 3000) throw Error('Financial parity failed');
measurements.push({ volume, strategies });
}
const sgf = 'C:/laragon/www/sgf-tempo', native = 'C:/laragon/www/compras';
const sources = [];
for (const [repo, files] of [[native, ['app/Services/SupplierPayables.php', 'app/Services/SupplierPayablePage.php', 'app/Http/Controllers/SupplierPayablesController.php', 'config/common-payables.php', 'tests/Feature/NativePayablePageTest.php', 'tests/Support/native-payable-page-worker.php', 'tests/Feature/SupplierPayableIntegrationTest.php']], [sgf, ['packages/payables/ui/page.php', 'scripts/native-payable-page-run.mjs', 'scripts/native-payable-page-proof.php', 'scripts/native-payable-page-load.mjs', 'scripts/native-payable-page-http.mjs', 'scripts/native-payable-page-http-router.php', 'scripts/native-payable-page-analyze.mjs', 'scripts/payable-history-sgf-proof.php', 'scripts/stock-receipt-composition.mjs']]]) for (const file of files) sources.push({ repository: repo === native ? 'compras' : 'sgf-tempo', file, sha256: hash(path.join(repo, file)) });
const previous = ['docs/proofs/sgf-payable-paged-read-20261102.json', 'docs/proofs/module-association-http-lock-summary-20261102.json'].map(file => ({ file, sha256: hash(path.join(sgf, file)) }));
const result = {
increment: 'NATIVE-PAYABLE-PAGED-READ-SIM-v1', date: '2026-11-02', synthetic_only: true,
tests: { new: { cases: feature.length, assertions: feature.reduce((n,c) => n + Number(c.assertions), 0) }, affected_compatibility: { distinct_cases: compat.size, assertions: [...compat.values()].reduce((n,c) => n + Number(c.assertions), 0), consolidation: '25 passing initial cases and one corrected target; failed/empty diagnostic runs excluded' } },
http, preservation, concurrency, query_shape, analysis, measurements,
conditions: { php: '8.4.27', memory_limit: '512M', independent_php_process_per_strategy: true, same_point_invoice_warmup: true, samples_per_strategy: 1, strategy_order: ['legacy', 'page25', 'page100', 'invoice'], new_indices: false, workload: 'One actual native workflow invoice with recognised obligation and three historical payments; remaining invoices are explicit unrecognised clones with one line and validation audit. First pages exclude oldest original; exact invoice lookup proves positive financial parity.', memory: 'PHP allocated heap peak; not process RSS', deployment_capacity_validated: false, visual_review: false },
deployment: { native_default_flag: false, installed_native_package_unchanged: true, canonical_common_package_used_only_by_owned_QA: true, old_package_paging_request: '503', new_rights_or_real_migrations: false },
sources, previous, evidence,
};
fs.writeFileSync(path.join(sgf, 'docs/proofs/native-payable-paged-read-20261102.json'), JSON.stringify(result, null, 2) + '\n');
process.stdout.write(JSON.stringify({ tests: result.tests, http: http.checks, measurements: measurements.length, sources: sources.length }) + '\n');