Keep PPC PEC estimates and reports consistent with the prepared L6 period
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-14 00:23:46 +02:00
parent e9278ee446
commit 078f770dea
14 changed files with 295 additions and 21 deletions
+22
View File
@@ -0,0 +1,22 @@
import fs from 'node:fs';
import assert from 'node:assert/strict';
import {periodAdvanceCase} from '../tests/frontend/helpers/irpc-advance-period-case.mjs';
import {annualAdvanceCashflow,annualAdvancePeriod,annualBook,annualCurrent,annualHtml,recordAnnual,saveAnnualBook} from '../resources/js/lib/irpc-annual-settlement.ts';
import {createProjectDossierReport} from '../resources/js/lib/project-dossier-report.ts';
const out=new URL('../outputs/irpc-period-consistency-20261113/',import.meta.url);fs.mkdirSync(out,{recursive:true});
for(const name of ['ordinary','noncivil','short','start']){
if(process.argv[2]==='generate'){
const {d,b}=periodAdvanceCase(name);const prior=recordAnnual(d,{...b,ppcObligation:undefined,pecObligation:undefined},'2026-11-13T22:05:00Z');
d.modelo_a_snapshot=saveAnnualBook(d,recordAnnual(d,{...prior,ppcObligation:b.ppcObligation,pecObligation:b.pecObligation},'2026-11-13T22:06:00Z'));fs.writeFileSync(new URL(name+'.json',out),JSON.stringify(d));
}else{
const d=JSON.parse(fs.readFileSync(new URL('recovered-'+name+'.json',out),'utf8')),b=annualBook(d),period=annualAdvancePeriod(d),m=annualAdvanceCashflow(b,period);
assert.equal(annualCurrent(d,b),true);assert.equal(b.history.length,1);assert.deepEqual(b.result.model.arithmeticBalance,b.history[0].model.arithmeticBalance);assert.deepEqual(b.result.model.advancePeriod,period);
if(name==='ordinary')assert.deepEqual(m.total,{numerator:'112000',denominator:'1'});else{assert.equal(m.total,null);assert.equal(m.rows.length,0);}
if(name==='start')assert.equal(m.pecKnown,true);
const html=annualHtml(d),report=createProjectDossierReport(d,{selectedSections:new Set(['finance']),generatedAt:'2026-11-13T22:07:00Z'});
assert.match(html,/Projecção mensal conjunta PPC\/PEC/);assert.match(JSON.stringify(report),/Projecção mensal conjunta PPC\/PEC/);
if(name!=='ordinary'){assert.match(html,/período L6/);assert.ok(!html.includes('Total da projecção: 112000'));}
fs.writeFileSync(new URL(name+'-report.html',out),html);fs.writeFileSync(new URL(name+'-verification.json',out),JSON.stringify({synthetic:true,nativeApiRecovery:true,annualCurrent:true,historyPreserved:true,annualCalculationUnchanged:true,report:true,period,model:m},null,2));
}
}
console.log(process.argv[2]==='generate'?'Generated four synthetic period consistency cases':'Verified four recovered period contexts and reports');
+23
View File
@@ -0,0 +1,23 @@
<?php
$root = dirname(__DIR__);
if (($argv[1] ?? '') !== 'test' || basename($root) !== 'portal-investidor') {
throw new RuntimeException('Explicit isolated QA test operation required');
}
foreach (['APP_ENV' => 'testing', 'APP_KEY' => 'base64:'.base64_encode(str_repeat('Q', 32)),
'APP_CONFIG_CACHE' => $root.'/outputs/irpc-period-consistency-20261113/no-config.php', 'DB_CONNECTION' => 'pgsql', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => '55441',
'DB_DATABASE' => 'investmoz_demography_test', 'DB_USERNAME' => 'demography_qa', 'DB_PASSWORD' => '', 'DB_URL' => '', 'DATABASE_URL' => '',
'CACHE_STORE' => 'array', 'SESSION_DRIVER' => 'array', 'QUEUE_CONNECTION' => 'sync', 'MAIL_MAILER' => 'array', 'SUITECRM_ENABLED' => 'false'] as $key => $value) {
putenv($key.'='.$value);
$_ENV[$key] = $_SERVER[$key] = $value;
}
$pdo = new PDO('pgsql:host=127.0.0.1;port=55441;dbname=investmoz_demography_test', 'demography_qa', '');
$identity = $pdo->query('select current_database(),inet_server_port()')->fetch(PDO::FETCH_NUM);
if ($identity !== ['investmoz_demography_test', 55441] && $identity !== ['investmoz_demography_test', '55441']) {
throw new RuntimeException('Isolated QA identity required');
}
$argv = ['phpunit', '-c', 'phpunit.investmoz.xml', '--do-not-cache-result', 'tests/Feature/IrpcAdvancePeriodDraftTest.php'];
$_SERVER['argv'] = $argv;
$_SERVER['argc'] = count($argv);
require $root.'/vendor/autoload.php';
require $root.'/vendor/phpunit/phpunit/phpunit';