TenantAtlas/tests/Browser/Spec174EvidenceFreshnessPublicationTrustSmokeTest.php
ahmido 44898a98ac feat: harden evidence freshness publication trust (#205)
## Summary
- harden governance artifact truth propagation so stale or partial evidence downgrades evidence snapshots, tenant reviews, review packs, the canonical evidence overview, and the canonical review register consistently
- add the full Spec 174 artifact set under `specs/174-evidence-freshness-publication-trust/` including spec, plan, research, data model, contracts, quickstart, checklist, and completed tasks
- add focused fixture helpers plus a new browser smoke test for the touched evidence, review, and review-pack trust surfaces

## Testing
- `vendor/bin/sail artisan test --compact tests/Feature/Evidence/EvidenceSnapshotResourceTest.php tests/Feature/Evidence/EvidenceOverviewPageTest.php tests/Feature/TenantReview/TenantReviewLifecycleTest.php tests/Feature/TenantReview/TenantReviewRegisterTest.php tests/Feature/ReviewPack/ReviewPackResourceTest.php tests/Feature/Monitoring/ArtifactTruthRunDetailTest.php tests/Browser/Spec174EvidenceFreshnessPublicationTrustSmokeTest.php`
- manual integrated-browser smoke pass across Evidence Overview, Review Register, tenant review detail, tenant evidence snapshot detail, and review-packs list

## Notes
- Livewire v4 compliance is preserved and no Filament v3/v4 APIs were introduced
- no panel or provider changes were made; Laravel 11+ provider registration remains in `bootstrap/providers.php`
- no new global-search behavior was introduced; existing resource view pages remain the relevant detail endpoints
- destructive actions were not broadened; existing confirmation and authorization behavior remains in place
- no new assets were added, so the current Filament asset strategy and deploy-time `php artisan filament:assets` behavior stay unchanged
- branch `174-evidence-freshness-publication-trust` is pushed at `7f2c82c26dc83bbc09fbf9e732d5644cdd143113` and targets `dev`

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #205
2026-04-04 11:31:27 +00:00

195 lines
7.2 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Resources\EvidenceSnapshotResource;
use App\Filament\Resources\ReviewPackResource;
use App\Filament\Resources\TenantReviewResource;
use App\Models\Tenant;
use App\Support\TenantReviewCompletenessState;
use App\Support\TenantReviewStatus;
use App\Support\Workspaces\WorkspaceContext;
use Tests\Feature\Concerns\BuildsGovernanceArtifactTruthFixtures;
uses(BuildsGovernanceArtifactTruthFixtures::class);
pest()->browser()->timeout(15_000);
it('smokes tenant-scoped evidence freshness and publication trust surfaces', function (): void {
$staleTenant = Tenant::factory()->create(['name' => 'Browser Smoke Stale Tenant']);
[$user, $staleTenant] = createUserWithTenant(tenant: $staleTenant, role: 'owner');
$partialTenant = Tenant::factory()->create([
'workspace_id' => (int) $staleTenant->workspace_id,
'name' => 'Browser Smoke Partial Tenant',
]);
createUserWithTenant(tenant: $partialTenant, user: $user, role: 'owner');
$staleSnapshot = seedStaleTenantReviewEvidence($staleTenant);
$partialSnapshot = seedPartialTenantReviewEvidence($partialTenant);
$partialReview = $this->makeArtifactTruthReview(
tenant: $partialTenant,
user: $user,
snapshot: $partialSnapshot,
reviewOverrides: [
'status' => TenantReviewStatus::Ready->value,
'completeness_state' => TenantReviewCompletenessState::Complete->value,
],
summaryOverrides: [
'publish_blockers' => [],
'section_state_counts' => [
'complete' => 6,
'partial' => 0,
'missing' => 0,
'stale' => 0,
],
],
);
$staleReview = $this->makeArtifactTruthReview(
tenant: $staleTenant,
user: $user,
snapshot: $staleSnapshot,
reviewOverrides: [
'status' => TenantReviewStatus::Published->value,
'published_at' => now(),
'published_by_user_id' => (int) $user->getKey(),
'completeness_state' => TenantReviewCompletenessState::Complete->value,
],
summaryOverrides: [
'publish_blockers' => [],
'section_state_counts' => [
'complete' => 6,
'partial' => 0,
'missing' => 0,
'stale' => 0,
],
],
);
$stalePack = $this->makeArtifactTruthReviewPack(
tenant: $staleTenant,
user: $user,
snapshot: $staleSnapshot,
review: $staleReview,
summaryOverrides: [
'review_status' => TenantReviewStatus::Published->value,
'review_completeness_state' => TenantReviewCompletenessState::Complete->value,
],
);
$this->actingAs($user)->withSession([
WorkspaceContext::SESSION_KEY => (int) $staleTenant->workspace_id,
]);
session()->put(WorkspaceContext::SESSION_KEY, (int) $staleTenant->workspace_id);
visit(EvidenceSnapshotResource::getUrl('view', ['record' => $staleSnapshot], tenant: $staleTenant))
->waitForText('Artifact truth')
->assertNoJavaScriptErrors()
->assertSee('Stale')
->assertSee('Refresh the stale evidence before relying on this snapshot');
visit(TenantReviewResource::tenantScopedUrl('view', ['record' => $partialReview], $partialTenant))
->waitForText('Artifact truth')
->assertNoJavaScriptErrors()
->assertSee('Internal only')
->assertSee('Complete the evidence basis before publishing this review');
visit(ReviewPackResource::getUrl('index', tenant: $staleTenant))
->waitForText('Artifact truth')
->assertNoJavaScriptErrors()
->assertSee('Internal only')
->assertSee('Refresh the source review before sharing this pack')
->assertSee('Download');
visit(ReviewPackResource::getUrl('view', ['record' => $stalePack], tenant: $staleTenant))
->waitForText('Artifact truth')
->assertNoJavaScriptErrors()
->assertSee('Internal only')
->assertSee('Refresh the source review before sharing this pack')
->assertSee('Download');
});
it('smokes canonical evidence and review trust surfaces', function (): void {
$staleTenant = Tenant::factory()->create(['name' => 'Browser Canonical Stale Tenant']);
[$user, $staleTenant] = createUserWithTenant(tenant: $staleTenant, role: 'owner');
$partialTenant = Tenant::factory()->create([
'workspace_id' => (int) $staleTenant->workspace_id,
'name' => 'Browser Canonical Partial Tenant',
]);
createUserWithTenant(tenant: $partialTenant, user: $user, role: 'owner');
$freshTenant = Tenant::factory()->create([
'workspace_id' => (int) $staleTenant->workspace_id,
'name' => 'Browser Canonical Fresh Tenant',
]);
createUserWithTenant(tenant: $freshTenant, user: $user, role: 'owner');
$staleSnapshot = $this->makeStaleArtifactTruthEvidenceSnapshot($staleTenant);
$freshSnapshot = $this->makeArtifactTruthEvidenceSnapshot($freshTenant);
$partialSnapshot = seedPartialTenantReviewEvidence($partialTenant);
$this->makeArtifactTruthReview(
tenant: $staleTenant,
user: $user,
snapshot: $staleSnapshot,
reviewOverrides: [
'status' => TenantReviewStatus::Published->value,
'published_at' => now(),
'published_by_user_id' => (int) $user->getKey(),
'completeness_state' => TenantReviewCompletenessState::Complete->value,
],
summaryOverrides: [
'publish_blockers' => [],
'section_state_counts' => [
'complete' => 6,
'partial' => 0,
'missing' => 0,
'stale' => 0,
],
],
);
$this->makeArtifactTruthReview(
tenant: $partialTenant,
user: $user,
snapshot: $partialSnapshot,
reviewOverrides: [
'status' => TenantReviewStatus::Ready->value,
'completeness_state' => TenantReviewCompletenessState::Complete->value,
],
summaryOverrides: [
'publish_blockers' => [],
'section_state_counts' => [
'complete' => 6,
'partial' => 0,
'missing' => 0,
'stale' => 0,
],
],
);
$this->actingAs($user)->withSession([
WorkspaceContext::SESSION_KEY => (int) $staleTenant->workspace_id,
]);
session()->put(WorkspaceContext::SESSION_KEY, (int) $staleTenant->workspace_id);
visit(route('admin.evidence.overview'))
->waitForText('Browser Canonical Stale Tenant')
->assertNoJavaScriptErrors()
->assertSee('Browser Canonical Fresh Tenant')
->assertSee('Refresh the stale evidence before relying on this snapshot')
->assertSee('Create a current review from this evidence snapshot');
visit('/admin/reviews')
->waitForText('Browser Canonical Stale Tenant')
->assertNoJavaScriptErrors()
->assertSee('Browser Canonical Partial Tenant')
->assertSee('Internal only')
->assertSee('Refresh the evidence basis before publishing this review')
->assertSee('Complete the evidence basis before publishing this review')
->assertDontSee('Publishable');
});