TenantAtlas/apps/platform/tests/Feature/Console/ReconcileBackupScheduleOperationRunsCommandTest.php
ahmido d8e331e92f Spec 207: implement shared test fixture slimming (#240)
## Summary
- implement the canonical shared fixture profile model with minimal, standard, and full semantics plus temporary legacy alias resolution
- slim default factory behavior for operation runs, backup sets, provider connections, and provider credentials while keeping explicit heavy opt-in states
- migrate the first console, navigation, RBAC, and drift caller packs to explicit lean helpers and wire lane comparison reporting into the existing Spec 206 seams
- reconcile spec 207 docs, contracts, quickstart guidance, and task tracking with the implemented behavior

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Unit/Support/CreateUserWithTenantProfilesTest.php tests/Unit/Factories/TenantFactoryTest.php tests/Unit/Factories/OperationRunFactoryTest.php tests/Unit/Factories/BackupSetFactoryTest.php tests/Unit/Factories/ProviderConnectionFactoryTest.php tests/Unit/Factories/ProviderCredentialFactoryTest.php tests/Feature/Guards/FixtureCostProfilesGuardTest.php tests/Feature/Guards/FixtureLaneImpactBudgetTest.php tests/Feature/Guards/TestLaneArtifactsContractTest.php tests/Feature/Console/ReconcileOperationRunsCommandTest.php tests/Feature/Console/ReconcileBackupScheduleOperationRunsCommandTest.php tests/Feature/Navigation/RelatedNavigationResolverMemoizationTest.php tests/Feature/Spec080WorkspaceManagedTenantAdminMigrationTest.php tests/Feature/BaselineDriftEngine/FindingFidelityTest.php`
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`
- `./scripts/platform-test-lane fast-feedback`
- `./scripts/platform-test-lane confidence`
- `./scripts/platform-test-report fast-feedback`
- `./scripts/platform-test-report confidence`

## Lane outcome
- `fast-feedback`: 136.400761s vs 176.73623s baseline, status `improved`
- `confidence`: 394.5669s vs 394.383441s baseline, status `stable`

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #240
2026-04-16 17:29:25 +00:00

72 lines
2.5 KiB
PHP

<?php
use App\Models\BackupSchedule;
use App\Models\OperationRun;
use App\Models\Tenant;
use Carbon\CarbonImmutable;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('reconciles stale running backup schedule operation runs', function () {
$tenant = Tenant::factory()->create();
$schedule = BackupSchedule::create([
'tenant_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');
});