TenantAtlas/apps/platform/tests/Unit/Filament/RestoreRunDetailPresenterDeterminismTest.php
ahmido 4edb047901 feat: productize restore run detail proof surface (#404)
## 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
2026-05-29 01:20:55 +00:00

103 lines
4.0 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Resources\RestoreRunResource\Presenters\RestoreRunDetailPresenter;
use App\Models\BackupSet;
use App\Models\EvidenceSnapshot;
use App\Models\OperationRun;
use App\Models\RestoreRun;
use App\Support\Evidence\EvidenceCompletenessState;
use App\Support\Evidence\EvidenceSnapshotStatus;
use App\Support\OperationRunOutcome;
use App\Support\OperationRunStatus;
use App\Support\OperationRunType;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('recomputes post-run evidence availability from current repo-backed state', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$this->actingAs($user);
Filament::setTenant($tenant, true);
$backupSet = BackupSet::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
]);
$operationRun = OperationRun::factory()->forTenant($tenant)->create([
'type' => OperationRunType::RestoreExecute->value,
'status' => OperationRunStatus::Completed->value,
'outcome' => OperationRunOutcome::Succeeded->value,
'completed_at' => now(),
]);
$restoreRun = RestoreRun::factory()->for($tenant, 'tenant')->for($backupSet)->create([
'status' => 'completed',
'operation_run_id' => (int) $operationRun->getKey(),
'metadata' => [
'total' => 1,
'succeeded' => 1,
'failed' => 0,
'skipped' => 0,
'partial' => 0,
'non_applied' => 0,
],
]);
$presenter = app(RestoreRunDetailPresenter::class);
$first = $presenter->forRun($restoreRun->fresh(['backupSet', 'operationRun', 'tenant']));
expect(data_get($first, 'decision.state'))->toBe('completed_proof_incomplete')
->and(data_get($first, 'operationProof.state'))->toBe('available')
->and(data_get($first, 'postRunEvidence.state'))->toBe('unavailable');
EvidenceSnapshot::query()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $tenant->workspace_id,
'operation_run_id' => (int) $operationRun->getKey(),
'status' => EvidenceSnapshotStatus::Active->value,
'completeness_state' => EvidenceCompletenessState::Complete->value,
'summary' => ['finding_count' => 0],
'generated_at' => now(),
]);
$second = $presenter->forRun($restoreRun->fresh(['backupSet', 'operationRun', 'tenant']));
expect(data_get($second, 'decision.state'))->toBe('completed_with_evidence')
->and(data_get($second, 'postRunEvidence.state'))->toBe('available')
->and(data_get($second, 'postRunEvidence.identifier'))->toContain('Evidence snapshot #');
});
it('does not expose operation proof from another workspace or environment', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$this->actingAs($user);
Filament::setTenant($tenant, true);
$backupSet = BackupSet::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
]);
$foreignTenant = \App\Models\ManagedEnvironment::factory()->create();
$foreignOperationRun = OperationRun::factory()->forTenant($foreignTenant)->create([
'type' => OperationRunType::RestoreExecute->value,
'status' => OperationRunStatus::Completed->value,
'outcome' => OperationRunOutcome::Succeeded->value,
'completed_at' => now(),
]);
$restoreRun = RestoreRun::factory()->for($tenant, 'tenant')->for($backupSet)->create([
'status' => 'completed',
'operation_run_id' => (int) $foreignOperationRun->getKey(),
]);
$surface = app(RestoreRunDetailPresenter::class)
->forRun($restoreRun->fresh(['backupSet', 'operationRun', 'tenant']));
expect(data_get($surface, 'operationProof.state'))->toBe('unavailable')
->and(data_get($surface, 'operationProof.url'))->toBeNull()
->and(data_get($surface, 'postRunEvidence.state'))->toBe('unavailable');
});