69 lines
4.4 KiB
PHP
69 lines
4.4 KiB
PHP
<?php
|
|
|
|
// Reproduce reported gaps on the verified restored QA, never on the active connection.
|
|
use App\Models\User;
|
|
use Illuminate\Contracts\Http\Kernel;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Str;
|
|
|
|
$root = dirname(__DIR__);
|
|
$proof = json_decode(file_get_contents($root.'/storage/app/private/investmoz-v2/opportunity-resources-backup-proof.json'), true, 512, JSON_THROW_ON_ERROR);
|
|
$target = $proof['restored_target'];
|
|
if (! ($proof['restore_verified'] ?? false) || ! preg_match('/^desk_restore_\d{8}_\d{6}_test$/', $target['database']) || (int) $target['port'] !== 55441) {
|
|
throw new RuntimeException('Verified QA target required.');
|
|
}
|
|
foreach (['APP_ENV' => 'testing', 'APP_KEY' => 'base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=', 'DB_CONNECTION' => 'pgsql', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => '55441', 'DB_DATABASE' => $target['database'], 'DB_USERNAME' => 'postgres', 'DB_PASSWORD' => '', 'DB_URL' => '', 'CACHE_STORE' => 'array', 'SESSION_DRIVER' => 'array', 'QUEUE_CONNECTION' => 'sync'] as $key => $value) {
|
|
putenv($key.'='.$value);
|
|
$_ENV[$key] = $_SERVER[$key] = $value;
|
|
}
|
|
require $root.'/vendor/autoload.php';
|
|
$app = require $root.'/bootstrap/app.php';
|
|
$kernel = $app->make(Kernel::class);
|
|
$kernel->bootstrap();
|
|
$identity = DB::selectOne('SELECT current_database() AS database,inet_server_port() AS port');
|
|
if ($identity->database !== $target['database'] || (int) $identity->port !== 55441 || ! app()->environment('testing')) {
|
|
throw new RuntimeException('Non-QA connection rejected.');
|
|
}
|
|
config(['portal.managers' => ['opportunity-manager@example.invalid'], 'education.enabled' => true, 'portal.notifications_enabled' => false, 'investmoz_ai.enabled' => false, 'suitecrm.enabled' => false]);
|
|
Http::fake();
|
|
$actor = User::where('email', 'opportunity-manager@example.invalid')->firstOrFail();
|
|
$snapshot = function (): array {
|
|
$result = [];
|
|
foreach (['opportunities', 'labour_demands', 'training_capacities', 'audit_events'] as $table) {
|
|
$rows = DB::select('SELECT row_to_json(t)::text AS row FROM "'.$table.'" t ORDER BY row_to_json(t)::text');
|
|
$result[$table] = ['rows' => count($rows), 'hash' => hash('sha256', implode("\n", array_column($rows, 'row')))];
|
|
}
|
|
|
|
return $result;
|
|
};
|
|
$before = $snapshot();
|
|
$cases = [];
|
|
foreach ([
|
|
['maturity_7', '/management/opportunities/drafts', ['maturity_level' => 7, 'creation_key' => (string) Str::uuid(), 'reason' => 'Ensaio exclusivamente sintético de maturidade na QA']],
|
|
['maturity_8', '/management/opportunities/drafts', ['maturity_level' => 8, 'creation_key' => (string) Str::uuid(), 'reason' => 'Ensaio exclusivamente sintético de maturidade na QA']],
|
|
['incomplete_demand', '/management/education/demands', ['qualification' => 'Rascunho incompleto exclusivamente QA']],
|
|
['incomplete_capacity', '/management/education/capacities', ['qualification' => 'Rascunho incompleto exclusivamente QA']],
|
|
] as [$case,$url,$payload]) {
|
|
$request = Request::create($url, 'POST', [], [], [], ['HTTP_ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json'], json_encode($payload, JSON_THROW_ON_ERROR));
|
|
$app->instance('request', $request);
|
|
Auth::guard('web')->setUser($actor);
|
|
$response = $kernel->handle($request);
|
|
$body = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
|
$cases[] = ['case' => $case, 'url' => $url, 'observed_http' => $response->getStatusCode(), 'errors' => array_keys($body['errors'] ?? []), 'requirement_satisfied' => false];
|
|
if ($response->getStatusCode() !== 422 || ($body['errors'] ?? []) === []) {
|
|
throw new RuntimeException('Reported gap reproduction changed: '.$case);
|
|
}
|
|
$kernel->terminate($request, $response);
|
|
}
|
|
$after = $snapshot();
|
|
if ($before !== $after) {
|
|
throw new RuntimeException('Diagnostic requests unexpectedly changed business/history data.');
|
|
}
|
|
Http::assertNothingSent();
|
|
$result = ['captured_at' => gmdate('c'), 'target' => $target, 'cases' => $cases, 'business_history_unchanged' => true, 'active_writes' => 0, 'visual_verified' => false, 'scope' => 'Diagnostic failures; these observations are not passing acceptance tests'];
|
|
file_put_contents($root.'/storage/app/private/investmoz-v2/portal-audit/pending-actions.json', json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
|
|
echo json_encode($result, JSON_THROW_ON_ERROR).PHP_EOL;
|