*/ function baselineCompareLandingGapContext(): array { return [ 'baseline_compare' => [ 'subjects_total' => 50, 'reason_code' => 'evidence_capture_incomplete', 'fidelity' => 'meta', 'coverage' => [ 'proof' => true, 'covered_types' => ['deviceConfiguration'], 'uncovered_types' => [], 'effective_types' => ['deviceConfiguration'], ], 'evidence_capture' => [ 'requested' => 50, 'succeeded' => 47, 'skipped' => 0, 'failed' => 3, 'throttled' => 0, ], 'evidence_gaps' => [ 'count' => 5, 'by_reason' => [ 'ambiguous_match' => 3, 'policy_not_found' => 2, ], 'ambiguous_match' => 3, 'policy_not_found' => 2, 'subjects' => [ 'ambiguous_match' => [ 'deviceConfiguration|WiFi-Corp-Profile', 'deviceConfiguration|VPN-Always-On', ], 'policy_not_found' => [ 'deviceConfiguration|Deleted-Policy-ABC', ], ], ], ], ]; } function seedBaselineCompareLandingGapRun(\App\Models\Tenant $tenant): OperationRun { $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(), ]); return 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(), 'context' => baselineCompareLandingGapContext(), ]); } it('can access baseline compare when only the remembered admin tenant is available', function (): void { [$user, $tenant] = createUserWithTenant(role: 'owner'); $this->actingAs($user); Filament::setCurrentPanel('admin'); Filament::setTenant(null, true); Filament::bootCurrentPanel(); session()->put(WorkspaceContext::SESSION_KEY, (int) $tenant->workspace_id); session()->put(WorkspaceContext::LAST_TENANT_IDS_SESSION_KEY, [ (string) $tenant->workspace_id => (int) $tenant->getKey(), ]); expect(BaselineCompareLanding::canAccess())->toBeTrue(); }); it('renders tenant landing evidence-gap details with the same search affordances as the canonical run detail', function (): void { [$user, $tenant] = createUserWithTenant(role: 'owner'); $this->actingAs($user); $tenant->makeCurrent(); Filament::setTenant($tenant, true); seedBaselineCompareLandingGapRun($tenant); Livewire::test(BaselineCompareLanding::class) ->assertSee('Evidence gap details') ->assertSee('Search gap details') ->assertSee('Search by reason, policy type, or subject key') ->assertSee('Reason') ->assertSee('Ambiguous inventory match') ->assertSee('Policy not found') ->assertSee('WiFi-Corp-Profile') ->assertSee('Baseline compare evidence'); }); it('renders tenant landing evidence-gap details without invoking graph during render', function (): void { [$user, $tenant] = createUserWithTenant(role: 'owner'); $this->actingAs($user); $tenant->makeCurrent(); Filament::setTenant($tenant, true); bindFailHardGraphClient(); seedBaselineCompareLandingGapRun($tenant); Livewire::test(BaselineCompareLanding::class) ->assertSee('Evidence gap details') ->assertSee('WiFi-Corp-Profile') ->assertSee('Baseline compare evidence'); }); it('returns 404 for non-members on the tenant landing even when evidence-gap details exist', function (): void { [$member, $tenant] = createUserWithTenant(role: 'owner'); $nonMember = \App\Models\User::factory()->create(); seedBaselineCompareLandingGapRun($tenant); $this->actingAs($nonMember) ->get(BaselineCompareLanding::getUrl(tenant: $tenant, panel: 'tenant')) ->assertNotFound(); });