TenantAtlas/tests/Feature/Guards/AdminTenantResolverGuardTest.php
ahmido cc93329672 feat: canonical tenant context resolution (#164)
## Summary
- introduce a canonical admin tenant filter-state helper and route all in-scope workspace-admin tenant resolution through `OperateHubShell::activeEntitledTenant()`
- align operations monitoring, operation-run deep links, Entra group admin list/view/search behavior, and shared context-bar rendering with the documented scope contract
- add the Spec 135 design artifacts, architecture note, focused guardrail coverage, and non-regression tests for filter persistence, direct-record access, and global search safety

## Validation
- `vendor/bin/sail bin pint --dirty --format agent`
- `vendor/bin/sail artisan test --compact tests/Feature/Monitoring/OperationsKpiHeaderTenantContextTest.php tests/Feature/Monitoring/OperationsTenantScopeTest.php tests/Feature/Monitoring/OperationsCanonicalUrlsTest.php tests/Feature/Spec085/OperationsIndexHeaderTest.php tests/Feature/Spec085/RunDetailBackAffordanceTest.php tests/Feature/Filament/OperationRunListFiltersTest.php tests/Feature/Filament/EntraGroupAdminScopeTest.php tests/Feature/Filament/EntraGroupGlobalSearchScopeTest.php tests/Feature/DirectoryGroups/BrowseGroupsTest.php tests/Feature/Filament/EntraGroupEnterpriseDetailPageTest.php tests/Feature/Filament/PolicyVersionResolvedReferenceLinksTest.php tests/Feature/Filament/EntraGroupResolvedReferencePresentationTest.php tests/Feature/Guards/AdminTenantResolverGuardTest.php tests/Feature/OpsUx/OperateHubShellTest.php tests/Feature/Filament/Alerts/AlertsKpiHeaderTest.php tests/Feature/Alerts/AlertDeliveryDeepLinkFiltersTest.php`
- `vendor/bin/sail artisan test --compact tests/Feature/Filament/TableStatePersistenceTest.php tests/Feature/Filament/TenantScopingTest.php tests/Feature/Filament/Alerts/AlertDeliveryViewerTest.php tests/Unit/Support/References/CapabilityAwareReferenceResolverTest.php`

## Notes
- Filament v5 remains on Livewire v4.0+ compliant surfaces only.
- No provider registration changes were needed; Laravel 12 provider registration remains in `bootstrap/providers.php`.
- Entra group global search remains enabled and is now scoped to the canonical admin tenant contract.

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #164
2026-03-11 21:24:28 +00:00

72 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
function adminTenantResolverGuardedFiles(): array
{
return [
'app/Filament/Pages/Monitoring/Operations.php',
'app/Filament/Pages/Operations/TenantlessOperationRunViewer.php',
'app/Filament/Widgets/Operations/OperationsKpiHeader.php',
'app/Filament/Resources/OperationRunResource.php',
'app/Filament/Resources/AlertDeliveryResource.php',
'app/Filament/Resources/AlertDeliveryResource/Pages/ListAlertDeliveries.php',
'app/Filament/Resources/EntraGroupResource/Pages/ListEntraGroups.php',
'app/Filament/Resources/EntraGroupResource/Pages/ViewEntraGroup.php',
];
}
function adminTenantResolverExceptionFiles(): array
{
return [
'app/Filament/Pages/ChooseTenant.php',
'app/Http/Controllers/SelectTenantController.php',
'app/Support/Middleware/EnsureFilamentTenantSelected.php',
'app/Filament/Resources/EntraGroupResource.php',
];
}
it('keeps raw panel-native tenant reads out of canonical admin resolver surfaces', function (): void {
$forbiddenPatterns = [
'/\bFilament::getTenant\s*\(/',
'/\bTenant::current\s*\(/',
];
$violations = [];
foreach (adminTenantResolverGuardedFiles() as $relativePath) {
$contents = file_get_contents(base_path($relativePath));
expect($contents)->not->toBeFalse();
foreach ($forbiddenPatterns as $pattern) {
if (preg_match($pattern, (string) $contents) === 1) {
$violations[] = $relativePath;
break;
}
}
}
expect($violations)
->toBeEmpty('Canonical admin surfaces must delegate tenant resolution to OperateHubShell. Offenders: '.implode(', ', $violations));
});
it('documents the approved panel-native exception inventory', function (): void {
$notes = file_get_contents(base_path('docs/research/canonical-tenant-context-resolution.md'));
expect($notes)->not->toBeFalse();
foreach (adminTenantResolverExceptionFiles() as $relativePath) {
expect($notes)->toContain($relativePath);
}
});
it('keeps the mixed-surface entra group resource explicit about admin and tenant-panel resolution', function (): void {
$contents = file_get_contents(base_path('app/Filament/Resources/EntraGroupResource.php'));
expect($contents)->not->toBeFalse()
->and($contents)->toContain('activeEntitledTenant(request())')
->and($contents)->toContain('Tenant::current()');
});