Files
Investidor-V2/outputs/investmoz-audit-current-20261012/option-B-preflight.php
T
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

53 lines
4.5 KiB
PHP

<?php
ini_set('zend.exception_ignore_args', '1');
putenv('STABILITY_QA_MODE=consumers');
$root = dirname(__DIR__, 2);
$qa = $root.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';
$scope = json_decode(file_get_contents(__DIR__.'/option-B-scope-frozen.json'), true, 512, JSON_THROW_ON_ERROR);
if (! $scope['frozen_before_product_execution'] || hash_file('sha256', $root.'/docs/investmoz/v2/auditoria-portal/ambito-B-aceitacao-QA.md') !== $scope['acceptance_scope_sha256']) {
throw new RuntimeException('Approved scope must be fixed before execution.');
}
$app = require $qa.'/tools/portal-stability-runtime.php';
$db = Illuminate\Support\Facades\DB::connection();
$actual = (array) $db->selectOne('SELECT current_database() AS database, inet_server_port() AS port');
if ($actual !== ['database'=>'stability_consumers_20261011_084534_test', 'port'=>55441]) {
throw new RuntimeException('Actual isolated QA required.');
}
$db->beginTransaction();
$db->statement('SET TRANSACTION READ ONLY');
try {
$migrations = $db->table('migrations')->where(function ($q) {
foreach (['030000','040000','050000','190000'] as $suffix) $q->orWhere('migration', 'like', '%'.$suffix.'%');
})->orderBy('migration')->pluck('migration')->all();
$definition = $db->table('questionnaire_versions')->where('code', 'investor-path-19')->where('status', 'published')->get(['id','version_no','schema_snapshot']);
$definitions=[];
foreach ($definition as $row) {
$content=json_decode($row->schema_snapshot,true,512,JSON_THROW_ON_ERROR);
App\Services\InvestorPathDefinition::validate($content);
$definitions[]=['id'=>$row->id,'version'=>$row->version_no,'phases'=>count($content['phases']),'steps'=>array_column($content['steps'],'code'),'source_sha256'=>$content['source_sha256']];
}
$snapshot=[];
foreach (['opportunities','opportunity_locations','opportunity_documents','opportunity_images','desk_cases','desk_requests','desk_documents','investor_journeys','journey_steps','simulation_form_drafts','tasks','documents','memberships','organizations'] as $name) {
if (! Illuminate\Support\Facades\Schema::hasTable($name)) { $snapshot[$name]=['available'=>false];continue; }
$rows=$db->table($name)->get();
$serialized=$rows->map(fn($r)=>json_encode($r,JSON_THROW_ON_ERROR))->all();
sort($serialized,SORT_STRING); // Existing pivot tables need not have an id.
$snapshot[$name]=['available'=>true,'count'=>$rows->count(),'sha256'=>hash('sha256',implode("\n",$serialized))];
}
$cases=$db->table('desk_cases')->whereNotNull('journey_id')->get(['id','journey_id','user_id','version','closed_at']);
$actors=$db->table('users')->whereIn('id',[18,21,22,23,24,25,26])->get(['id','email_verified_at','two_factor_confirmed_at']);
$safeActors=$actors->map(fn($a)=>['id'=>$a->id,'email_verified'=>$a->email_verified_at!==null,'MFA_confirmed'=>$a->two_factor_confirmed_at!==null])->all();
$p=['at'=>gmdate('c'),'scope'=>'B','target'=>$actual,'SQL_read_only'=>true,'active_writes'=>0,
'installed_migrations'=>$migrations,'path_available'=>app(App\Services\InvestorPath::class)->available(),'path_enabled_config'=>config('investor-path.enabled'),
'desk_installed'=>app(App\Services\VirtualDesk::class)->installed(),
'path_columns_present'=>[Illuminate\Support\Facades\Schema::hasColumn('investor_journeys','path_definition_id'),Illuminate\Support\Facades\Schema::hasColumn('journey_steps','path_detail')],
'path_definitions'=>$definitions,
'gates'=>['country'=>config('portal.organization_country_enabled'),'profile_access'=>config('portal.profile_access_enabled'),
'opportunity_access'=>config('portal.opportunity_dashboard_access_enabled'),'specialized_drafts'=>config('portal.opportunity_specialized_drafts_enabled'),
'notifications'=>config('portal.notifications_enabled'),'external_CRM'=>config('suitecrm.enabled'),'external_AI'=>config('investmoz_ai.enabled')],
'synthetic_QA_actors'=>$safeActors,'existing_integrated_cases'=>$cases->all(),'protected_table_snapshot'=>$snapshot,
'scope_sha256'=>$scope['acceptance_scope_sha256'],'no_installation_repeated'=>true,'visual_criteria_closed'=>0];
file_put_contents(__DIR__.'/option-B-preflight.json',json_encode($p,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
echo json_encode(array_diff_key($p,['protected_table_snapshot'=>true,'existing_integrated_cases'=>true]),JSON_THROW_ON_ERROR).PHP_EOL;
} finally { $db->rollBack(); }