TenantAtlas/tests/Feature/BaselineDriftEngine/PerformanceGuardTest.php
ahmido f08924525d Spec 117: Baseline Drift Engine + evidence fidelity/provenance (#142)
Implements Spec 117 (Golden Master Baseline Drift Engine):

- Adds provider-chain resolver for current state hashes (content evidence via PolicyVersion, meta evidence via inventory)
- Updates baseline capture + compare jobs to use resolver and persist provenance + fidelity
- Adds evidence_fidelity column/index + Filament UI badge/filter/provenance display for findings
- Adds performance guard test + integration tests for drift, fidelity semantics, provenance, filter behavior
- UX fix: Policies list shows "Sync from Intune" header action only when records exist; empty-state CTA remains and is functional

Tests:
- `vendor/bin/sail artisan test --compact tests/Feature/Filament/PolicySyncCtaPlacementTest.php`
- `vendor/bin/sail artisan test --compact --filter=Baseline`

Checklist:
- specs/117-baseline-drift-engine/checklists/requirements.md ✓

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #142
2026-03-03 07:23:01 +00:00

44 lines
1.3 KiB
PHP

<?php
use App\Models\InventoryItem;
use App\Services\Baselines\CurrentStateHashResolver;
use Illuminate\Support\Facades\DB;
it('Baseline resolver remains batch-oriented (bounded query count)', function () {
[, $tenant] = createUserWithTenant();
$inventoryItems = InventoryItem::factory()
->count(500)
->create([
'tenant_id' => (int) $tenant->getKey(),
'policy_type' => 'deviceConfiguration',
'meta_jsonb' => [
'odata_type' => '#microsoft.graph.deviceConfiguration',
'etag' => 'E',
'scope_tag_ids' => [],
'assignment_target_count' => 1,
],
'last_seen_operation_run_id' => null,
'last_seen_at' => now(),
]);
$subjects = $inventoryItems->map(static fn (InventoryItem $item): array => [
'policy_type' => (string) $item->policy_type,
'subject_external_id' => (string) $item->external_id,
])->all();
DB::enableQueryLog();
DB::flushQueryLog();
app(CurrentStateHashResolver::class)->resolveForSubjects(
tenant: $tenant,
subjects: $subjects,
since: null,
latestInventorySyncRunId: null,
);
$queryCount = count(DB::getQueryLog());
expect($queryCount)->toBeLessThanOrEqual(20);
});