TenantAtlas/apps/platform/tests/Feature/Navigation/Spec338OperationRunLinksQueryContractTest.php
ahmido e0c2cdb1f4 feat: enforce workspace and environment scope contract (Spec 338) (#409)
## Summary
- enforce the canonical workspace/environment scope contract for workspace hubs and environment-owned surfaces
- replace first-party Operations deep links that leaked Filament `tableFilters[...]` internals with stable product-level query behavior
- add the sidebar scope indicator and split environment-page navigation into explicit `Workspace-wide` and `Workspace admin` groups
- remove redundant tenantless `All environments` scope badges from workspace-wide pages while preserving explicit environment filter affordances
- include the Spec 338 artifacts, guard tests, and browser smoke coverage for the new contract

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Navigation/Spec338EnvironmentSidebarSeparationTest.php tests/Feature/Navigation/Spec338OperationRunLinksQueryContractTest.php tests/Feature/Navigation/Spec338SidebarScopeIndicatorTest.php tests/Feature/Filament/PanelNavigationSegregationTest.php`
- `cd apps/platform && ./vendor/bin/sail php vendor/bin/pest tests/Browser/Spec338ScopeContractSmokeTest.php --compact`

## Notes
- Livewire v4 compliance unchanged
- Filament provider registration remains in `bootstrap/providers.php`
- no destructive action behavior changed
- no migrations, env var changes, or new Filament asset registration

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #409
2026-05-31 01:36:08 +00:00

52 lines
1.8 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 Livewire\Livewire;
it('Spec338 OperationRunLinks operation type deep links use operation_type and never tableFilters', function (): void {
[$workspace] = localizationWorkspaceMember();
$url = OperationRunLinks::index(operationType: 'inventory_sync', workspace: $workspace);
expect($url)
->toContain('/admin/workspaces/'.$workspace->getRouteKey().'/operations')
->toContain('operation_type=inventory.sync')
->not->toContain('tableFilters')
->not->toContain('inventory_sync');
});
it('Spec338 operations hub maps operation_type query into the type table filter', function (): void {
$environment = ManagedEnvironment::factory()->active()->create([
'name' => 'Spec338 Environment A',
'external_id' => 'spec338-environment-a',
]);
[$user, $environment] = createUserWithTenant(tenant: $environment, role: 'owner', workspaceRole: 'owner');
$workspace = $environment->workspace()->firstOrFail();
$runInventory = OperationRun::factory()
->forTenant($environment)
->create(['type' => 'inventory_sync']);
$runPolicy = OperationRun::factory()
->forTenant($environment)
->create(['type' => 'policy.sync']);
$this->actingAs($user);
setAdminPanelContext();
session()->put(WorkspaceContext::SESSION_KEY, (int) $workspace->getKey());
Livewire::withQueryParams(['operation_type' => 'inventory.sync'])
->actingAs($user)
->test(Operations::class)
->assertSet('tableFilters.type.value', 'inventory.sync')
->assertCanSeeTableRecords([$runInventory])
->assertCanNotSeeTableRecords([$runPolicy]);
});