88 lines
6.7 KiB
PHP
88 lines
6.7 KiB
PHP
<?php
|
|
ini_set('zend.exception_ignore_args', '1');
|
|
putenv('STABILITY_QA_MODE=consumers');
|
|
$verificationRoot = dirname(__DIR__, 2);
|
|
$verificationQA = $verificationRoot.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';
|
|
$verificationName = $argv[1] ?? 'case32-review-correction-readonly-20261013.json';
|
|
if (! preg_match('/^case32-review-correction[-a-z0-9]*-2026101[34]\.json$/', $verificationName)) {
|
|
throw new RuntimeException('Nome de evidência inválido.');
|
|
}
|
|
$retryReported = ($argv[2] ?? '') === 'retry';
|
|
$correctionReported = ($argv[2] ?? '') === 'correction-done';
|
|
$successReported = ($argv[2] ?? '') === 'success-message';
|
|
$manualConfirmed = ($argv[2] ?? '') === 'manual' || $retryReported || $correctionReported || $successReported;
|
|
$formShown = ($argv[2] ?? '') === 'form';
|
|
$verificationPath = __DIR__.'/'.$verificationName;
|
|
if (is_file($verificationPath)) { throw new RuntimeException('Verificação já registada; preservar prova.'); }
|
|
$submission = json_decode(file_get_contents(__DIR__.'/case32-manual-submission-readonly-20261013.json'), true, 512, JSON_THROW_ON_ERROR);
|
|
$app = require $verificationQA.'/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);
|
|
if ($record->opportunity_category !== 'land_rights') { throw new RuntimeException('Categoria divergente.'); }
|
|
$context = $record->workflow_context ?? [];
|
|
$cutoff = new DateTimeImmutable($submission['latest_submission_event']['at']);
|
|
$cycle = (int) ($submission['latest_submission_event']['review_cycle'] ?? 0);
|
|
if ($successReported) {
|
|
$submittedEvents = array_values(array_filter($context['events'] ?? [], fn ($event)=>
|
|
($event['action'] ?? null) === 'submit' && (int) ($event['actor_id'] ?? 0) === 21));
|
|
if ($submittedEvents === []) { throw new RuntimeException('Submissão de referência ausente.'); }
|
|
$latestSubmission = $submittedEvents[count($submittedEvents)-1];
|
|
$cutoff = new DateTimeImmutable($latestSubmission['at']);
|
|
$cycle = (int) ($latestSubmission['review_cycle'] ?? 0);
|
|
}
|
|
$steps = [];
|
|
foreach (['start_review', 'request_correction'] as $action) {
|
|
$candidates = array_values(array_filter($context['events'] ?? [], fn ($event) =>
|
|
($event['action'] ?? null) === $action && (int) ($event['actor_id'] ?? 0) === 24
|
|
&& (int) ($event['review_cycle'] ?? 0) === $cycle
|
|
&& isset($event['at']) && new DateTimeImmutable($event['at']) >= $cutoff));
|
|
$event = $candidates ? $candidates[count($candidates)-1] : null;
|
|
$audit = $db->table('audit_events')->where('source_system', 'portal-profiles-v1')
|
|
->where('action', 'workflow_'.$action)->where('actor_user_id', 24)
|
|
->whereRaw("after_data->>'record_id' = ?", ['32'])->orderByDesc('created_at')
|
|
->first(['id', 'created_at', 'after_data']);
|
|
$data = $audit ? json_decode($audit->after_data, true, 512, JSON_THROW_ON_ERROR) : [];
|
|
$auditMatches = $event && $audit && ($data['after']['status'] ?? null) === ($event['to'] ?? null)
|
|
&& new DateTimeImmutable($audit->created_at) >= $cutoff;
|
|
$steps[$action] = [
|
|
'persisted_in_current_cycle'=>(bool) ($event && $auditMatches),
|
|
'event'=>$event ? array_intersect_key($event, array_flip(['action', 'actor_id', 'at', 'from', 'to', 'review_cycle', 'content_revision'])) : null,
|
|
'audit_id'=>$auditMatches ? $audit->id : null,
|
|
'audit_matches_event'=>(bool) $auditMatches,
|
|
];
|
|
}
|
|
$state = app(App\Services\PortalProfileAccess::class)->state($record);
|
|
$receipt = [
|
|
'at'=>gmdate('c'), 'base_review'=>'396c691930bc', 'target'=>$target,
|
|
'SQL_read_only'=>true, 'QA_database_changes'=>0, 'active_changes'=>0,
|
|
'user_request'=>$successReported ? 'Ação interna registada; não representa decisão externa.' : ($correctionReported ? 'ja feito' : ($retryReported ? 'refiz o processo' : ($formShown ? 'Texto do formulário Workflow interno com fundamentação preenchida e opção Decisão: Aprovada.' : ($manualConfirmed ? 'os passos solicitados foram executados' : 'confirma')))),
|
|
'form_presentation_reported'=>$formShown,
|
|
'manual_execution_confirmed_by_user'=>$manualConfirmed,
|
|
'confirmation_scope'=>$successReported ? 'Responsável copiou a mensagem de sucesso após orientação para Solicitar correções; ação e estado conferidos separadamente no ciclo da última submissão de QA21. Não inferir foco, MFA, aprovação ou publicação.' : ($correctionReported ? 'Responsável informou ja feito após orientação para Solicitar correções; conferir persistência separadamente, sem inferir mensagem apresentada ou etapas posteriores.' : ($manualConfirmed ? 'Responsável informou execução; persistência e auditoria verificadas separadamente por leitura, sem inferir mensagem apresentada.' : 'Verificação por leitura; pedido do utilizador não tratado como confirmação visual de cada passo.')),
|
|
'opportunity_id'=>32, 'QA_account'=>24, 'review_cycle_checked'=>$cycle,
|
|
'working_state'=>$state, 'management_version'=>(int) $record->management_version,
|
|
'steps'=>$steps,
|
|
'correction_items_count'=>count($context['correction_items'] ?? []),
|
|
'correction_task_present'=>! empty($context['correction_task_id']),
|
|
'last_decision'=>array_intersect_key($context['last_decision'] ?? [], array_flip(['action', 'actor_id', 'at', 'review_cycle'])),
|
|
'UI_result_confirmation_not_inferred'=>true,
|
|
'confirmed_manual_actions_with_persistence'=>$manualConfirmed ? array_keys(array_filter($steps, fn ($step) => $step['persisted_in_current_cycle'])) : [],
|
|
'new_visual_criteria_closed'=>0,
|
|
'limits'=>['No HTTP action or workflow transition executed by this diagnostic.', 'Correction text and any session/MFA data omitted.'],
|
|
];
|
|
file_put_contents($verificationPath, json_encode($receipt, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL);
|
|
echo json_encode(['case'=>32, 'working_state'=>$state,
|
|
'QA24_started_review'=>$steps['start_review']['persisted_in_current_cycle'],
|
|
'QA24_requested_correction'=>$steps['request_correction']['persisted_in_current_cycle'],
|
|
'correction_items_count'=>$receipt['correction_items_count'], 'active_changes'=>0, 'QA_database_changes'=>0], JSON_THROW_ON_ERROR).PHP_EOL;
|
|
} finally {
|
|
$db->rollBack();
|
|
}
|