## Summary - replace the baseline snapshot detail page with a structured summary-first rendering flow - add a presenter plus renderer registry with RBAC, compliance, and fallback renderers - add grouped policy-type browsing, fidelity and gap badges, and workspace authorization coverage - add Feature 130 spec, plan, contract, research, quickstart, and completed task artifacts ## Testing - focused Pest coverage was added for structured rendering, fallback behavior, degraded states, authorization, presenter logic, renderer resolution, and badge mapping - I did not rerun the full validation suite in this final PR step ## Notes - base branch: `dev` - feature branch: `130-structured-snapshot-rendering` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #158
115 lines
4.6 KiB
PHP
115 lines
4.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\BaselineProfile;
|
|
use App\Models\BaselineSnapshot;
|
|
use App\Models\BaselineSnapshotItem;
|
|
use App\Services\Baselines\SnapshotRendering\BaselineSnapshotPresenter;
|
|
use App\Services\Baselines\SnapshotRendering\Renderers\DeviceComplianceSnapshotTypeRenderer;
|
|
use App\Services\Baselines\SnapshotRendering\Renderers\FallbackSnapshotTypeRenderer;
|
|
use App\Services\Baselines\SnapshotRendering\Renderers\IntuneRoleDefinitionSnapshotTypeRenderer;
|
|
use App\Services\Baselines\SnapshotRendering\SnapshotTypeRendererRegistry;
|
|
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
|
|
|
it('builds summary rows and grouped output for mixed snapshot types', function (): void {
|
|
$presenter = new BaselineSnapshotPresenter(
|
|
new SnapshotTypeRendererRegistry(
|
|
renderers: [
|
|
new IntuneRoleDefinitionSnapshotTypeRenderer,
|
|
new DeviceComplianceSnapshotTypeRenderer,
|
|
],
|
|
fallbackRenderer: new FallbackSnapshotTypeRenderer,
|
|
),
|
|
);
|
|
|
|
$snapshot = new BaselineSnapshot([
|
|
'id' => 130,
|
|
'snapshot_identity_hash' => 'snapshot-hash-130',
|
|
'captured_at' => now(),
|
|
'summary_jsonb' => [
|
|
'total_items' => 3,
|
|
'policy_type_counts' => [
|
|
'intuneRoleDefinition' => 1,
|
|
'deviceCompliancePolicy' => 1,
|
|
'mysteryPolicyType' => 1,
|
|
],
|
|
'fidelity_counts' => [
|
|
'content' => 2,
|
|
'meta' => 1,
|
|
],
|
|
'gaps' => [
|
|
'count' => 1,
|
|
'by_reason' => ['meta_fallback' => 1],
|
|
],
|
|
],
|
|
]);
|
|
|
|
$snapshot->setRelation('baselineProfile', new BaselineProfile(['name' => 'Security Baseline']));
|
|
$snapshot->setRelation('items', new EloquentCollection([
|
|
new BaselineSnapshotItem([
|
|
'id' => 1,
|
|
'policy_type' => 'intuneRoleDefinition',
|
|
'subject_key' => hash('sha256', 'intuneRoleDefinition|security-reader'),
|
|
'subject_external_id' => hash('sha256', 'intuneRoleDefinition|security-reader'),
|
|
'meta_jsonb' => [
|
|
'display_name' => 'Security Reader',
|
|
'evidence' => [
|
|
'fidelity' => 'content',
|
|
'source' => 'policy_version',
|
|
'observed_at' => '2026-03-09T12:00:00+00:00',
|
|
],
|
|
'identity' => ['strategy' => 'external_id'],
|
|
'rbac' => [
|
|
'is_built_in' => false,
|
|
'role_permission_count' => 2,
|
|
],
|
|
'version_reference' => ['policy_version_id' => 42],
|
|
],
|
|
]),
|
|
new BaselineSnapshotItem([
|
|
'id' => 2,
|
|
'policy_type' => 'deviceCompliancePolicy',
|
|
'subject_key' => 'bitlocker require',
|
|
'subject_external_id' => hash('sha256', 'deviceCompliancePolicy|bitlocker require'),
|
|
'meta_jsonb' => [
|
|
'display_name' => 'Bitlocker Require',
|
|
'platform' => 'windows',
|
|
'assignment_target_count' => 3,
|
|
'evidence' => [
|
|
'fidelity' => 'meta',
|
|
'source' => 'inventory',
|
|
'observed_at' => '2026-03-09T11:00:00+00:00',
|
|
],
|
|
],
|
|
]),
|
|
new BaselineSnapshotItem([
|
|
'id' => 3,
|
|
'policy_type' => 'mysteryPolicyType',
|
|
'subject_key' => 'mystery policy',
|
|
'subject_external_id' => hash('sha256', 'mysteryPolicyType|mystery policy'),
|
|
'meta_jsonb' => [
|
|
'display_name' => 'Mystery Policy',
|
|
'category' => 'Other',
|
|
'platform' => 'windows',
|
|
'evidence' => [
|
|
'fidelity' => 'content',
|
|
'source' => 'policy_version',
|
|
'observed_at' => '2026-03-09T10:00:00+00:00',
|
|
],
|
|
],
|
|
]),
|
|
]));
|
|
|
|
$rendered = $presenter->present($snapshot)->toArray();
|
|
|
|
expect(data_get($rendered, 'snapshot.snapshotId'))->toBe(130)
|
|
->and(data_get($rendered, 'snapshot.baselineProfileName'))->toBe('Security Baseline')
|
|
->and(data_get($rendered, 'snapshot.overallFidelity'))->toBe('partial')
|
|
->and(data_get($rendered, 'snapshot.overallGapCount'))->toBe(1)
|
|
->and($rendered['summaryRows'])->toHaveCount(3)
|
|
->and(collect($rendered['groups'])->pluck('label')->all())
|
|
->toContain('Intune RBAC Role Definition', 'Device Compliance', 'Mystery Policy Type')
|
|
->and(data_get($rendered, 'technicalDetail.defaultCollapsed'))->toBeTrue();
|
|
});
|