## Summary - add a dedicated Recovery Readiness dashboard widget for backup posture and recovery evidence - group Needs Attention items by domain and elevate the recovery call-to-action - align restore-run and recovery posture tests with the extracted widget and continuity flows - include the related spec artifacts for 184-dashboard-recovery-honesty ## Verification - `cd /Users/ahmeddarrazi/Documents/projects/TenantAtlas/apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` - `cd /Users/ahmeddarrazi/Documents/projects/TenantAtlas/apps/platform && ./vendor/bin/sail artisan test --compact --filter="DashboardKpisWidget|DashboardRecoveryPosture|TenantDashboardDbOnly|TenantpilotSeedBackupHealthBrowserFixtureCommand|NeedsAttentionWidget"` - browser smoke verified on the calm, unvalidated, and weakened dashboard states ## Notes - Livewire v4.0+ compliant with Filament v5 - no panel provider changes; Laravel 11+ provider registration remains in `bootstrap/providers.php` - Recovery Readiness stays within the existing tenant dashboard asset strategy; no new Filament asset registration required Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #215
140 lines
4.2 KiB
PHP
140 lines
4.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\RestoreRunResource;
|
|
use App\Filament\Widgets\Dashboard\RecoveryReadiness;
|
|
use App\Models\BackupItem;
|
|
use App\Models\BackupSet;
|
|
use App\Models\RestoreRun;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Livewire\Livewire;
|
|
|
|
function makeHealthyBackupForRecoveryPerformance(\App\Models\Tenant $tenant): BackupSet
|
|
{
|
|
$backupSet = BackupSet::factory()->for($tenant)->recentCompleted()->create([
|
|
'name' => 'Performance healthy backup',
|
|
'item_count' => 1,
|
|
]);
|
|
|
|
BackupItem::factory()->for($tenant)->for($backupSet)->create([
|
|
'payload' => ['id' => 'performance-policy'],
|
|
'metadata' => [],
|
|
'assignments' => [],
|
|
]);
|
|
|
|
return $backupSet;
|
|
}
|
|
|
|
it('caps dashboard recovery evidence derivation to the latest 10 restore-run candidates', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
|
|
$this->actingAs($user);
|
|
|
|
makeHealthyBackupForRecoveryPerformance($tenant);
|
|
|
|
$historyBackupSet = BackupSet::factory()->for($tenant)->create([
|
|
'name' => 'Candidate cap backup',
|
|
]);
|
|
|
|
foreach (range(1, 10) as $minutesAgo) {
|
|
RestoreRun::factory()
|
|
->for($tenant)
|
|
->for($historyBackupSet)
|
|
->previewOnly()
|
|
->create([
|
|
'created_at' => now()->subMinutes($minutesAgo),
|
|
'started_at' => now()->subMinutes($minutesAgo),
|
|
'completed_at' => null,
|
|
]);
|
|
}
|
|
|
|
RestoreRun::factory()
|
|
->for($tenant)
|
|
->for($historyBackupSet)
|
|
->failedOutcome()
|
|
->create([
|
|
'created_at' => now()->subMinutes(11),
|
|
'started_at' => now()->subMinutes(11),
|
|
'completed_at' => now()->subMinutes(11),
|
|
]);
|
|
|
|
Filament::setCurrentPanel(Filament::getPanel('tenant'));
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::test(RecoveryReadiness::class)
|
|
->assertSee('Recovery evidence')
|
|
->assertSee('Unvalidated')
|
|
->assertDontSee('Weakened');
|
|
});
|
|
|
|
it('renders dashboard recovery posture and restore-history list with bounded query volume', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
|
|
$this->actingAs($user);
|
|
|
|
makeHealthyBackupForRecoveryPerformance($tenant);
|
|
|
|
$historyBackupSet = BackupSet::factory()->for($tenant)->create([
|
|
'name' => 'Query-shape backup',
|
|
]);
|
|
|
|
foreach (range(1, 5) as $offset) {
|
|
RestoreRun::factory()
|
|
->for($tenant)
|
|
->for($historyBackupSet)
|
|
->failedOutcome()
|
|
->create([
|
|
'completed_at' => now()->subMinutes($offset),
|
|
]);
|
|
}
|
|
|
|
foreach (range(6, 10) as $offset) {
|
|
RestoreRun::factory()
|
|
->for($tenant)
|
|
->for($historyBackupSet)
|
|
->completedWithFollowUp()
|
|
->create([
|
|
'completed_at' => now()->subMinutes($offset),
|
|
]);
|
|
}
|
|
|
|
foreach (range(11, 15) as $offset) {
|
|
RestoreRun::factory()
|
|
->for($tenant)
|
|
->for($historyBackupSet)
|
|
->completedOutcome()
|
|
->create([
|
|
'completed_at' => now()->subMinutes($offset),
|
|
]);
|
|
}
|
|
|
|
Filament::setCurrentPanel(Filament::getPanel('tenant'));
|
|
Filament::setTenant($tenant, true);
|
|
|
|
DB::flushQueryLog();
|
|
DB::enableQueryLog();
|
|
|
|
assertNoOutboundHttp(function (): void {
|
|
Livewire::test(RecoveryReadiness::class)
|
|
->assertSee('Recovery evidence')
|
|
->assertSee('Weakened');
|
|
});
|
|
|
|
$dashboardQueries = count(DB::getQueryLog());
|
|
|
|
DB::flushQueryLog();
|
|
DB::enableQueryLog();
|
|
|
|
assertNoOutboundHttp(function () use ($tenant): void {
|
|
$this->get(RestoreRunResource::getUrl('index', tenant: $tenant))
|
|
->assertOk()
|
|
->assertSee('Result attention')
|
|
->assertSee('The restore did not complete successfully. Follow-up is still required.');
|
|
});
|
|
|
|
$listQueries = count(DB::getQueryLog());
|
|
|
|
expect($dashboardQueries)->toBeLessThanOrEqual(20)
|
|
->and($listQueries)->toBeLessThanOrEqual(40);
|
|
});
|