- Implement Spec 116 baseline capture/compare + coverage guard\n- Add UI surfaces and widgets for baseline compare\n- Add tests and research report
105 lines
3.7 KiB
PHP
105 lines
3.7 KiB
PHP
<?php
|
|
|
|
use App\Filament\Pages\DriftLanding;
|
|
use App\Models\BaselineProfile;
|
|
use App\Models\BaselineSnapshot;
|
|
use App\Models\BaselineTenantAssignment;
|
|
use App\Models\OperationRun;
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\OperationRunStatus;
|
|
use App\Support\OperationRunType;
|
|
use Filament\Facades\Filament;
|
|
use Livewire\Livewire;
|
|
|
|
test('drift landing exposes baseline/current run ids and timestamps', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'manager');
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$scopeKey = hash('sha256', 'scope-landing-comparison-info');
|
|
|
|
$baseline = createInventorySyncOperationRun($tenant, [
|
|
'selection_hash' => $scopeKey,
|
|
'status' => 'success',
|
|
'finished_at' => now()->subDays(2),
|
|
]);
|
|
|
|
$current = createInventorySyncOperationRun($tenant, [
|
|
'selection_hash' => $scopeKey,
|
|
'status' => 'success',
|
|
'finished_at' => now()->subDay(),
|
|
]);
|
|
|
|
Livewire::test(DriftLanding::class)
|
|
->assertSet('scopeKey', $scopeKey)
|
|
->assertSet('baselineRunId', (int) $baseline->getKey())
|
|
->assertSet('currentRunId', (int) $current->getKey())
|
|
->assertSet('baselineFinishedAt', $baseline->finished_at->toDateTimeString())
|
|
->assertSet('currentFinishedAt', $current->finished_at->toDateTimeString());
|
|
});
|
|
|
|
test('drift landing exposes baseline compare coverage + fidelity context when available', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'manager');
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$scopeKey = hash('sha256', 'scope-landing-comparison-info');
|
|
|
|
createInventorySyncOperationRun($tenant, [
|
|
'selection_hash' => $scopeKey,
|
|
'status' => 'success',
|
|
'finished_at' => now()->subDays(2),
|
|
]);
|
|
|
|
createInventorySyncOperationRun($tenant, [
|
|
'selection_hash' => $scopeKey,
|
|
'status' => 'success',
|
|
'finished_at' => now()->subDay(),
|
|
]);
|
|
|
|
$profile = BaselineProfile::factory()->active()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
]);
|
|
|
|
$snapshot = BaselineSnapshot::factory()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'baseline_profile_id' => (int) $profile->getKey(),
|
|
]);
|
|
|
|
$profile->update(['active_snapshot_id' => (int) $snapshot->getKey()]);
|
|
|
|
BaselineTenantAssignment::factory()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'baseline_profile_id' => (int) $profile->getKey(),
|
|
]);
|
|
|
|
$compareRun = OperationRun::factory()->create([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'type' => OperationRunType::BaselineCompare->value,
|
|
'status' => OperationRunStatus::Completed->value,
|
|
'outcome' => OperationRunOutcome::PartiallySucceeded->value,
|
|
'completed_at' => now()->subMinutes(5),
|
|
'context' => [
|
|
'baseline_profile_id' => (int) $profile->getKey(),
|
|
'baseline_snapshot_id' => (int) $snapshot->getKey(),
|
|
'baseline_compare' => [
|
|
'coverage' => [
|
|
'effective_types' => ['deviceConfiguration'],
|
|
'covered_types' => [],
|
|
'uncovered_types' => ['deviceConfiguration'],
|
|
'proof' => false,
|
|
],
|
|
'fidelity' => 'meta',
|
|
],
|
|
],
|
|
]);
|
|
|
|
Livewire::test(DriftLanding::class)
|
|
->assertSet('baselineCompareRunId', (int) $compareRun->getKey())
|
|
->assertSet('baselineCompareCoverageStatus', 'unproven')
|
|
->assertSet('baselineCompareFidelity', 'meta')
|
|
->assertSet('baselineCompareUncoveredTypesCount', 1);
|
|
});
|