TenantAtlas/apps/platform/tests/Feature/Guards/ArtifactSourceProviderTruthGuardTest.php
ahmido 75ebade345 feat: implement provider-neutral artifact source taxonomy (#343)
## Summary

Implements Spec 284 for provider-neutral artifact source taxonomy.

- add shared artifact source descriptor, resolver, taxonomy, and provider-detail support
- update findings, evidence snapshots, stored reports, inventory items, and tenant review surfaces to disclose descriptor-first artifact summaries
- add bounded Pest unit, feature, guard, and browser coverage for the taxonomy slice
- include the completed Spec 284 package artifacts under `specs/284-provider-neutral-artifact-source-taxonomy/`

## Notes

- branch: `284-provider-neutral-artifact-source-taxonomy`
- commit: `bf8d59e0`
- this PR was created as part of the requested commit/push/PR flow against `platform-dev`

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #343
2026-05-08 23:47:31 +00:00

62 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\Finding;
use App\Models\InventoryItem;
use App\Models\StoredReport;
use App\Support\Ai\AiUseCaseCatalog;
use App\Support\Artifacts\ArtifactSourceDescriptor;
use App\Support\Artifacts\ArtifactSourceTaxonomy;
it('keeps provider-native type names out of descriptor top-level truth', function (): void {
[$user, $tenant] = createUserWithTenant();
$finding = Finding::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $tenant->workspace_id,
'evidence_jsonb' => ['policy_type' => 'deviceCompliancePolicy'],
]);
$report = StoredReport::factory()->permissionPosture()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $tenant->workspace_id,
]);
$inventory = InventoryItem::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $tenant->workspace_id,
'policy_type' => 'deviceCompliancePolicy',
]);
foreach ([$finding->artifactSourceDescriptor(), $report->artifactSourceDescriptor(), $inventory->artifactSourceDescriptor()] as $descriptor) {
$payload = $descriptor->toArray();
expect($payload)->not->toHaveKeys(['finding_type', 'report_type', 'policy_type'])
->and($payload['package_run_id'])->toBeNull();
}
expect($finding->artifactProviderDetail()->toArray()['legacy_policy_type'])->toBe('deviceCompliancePolicy')
->and($report->artifactProviderDetail()->toArray()['legacy_report_type'])->toBe(StoredReport::REPORT_TYPE_PERMISSION_POSTURE)
->and($inventory->artifactProviderDetail()->toArray()['legacy_policy_type'])->toBe('deviceCompliancePolicy');
$this->actingAs($user);
});
it('keeps package_run_id optional and does not recast AI source families as artifact runtime truth', function (): void {
$descriptor = ArtifactSourceDescriptor::fromArray([
'workspace_id' => 1,
'tenant_id' => 2,
'managed_environment_id' => 2,
'source_family' => 'finding',
'source_kind' => 'model_summary',
'provider_key' => 'microsoft',
'source_target_kind' => 'managed_environment',
'package_run_id' => 123,
]);
$aiSourceFamilies = collect(app(AiUseCaseCatalog::class)->all())->pluck('source_family');
expect($descriptor->packageRunId)->toBe(123)
->and($aiSourceFamilies->intersect(ArtifactSourceTaxonomy::sourceFamilies())->values()->all())->toBe([])
->and($aiSourceFamilies->all())->toContain('product_knowledge', 'support_diagnostics');
});