## Summary - productize the Restore Run detail surface around post-execution proof, evidence availability, and decision-first outcome framing - add a dedicated restore run detail presenter and update the resource/detail rendering for clearer result and diagnostics states - add Spec 335 feature, unit, and browser coverage plus screenshot artifacts ## Testing - Not run as part of this commit/PR task Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #404
196 lines
7.3 KiB
PHP
196 lines
7.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\RestoreRunResource;
|
|
use App\Models\BackupSet;
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Models\OperationRun;
|
|
use App\Models\RestoreRun;
|
|
use App\Models\User;
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\OperationRunStatus;
|
|
use App\Support\OperationRunType;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
pest()->browser()->timeout(60_000);
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
function spec335BrowserScreenshotName(string $name): string
|
|
{
|
|
return 'spec335-restore-run-detail-'.$name;
|
|
}
|
|
|
|
function spec335BrowserLoginUrl(User $user, ManagedEnvironment $tenant, string $redirect): string
|
|
{
|
|
return route('admin.local.smoke-login', [
|
|
'email' => $user->email,
|
|
'tenant' => $tenant->external_id,
|
|
'workspace' => $tenant->workspace->slug,
|
|
'redirect' => $redirect,
|
|
]);
|
|
}
|
|
|
|
function spec335BrowserViewPath(ManagedEnvironment $tenant, RestoreRun $restoreRun): string
|
|
{
|
|
$url = RestoreRunResource::getUrl('view', ['record' => $restoreRun], panel: 'admin', tenant: $tenant);
|
|
|
|
return parse_url($url, PHP_URL_PATH) ?: '/admin';
|
|
}
|
|
|
|
function spec335BrowserBackupSet(ManagedEnvironment $tenant): BackupSet
|
|
{
|
|
return BackupSet::factory()->create([
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
'name' => 'Spec335 Browser Backup',
|
|
'status' => 'completed',
|
|
'item_count' => 4,
|
|
]);
|
|
}
|
|
|
|
function spec335BrowserOperationRun(ManagedEnvironment $tenant, string $outcome = OperationRunOutcome::Succeeded->value): OperationRun
|
|
{
|
|
return OperationRun::factory()->forTenant($tenant)->create([
|
|
'type' => OperationRunType::RestoreExecute->value,
|
|
'status' => OperationRunStatus::Completed->value,
|
|
'outcome' => $outcome,
|
|
'completed_at' => now(),
|
|
]);
|
|
}
|
|
|
|
function spec335BrowserCompletedRestoreRun(ManagedEnvironment $tenant, BackupSet $backupSet, OperationRun $operationRun): RestoreRun
|
|
{
|
|
return RestoreRun::factory()->for($tenant, 'tenant')->for($backupSet)->create([
|
|
'status' => 'completed',
|
|
'operation_run_id' => (int) $operationRun->getKey(),
|
|
'requested_by' => 'Spec335 Browser Operator',
|
|
'results' => [
|
|
'foundations' => [],
|
|
'items' => [
|
|
[
|
|
'status' => 'applied',
|
|
'policy_identifier' => 'Spec335 Browser Policy',
|
|
'policy_type' => 'settingsCatalogPolicy',
|
|
'platform' => 'windows',
|
|
'assignment_summary' => [
|
|
'success' => 1,
|
|
'failed' => 0,
|
|
'skipped' => 1,
|
|
],
|
|
'settings_apply' => [
|
|
'applied' => 4,
|
|
'failed' => 0,
|
|
'manual_required' => 0,
|
|
],
|
|
'graph_error_message' => 'browser raw payload should stay hidden',
|
|
],
|
|
],
|
|
],
|
|
'metadata' => [
|
|
'total' => 4,
|
|
'succeeded' => 3,
|
|
'failed' => 0,
|
|
'skipped' => 1,
|
|
'partial' => 0,
|
|
'non_applied' => 1,
|
|
'execution_safety_snapshot' => [
|
|
'safety_state' => 'ready_with_caution',
|
|
],
|
|
],
|
|
'completed_at' => now(),
|
|
]);
|
|
}
|
|
|
|
it('Spec335 smokes restore run detail post-execution proof states and screenshots', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$backupSet = spec335BrowserBackupSet($tenant);
|
|
|
|
$draftRun = RestoreRun::factory()->for($tenant, 'tenant')->for($backupSet)->create([
|
|
'status' => 'draft',
|
|
'is_dry_run' => true,
|
|
'results' => [],
|
|
'metadata' => [],
|
|
'started_at' => null,
|
|
'completed_at' => null,
|
|
]);
|
|
|
|
$completedOperation = spec335BrowserOperationRun($tenant);
|
|
$completedRun = spec335BrowserCompletedRestoreRun($tenant, $backupSet, $completedOperation);
|
|
|
|
$failedOperation = spec335BrowserOperationRun($tenant, OperationRunOutcome::Failed->value);
|
|
$failedRun = RestoreRun::factory()->for($tenant, 'tenant')->for($backupSet)->create([
|
|
'status' => 'failed',
|
|
'operation_run_id' => (int) $failedOperation->getKey(),
|
|
'results' => [
|
|
'foundations' => [],
|
|
'items' => [
|
|
[
|
|
'status' => 'failed',
|
|
'policy_identifier' => 'Spec335 Failed Browser Policy',
|
|
'policy_type' => 'settingsCatalogPolicy',
|
|
'platform' => 'windows',
|
|
],
|
|
],
|
|
],
|
|
'metadata' => [
|
|
'total' => 1,
|
|
'succeeded' => 0,
|
|
'failed' => 1,
|
|
],
|
|
'completed_at' => now(),
|
|
]);
|
|
|
|
$page = visit(spec335BrowserLoginUrl($user, $tenant, spec335BrowserViewPath($tenant, $draftRun)))
|
|
->resize(1440, 1100)
|
|
->waitForText('Was this restore executed safely, and is recovery proof available?')
|
|
->assertSee('Not executed')
|
|
->assertSee('Operation proof unavailable')
|
|
->assertSee('Post-run evidence unavailable')
|
|
->assertScript('document.querySelector("[data-testid=\"restore-run-diagnostics\"]")?.open === false', true)
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, spec335BrowserScreenshotName('01-restore-run-draft'));
|
|
|
|
$page = visit(spec335BrowserViewPath($tenant, $completedRun))
|
|
->resize(1440, 1100)
|
|
->waitForText('Completed, recovery proof incomplete')
|
|
->assertSee('Operation proof available')
|
|
->assertSee('Post-run evidence unavailable')
|
|
->assertSee('Restore result summary')
|
|
->assertSee('Item outcomes')
|
|
->assertSee('Spec335 Browser Policy')
|
|
->assertDontSee('browser raw payload should stay hidden')
|
|
->assertScript('document.querySelector("[data-testid=\"restore-run-diagnostics\"]")?.open === false', true)
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, spec335BrowserScreenshotName('02-restore-run-completed-proof-incomplete'));
|
|
|
|
$page->screenshot(true, spec335BrowserScreenshotName('03-restore-run-operation-proof'));
|
|
|
|
$page->screenshot(true, spec335BrowserScreenshotName('04-restore-run-evidence-unavailable'));
|
|
|
|
$page->screenshot(true, spec335BrowserScreenshotName('05-restore-run-item-outcomes'));
|
|
|
|
$page->screenshot(true, spec335BrowserScreenshotName('07-restore-run-diagnostics-collapsed'));
|
|
|
|
visit(spec335BrowserViewPath($tenant, $failedRun))
|
|
->resize(1440, 1100)
|
|
->waitForText('Restore failed')
|
|
->assertSee('Review failure details')
|
|
->assertSee('Spec335 Failed Browser Policy')
|
|
->assertScript('document.querySelector("[data-testid=\"restore-run-diagnostics\"]")?.open === false', true)
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, spec335BrowserScreenshotName('06-restore-run-failed-if-supported'));
|
|
|
|
visit(spec335BrowserLoginUrl($user, $tenant, spec335BrowserViewPath($tenant, $completedRun)))
|
|
->inDarkMode()
|
|
->resize(1440, 1100)
|
|
->waitForText('Completed, recovery proof incomplete')
|
|
->assertSee('Operation proof available')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs()
|
|
->screenshot(true, spec335BrowserScreenshotName('08-restore-run-dark-mode'));
|
|
});
|