## Summary - add the Spec 181 restore-safety layer with scope fingerprinting, preview/check integrity states, execution safety snapshots, result attention, and operator-facing copy across the wizard, restore detail, and canonical operation detail - add focused unit and feature coverage for restore-safety assessment, result attention, and restore-linked operation detail - switch the finding exceptions queue `Inspect exception` action to a native Filament slide-over while preserving query-param-backed inline summary behavior ## Testing - `vendor/bin/sail artisan test --compact tests/Feature/Monitoring/FindingExceptionsQueueTest.php tests/Feature/Filament/RestoreSafetyIntegrityWizardTest.php tests/Feature/Filament/RestoreResultAttentionSurfaceTest.php tests/Feature/Operations/RestoreLinkedOperationDetailTest.php tests/Unit/Support/RestoreSafety` ## Notes - Spec 181 checklist is complete (`specs/181-restore-safety-integrity/checklists/requirements.md`) - the branch still has unchecked follow-up tasks in `specs/181-restore-safety-integrity/tasks.md`: `T012`, `T018`, `T019`, `T023`, `T025`, `T029`, `T032`, `T033`, `T041`, `T042`, `T043`, `T044` - Filament v5 / Livewire v4 compliance is preserved, no panel provider registration changes were made, no global-search behavior was added, destructive actions remain confirmation-gated, and no new Filament assets were introduced Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #210
218 lines
7.3 KiB
PHP
218 lines
7.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\RestoreRunResource\Pages\ViewRestoreRun;
|
|
use App\Models\BackupSet;
|
|
use App\Models\RestoreRun;
|
|
use App\Support\RestoreSafety\RestoreSafetyResolver;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('elevates restore result attention above raw item diagnostics', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
]);
|
|
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'backup_set_id' => $backupSet->id,
|
|
'status' => 'completed',
|
|
'results' => [
|
|
'foundations' => [],
|
|
'items' => [
|
|
1 => [
|
|
'status' => 'applied',
|
|
'policy_identifier' => 'policy-1',
|
|
'assignment_outcomes' => [
|
|
['status' => 'skipped', 'assignment' => []],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
'metadata' => [
|
|
'non_applied' => 1,
|
|
'scope_basis' => [
|
|
'fingerprint' => 'scope-1',
|
|
'scope_mode' => 'selected',
|
|
'selected_item_ids' => [1],
|
|
],
|
|
'preview_basis' => [
|
|
'fingerprint' => 'scope-1',
|
|
'generated_at' => now('UTC')->toIso8601String(),
|
|
],
|
|
'check_basis' => [
|
|
'fingerprint' => 'scope-1',
|
|
'ran_at' => now('UTC')->toIso8601String(),
|
|
'blocking_count' => 0,
|
|
'warning_count' => 0,
|
|
],
|
|
'execution_safety_snapshot' => [
|
|
'safety_state' => 'ready_with_caution',
|
|
'follow_up_boundary' => 'run_completed_not_recovery_proven',
|
|
],
|
|
],
|
|
]);
|
|
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::test(ViewRestoreRun::class, ['record' => $restoreRun->getKey()])
|
|
->assertSee('Follow-up required')
|
|
->assertSee('Review skipped or non-applied items before closing the run.')
|
|
->assertSee('No dominant cause recorded')
|
|
->assertSee('Tenant-wide recovery is not proven.')
|
|
->assertDontSee('review_skipped_items')
|
|
->assertDontSee('run_completed_not_recovery_proven');
|
|
});
|
|
|
|
it('shows not run checks instead of legacy stale for preview-only runs without checks evidence', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
]);
|
|
|
|
/** @var RestoreSafetyResolver $resolver */
|
|
$resolver = app(RestoreSafetyResolver::class);
|
|
|
|
$previewData = [
|
|
'backup_set_id' => (int) $backupSet->getKey(),
|
|
'scope_mode' => 'all',
|
|
'backup_item_ids' => [],
|
|
'group_mapping' => [],
|
|
'preview_summary' => [
|
|
'generated_at' => now('UTC')->toIso8601String(),
|
|
'policies_total' => 1,
|
|
'policies_changed' => 1,
|
|
'assignments_changed' => 0,
|
|
'scope_tags_changed' => 0,
|
|
],
|
|
'preview_ran_at' => now('UTC')->toIso8601String(),
|
|
];
|
|
$previewBasis = $resolver->previewBasisFromData($previewData);
|
|
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'backup_set_id' => $backupSet->id,
|
|
'status' => 'previewed',
|
|
'is_dry_run' => true,
|
|
'preview' => [
|
|
[
|
|
'policy_identifier' => 'policy-1',
|
|
'policy_type' => 'settingsCatalogPolicy',
|
|
'platform' => 'windows',
|
|
'action' => 'update',
|
|
],
|
|
],
|
|
'metadata' => [
|
|
'scope_basis' => [
|
|
'fingerprint' => 'scope-1',
|
|
'scope_mode' => 'all',
|
|
'selected_item_ids' => [],
|
|
],
|
|
'preview_summary' => $previewData['preview_summary'],
|
|
'preview_ran_at' => $previewData['preview_ran_at'],
|
|
'preview_basis' => $previewBasis,
|
|
'check_basis' => [],
|
|
'check_summary' => [],
|
|
],
|
|
]);
|
|
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::test(ViewRestoreRun::class, ['record' => $restoreRun->getKey()])
|
|
->assertSee('Current basis')
|
|
->assertSee('Not run')
|
|
->assertSee('Preview evidence is current for the selected restore scope.')
|
|
->assertSee('No execution was performed from this record.')
|
|
->assertDontSee('preview_only_no_execution_proven')
|
|
->assertDontSee('Legacy stale');
|
|
});
|
|
|
|
it('renders preview-only foundations without falling back to unknown', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
]);
|
|
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'backup_set_id' => $backupSet->id,
|
|
'status' => 'previewed',
|
|
'is_dry_run' => true,
|
|
'preview' => [
|
|
[
|
|
'type' => 'intuneRoleDefinition',
|
|
'sourceId' => 'role-def-1',
|
|
'sourceName' => 'Application Manager',
|
|
'decision' => 'dry_run',
|
|
'reason' => 'preview_only',
|
|
],
|
|
],
|
|
'metadata' => [
|
|
'scope_basis' => [
|
|
'fingerprint' => 'scope-1',
|
|
'scope_mode' => 'all',
|
|
'selected_item_ids' => [],
|
|
],
|
|
'preview_basis' => [
|
|
'fingerprint' => 'scope-1',
|
|
'generated_at' => now('UTC')->toIso8601String(),
|
|
],
|
|
],
|
|
]);
|
|
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::test(ViewRestoreRun::class, ['record' => $restoreRun->getKey()])
|
|
->assertSee('Application Manager')
|
|
->assertSee('Preview only')
|
|
->assertSee('Preview only. This foundation type is not applied during execution.')
|
|
->assertDontSee('Unknown');
|
|
});
|
|
|
|
it('renders preview-only result foundations without exposing raw reason codes', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
]);
|
|
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'backup_set_id' => $backupSet->id,
|
|
'status' => 'completed',
|
|
'is_dry_run' => false,
|
|
'results' => [
|
|
'foundations' => [
|
|
[
|
|
'type' => 'intuneRoleDefinition',
|
|
'sourceId' => 'role-def-1',
|
|
'sourceName' => 'Application Manager',
|
|
'decision' => 'dry_run',
|
|
'reason' => 'preview_only',
|
|
],
|
|
],
|
|
'items' => [],
|
|
],
|
|
]);
|
|
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::test(ViewRestoreRun::class, ['record' => $restoreRun->getKey()])
|
|
->assertSee('Application Manager')
|
|
->assertSee('Preview only')
|
|
->assertSee('Preview only. This foundation type is not applied during execution.')
|
|
->assertDontSee('Unknown');
|
|
});
|