import assert from 'node:assert/strict'; import test from 'node:test'; import { recoverPathResult } from '../../resources/js/lib/investor-path.ts'; import { serializeFinancialToolsSnapshot } from '../../resources/js/lib/financial-calculators.ts'; const inputs = { budgetPeriod: 'Mensal', loan: { principal: '100000', rate: '0', months: '24', rateType: 'nominal', periodMonths: '1', gracePeriods: '0', upfrontFee: '0', recurringFee: '0', }, breakEven: { fixed: '1000', price: '100', variable: '50' }, funding: { total: '100000', secured: '30000' }, incomes: [{ label: 'Receita QA', amount: '100' }], expenses: [{ label: 'Custo QA', amount: '50' }], }; void test('A/B returned dossier evidence reuses the tool formulas after a JSON round trip', () => { const result = JSON.parse( JSON.stringify({ engine: 'financial-calculators:v1', financial_snapshot: serializeFinancialToolsSnapshot(inputs), }), ); const recovered = recoverPathResult(result); assert.equal(recovered.breakEven.value.breakEvenUnits, '20'); assert.equal(recovered.funding.value.gap, '70000.00'); }); void test('missing or invalid financial evidence stays indeterminate without hiding an independent calculation', () => { const recovered = recoverPathResult({ engine: 'financial-calculators:v1', financial_snapshot: serializeFinancialToolsSnapshot({ ...inputs, breakEven: { fixed: '', price: '100', variable: '50' }, }), }); assert.equal(recovered.breakEven.value, null); assert.equal(recovered.funding.value.gap, '70000.00'); assert.throws( () => recoverPathResult({ engine: 'unknown', financial_snapshot: '{}' }), /Versão/, ); assert.throws( () => recoverPathResult({ engine: 'financial-calculators:v1', financial_snapshot: '{}', }), /Entradas/, ); });