TenantAtlas/apps/platform/tests/Feature/Monitoring/OperationsWorkspaceHubContractTest.php
ahmido d85ef4cc1c Spec 314: enforce workspace hub navigation context contract (#369)
## Summary
- add a shared workspace hub registry for canonical workspace-scoped navigation entry
- keep sidebar and global workspace hub URLs free of inherited environment query and filter state
- add focused feature and browser coverage for workspace hub shell and data-scope contracts

## Validation
- 54 focused feature tests passed (205 assertions)
- 1 browser smoke test passed (361 assertions)
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`
- `git diff --check`

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #369
2026-05-16 09:54:29 +00:00

86 lines
3.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\Monitoring\Operations;
use App\Models\ManagedEnvironment;
use App\Models\OperationRun;
use App\Support\OperationRunLinks;
use App\Support\Workspaces\WorkspaceContext;
use Filament\Facades\Filament;
use Livewire\Livewire;
it('Spec314 operations sidebar entry does not carry managed environment filters', function (): void {
$environment = ManagedEnvironment::factory()->active()->create();
[$user, $environment] = createUserWithTenant(tenant: $environment, role: 'owner');
$workspace = $environment->workspace()->firstOrFail();
Filament::setTenant($environment, true);
session()->put(WorkspaceContext::SESSION_KEY, (int) $workspace->getKey());
session()->put(WorkspaceContext::LAST_TENANT_IDS_SESSION_KEY, [
(string) $workspace->getKey() => (int) $environment->getKey(),
]);
$url = OperationRunLinks::index();
expect($url)->not->toContain('managed_environment_id')
->and($url)->not->toContain('tenant_scope')
->and($url)->not->toContain('tableFilters');
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
->get($url)
->assertOk()
->assertSee(__('localization.shell.no_environment_selected'))
->assertSee(__('localization.shell.all_environments'));
});
it('Spec314 operations clean workspace entry sees runs across entitled environments', function (): void {
$environmentA = ManagedEnvironment::factory()->active()->create();
[$user, $environmentA] = createUserWithTenant(tenant: $environmentA, role: 'owner');
$environmentB = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $environmentA->workspace_id,
]);
createUserWithTenant(tenant: $environmentB, user: $user, role: 'owner');
$runA = OperationRun::factory()->forTenant($environmentA)->create(['type' => 'policy.sync']);
$runB = OperationRun::factory()->forTenant($environmentB)->create(['type' => 'inventory_sync']);
$this->actingAs($user);
setAdminPanelContext();
session()->put(WorkspaceContext::SESSION_KEY, (int) $environmentA->workspace_id);
Livewire::test(Operations::class)
->assertCanSeeTableRecords([$runA, $runB]);
});
it('Spec314 operations ignores stale persisted environment filters on clean entry', function (): void {
$environmentA = ManagedEnvironment::factory()->active()->create();
[$user, $environmentA] = createUserWithTenant(tenant: $environmentA, role: 'owner');
$environmentB = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $environmentA->workspace_id,
]);
createUserWithTenant(tenant: $environmentB, user: $user, role: 'owner');
$runA = OperationRun::factory()->forTenant($environmentA)->create();
$runB = OperationRun::factory()->forTenant($environmentB)->create();
$this->actingAs($user);
setAdminPanelContext();
session()->put(WorkspaceContext::SESSION_KEY, (int) $environmentA->workspace_id);
$component = Livewire::test(Operations::class);
$filtersSessionKey = $component->instance()->getTableFiltersSessionKey();
session()->put($filtersSessionKey, [
'managed_environment_id' => ['value' => (string) $environmentA->getKey()],
]);
Livewire::test(Operations::class)
->assertCanSeeTableRecords([$runA, $runB]);
expect(data_get(session()->get($filtersSessionKey, []), 'managed_environment_id.value'))->toBeNull();
});