TenantAtlas/apps/platform/tests/Browser/Spec391OperationsHubStabilitySmokeTest.php
Ahmed Darrazi 6918b8af5a
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 1m34s
feat: add operations hub stability and safety runtime checks
2026-06-20 16:15:55 +02:00

151 lines
5.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Http\Middleware\SuppressDebugbarForSmokeRequests;
use App\Models\ManagedEnvironment;
use App\Models\OperationRun;
use App\Models\User;
use App\Support\OperationRunLinks;
use App\Support\OperationRunOutcome;
use App\Support\OperationRunStatus;
use App\Support\Workspaces\WorkspaceContext;
pest()->browser()->timeout(60_000);
it('Spec391 smokes the environment-filtered Operations Hub without debug or asset failure signatures', function (): void {
[$user, $environment] = spec391OperationsHubSmokeFixture();
spec391AuthenticateOperationsHubBrowser($this, $user, $environment);
visit(OperationRunLinks::index($environment))
->resize(1440, 1100)
->waitForText('Operations Hub')
->assertSee('Environment filter: '.$environment->name)
->assertSee('Which operation needs attention now?')
->assertSee('Inventory sync')
->assertSee('Recent runs')
->assertDontSee('Spec391 browser hidden sibling operator')
->assertDontSee('Maximum execution time')
->assertDontSee('HasAttributes.php')
->assertDontSee('Stack trace')
->assertDontSee('spec391 browser raw payload should stay hidden')
->assertDontSee('spec391 browser stack trace should stay hidden')
->assertDontSee('filamentSchema is not defined')
->assertScript('typeof window.Livewire !== "undefined"', true)
->assertScript('typeof window.Alpine !== "undefined"', true)
->assertScript('(() => {
const html = document.documentElement.outerHTML;
const urls = Array.from(document.querySelectorAll("a[href], script[src], link[href]"))
.map((element) => element.getAttribute("href") || element.getAttribute("src") || "");
return ! html.includes("_debugbar")
&& ! html.includes("phpstorm://")
&& urls.every((url) => ! url.includes("_debugbar") && ! url.startsWith("phpstorm://"));
})()', true)
->assertNoJavaScriptErrors()
->assertNoConsoleLogs()
->screenshot(true, spec391OperationsHubScreenshot('operations-hub-stability'));
expect(base_path('tests/Browser/Screenshots/'.spec391OperationsHubScreenshot('operations-hub-stability').'.png'))
->toBeFile();
});
/**
* @return array{0: User, 1: ManagedEnvironment}
*/
function spec391OperationsHubSmokeFixture(): array
{
bindFailHardGraphClient();
$environment = ManagedEnvironment::factory()->active()->create([
'name' => 'Spec391 Browser Stable Environment',
'external_id' => 'spec391-browser-stable-environment',
]);
[$user, $environment] = createUserWithTenant(
tenant: $environment,
role: 'owner',
workspaceRole: 'owner',
);
$siblingEnvironment = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $environment->workspace_id,
'name' => 'Spec391 Browser Hidden Sibling',
'external_id' => 'spec391-browser-hidden-sibling',
]);
createUserWithTenant(
tenant: $siblingEnvironment,
user: $user,
role: 'owner',
workspaceRole: 'owner',
);
OperationRun::factory()->forTenant($environment)->create([
'type' => 'inventory_sync',
'status' => OperationRunStatus::Completed->value,
'outcome' => OperationRunOutcome::Blocked->value,
'initiator_name' => 'Spec391 browser visible operator',
'context' => [
'reason_code' => 'write_gate_blocked',
'raw_payload' => 'spec391 browser raw payload should stay hidden',
'stack_trace' => 'spec391 browser stack trace should stay hidden',
'target_scope' => [
'scope_display_name' => 'Spec391 Browser Stable Environment',
],
],
'completed_at' => null,
]);
foreach (range(1, 8) as $index) {
OperationRun::factory()->forTenant($environment)->create([
'type' => $index % 2 === 0 ? 'policy.sync' : 'backup.schedule.execute',
'status' => OperationRunStatus::Completed->value,
'outcome' => $index % 3 === 0
? OperationRunOutcome::Failed->value
: OperationRunOutcome::Succeeded->value,
'initiator_name' => 'Spec391 browser bulk operator '.$index,
'completed_at' => now()->subMinutes($index),
]);
}
OperationRun::factory()->forTenant($siblingEnvironment)->create([
'type' => 'restore.execute',
'status' => OperationRunStatus::Completed->value,
'outcome' => OperationRunOutcome::Failed->value,
'initiator_name' => 'Spec391 browser hidden sibling operator',
]);
return [$user, $environment];
}
function spec391AuthenticateOperationsHubBrowser(
mixed $test,
User $user,
ManagedEnvironment $environment,
): void {
$workspaceId = (int) $environment->workspace_id;
$session = [
WorkspaceContext::SESSION_KEY => $workspaceId,
WorkspaceContext::LAST_ENVIRONMENT_IDS_SESSION_KEY => [
(string) $workspaceId => (int) $environment->getKey(),
],
SuppressDebugbarForSmokeRequests::SESSION_KEY => SuppressDebugbarForSmokeRequests::COOKIE_VALUE,
];
$test->actingAs($user)->withSession($session);
foreach ($session as $key => $value) {
session()->put($key, $value);
}
setAdminPanelContext($environment);
}
function spec391OperationsHubScreenshot(string $name): string
{
return 'spec391-'.$name;
}