Implements Spec 087: Legacy Runs Removal (rigorous). ### What changed - Canonicalized run history: **`operation_runs` is the only run system** for inventory sync, Entra group sync, backup schedule execution/retention/purge. - Removed legacy UI surfaces (Filament Resources / relation managers) for legacy run models. - Legacy run URLs now return **404** (no redirects), with RBAC semantics preserved (404 vs 403 as specified). - Canonicalized affected `operation_runs.type` values (dotted → underscore) via migration. - Drift + inventory references now point to canonical operation runs; includes backfills and then drops legacy FK columns. - Drops legacy run tables after cutover. - Added regression guards to prevent reintroducing legacy run tokens or “backfilling” canonical runs from legacy tables. ### Migrations - `2026_02_12_000001..000006_*` canonicalize types, add/backfill operation_run_id references, drop legacy columns, and drop legacy run tables. ### Tests Focused pack for this spec passed: - `tests/Feature/Guards/NoLegacyRunsTest.php` - `tests/Feature/Guards/NoLegacyRunBackfillTest.php` - `tests/Feature/Operations/LegacyRunRoutesNotFoundTest.php` - `tests/Feature/Monitoring/MonitoringOperationsTest.php` - `tests/Feature/Jobs/RunInventorySyncJobTest.php` ### Notes / impact - Destructive cleanup is handled via migrations (drops legacy tables) after code cutover; deploy should run migrations in the same release. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #106
71 lines
2.2 KiB
PHP
71 lines
2.2 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::create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'tenant_id' => $tenant->id,
|
|
'user_id' => null,
|
|
'initiator_name' => 'System',
|
|
'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' => 'backup_schedule.stalled',
|
|
'message' => 'Backup schedule run exceeded reconciliation timeout and was marked failed.',
|
|
'reason_code' => 'unknown_error',
|
|
],
|
|
]);
|
|
expect($operationRun->context)->toMatchArray([
|
|
'backup_schedule_id' => (int) $schedule->id,
|
|
]);
|
|
});
|