active()->create([ 'workspace_id' => $tenant->workspace_id, 'scope_jsonb' => ['policy_types' => ['deviceConfiguration'], 'foundation_types' => []], ]); $baselineCapturedAt = CarbonImmutable::parse('2026-03-01 00:00:00'); $snapshot = BaselineSnapshot::factory()->create([ 'workspace_id' => $tenant->workspace_id, 'baseline_profile_id' => (int) $profile->getKey(), 'captured_at' => $baselineCapturedAt, ]); $inventorySyncRun = createInventorySyncOperationRunWithCoverage( tenant: $tenant, statusByType: ['deviceConfiguration' => 'succeeded'], ); $policy = Policy::factory()->create([ 'tenant_id' => (int) $tenant->getKey(), 'policy_type' => 'deviceConfiguration', 'external_id' => 'policy-fidelity-content', 'platform' => 'windows', 'display_name' => 'Policy Fidelity Content', ]); $baselineSnapshotPayload = [ 'settings' => [ ['displayName' => 'SettingA', 'value' => 1], ], ]; $baselineHash = app(DriftHasher::class)->hashNormalized( app(SettingsNormalizer::class)->normalizeForDiff($baselineSnapshotPayload, 'deviceConfiguration', 'windows'), ); BaselineSnapshotItem::factory()->create([ 'baseline_snapshot_id' => (int) $snapshot->getKey(), 'subject_type' => 'policy', 'subject_external_id' => (string) $policy->external_id, 'policy_type' => (string) $policy->policy_type, 'baseline_hash' => $baselineHash, 'meta_jsonb' => [ 'display_name' => (string) $policy->display_name, 'evidence' => [ 'fidelity' => 'content', 'source' => 'policy_version', 'observed_at' => $baselineCapturedAt->toIso8601String(), 'observed_operation_run_id' => null, ], ], ]); InventoryItem::factory()->create([ 'tenant_id' => (int) $tenant->getKey(), 'external_id' => (string) $policy->external_id, 'policy_type' => (string) $policy->policy_type, 'display_name' => (string) $policy->display_name, 'meta_jsonb' => [ 'odata_type' => '#microsoft.graph.deviceConfiguration', 'etag' => 'W/"same-etag"', 'scope_tag_ids' => [], 'assignment_target_count' => 1, ], 'last_seen_operation_run_id' => (int) $inventorySyncRun->getKey(), 'last_seen_at' => now(), ]); PolicyVersion::factory()->create([ 'tenant_id' => (int) $tenant->getKey(), 'policy_id' => (int) $policy->getKey(), 'policy_type' => (string) $policy->policy_type, 'platform' => (string) $policy->platform, 'captured_at' => $baselineCapturedAt->addHour(), 'snapshot' => [ 'settings' => [ ['displayName' => 'SettingA', 'value' => 2], ], ], ]); $opService = app(OperationRunService::class); $compareRun = $opService->ensureRunWithIdentity( tenant: $tenant, type: OperationRunType::BaselineCompare->value, identityInputs: ['baseline_profile_id' => (int) $profile->getKey()], context: [ 'baseline_profile_id' => (int) $profile->getKey(), 'baseline_snapshot_id' => (int) $snapshot->getKey(), 'effective_scope' => ['policy_types' => ['deviceConfiguration'], 'foundation_types' => []], ], initiator: $user, ); (new CompareBaselineToTenantJob($compareRun))->handle( app(BaselineSnapshotIdentity::class), app(AuditLogger::class), $opService, ); $finding = Finding::query() ->where('tenant_id', (int) $tenant->getKey()) ->where('subject_external_id', (string) $policy->external_id) ->sole(); expect($finding->evidence_fidelity)->toBe('content'); }); it('Baseline finding fidelity is meta when baseline evidence is meta (even if current content exists)', function () { [$user, $tenant] = createUserWithTenant(); $profile = BaselineProfile::factory()->active()->create([ 'workspace_id' => $tenant->workspace_id, 'scope_jsonb' => ['policy_types' => ['deviceConfiguration'], 'foundation_types' => []], ]); $baselineCapturedAt = CarbonImmutable::parse('2026-03-02 00:00:00'); $snapshot = BaselineSnapshot::factory()->create([ 'workspace_id' => $tenant->workspace_id, 'baseline_profile_id' => (int) $profile->getKey(), 'captured_at' => $baselineCapturedAt, ]); $inventorySyncRun = createInventorySyncOperationRunWithCoverage( tenant: $tenant, statusByType: ['deviceConfiguration' => 'succeeded'], ); $policy = Policy::factory()->create([ 'tenant_id' => (int) $tenant->getKey(), 'policy_type' => 'deviceConfiguration', 'external_id' => 'policy-fidelity-meta', 'platform' => 'windows', 'display_name' => 'Policy Fidelity Meta', ]); $baselineMetaJsonb = [ 'odata_type' => '#microsoft.graph.deviceConfiguration', 'etag' => 'W/"E_BASELINE"', 'scope_tag_ids' => [], 'assignment_target_count' => 1, ]; $baselineHash = app(BaselineSnapshotIdentity::class)->hashItemContent( policyType: (string) $policy->policy_type, subjectExternalId: (string) $policy->external_id, metaJsonb: $baselineMetaJsonb, ); BaselineSnapshotItem::factory()->create([ 'baseline_snapshot_id' => (int) $snapshot->getKey(), 'subject_type' => 'policy', 'subject_external_id' => (string) $policy->external_id, 'policy_type' => (string) $policy->policy_type, 'baseline_hash' => $baselineHash, 'meta_jsonb' => [ 'display_name' => (string) $policy->display_name, 'evidence' => [ 'fidelity' => 'meta', 'source' => 'inventory', 'observed_at' => $baselineCapturedAt->toIso8601String(), 'observed_operation_run_id' => null, ], ], ]); InventoryItem::factory()->create([ 'tenant_id' => (int) $tenant->getKey(), 'external_id' => (string) $policy->external_id, 'policy_type' => (string) $policy->policy_type, 'display_name' => (string) $policy->display_name, 'meta_jsonb' => [ 'odata_type' => '#microsoft.graph.deviceConfiguration', 'etag' => 'W/"E_CURRENT"', 'scope_tag_ids' => [], 'assignment_target_count' => 1, ], 'last_seen_operation_run_id' => (int) $inventorySyncRun->getKey(), 'last_seen_at' => now(), ]); PolicyVersion::factory()->create([ 'tenant_id' => (int) $tenant->getKey(), 'policy_id' => (int) $policy->getKey(), 'policy_type' => (string) $policy->policy_type, 'platform' => (string) $policy->platform, 'captured_at' => $baselineCapturedAt->addHour(), 'snapshot' => [ 'settings' => [ ['displayName' => 'SettingA', 'value' => 99], ], ], ]); $opService = app(OperationRunService::class); $compareRun = $opService->ensureRunWithIdentity( tenant: $tenant, type: OperationRunType::BaselineCompare->value, identityInputs: ['baseline_profile_id' => (int) $profile->getKey()], context: [ 'baseline_profile_id' => (int) $profile->getKey(), 'baseline_snapshot_id' => (int) $snapshot->getKey(), 'effective_scope' => ['policy_types' => ['deviceConfiguration'], 'foundation_types' => []], ], initiator: $user, ); (new CompareBaselineToTenantJob($compareRun))->handle( app(BaselineSnapshotIdentity::class), app(AuditLogger::class), $opService, ); $finding = Finding::query() ->where('tenant_id', (int) $tenant->getKey()) ->where('subject_external_id', (string) $policy->external_id) ->sole(); expect($finding->evidence_fidelity)->toBe('meta'); });