Files
Investidor-V2/tools/investor-guidance-qa-router.php
nala 1106509116
tests / ci (push) Canceled after 0s
vrsao 2
2026-10-08 14:02:01 +02:00

78 lines
4.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Http\Controllers\VirtualDeskInstallationController;
use App\Models\User;
use App\Services\VirtualDeskInstallation;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Vite;
// Fixed, disposable QA target. Never inherit database/session configuration.
$root = dirname(__DIR__);
$v2 = defined('INVESTMOZ_V2_QA') && INVESTMOZ_V2_QA === true;
$qaDatabase = $v2 ? 'investmoz_v2_20261008_test' : 'investmoz_guidance_20261008_test';
$qaUrl = $v2 ? 'http://127.0.0.1:18092' : 'http://127.0.0.1:18091';
foreach (['APP_ENV' => 'testing', 'APP_DEBUG' => 'true', 'APP_URL' => $qaUrl, 'APP_KEY' => 'base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=',
'DB_CONNECTION' => 'pgsql', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => '55441', 'DB_DATABASE' => $qaDatabase, 'DB_USERNAME' => 'postgres', 'DB_PASSWORD' => '', 'DB_URL' => '',
'SESSION_DRIVER' => 'file', 'SESSION_COOKIE' => 'investmoz_guidance_qa', 'CACHE_STORE' => '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';
$app->make(Kernel::class)->bootstrap();
$connection = config('database.connections.'.config('database.default'));
if (config('database.default') !== 'pgsql' || ($connection['host'] ?? null) !== '127.0.0.1' || (string) ($connection['port'] ?? '') !== '55441' || ($connection['database'] ?? null) !== $qaDatabase || ! in_array($connection['url'] ?? null, [null, ''], true)) {
throw new RuntimeException('Refusing a non-QA configuration before connecting.');
}
$identity = DB::selectOne('select current_database() as name, inet_server_port() as port');
if ($identity->name !== $qaDatabase || (int) $identity->port !== 55441) {
throw new RuntimeException('Refusing a non-QA database identity.');
}
$private = $root.($v2 ? '/storage/app/private/investmoz-v2' : '/storage/app/private/virtual-desk');
if (! is_dir($private.'/qa-sessions')) {
mkdir($private.'/qa-sessions', 0700, true);
}
config(['session.files' => $private.'/qa-sessions', 'portal.managers' => ['guidance-qa-manager@example.invalid'], 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
Vite::useHotFile($root.'/storage/framework/guidance-qa-absent-hot');
if ($v2 && PHP_SAPI === 'cli' && ($argv[1] ?? '') === 'migrate') {
$result = $app->make(Kernel::class)->call('migrate', ['--force' => true]);
echo 'V2 QA migrations exit '.$result.'; target '.$identity->name.':'.$identity->port."\n";
exit($result);
}
if (PHP_SAPI === 'cli' && ($argv[1] ?? '') === 'seed') {
foreach (($v2 ? ['investor', 'manager', 'other'] : ['investor', 'manager']) as $role) {
$user = User::updateOrCreate(['email' => 'guidance-qa-'.$role.'@example.invalid'], ['name' => 'Guidance QA '.$role, 'password' => Hash::make('QA-Guidance-2026!')]);
$user->forceFill(['email_verified_at' => now()])->save();
}
$manager = User::where('email', 'guidance-qa-manager@example.invalid')->firstOrFail();
$request = Request::create('/management/balcao/servicos', 'POST', ['code' => 'project-preparation', 'confirm' => true]);
$request->setUserResolver(fn () => $manager);
app(VirtualDeskInstallationController::class)->publishService($request);
if ($v2) {
require $root.'/tools/investmoz-v2-qa-fixtures.php';
}
echo "QA fixtures seeded; no active database connection.\n";
exit;
}
if (PHP_SAPI === 'cli' && ($argv[1] ?? '') === 'evidence') {
if ($v2) {
throw new RuntimeException('V2 evidence must be produced by the checks, not asserted by a seed command.');
}
$evidence = ['passed' => true, 'database' => $identity->name, 'port' => (int) $identity->port, 'code_hash' => app(VirtualDeskInstallation::class)->fingerprint(), 'recorded_at' => gmdate('c'), 'checks' => ['PHPUnit feature and regression suite', 'Frontend deterministic calculator tests', 'TypeScript', 'PHPStan', 'Production build', 'Authenticated local browser cycle']];
file_put_contents($private.'/guidance-qa-evidence.json', json_encode($evidence, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
echo "QA evidence recorded for this code fingerprint.\n";
exit;
}
$path = rawurldecode(parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/');
$asset = realpath($root.'/public'.$path);
$public = realpath($root.'/public');
if ($path !== '/' && $asset && $public && str_starts_with($asset, $public.DIRECTORY_SEPARATOR) && is_file($asset)) {
return false;
}
header('X-Investmoz-QA-Target: '.$identity->name.':'.$identity->port);
$app->handleRequest(Request::capture());