Some checks failed
Main Confidence / confidence (push) Failing after 54s
## Summary - harden baseline capture truth, compare readiness, and monitoring explanations around latest inventory eligibility, blocked prerequisites, and zero-subject outcomes - improve onboarding verification and bootstrap recovery handling, including admin-consent callback invalidation and queued execution legitimacy/report behavior - align workspace findings/workspace overview signals and refresh the related spec, roadmap, and spec-candidate artifacts ## Validation - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/BaselineDriftEngine/BaselineCaptureAuditEventsTest.php tests/Feature/BaselineDriftEngine/BaselineSnapshotNoTenantIdentifiersTest.php tests/Feature/BaselineDriftEngine/CaptureBaselineContentTest.php tests/Feature/BaselineDriftEngine/CaptureBaselineFullContentOnDemandTest.php tests/Feature/BaselineDriftEngine/CaptureBaselineMetaFallbackTest.php tests/Feature/Baselines/BaselineCaptureTest.php tests/Feature/Baselines/BaselineCompareFindingsTest.php tests/Feature/Baselines/BaselineSnapshotBackfillTest.php tests/Feature/Filament/BaselineCaptureResultExplanationSurfaceTest.php tests/Feature/Filament/BaselineCompareLandingStartSurfaceTest.php tests/Feature/Filament/BaselineProfileCaptureStartSurfaceTest.php tests/Feature/Filament/OperationRunBaselineTruthSurfaceTest.php tests/Feature/Monitoring/AuditCoverageGovernanceTest.php tests/Feature/Monitoring/GovernanceOperationRunSummariesTest.php tests/Feature/Notifications/OperationRunNotificationTest.php tests/Feature/Authorization/OperatorExplanationSurfaceAuthorizationTest.php` - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/AdminConsentCallbackTest.php tests/Feature/Filament/WorkspaceOverviewDbOnlyTest.php tests/Feature/Guards/Spec194GovernanceActionSemanticsGuardTest.php tests/Feature/ManagedTenantOnboardingWizardTest.php tests/Feature/Onboarding/OnboardingVerificationTest.php tests/Feature/Operations/QueuedExecutionAuditTrailTest.php tests/Unit/Operations/QueuedExecutionLegitimacyGateTest.php` ## Notes - browser validation was not re-run in this pass Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #271
115 lines
4.7 KiB
PHP
115 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\BaselineProfile;
|
|
use App\Models\BaselineSnapshot;
|
|
use App\Models\BaselineSnapshotItem;
|
|
use App\Models\OperationRun;
|
|
use App\Models\Workspace;
|
|
use App\Support\Baselines\BaselineReasonCodes;
|
|
use App\Support\Baselines\BaselineSnapshotLifecycleState;
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\OperationRunType;
|
|
use Illuminate\Database\Migrations\Migration;
|
|
|
|
function classifyLegacySnapshotForTest(BaselineSnapshot $snapshot): array
|
|
{
|
|
/** @var Migration $migration */
|
|
$migration = require base_path('database/migrations/2026_03_23_000001_add_lifecycle_state_to_baseline_snapshots_table.php');
|
|
|
|
$reflection = new ReflectionMethod($migration, 'classifyLegacySnapshot');
|
|
$reflection->setAccessible(true);
|
|
|
|
return $reflection->invoke(
|
|
$migration,
|
|
(object) [
|
|
'id' => (int) $snapshot->getKey(),
|
|
'workspace_id' => (int) $snapshot->workspace_id,
|
|
'baseline_profile_id' => (int) $snapshot->baseline_profile_id,
|
|
'captured_at' => $snapshot->captured_at,
|
|
'created_at' => $snapshot->created_at,
|
|
'updated_at' => $snapshot->updated_at,
|
|
'summary_jsonb' => json_encode($snapshot->summary_jsonb),
|
|
],
|
|
is_array($snapshot->summary_jsonb) ? $snapshot->summary_jsonb : [],
|
|
BaselineSnapshotItem::query()->where('baseline_snapshot_id', (int) $snapshot->getKey())->count(),
|
|
);
|
|
}
|
|
|
|
it('classifies legacy snapshots as complete when summary counts prove completion', function (): void {
|
|
$workspace = Workspace::factory()->create();
|
|
$profile = BaselineProfile::factory()->active()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
]);
|
|
|
|
$snapshot = BaselineSnapshot::factory()->complete()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'baseline_profile_id' => (int) $profile->getKey(),
|
|
'summary_jsonb' => ['total_items' => 2],
|
|
]);
|
|
|
|
BaselineSnapshotItem::factory()->count(2)->create([
|
|
'baseline_snapshot_id' => (int) $snapshot->getKey(),
|
|
]);
|
|
|
|
$classification = classifyLegacySnapshotForTest($snapshot);
|
|
|
|
expect($classification['lifecycle_state'])->toBe(BaselineSnapshotLifecycleState::Complete->value)
|
|
->and(data_get($classification, 'completion_meta.expected_items'))->toBe(2)
|
|
->and(data_get($classification, 'completion_meta.persisted_items'))->toBe(2);
|
|
});
|
|
|
|
it('classifies proven empty legacy captures as incomplete no-data snapshots when the producer run confirms zero subjects', function (): void {
|
|
$workspace = Workspace::factory()->create();
|
|
$profile = BaselineProfile::factory()->active()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
]);
|
|
|
|
$snapshot = BaselineSnapshot::factory()->complete()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'baseline_profile_id' => (int) $profile->getKey(),
|
|
'summary_jsonb' => ['total_items' => 0],
|
|
]);
|
|
|
|
OperationRun::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'type' => OperationRunType::BaselineCapture->value,
|
|
'outcome' => OperationRunOutcome::Succeeded->value,
|
|
'context' => [
|
|
'baseline_profile_id' => (int) $profile->getKey(),
|
|
'result' => ['snapshot_id' => (int) $snapshot->getKey()],
|
|
'baseline_capture' => ['subjects_total' => 0],
|
|
],
|
|
'completed_at' => now(),
|
|
]);
|
|
|
|
$classification = classifyLegacySnapshotForTest($snapshot);
|
|
|
|
expect($classification['lifecycle_state'])->toBe(BaselineSnapshotLifecycleState::Incomplete->value)
|
|
->and(data_get($classification, 'completion_meta.was_empty_capture'))->toBeTrue()
|
|
->and(data_get($classification, 'completion_meta.finalization_reason_code'))->toBe(BaselineReasonCodes::CAPTURE_ZERO_SUBJECTS);
|
|
});
|
|
|
|
it('classifies ambiguous legacy snapshots as incomplete with a conservative reason code', function (): void {
|
|
$workspace = Workspace::factory()->create();
|
|
$profile = BaselineProfile::factory()->active()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
]);
|
|
|
|
$snapshot = BaselineSnapshot::factory()->complete()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'baseline_profile_id' => (int) $profile->getKey(),
|
|
'summary_jsonb' => ['total_items' => 2],
|
|
]);
|
|
|
|
BaselineSnapshotItem::factory()->create([
|
|
'baseline_snapshot_id' => (int) $snapshot->getKey(),
|
|
]);
|
|
|
|
$classification = classifyLegacySnapshotForTest($snapshot);
|
|
|
|
expect($classification['lifecycle_state'])->toBe(BaselineSnapshotLifecycleState::Incomplete->value)
|
|
->and(data_get($classification, 'completion_meta.finalization_reason_code'))->toBe(BaselineReasonCodes::SNAPSHOT_LEGACY_CONTRADICTORY);
|
|
});
|