## Summary - codify Spec 193 as an explicit monitoring/workbench surface inventory with validator and guard coverage - refactor the Finding Exceptions Queue, Operations landing, and tenantless operation viewer into clearer context, navigation, utility, drilldown, and focused-work lanes - align Alerts, Audit Log, and Alert Deliveries with quiet origin-context handling while preserving calm reference surfaces and the explicit Tenant Diagnostics exception - add focused feature coverage, guard coverage, browser smoke coverage, and the full spec artifacts for Spec 193 ## Verification - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Guards/ActionSurfaceContractTest.php tests/Feature/Guards/ActionSurfaceValidatorTest.php tests/Feature/Guards/Spec193MonitoringSurfaceHierarchyGuardTest.php tests/Feature/OpsUx/OperateHubShellTest.php tests/Feature/Operations/TenantlessOperationRunViewerTest.php tests/Feature/Monitoring/FindingExceptionsQueueHierarchyTest.php tests/Browser/Spec193MonitoringSurfaceHierarchySmokeTest.php` - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` - integrated-browser smoke pass over queue, operations, operation detail, alerts, audit log, and tenant diagnostics ## Notes - Livewire v4 / Filament v5 stack unchanged - no provider-registration changes; Laravel 11+ provider registration remains in `bootstrap/providers.php` - no new global-search behavior was introduced - destructive and governance-changing actions keep their existing confirmation and authorization semantics - no new assets or migrations were added Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #227
204 lines
7.6 KiB
PHP
204 lines
7.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Pages\Monitoring\AuditLog as AuditLogPage;
|
|
use App\Models\AuditLog;
|
|
use App\Models\OperationRun;
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\OperationRunStatus;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Facades\Filament;
|
|
use Livewire\Livewire;
|
|
|
|
it('opens the selected audit event in a slideover inspection surface', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$audit = AuditLog::query()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'actor_email' => 'owner@example.com',
|
|
'actor_name' => 'Owner',
|
|
'actor_type' => 'human',
|
|
'action' => 'workspace.selected',
|
|
'status' => 'success',
|
|
'resource_type' => 'workspace',
|
|
'resource_id' => (string) $tenant->workspace_id,
|
|
'target_label' => 'Workspace 1',
|
|
'summary' => 'Workspace selected for Workspace 1',
|
|
'metadata' => [
|
|
'reason' => 'chooser',
|
|
'method' => 'manual',
|
|
],
|
|
'recorded_at' => now(),
|
|
]);
|
|
|
|
session()->put(WorkspaceContext::SESSION_KEY, (int) $tenant->workspace_id);
|
|
Filament::setTenant(null, true);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(AuditLogPage::class)
|
|
->assertCanSeeTableRecords([$audit])
|
|
->mountTableAction('inspect', $audit)
|
|
->assertMountedActionModalSee('Workspace selected for Workspace 1')
|
|
->assertMountedActionModalSee('Readable context')
|
|
->assertMountedActionModalSee('Technical metadata');
|
|
});
|
|
|
|
it('shows operation-run navigation only for the currently inspected operation run event', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$run = OperationRun::factory()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'type' => 'baseline_compare',
|
|
'status' => OperationRunStatus::Completed->value,
|
|
'outcome' => OperationRunOutcome::Succeeded->value,
|
|
]);
|
|
|
|
$withRunLink = AuditLog::query()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'actor_email' => 'owner@example.com',
|
|
'actor_name' => 'Owner',
|
|
'actor_type' => 'human',
|
|
'action' => 'operation_run.completed',
|
|
'status' => 'success',
|
|
'resource_type' => 'operation_run',
|
|
'resource_id' => (string) $run->getKey(),
|
|
'target_label' => 'Baseline compare #'.$run->getKey(),
|
|
'summary' => 'Baseline compare completed for Operation run',
|
|
'recorded_at' => now(),
|
|
]);
|
|
|
|
$withoutRunLink = AuditLog::query()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'tenant_id' => null,
|
|
'actor_email' => 'owner@example.com',
|
|
'actor_name' => 'Owner',
|
|
'actor_type' => 'human',
|
|
'action' => 'workspace.selected',
|
|
'status' => 'success',
|
|
'resource_type' => 'workspace',
|
|
'resource_id' => (string) $tenant->workspace_id,
|
|
'target_label' => 'Workspace 1',
|
|
'summary' => 'Workspace selected for Workspace 1',
|
|
'recorded_at' => now()->addSecond(),
|
|
]);
|
|
|
|
session()->put(WorkspaceContext::SESSION_KEY, (int) $tenant->workspace_id);
|
|
Filament::setTenant(null, true);
|
|
|
|
$component = Livewire::actingAs($user)
|
|
->test(AuditLogPage::class)
|
|
->assertCanSeeTableRecords([$withRunLink, $withoutRunLink])
|
|
->mountTableAction('inspect', $withRunLink)
|
|
->assertMountedActionModalSee('Open operation');
|
|
|
|
$component
|
|
->call('replaceMountedTableAction', 'inspect', (string) $withoutRunLink->getKey())
|
|
->assertMountedActionModalSee('Workspace selected for Workspace 1')
|
|
->assertMountedActionModalDontSee('Open operation')
|
|
->assertMountedActionModalDontSee('Baseline compare completed for Operation run');
|
|
});
|
|
|
|
it('clearing the slideover closes the inspection surface cleanly', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$audit = AuditLog::query()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'actor_email' => 'owner@example.com',
|
|
'actor_name' => 'Owner',
|
|
'actor_type' => 'human',
|
|
'action' => 'workspace.selected',
|
|
'status' => 'success',
|
|
'resource_type' => 'workspace',
|
|
'resource_id' => (string) $tenant->workspace_id,
|
|
'target_label' => 'Workspace 1',
|
|
'summary' => 'Workspace selected for Workspace 1',
|
|
'recorded_at' => now(),
|
|
]);
|
|
|
|
session()->put(WorkspaceContext::SESSION_KEY, (int) $tenant->workspace_id);
|
|
Filament::setTenant(null, true);
|
|
|
|
$component = Livewire::actingAs($user)
|
|
->test(AuditLogPage::class)
|
|
->mountTableAction('inspect', $audit)
|
|
->unmountTableAction()
|
|
->assertTableActionNotMounted('inspect');
|
|
|
|
expect($component->instance()->getMountedTableAction())->toBeNull();
|
|
});
|
|
|
|
it('keeps record inspection actions out of the global page header', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$run = OperationRun::factory()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'type' => 'baseline_compare',
|
|
'status' => OperationRunStatus::Completed->value,
|
|
'outcome' => OperationRunOutcome::Succeeded->value,
|
|
]);
|
|
|
|
AuditLog::query()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'actor_email' => 'owner@example.com',
|
|
'actor_name' => 'Owner',
|
|
'actor_type' => 'human',
|
|
'action' => 'operation_run.completed',
|
|
'status' => 'success',
|
|
'resource_type' => 'operation_run',
|
|
'resource_id' => (string) $run->getKey(),
|
|
'target_label' => 'Baseline compare #'.$run->getKey(),
|
|
'summary' => 'Baseline compare completed for Operation run',
|
|
'recorded_at' => now(),
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
|
|
->get(route('admin.monitoring.audit-log'))
|
|
->assertOk()
|
|
->assertDontSee('Close details')
|
|
->assertDontSee('Open operation');
|
|
});
|
|
|
|
it('surfaces origin context quietly when deep-linked to a selected audit event', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$audit = AuditLog::query()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'actor_email' => 'owner@example.com',
|
|
'actor_name' => 'Owner',
|
|
'actor_type' => 'human',
|
|
'action' => 'workspace.selected',
|
|
'status' => 'success',
|
|
'resource_type' => 'workspace',
|
|
'resource_id' => (string) $tenant->workspace_id,
|
|
'target_label' => 'Workspace 1',
|
|
'summary' => 'Workspace selected for Workspace 1',
|
|
'recorded_at' => now(),
|
|
]);
|
|
|
|
session()->put(WorkspaceContext::SESSION_KEY, (int) $tenant->workspace_id);
|
|
Filament::setTenant(null, true);
|
|
|
|
Livewire::withQueryParams([
|
|
'event' => (int) $audit->getKey(),
|
|
'nav' => [
|
|
'source_surface' => 'alerts.overview',
|
|
'canonical_route_name' => 'admin.monitoring.audit-log',
|
|
'back_label' => 'Back to alerts',
|
|
'back_url' => '/admin/alerts',
|
|
],
|
|
])
|
|
->actingAs($user)
|
|
->test(AuditLogPage::class)
|
|
->assertSet('selectedAuditLogId', (int) $audit->getKey())
|
|
->assertActionVisible('operate_hub_back_to_origin_audit_log');
|
|
});
|