## 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
147 lines
5.8 KiB
PHP
147 lines
5.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Services\TenantReviews\TenantReviewLifecycleService;
|
|
use App\Services\TenantReviews\TenantReviewReadinessGate;
|
|
use App\Support\TenantReviewCompletenessState;
|
|
use App\Support\TenantReviewStatus;
|
|
use App\Support\Ui\GovernanceArtifactTruth\ArtifactTruthPresenter;
|
|
use Tests\Feature\Concerns\BuildsGovernanceArtifactTruthFixtures;
|
|
|
|
uses(BuildsGovernanceArtifactTruthFixtures::class);
|
|
|
|
it('blocks publication when required review sections are missing from the anchored evidence basis', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$review = composeTenantReviewForTest($tenant, $user, seedTenantReviewEvidence(
|
|
tenant: $tenant,
|
|
permissionPayload: [
|
|
'required_count' => 11,
|
|
'granted_count' => 7,
|
|
],
|
|
operationRunCount: 0,
|
|
));
|
|
|
|
expect(app(TenantReviewReadinessGate::class)->canPublish($review))->toBeFalse()
|
|
->and($review->publishBlockers())->not->toBeEmpty();
|
|
|
|
$truth = app(ArtifactTruthPresenter::class)->forTenantReview($review);
|
|
|
|
expect($truth->artifactExistence)->toBe('created')
|
|
->and($truth->publicationReadiness)->toBe('blocked')
|
|
->and($truth->primaryLabel)->toBe('Publication blocked')
|
|
->and($truth->nextStepText())->toBe('Resolve the review blockers before publication');
|
|
|
|
expect(fn () => app(TenantReviewLifecycleService::class)->publish($review, $user))
|
|
->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
|
|
it('publishes ready tenant reviews and archives them without mutating the published evidence history', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$review = $this->makeArtifactTruthReview(
|
|
tenant: $tenant,
|
|
user: $user,
|
|
snapshot: $this->makeArtifactTruthEvidenceSnapshot($tenant),
|
|
reviewOverrides: [
|
|
'status' => TenantReviewStatus::Ready->value,
|
|
'completeness_state' => TenantReviewCompletenessState::Complete->value,
|
|
],
|
|
summaryOverrides: [
|
|
'publish_blockers' => [],
|
|
'section_state_counts' => [
|
|
'complete' => 6,
|
|
'partial' => 0,
|
|
'missing' => 0,
|
|
'stale' => 0,
|
|
],
|
|
],
|
|
);
|
|
|
|
$published = app(TenantReviewLifecycleService::class)->publish($review, $user);
|
|
$publishedAt = $published->published_at?->toIso8601String();
|
|
|
|
expect($published->status)->toBe(TenantReviewStatus::Published->value)
|
|
->and($published->published_by_user_id)->toBe((int) $user->getKey())
|
|
->and($publishedAt)->not->toBeNull();
|
|
|
|
$publishedTruth = app(ArtifactTruthPresenter::class)->forTenantReview($published);
|
|
|
|
$archived = app(TenantReviewLifecycleService::class)->archive($published, $user);
|
|
$archivedTruth = app(ArtifactTruthPresenter::class)->forTenantReview($archived);
|
|
|
|
expect($archived->status)->toBe(TenantReviewStatus::Archived->value)
|
|
->and($archived->archived_at)->not->toBeNull()
|
|
->and($archived->published_at?->toIso8601String())->toBe($publishedAt)
|
|
->and($publishedTruth->publicationReadiness)->toBe('publishable')
|
|
->and($publishedTruth->nextStepText())->toBe('No action needed')
|
|
->and($archivedTruth->artifactExistence)->toBe('historical_only')
|
|
->and($archivedTruth->publicationReadiness)->toBe('internal_only')
|
|
->and($archivedTruth->nextStepText())->toBe('No action needed');
|
|
});
|
|
|
|
it('keeps stale published reviews internal only even when the lifecycle status is published', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$snapshot = seedStaleTenantReviewEvidence($tenant);
|
|
|
|
$review = $this->makeArtifactTruthReview(
|
|
tenant: $tenant,
|
|
user: $user,
|
|
snapshot: $snapshot,
|
|
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,
|
|
],
|
|
],
|
|
);
|
|
|
|
$truth = app(ArtifactTruthPresenter::class)->forTenantReview($review);
|
|
|
|
expect($truth->freshnessState)->toBe('stale')
|
|
->and($truth->publicationReadiness)->toBe('internal_only')
|
|
->and($truth->primaryLabel)->toBe('Internal only')
|
|
->and($truth->nextStepText())->toBe('Refresh the evidence basis before publishing this review');
|
|
});
|
|
|
|
it('downgrades structurally ready reviews with partial evidence to internal only', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$snapshot = seedPartialTenantReviewEvidence($tenant);
|
|
|
|
$review = $this->makeArtifactTruthReview(
|
|
tenant: $tenant,
|
|
user: $user,
|
|
snapshot: $snapshot,
|
|
reviewOverrides: [
|
|
'status' => TenantReviewStatus::Ready->value,
|
|
'completeness_state' => TenantReviewCompletenessState::Complete->value,
|
|
],
|
|
summaryOverrides: [
|
|
'publish_blockers' => [],
|
|
'section_state_counts' => [
|
|
'complete' => 6,
|
|
'partial' => 0,
|
|
'missing' => 0,
|
|
'stale' => 0,
|
|
],
|
|
],
|
|
);
|
|
|
|
$truth = app(ArtifactTruthPresenter::class)->forTenantReview($review);
|
|
|
|
expect($truth->contentState)->toBe('partial')
|
|
->and($truth->freshnessState)->toBe('current')
|
|
->and($truth->publicationReadiness)->toBe('internal_only')
|
|
->and($truth->primaryLabel)->toBe('Internal only')
|
|
->and($truth->nextStepText())->toBe('Complete the evidence basis before publishing this review');
|
|
});
|