actingAs($user); $scopeKey = hash('sha256', 'scope-a'); createInventorySyncOperationRun($tenant, [ 'selection_hash' => $scopeKey, 'status' => 'success', 'finished_at' => now()->subDays(3), ]); $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(), ]); createInventorySyncOperationRun($tenant, [ 'selection_hash' => $scopeKey, 'status' => 'failed', 'finished_at' => now(), ]); $selector = app(DriftRunSelector::class); $selected = $selector->selectBaselineAndCurrent($tenant, $scopeKey); expect($selected)->not->toBeNull(); expect($selected['baseline']->getKey())->toBe($baseline->getKey()); expect($selected['current']->getKey())->toBe($current->getKey()); }); test('it returns null when fewer than two successful runs exist for scope', function () { [$user, $tenant] = createUserWithTenant(role: 'manager'); $this->actingAs($user); $scopeKey = hash('sha256', 'scope-b'); createInventorySyncOperationRun($tenant, [ 'selection_hash' => $scopeKey, 'status' => 'success', 'finished_at' => now()->subDay(), ]); $selector = app(DriftRunSelector::class); expect($selector->selectBaselineAndCurrent($tenant, $scopeKey))->toBeNull(); });