## Summary - replace the legacy Tenant and TenantMembership core models with ManagedEnvironment and ManagedEnvironmentMembership - propagate the managed environment naming and key changes across Filament resources, pages, controllers, jobs, models, and supporting runtime paths - add feature 279 spec artifacts and focused managed-environment test coverage for model behavior, route binding, panel context, authorization, and legacy guardrails ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/ManagedEnvironment/LegacyTenantCoreGuardTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentAuthorizationTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentPanelContextTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentRouteBindingTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentContextResolverTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentModelTest.php` - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` ## Notes - branch pushed from commit `1123b122` - browser smoke test file was added but not run in this pass Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #335
104 lines
4.4 KiB
PHP
104 lines
4.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Support\Workspaces\WorkspaceOverviewBuilder;
|
|
use Carbon\CarbonImmutable;
|
|
|
|
afterEach(function (): void {
|
|
CarbonImmutable::setTestNow();
|
|
});
|
|
|
|
it('orders backup-health and recovery-evidence attention by severity and suppresses calm recovery history', function (): void {
|
|
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 4, 9, 9, 0, 0, 'UTC'));
|
|
|
|
$absentTenant = ManagedEnvironment::factory()->create([
|
|
'status' => 'active',
|
|
'name' => 'Absent Backup ManagedEnvironment',
|
|
]);
|
|
[$user, $absentTenant] = createUserWithTenant($absentTenant, role: 'owner', workspaceRole: 'readonly');
|
|
workspaceOverviewSeedQuietTenantTruth($absentTenant);
|
|
|
|
$staleTenant = ManagedEnvironment::factory()->create([
|
|
'status' => 'active',
|
|
'workspace_id' => (int) $absentTenant->workspace_id,
|
|
'name' => 'Stale Backup ManagedEnvironment',
|
|
]);
|
|
createUserWithTenant($staleTenant, $user, role: 'owner', workspaceRole: 'readonly');
|
|
workspaceOverviewSeedQuietTenantTruth($staleTenant);
|
|
workspaceOverviewSeedHealthyBackup($staleTenant, [
|
|
'name' => 'Stale backup',
|
|
'completed_at' => now()->subDays(2),
|
|
]);
|
|
|
|
$degradedTenant = ManagedEnvironment::factory()->create([
|
|
'status' => 'active',
|
|
'workspace_id' => (int) $absentTenant->workspace_id,
|
|
'name' => 'Degraded Backup ManagedEnvironment',
|
|
]);
|
|
createUserWithTenant($degradedTenant, $user, role: 'owner', workspaceRole: 'readonly');
|
|
workspaceOverviewSeedQuietTenantTruth($degradedTenant);
|
|
workspaceOverviewSeedHealthyBackup($degradedTenant, [
|
|
'name' => 'Degraded backup',
|
|
'completed_at' => now()->subMinutes(30),
|
|
], [
|
|
'payload' => [],
|
|
'metadata' => [
|
|
'source' => 'metadata_only',
|
|
'assignments_fetch_failed' => true,
|
|
],
|
|
'assignments' => [],
|
|
]);
|
|
|
|
$weakenedTenant = ManagedEnvironment::factory()->create([
|
|
'status' => 'active',
|
|
'workspace_id' => (int) $absentTenant->workspace_id,
|
|
'name' => 'Weakened Recovery ManagedEnvironment',
|
|
]);
|
|
createUserWithTenant($weakenedTenant, $user, role: 'owner', workspaceRole: 'readonly');
|
|
workspaceOverviewSeedQuietTenantTruth($weakenedTenant);
|
|
$weakenedBackup = workspaceOverviewSeedHealthyBackup($weakenedTenant, [
|
|
'name' => 'Weakened backup',
|
|
'completed_at' => now()->subMinutes(25),
|
|
]);
|
|
workspaceOverviewSeedRestoreHistory($weakenedTenant, $weakenedBackup, 'follow_up');
|
|
|
|
$unvalidatedTenant = ManagedEnvironment::factory()->create([
|
|
'status' => 'active',
|
|
'workspace_id' => (int) $absentTenant->workspace_id,
|
|
'name' => 'Unvalidated Recovery ManagedEnvironment',
|
|
]);
|
|
createUserWithTenant($unvalidatedTenant, $user, role: 'owner', workspaceRole: 'readonly');
|
|
workspaceOverviewSeedQuietTenantTruth($unvalidatedTenant);
|
|
workspaceOverviewSeedHealthyBackup($unvalidatedTenant, [
|
|
'name' => 'Unvalidated backup',
|
|
'completed_at' => now()->subMinutes(20),
|
|
]);
|
|
|
|
$calmTenant = ManagedEnvironment::factory()->create([
|
|
'status' => 'active',
|
|
'workspace_id' => (int) $absentTenant->workspace_id,
|
|
'name' => 'Calm ManagedEnvironment',
|
|
]);
|
|
createUserWithTenant($calmTenant, $user, role: 'owner', workspaceRole: 'readonly');
|
|
workspaceOverviewSeedQuietTenantTruth($calmTenant);
|
|
$calmBackup = workspaceOverviewSeedHealthyBackup($calmTenant, [
|
|
'name' => 'Calm backup',
|
|
'completed_at' => now()->subMinutes(15),
|
|
]);
|
|
workspaceOverviewSeedRestoreHistory($calmTenant, $calmBackup, 'completed');
|
|
|
|
$workspace = $absentTenant->workspace()->firstOrFail();
|
|
$overview = app(WorkspaceOverviewBuilder::class)->build($workspace, $user);
|
|
$items = collect($overview['attention_items']);
|
|
|
|
expect($items)->toHaveCount(5)
|
|
->and($items->where('family', 'backup_health')->pluck('reason_context.state')->values()->all())
|
|
->toBe(['absent', 'stale', 'degraded'])
|
|
->and($items->where('family', 'recovery_evidence')->pluck('reason_context.state')->values()->all())
|
|
->toBe(['weakened', 'unvalidated'])
|
|
->and($items->pluck('tenant_label')->all())->not->toContain((string) $calmTenant->name)
|
|
->and($items->pluck('reason_context.reason')->filter()->all())->not->toContain('no_recent_issues_visible');
|
|
});
|