TenantAtlas/apps/platform/tests/Feature/Filament/WorkspaceOverviewOperationsTest.php
ahmido e64bae9cfc feat: cut over tenant core to managed environments (#335)
## Summary
- replace the legacy Tenant and TenantMembership core models with ManagedEnvironment and ManagedEnvironmentMembership
- propagate the managed environment naming and key changes across Filament resources, pages, controllers, jobs, models, and supporting runtime paths
- add feature 279 spec artifacts and focused managed-environment test coverage for model behavior, route binding, panel context, authorization, and legacy guardrails

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/ManagedEnvironment/LegacyTenantCoreGuardTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentAuthorizationTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentPanelContextTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentRouteBindingTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentContextResolverTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentModelTest.php`
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`

## Notes
- branch pushed from commit `1123b122`
- browser smoke test file was added but not run in this pass

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #335
2026-05-07 06:38:14 +00:00

89 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\OperationRun;
use App\Models\ManagedEnvironment;
use App\Support\Workspaces\WorkspaceContext;
it('shows only recent operations from the current users authorized tenant slice and does not enable polling', function (): void {
$tenantA = ManagedEnvironment::factory()->create(['status' => 'active']);
[$user, $tenantA] = createUserWithTenant($tenantA, role: 'owner', workspaceRole: 'readonly');
$tenantB = ManagedEnvironment::factory()->create([
'status' => 'active',
'workspace_id' => (int) $tenantA->workspace_id,
'name' => 'Forbidden ManagedEnvironment',
]);
OperationRun::factory()->create([
'managed_environment_id' => (int) $tenantA->getKey(),
'workspace_id' => (int) $tenantA->workspace_id,
'type' => 'inventory_sync',
'initiator_name' => 'Accessible run',
]);
OperationRun::factory()->create([
'managed_environment_id' => (int) $tenantB->getKey(),
'workspace_id' => (int) $tenantB->workspace_id,
'type' => 'policy.sync',
'initiator_name' => 'Forbidden run',
]);
$response = $this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $tenantA->workspace_id])
->get('/admin')
->assertOk()
->assertSee('Inventory sync')
->assertDontSee('Forbidden ManagedEnvironment')
->assertDontSee('Policy sync');
expect((string) $response->getContent())->not->toContain('wire:poll');
});
it('keeps recent operations diagnostic and separate from calm governance messaging', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
[$profile, $snapshot] = seedActiveBaselineForTenant($tenant);
seedBaselineCompareRun($tenant, $profile, $snapshot, workspaceOverviewCompareCoverage());
OperationRun::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $tenant->workspace_id,
'type' => 'inventory_sync',
'status' => \App\Support\OperationRunStatus::Running->value,
'outcome' => \App\Support\OperationRunOutcome::Pending->value,
'created_at' => now()->subHour(),
'started_at' => now()->subHour(),
]);
OperationRun::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $tenant->workspace_id,
'type' => 'restore.execute',
'status' => \App\Support\OperationRunStatus::Completed->value,
'outcome' => \App\Support\OperationRunOutcome::Failed->value,
'context' => [
'reconciliation' => [
'reconciled_at' => now()->toIso8601String(),
'reason' => 'run.infrastructure_timeout_or_abandonment',
'reason_code' => 'run.infrastructure_timeout_or_abandonment',
'source' => 'failed_callback',
],
],
'failure_summary' => [[
'code' => 'operation.failed',
'reason_code' => 'run.infrastructure_timeout_or_abandonment',
'message' => 'Infrastructure ended the run before completion.',
]],
]);
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
->get('/admin')
->assertOk()
->assertSee('Diagnostic recency across your visible workspace slice. This does not define governance health on its own.')
->assertSee('Likely stale')
->assertSee('Automatically reconciled')
->assertDontSee('Visible governance, findings, compare posture, and activity currently look calm.');
});