Files
Investidor-V2/tools/portal-path-result-qa.mjs
T
nala 6ddafc95ba
tests / ci (push) Canceled after 0s
oportunidades 4
2026-10-10 07:03:59 +02:00

47 lines
3.0 KiB
JavaScript

// Recalculate actual frozen evidence recovered by HTTP, without UI or database writes.
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { recoverPathResult } from '../resources/js/lib/investor-path.ts';
const directory = new URL('../storage/app/private/investmoz-v2/portal-audit/', import.meta.url);
const http = JSON.parse(fs.readFileSync(new URL('investor-path-http-qa.json', directory), 'utf8'));
assert.match(http.target.database, /^desk_restore_\d{8}_\d{6}_test$/);
assert.equal(http.target.port, 55441);
assert.equal(http.api_persistence_passed, true);
const results = http.scenarios.map(scenario => {
const result = recoverPathResult(scenario.recovered_financial_result);
assert.equal(result.breakEven.value.breakEvenUnits, String(scenario.expected_break_even_units));
assert.equal(result.funding.value.gap, scenario.expected_funding_gap.toFixed(2));
return {scenario: scenario.scenario, case_id: scenario.id, result_id: scenario.result_id,
units: result.breakEven.value.breakEvenUnits, funding_gap: result.funding.value.gap, ui_verified: false};
});
const incompatible = [];
for (const filename of fs.readdirSync(directory).filter(name => /^investor-path-http-qa-\d.*\.json$/.test(name))) {
const previous = JSON.parse(fs.readFileSync(new URL(filename, directory), 'utf8'));
for (const scenario of previous.scenarios ?? []) {
const result = scenario.recovered_financial_result;
const current = http.scenarios.find(item => item.id === scenario.id);
if (!result || !current?.prior_result_ids_preserved.includes(result.id) || incompatible.includes(result.id)) continue;
const snapshot = JSON.parse(result.financial_snapshot);
if (snapshot.data.incomes.length || snapshot.data.expenses.length) continue;
assert.throws(() => recoverPathResult(result), /Entradas incompatíveis/);
incompatible.push(result.id);
}
}
const proof = {captured_at: new Date().toISOString(), target: http.target, results, passed: true,
source: 'Actual frozen financial result recovered after a new authenticated HTTP session',
preserved_incompatible_prior_results: incompatible,
engine: 'financial-calculators:v1', interface_observed: false, active_writes: 0};
const mfaFile = new URL('mfa-http-qa.json', directory);
if (fs.existsSync(mfaFile)) {
const mfa = JSON.parse(fs.readFileSync(mfaFile, 'utf8'));
assert.deepEqual(mfa.target, http.target);
assert.equal(mfa.login_mfa_logout_new_session_passed, true);
const result = recoverPathResult(mfa.scenario_A.recovered_financial_result);
assert.equal(result.breakEven.value.breakEvenUnits, '20');
assert.equal(result.funding.value.gap, '0.00');
proof.mfa_scenario_A = {case_id: mfa.scenario_A.id, result_id: mfa.scenario_A.result_id,
units: '20', funding_gap: '0.00', source: 'Recovered after a new MFA-authenticated HTTP session', ui_verified: false};
}
fs.writeFileSync(new URL('investor-path-recovered-calculations.json', directory), JSON.stringify(proof, null, 2));
console.log(JSON.stringify(proof));