Prepare supplied financial directory with product coverage and native dossier continuity
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import fs from 'node:fs';
|
||||
import assert from 'node:assert/strict';
|
||||
import {compileFunction} from 'node:vm';
|
||||
import {createRequire} from 'node:module';
|
||||
import {createHash} from 'node:crypto';
|
||||
import ts from 'typescript';
|
||||
import React from 'react';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
const require=createRequire(import.meta.url),root=new URL('../',import.meta.url),out=new URL('outputs/funding-directory-20261110/',root);
|
||||
const content=JSON.parse(fs.readFileSync(new URL('content-qa.json',out),'utf8')),dossier=JSON.parse(fs.readFileSync(new URL('dossier-qa.json',out),'utf8'));
|
||||
const records=Object.values(content.records),ids=Object.fromEntries(records.map(r=>[r.id,r.code]));
|
||||
assert.equal(records.length,11);assert.equal(records.filter(r=>r.payload.kind==='institution').length,7);
|
||||
assert.ok(content.cabo_delgado_investment_results.includes('bni'));assert.ok(!content.cabo_delgado_investment_results.includes('fcid-viii'));
|
||||
assert.equal(content.records.bni.payload.products[1].needs[0],'equity');assert.equal(content.records.semeia.payload.windows[0].state,'closed');
|
||||
assert.equal(dossier.recovered.selections.length,1);assert.equal(dossier.recovered.selections[0].title,content.records.bni.payload.title);
|
||||
assert.equal(dossier.no_external_submission,true);
|
||||
const cache={};
|
||||
function load(file){
|
||||
if(cache[file])return cache[file];
|
||||
const module={exports:{}};cache[file]=module.exports;
|
||||
const code=ts.transpileModule(fs.readFileSync(new URL('resources/js/'+file,root),'utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,jsx:ts.JsxEmit.ReactJSX}}).outputText;
|
||||
compileFunction(code,['require','module','exports'])(name=>{
|
||||
if(name==='@inertiajs/react')return {Link:({href,children,...props})=>{let target=href;if(href==='/fundos')target='../catalogo-qa.html';else if(typeof href==='string'&&href.startsWith('/fundos/')){const id=href.split('/')[2].split('?')[0];if(ids[id])target='fichas/'+ids[id]+'.html';}return React.createElement('a',{...props,href:target},children);},useForm:data=>({data,processing:false,setData:()=>{},get:()=>{}}),router:{}};
|
||||
if(name==='@/pages/investment/shared')return {Frame:({title,children})=>React.createElement('main',{},React.createElement('h1',{},title),children),card:'card',button:'button'};
|
||||
if(name==='./shared')return {windowLabels:{closed:'Janela encerrada',unknown:'Janela por confirmar',open:'Segundo datas documentadas'}};
|
||||
if(name==='@/components/funding-institution')return load('components/funding-institution.tsx');
|
||||
if(name==='@/components/funding-dossier-choice')return {};
|
||||
if(name==='@/components/funding-criteria-assessment')return {default:()=>null};
|
||||
return require(name);
|
||||
},module,module.exports);cache[file]=module.exports;return module.exports;
|
||||
}
|
||||
const wrap=body=>'<!doctype html><html lang="pt"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Directório financeiro — revisão QA</title><style>body{font:16px/1.5 system-ui;max-width:1100px;margin:auto;padding:24px;color:#172a29;background:#f5f7f6}.card{background:white;border:1px solid #ccd8d1;border-radius:10px;padding:18px;margin:16px 0}a{color:#006546}label{display:block;margin:8px}input,select{padding:8px;max-width:100%}h2,h3{margin-bottom:8px}article{overflow-wrap:anywhere}</style><p><strong>Revisão QA — conteúdo fornecido; sem publicação na homologação.</strong> Renderização estática dos componentes; não é conferência visual num navegador. Não envia dados ou candidaturas.</p>'+body+'</html>';
|
||||
fs.mkdirSync(new URL('fichas/',out),{recursive:true});
|
||||
const Show=load('pages/funding/show.tsx').default,Index=load('pages/funding/index.tsx').default;
|
||||
for(const record of records){const html=renderToStaticMarkup(React.createElement(Show,{record,saved:null,authenticated:false}));assert.ok(html.includes(record.payload.title.replace(/&/g,'&')));fs.writeFileSync(new URL('fichas/'+record.code+'.html',out),wrap(html));}
|
||||
const catalogue=renderToStaticMarkup(React.createElement(Index,{items:{data:records,links:[]},filters:{},kinds:{institution:'Instituição financeira',fund:'Fundo',programme:'Programa'},management:false,options:{territories:[],sectors:[]},needs:{investment:'Investimento',working_capital:'Fundo de maneio'}}));
|
||||
fs.writeFileSync(new URL('catalogo-qa.html',out),wrap(catalogue));
|
||||
const pkg=JSON.parse(fs.readFileSync(new URL('database/data/funding-references.json',root),'utf8'));
|
||||
assert.equal(Object.keys(pkg.references).length,12);assert.ok(pkg.references.fdel);
|
||||
const proof={provided_source_sha256:content.provided_source_sha256,provided_entries:12,prepared_fiches:11,institutions:7,programmes_or_funds:4,bni_capital:'BNI product; no duplicate institution',headquarters_and_lending_coverage_distinct:true,one_product_must_match_need_and_territory:true,unknowns_explicit:true,fcid_six_provinces:true,semeia_closed:true,dossier_save_recovery_native:true,one_selection_without_duplicate_event:true,withdrawn_public_source_snapshot_retained:true,qa_transactions_rolled_back:true,qa_port:55441,installed:false,live_publication:false,visual_review:'pending; browser connector unavailable',package_data_sha256:createHash('sha256').update(fs.readFileSync(new URL('database/data/funding-references.json',root))).digest('hex')};
|
||||
fs.writeFileSync(new URL('verification.json',out),JSON.stringify(proof,null,2));console.log(JSON.stringify(proof));
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
if (! in_array($argv[1] ?? '', ['test', 'analyse'], true) || basename($root) !== 'portal-investidor') {
|
||||
throw new RuntimeException('Explicit local test operation required.');
|
||||
}
|
||||
$proofDirectory = $root.'/outputs/funding-directory-20261110';
|
||||
if (! is_dir($proofDirectory)) {
|
||||
mkdir($proofDirectory, 0700, true);
|
||||
}
|
||||
$analysisConfiguration = "includes:\n - ../../phpstan.neon\nparameters:\n tmpDir: phpstan-cache\n";
|
||||
if (! is_file($proofDirectory.'/phpstan.neon')) {
|
||||
file_put_contents($proofDirectory.'/phpstan.neon', $analysisConfiguration);
|
||||
}
|
||||
foreach (['APP_ENV' => 'testing', 'APP_KEY' => 'base64:'.base64_encode(str_repeat('Q', 32)),
|
||||
'APP_CONFIG_CACHE' => $root.'/outputs/funding-directory-20261110/no-config.php',
|
||||
'DB_CONNECTION' => 'pgsql', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => '55441',
|
||||
'DB_DATABASE' => 'simulator_fiscal_delta_20261021_test', 'DB_USERNAME' => 'investmoz_test', '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=simulator_fiscal_delta_20261021_test', 'investmoz_test', '');
|
||||
$identity = $pdo->query('select current_database() as name,inet_server_port() as port')->fetch(PDO::FETCH_ASSOC);
|
||||
if ($identity['name'] !== 'simulator_fiscal_delta_20261021_test' || (int) $identity['port'] !== 55441) {
|
||||
throw new RuntimeException('Isolated QA identity required.');
|
||||
}
|
||||
if ($argv[1] === 'analyse') {
|
||||
$argv = ['phpstan', 'analyse', '--no-progress', '--memory-limit=512M', '--configuration='.$root.'/outputs/funding-directory-20261110/phpstan.neon', 'app/Services/FundingInstitutionDetails.php', 'app/Services/FundingDossierPreparation.php', 'app/Services/FundingProgrammes.php', 'app/Services/FundingProgrammeReferences.php', 'app/Http/Controllers/FundingProgrammeController.php'];
|
||||
$_SERVER['argv'] = $argv;
|
||||
$_SERVER['argc'] = count($argv);
|
||||
require $root.'/vendor/autoload.php';
|
||||
require $root.'/vendor/phpstan/phpstan/phpstan';
|
||||
exit;
|
||||
}
|
||||
$case = 'FundingDirectoryTest';
|
||||
$filter = $argv[2] ?? null;
|
||||
if ($filter !== null && (strlen($filter) > 128 || ! preg_match('/^[a-zA-Z0-9_|]+$/D', $filter))) {
|
||||
throw new RuntimeException('Explicit QA test filter required.');
|
||||
}
|
||||
$argv = ['phpunit', '-c', 'phpunit.investmoz.xml', '--do-not-cache-result', 'tests/Feature/'.$case.'.php'];
|
||||
if ($filter !== null) {
|
||||
$argv[] = '--filter';
|
||||
$argv[] = $filter;
|
||||
}
|
||||
$argc = count($argv);
|
||||
$_SERVER['argv'] = $argv;
|
||||
$_SERVER['argc'] = $argc;
|
||||
require $root.'/vendor/autoload.php';
|
||||
require $root.'/vendor/phpunit/phpunit/phpunit';
|
||||
Reference in New Issue
Block a user