TenantAtlas/apps/platform/tests/Feature/Filament/WorkspaceOverviewContentTest.php
ahmido b98bafcf86 feat: finalize managed environment cutover seal (#354)
## Summary
- replace the remaining workspace overview tenant-first copy with environment-first wording in the builder, Blade view, and focused feature assertions
- add the Spec 299 workspace overview browser smoke and the final cutover audit documenting fixed copy, clean runtime scans, and allowed internal/provider/regression-guard `Tenant` references
- add the Spec 299 spec package (`spec.md`, `plan.md`, `tasks.md`, checklist, audit) to close the managed-environment cutover with an explicit final seal decision

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Filament/WorkspaceOverviewContentTest.php tests/Feature/Filament/AdminHomeRedirectsToChooseTenantWhenWorkspaceSelectedTest.php tests/Feature/Filament/WorkspaceOverviewEmptyStatesTest.php`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Guards/NoLegacyTenantPanelRuntimeTest.php tests/Feature/Guards/NoActiveTenantResourceRoutesTest.php tests/Feature/Guards/ManagedEnvironmentCanonicalRouteContractTest.php tests/Feature/Filament/PanelNavigationSegregationTest.php tests/Feature/Workspaces/WorkspaceIntendedUrlLegacyRejectionTest.php tests/Feature/ProviderConnections/LegacyRedirectTest.php tests/Feature/ManagedEnvironment/LegacyTenantCoreGuardTest.php tests/Feature/Spec080WorkspaceManagedTenantAdminMigrationTest.php tests/Feature/Filament/ManagedEnvironmentAccessScopeManagementTest.php tests/Feature/Rbac/ProviderConnectionWorkspaceFirstPolicyTest.php`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Guards`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Workspaces`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/ProviderConnections`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/RequiredPermissions`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Filament`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Browser/Spec299WorkspaceOverviewCutoverSealSmokeTest.php`
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`
- `git diff --check`

## Notes
- Filament remains on Livewire v4.
- Provider registration remains in `apps/platform/bootstrap/providers.php`.
- No new panel provider or asset-strategy changes are included.
- Remaining technical `Tenant` references are documented in `specs/299-managed-environment-cutover-final-seal/final-cutover-audit.md`.

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #354
2026-05-13 20:33:30 +00:00

126 lines
5.9 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Resources\TenantResource;
use App\Models\ManagedEnvironment;
use App\Models\OperationRun;
use App\Support\OperationRunStatus;
use App\Support\RestoreSafety\RestoreResultAttention;
use App\Support\Workspaces\WorkspaceOverviewBuilder;
use App\Support\Workspaces\WorkspaceContext;
it('shows workspace identity, summary cards, recent operations, and quick actions', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
workspaceOverviewSeedQuietTenantTruth($tenant);
$backupSet = workspaceOverviewSeedHealthyBackup($tenant, [
'completed_at' => now()->subMinutes(10),
]);
workspaceOverviewSeedRestoreHistory($tenant, $backupSet, 'completed');
OperationRun::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $tenant->workspace_id,
'type' => 'inventory_sync',
'status' => OperationRunStatus::Running->value,
'outcome' => 'pending',
]);
$response = $this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
->get(route('admin.workspace.home', ['workspace' => $tenant->workspace]));
$response
->assertOk()
->assertSee('Workspace overview')
->assertSee('Accessible environments')
->assertSee('Governance attention')
->assertSee('Backup attention')
->assertSee('Recovery attention')
->assertSee('Active operations')
->assertSee('Needs attention')
->assertSee('Recent operations')
->assertSee(__('localization.shell.choose_environment'))
->assertSee('Open operations')
->assertSee('Open alerts')
->assertSee('Review current and recent workspace-wide operations.')
->assertSee('Activity only. Active execution does not imply governance health.')
->assertSee('Visible environments with non-healthy backup posture.')
->assertSee('Visible environments with weakened or unvalidated recovery evidence.')
->assertSee('Governance risk counts affected environments')
->assertSee('Backup health stays separate from recovery evidence')
->assertSee('Calm wording stays bounded to visible environments and checked domains')
->assertDontSee('Accessible tenants')
->assertDontSee('Governance risk counts affected tenants')
->assertDontSee('Calm wording stays bounded to visible tenants and checked domains')
->assertSee('Inventory sync');
});
it('keeps multi-tenant backup and recovery metric drilldowns on the registry when multiple tenants remain in scope', function (): void {
[$user, $anchorTenant] = createUserWithTenant(role: 'owner', workspaceRole: 'readonly');
workspaceOverviewSeedQuietTenantTruth($anchorTenant);
$backupTenant = ManagedEnvironment::factory()->create([
'status' => 'active',
'workspace_id' => (int) $anchorTenant->workspace_id,
'name' => 'Backup Attention ManagedEnvironment',
]);
createUserWithTenant($backupTenant, $user, role: 'owner', workspaceRole: 'readonly');
workspaceOverviewSeedQuietTenantTruth($backupTenant);
workspaceOverviewSeedHealthyBackup($backupTenant, [
'completed_at' => now()->subDays(2),
]);
$backupTenantB = ManagedEnvironment::factory()->create([
'status' => 'active',
'workspace_id' => (int) $anchorTenant->workspace_id,
'name' => 'Backup Attention ManagedEnvironment B',
]);
createUserWithTenant($backupTenantB, $user, role: 'owner', workspaceRole: 'readonly');
workspaceOverviewSeedQuietTenantTruth($backupTenantB);
workspaceOverviewSeedHealthyBackup($backupTenantB, [
'completed_at' => now()->subMinutes(19),
], [
'payload' => [],
'metadata' => [
'source' => 'metadata_only',
'assignments_fetch_failed' => true,
],
'assignments' => [],
]);
$recoveryTenantA = ManagedEnvironment::factory()->create([
'status' => 'active',
'workspace_id' => (int) $anchorTenant->workspace_id,
'name' => 'Recovery Attention ManagedEnvironment A',
]);
createUserWithTenant($recoveryTenantA, $user, role: 'owner', workspaceRole: 'readonly');
workspaceOverviewSeedQuietTenantTruth($recoveryTenantA);
$recoveryBackupA = workspaceOverviewSeedHealthyBackup($recoveryTenantA, [
'completed_at' => now()->subMinutes(18),
]);
workspaceOverviewSeedRestoreHistory($recoveryTenantA, $recoveryBackupA, 'failed');
$recoveryTenantB = ManagedEnvironment::factory()->create([
'status' => 'active',
'workspace_id' => (int) $anchorTenant->workspace_id,
'name' => 'Recovery Attention ManagedEnvironment B',
]);
createUserWithTenant($recoveryTenantB, $user, role: 'owner', workspaceRole: 'readonly');
workspaceOverviewSeedQuietTenantTruth($recoveryTenantB);
$recoveryBackupB = workspaceOverviewSeedHealthyBackup($recoveryTenantB, [
'completed_at' => now()->subMinutes(17),
]);
workspaceOverviewSeedRestoreHistory($recoveryTenantB, $recoveryBackupB, 'follow_up');
$overview = app(WorkspaceOverviewBuilder::class)->build($anchorTenant->workspace()->firstOrFail(), $user);
$metrics = collect($overview['summary_metrics'])->keyBy('key');
expect($metrics->get('backup_attention_tenants')['destination']['kind'])->toBe('choose_tenant')
->and($metrics->get('backup_attention_tenants')['destination_url'])->toContain(TenantResource::getUrl('index', panel: 'admin'))
->and($metrics->get('backup_attention_tenants')['destination_url'])->not->toContain('arrival=')
->and($metrics->get('recovery_attention_tenants')['destination']['kind'])->toBe('choose_tenant')
->and($metrics->get('recovery_attention_tenants')['destination_url'])->toContain(TenantResource::getUrl('index', panel: 'admin'))
->and($metrics->get('recovery_attention_tenants')['destination_url'])->not->toContain('arrival=');
});