Added `ProviderResourceBinding` model, migrations, policies, and supporting framework for canonical resource identity mapping as defined in Spec 381. This provides the structural capability to resolve baseline and posture discrepancies by binding logical entities across source providers to canonical identities. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #452
70 lines
3.0 KiB
PHP
70 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\ProviderResourceBinding;
|
|
use App\Services\Evidence\Sources\BaselineDriftPostureSource;
|
|
use App\Support\Evidence\EvidenceCompletenessState;
|
|
use App\Support\OperationRunOutcome;
|
|
|
|
it('keeps baseline drift posture missing when no drift findings or compare proof exist', function (): void {
|
|
[, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
ProviderResourceBinding::factory()->create([
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
]);
|
|
|
|
$payload = app(BaselineDriftPostureSource::class)->collect($tenant);
|
|
|
|
expect($payload['state'])->toBe(EvidenceCompletenessState::Missing->value)
|
|
->and($payload['summary_payload']['drift_count'])->toBe(0)
|
|
->and($payload['summary_payload'])->not->toHaveKey('provider_resource_bindings')
|
|
->and($payload['summary_payload']['latest_compare_run_id'])->toBeNull();
|
|
});
|
|
|
|
it('marks no baseline drift as complete when the latest compare succeeded', function (): void {
|
|
[, $tenant] = createUserWithTenant(role: 'owner');
|
|
[$profile, $snapshot] = seedActiveBaselineForTenant($tenant);
|
|
|
|
$run = seedBaselineCompareRun(
|
|
tenant: $tenant,
|
|
profile: $profile,
|
|
snapshot: $snapshot,
|
|
compareContext: ['reason_code' => 'baseline.compare.no_drift_detected'],
|
|
outcome: OperationRunOutcome::Succeeded->value,
|
|
);
|
|
|
|
$payload = app(BaselineDriftPostureSource::class)->collect($tenant);
|
|
|
|
expect($payload['state'])->toBe(EvidenceCompletenessState::Complete->value)
|
|
->and($payload['measured_at']?->equalTo($run->completed_at))->toBeTrue()
|
|
->and($payload['summary_payload']['drift_count'])->toBe(0)
|
|
->and($payload['summary_payload']['latest_compare_run_id'])->toBe((int) $run->getKey())
|
|
->and($payload['summary_payload']['latest_compare_outcome'])->toBe(OperationRunOutcome::Succeeded->value);
|
|
});
|
|
|
|
it('marks no baseline drift as partial when the latest compare completed with warnings', function (): void {
|
|
[, $tenant] = createUserWithTenant(role: 'owner');
|
|
[$profile, $snapshot] = seedActiveBaselineForTenant($tenant);
|
|
|
|
$run = seedBaselineCompareRun(
|
|
tenant: $tenant,
|
|
profile: $profile,
|
|
snapshot: $snapshot,
|
|
compareContext: [
|
|
'reason_code' => 'baseline.compare.no_drift_detected',
|
|
'evidence_gaps' => ['count' => 3],
|
|
],
|
|
outcome: OperationRunOutcome::PartiallySucceeded->value,
|
|
);
|
|
|
|
$payload = app(BaselineDriftPostureSource::class)->collect($tenant);
|
|
|
|
expect($payload['state'])->toBe(EvidenceCompletenessState::Partial->value)
|
|
->and($payload['measured_at']?->equalTo($run->completed_at))->toBeTrue()
|
|
->and($payload['summary_payload']['drift_count'])->toBe(0)
|
|
->and($payload['summary_payload']['latest_compare_run_id'])->toBe((int) $run->getKey())
|
|
->and($payload['summary_payload']['latest_compare_outcome'])->toBe(OperationRunOutcome::PartiallySucceeded->value);
|
|
});
|