TenantAtlas/apps/platform/tests/Feature/Console/ReconcileBackupScheduleOperationRunsCommandTest.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

72 lines
2.5 KiB
PHP

<?php
use App\Models\BackupSchedule;
use App\Models\OperationRun;
use App\Models\ManagedEnvironment;
use Carbon\CarbonImmutable;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('reconciles stale running backup schedule operation runs', function () {
$tenant = ManagedEnvironment::factory()->create();
$schedule = BackupSchedule::create([
'managed_environment_id' => $tenant->id,
'name' => 'Daily',
'is_enabled' => true,
'timezone' => 'UTC',
'frequency' => 'daily',
'time_of_day' => '10:00:00',
'days_of_week' => null,
'policy_types' => ['deviceConfiguration'],
'include_foundations' => true,
'retention_keep_last' => 30,
'last_run_at' => null,
'last_run_status' => null,
'next_run_at' => null,
]);
$startedAt = CarbonImmutable::parse('2026-01-01 00:00:00', 'UTC');
$operationRun = OperationRun::factory()
->minimal()
->forTenant($tenant)
->create([
'type' => 'backup_schedule_run',
'status' => 'running',
'outcome' => 'pending',
'run_identity_hash' => hash('sha256', 'backup_schedule_run:'.$schedule->id),
'summary_counts' => [],
'failure_summary' => [],
'context' => [
'backup_schedule_id' => (int) $schedule->id,
],
'started_at' => $startedAt,
'created_at' => $startedAt,
'updated_at' => $startedAt,
]);
$this->artisan('tenantpilot:operation-runs:reconcile-backup-schedules', [
'--tenant' => [$tenant->id],
'--older-than' => 0,
])->assertSuccessful();
$operationRun->refresh();
expect($operationRun->status)->toBe('completed');
expect($operationRun->outcome)->toBe('failed');
expect($operationRun->failure_summary)->toMatchArray([
[
'code' => 'run.stale_running',
'message' => 'The run stayed active past its lifecycle window and was marked failed.',
'reason_code' => 'run.stale_running',
],
]);
expect(data_get($operationRun->context, 'backup_schedule_id'))->toBe((int) $schedule->id)
->and(data_get($operationRun->context, 'reason_code'))->toBe('run.stale_running')
->and(data_get($operationRun->context, 'reconciliation.reason'))->toBe('run.stale_running')
->and(data_get($operationRun->context, 'reconciliation.reason_code'))->toBe('run.stale_running')
->and(data_get($operationRun->context, 'reconciliation.source'))->toBe('scheduled_reconciler');
});