TenantAtlas/apps/platform/tests/Feature/Operations/ReconcileAdapterRunsJobTrackingTest.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

85 lines
2.9 KiB
PHP

<?php
use App\Jobs\ReconcileAdapterRunsJob;
use App\Models\OperationRun;
use App\Models\Workspace;
use App\Services\AdapterRunReconciler;
use App\Services\OperationRunService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Queue\Middleware\WithoutOverlapping;
uses(RefreshDatabase::class);
test('reconcile adapter runs job tracks successful execution in operation runs', function (): void {
$workspace = Workspace::factory()->create();
$job = new class((int) $workspace->getKey(), '2026-02-15 10:00:00') extends ReconcileAdapterRunsJob
{
protected function reconcile(AdapterRunReconciler $reconciler): array
{
return [
'candidates' => 4,
'reconciled' => 3,
'skipped' => 1,
];
}
};
$job->handle(new AdapterRunReconciler, app(OperationRunService::class));
$run = OperationRun::query()
->where('workspace_id', (int) $workspace->getKey())
->whereNull('managed_environment_id')
->where('type', 'ops.reconcile_adapter_runs')
->first();
expect($run)->not->toBeNull();
expect($run?->status)->toBe('completed');
expect($run?->outcome)->toBe('succeeded');
expect($run?->summary_counts ?? [])->toMatchArray([
'total' => 4,
'processed' => 4,
'failed' => 0,
]);
});
test('reconcile adapter runs job tracks failure with stable code and sanitized message', function (): void {
$workspace = Workspace::factory()->create();
$job = new class((int) $workspace->getKey(), '2026-02-15 10:30:00') extends ReconcileAdapterRunsJob
{
protected function reconcile(AdapterRunReconciler $reconciler): array
{
throw new RuntimeException('Authorization: Bearer highly-sensitive-token-for-user@example.com');
}
};
expect(fn () => $job->handle(new AdapterRunReconciler, app(OperationRunService::class)))
->toThrow(\RuntimeException::class);
$run = OperationRun::query()
->where('workspace_id', (int) $workspace->getKey())
->whereNull('managed_environment_id')
->where('type', 'ops.reconcile_adapter_runs')
->first();
expect($run)->not->toBeNull();
expect($run?->status)->toBe('completed');
expect($run?->outcome)->toBe('failed');
$failure = $run?->failure_summary[0] ?? [];
expect($failure['code'] ?? null)->toBe('ops.reconcile_adapter_runs.failed');
expect((string) ($failure['message'] ?? ''))->not->toContain('Bearer');
expect((string) ($failure['message'] ?? ''))->not->toContain('@example.com');
});
test('reconcile adapter runs job enforces server-side overlap middleware', function (): void {
$job = new ReconcileAdapterRunsJob;
$hasWithoutOverlapping = collect($job->middleware())
->contains(fn (mixed $middleware): bool => $middleware instanceof WithoutOverlapping);
expect($hasWithoutOverlapping)->toBeTrue();
});