Files
Investidor-V2/outputs/investmoz-audit-current-20261012/case32-schema-feedback-regression-QA-20261014.php
T
nala 5738418838
tests / ci (push) Canceled after 0s
oportunidades 9
2026-10-14 16:57:56 +02:00

36 lines
3.7 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1');putenv('STABILITY_QA_MODE=consumers');
$regRoot=dirname(__DIR__,2);$regQA=$regRoot.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';
$path=__DIR__.'/case32-schema-feedback-regression-QA-20261014.json';if(is_file($path)){throw new RuntimeException('Preservar prova.');}
$app=require $regQA.'/tools/portal-stability-runtime.php';$db=Illuminate\Support\Facades\DB::connection();
$target=(array)$db->selectOne('SELECT current_database() AS database,inet_server_port() AS port');
if($target!==['database'=>'stability_consumers_20261011_084534_test','port'=>55441]){throw new RuntimeException('QA isolada obrigatória.');}
$db->beginTransaction();$db->statement('SET TRANSACTION READ ONLY');
try{
$record=App\Models\Opportunity::findOrFail(32);$version=$record->management_version;
$payload=app(App\Services\OpportunityManagement::class)->values($record)['canonical'];
$long=$payload;$long['demand_statement']=str_repeat('Texto sintético apenas para regressão QA. ',4);
$contract=app(App\Services\OpportunityCanonicalContract::class);$method=new ReflectionMethod($contract,'validateSchema');
$cases=[];
$check=function($name,$data,$expected)use($contract,$method,&$cases){
try{$method->invoke($contract,$data,false);throw new RuntimeException('Recusa esperada ausente.');}
catch(Illuminate\Validation\ValidationException $e){$errors=$e->errors();if(!isset($errors[$expected])){throw new RuntimeException('Campo de erro divergente.');}$cases[$name]=['rejected'=>true,'fields'=>array_keys($errors)];}
};
$missing=$long;unset($missing['official_title']);$check('missing_required_title',$missing,'canonical.official_title');
$nested=$long;$nested['land_rights']['unexpected_qa_property']='synthetic';$check('nested_unknown_property',$nested,'canonical.land_rights.unexpected_qa_property');
$shortNested=$payload;$shortNested['land_rights']['unexpected_qa_property']='synthetic';$check('short_and_nested_unknown',$shortNested,'canonical.land_rights.unexpected_qa_property');
$badEnum=$long;$badEnum['geographic_scope']='unexpected_qa_value';$check('invalid_enum',$badEnum,'canonical.geographic_scope');
$badConsent=$long;$badConsent['truth_declaration']=false;$check('false_truth_declaration',$badConsent,'canonical.truth_declaration');
$schema=$contract->schema(false);$raw=json_decode(file_get_contents($regQA.'/resources/data/investmoz-opportunity-modular.schema.json'),true,512,JSON_THROW_ON_ERROR);
$limits=$schema['$defs']['opportunityCreate']['properties']['demand_statement'];
if($limits!==$raw['$defs']['opportunityCreate']['properties']['demand_statement']){throw new RuntimeException('Limites normativos alterados.');}
$options=$contract->options(App\Models\User::findOrFail(21),$record);
if($options['submissionTextLimits']['demand_statement']!==['minLength'=>100,'maxLength'=>2000]||$options['schema']['properties']['demand_statement']['minLength']!==0){throw new RuntimeException('Metadados de limite divergentes.');}
if(App\Models\Opportunity::findOrFail(32)->management_version!==$version){throw new RuntimeException('Versão alterada.');}
$receipt=['at'=>gmdate('c'),'result'=>'passed','target'=>$target,'SQL_read_only'=>true,'cases'=>$cases,
'submission_limits_unchanged'=>true,'draft_min_length'=>0,'metadata_submission_limits'=>$options['submissionTextLimits']['demand_statement'],
'variants_in_memory_only'=>true,'stored_draft_unchanged'=>true,'active_changes'=>0,'QA_database_changes'=>0];
file_put_contents($path,json_encode($receipt,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL);
echo json_encode($receipt,JSON_THROW_ON_ERROR).PHP_EOL;
}finally{$db->rollBack();}