TenantAtlas/tests/Feature/Filament/BaselineSnapshotFidelityVisibilityTest.php
ahmido 92704a2f7e Spec 118: Resumable baseline evidence capture + snapshot UX (#143)
Implements Spec 118 baseline drift engine improvements:

- Resumable, budget-aware evidence capture for baseline capture/compare runs (resume token + UI action)
- “Why no findings?” reason-code driven explanations and richer run context panels
- Baseline Snapshot resource (list/detail) with fidelity visibility
- Retention command + schedule for pruning baseline-purpose PolicyVersions
- i18n strings for Baseline Compare landing

Verification:
- `vendor/bin/sail bin pint --dirty --format agent`
- `vendor/bin/sail artisan test --compact --filter=Baseline` (159 passed)

Note:
- `docs/audits/redaction-audit-2026-03-04.md` left untracked (not part of PR).

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #143
2026-03-04 22:34:13 +00:00

65 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Resources\BaselineSnapshotResource;
use App\Models\BaselineProfile;
use App\Models\BaselineSnapshot;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('shows snapshot fidelity counts and gap state on list and view pages', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'readonly');
$profile = BaselineProfile::factory()->active()->create([
'workspace_id' => (int) $tenant->workspace_id,
]);
$complete = BaselineSnapshot::factory()->create([
'workspace_id' => (int) $tenant->workspace_id,
'baseline_profile_id' => (int) $profile->getKey(),
'captured_at' => now()->subHour(),
'summary_jsonb' => [
'total_items' => 5,
'fidelity_counts' => ['content' => 5, 'meta' => 0],
'gaps' => ['count' => 0, 'by_reason' => []],
],
]);
$withGaps = BaselineSnapshot::factory()->create([
'workspace_id' => (int) $tenant->workspace_id,
'baseline_profile_id' => (int) $profile->getKey(),
'captured_at' => now()->subMinutes(10),
'summary_jsonb' => [
'total_items' => 5,
'fidelity_counts' => ['content' => 3, 'meta' => 2],
'gaps' => ['count' => 2, 'by_reason' => ['meta_fallback' => 2]],
],
]);
$this->actingAs($user)
->get(BaselineSnapshotResource::getUrl(panel: 'admin'))
->assertOk()
->assertSee('Complete')
->assertSee('Captured with gaps')
->assertSee('Content 5, Meta 0')
->assertSee('Content 3, Meta 2');
$this->actingAs($user)
->get(BaselineSnapshotResource::getUrl('view', ['record' => $withGaps], panel: 'admin'))
->assertOk()
->assertSee('Captured with gaps')
->assertSee('Content 3, Meta 2')
->assertSee('Evidence gaps')
->assertSee('2');
$this->actingAs($user)
->get(BaselineSnapshotResource::getUrl('view', ['record' => $complete], panel: 'admin'))
->assertOk()
->assertSee('Complete')
->assertSee('Content 5, Meta 0')
->assertSee('Evidence gaps')
->assertSee('0');
});