Files
Investidor-V2/outputs/investmoz-staff-preparation-20261012/test-session-gate-qa.php
T
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

47 lines
3.4 KiB
PHP

<?php
ini_set('zend.exception_ignore_args', '1');
try {
$portal = dirname(__DIR__, 2);
$plan = json_decode(file_get_contents($portal.'/storage/app/private/investmoz-v2/portal-audit/internal-designation-plan.json'), true, 512, JSON_THROW_ON_ERROR);
$qa = $plan['source'];
if (!str_contains($qa, 'onboarding-qa-internal-')) throw new RuntimeException('QA source refused');
require $qa.'/qa-autoload.php';
$app = require $qa.'/bootstrap/app.php';
(new Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables)->bootstrap($app);
(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app);
$c = config('database.connections.'.config('database.default'));
if ($c['driver'] !== 'pgsql' || (int)$c['port'] !== 55441 || $c['database'] !== 'onboarding_internal_20261011_191450_test' || !empty($c['url'])) throw new RuntimeException('QA target refused');
config(['session.driver' => 'array', 'mail.default' => 'array']);
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
Illuminate\Support\Facades\DB::beginTransaction();
$actors = json_decode(file_get_contents($qa.'/storage/app/private/onboarding-actors-local.json'), true, 512, JSON_THROW_ON_ERROR);
$actor = App\Models\User::findOrFail($actors['promoter']['id']);
// Reproduce the revision increment that the real assignment mechanism performs.
// This synthetic fixture mutation is rolled back below.
if ($actor->portal_access_revision < 1) $actor->forceFill(['portal_access_revision' => 2])->save();
$request = Illuminate\Http\Request::create('/settings/profile');
$request->setLaravelSession($app->make('session')->driver());
$request->setUserResolver(fn () => $actor);
$app->instance('request', $request);
$proof = ['QA_only' => true, 'active_writes' => 0, 'policy_event_fixture' => true, 'criteria' => []];
foreach ([false, true] as $workflow) {
config(['portal.profile_administration_enabled' => true, 'portal.profile_access_enabled' => $workflow]);
session()->flush();
Illuminate\Support\Facades\Auth::guard('web')->setUser($actor);
Illuminate\Support\Facades\Event::dispatch(new Illuminate\Auth\Events\Login('web', $actor, false));
$bound = session()->get('portal.access_revision');
$response = (new App\Http\Middleware\PortalProfileSession)->handle($request, fn () => response('OK'));
$proof['criteria'][$workflow ? 'workflow_on' : 'administration_only'] = ['revision_bound' => $bound === (int)$actor->portal_access_revision, 'status' => $response->getStatusCode()];
}
session()->put('portal.access_revision', (int)$actor->portal_access_revision - 1);
$rejected = (new App\Http\Middleware\PortalProfileSession)->handle($request, fn () => response('OK'));
$proof['stale_revision_rejected'] = $rejected->getStatusCode() === 302;
$proof['result'] = $proof['criteria']['administration_only']['status'] === 200 && $proof['criteria']['workflow_on']['status'] === 200 && $proof['stale_revision_rejected'] ? 'passed' : 'reproduced';
Illuminate\Support\Facades\DB::rollBack();
$name = $proof['result'] === 'passed' ? 'session-gate-after.json' : 'session-gate-before.json';
file_put_contents(__DIR__.'/'.$name, json_encode($proof, JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
echo json_encode($proof, JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR);
} catch (Throwable $e) {
echo json_encode(['result' => 'failed', 'type' => $e::class, 'line' => $e->getLine()]); exit(1);
}