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
105 lines
3.5 KiB
PHP
105 lines
3.5 KiB
PHP
<?php
|
|
|
|
use App\Jobs\RunBackupScheduleJob;
|
|
use App\Models\BackupSchedule;
|
|
use App\Models\OperationRun;
|
|
use App\Services\BackupScheduling\BackupScheduleDispatcher;
|
|
use App\Services\OperationRunService;
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Support\Facades\Bus;
|
|
|
|
it('dispatching the same slot twice creates only one run', function () {
|
|
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 1, 5, 10, 0, 30, 'UTC'));
|
|
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
BackupSchedule::query()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Daily 10:00',
|
|
'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,
|
|
'next_run_at' => null,
|
|
]);
|
|
|
|
Bus::fake();
|
|
|
|
$dispatcher = app(BackupScheduleDispatcher::class);
|
|
|
|
$dispatcher->dispatchDue([$tenant->external_id]);
|
|
$dispatcher->dispatchDue([$tenant->external_id]);
|
|
|
|
expect(OperationRun::query()
|
|
->where('tenant_id', $tenant->getKey())
|
|
->where('type', 'backup_schedule_run')
|
|
->count())->toBe(1);
|
|
|
|
Bus::assertDispatchedTimes(RunBackupScheduleJob::class, 1);
|
|
|
|
Bus::assertDispatched(RunBackupScheduleJob::class, function (RunBackupScheduleJob $job) use ($tenant): bool {
|
|
return $job->backupScheduleId !== null
|
|
&& $job->backupScheduleRunId === 0
|
|
&& $job->operationRun?->tenant_id === $tenant->getKey()
|
|
&& $job->operationRun?->type === 'backup_schedule_run';
|
|
});
|
|
});
|
|
|
|
it('treats an existing canonical run as already-dispatched and advances next_run_at', function () {
|
|
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 1, 5, 10, 0, 30, 'UTC'));
|
|
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
$schedule = BackupSchedule::query()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Daily 10:00',
|
|
'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,
|
|
'next_run_at' => null,
|
|
]);
|
|
|
|
/** @var OperationRunService $operationRunService */
|
|
$operationRunService = app(OperationRunService::class);
|
|
|
|
$operationRunService->ensureRunWithIdentityStrict(
|
|
tenant: $tenant,
|
|
type: 'backup_schedule_run',
|
|
identityInputs: [
|
|
'backup_schedule_id' => (int) $schedule->id,
|
|
'scheduled_for' => CarbonImmutable::now('UTC')->startOfMinute()->toDateTimeString(),
|
|
],
|
|
context: [
|
|
'backup_schedule_id' => (int) $schedule->id,
|
|
'scheduled_for' => CarbonImmutable::now('UTC')->startOfMinute()->toDateTimeString(),
|
|
'trigger' => 'scheduled',
|
|
],
|
|
);
|
|
|
|
Bus::fake();
|
|
|
|
$dispatcher = app(BackupScheduleDispatcher::class);
|
|
$dispatcher->dispatchDue([$tenant->external_id]);
|
|
Bus::assertNotDispatched(RunBackupScheduleJob::class);
|
|
|
|
expect(OperationRun::query()
|
|
->where('tenant_id', $tenant->getKey())
|
|
->where('type', 'backup_schedule_run')
|
|
->count())->toBe(1);
|
|
|
|
$schedule->refresh();
|
|
expect($schedule->next_run_at)->not->toBeNull();
|
|
expect($schedule->next_run_at->toDateTimeString())->toBe('2026-01-06 10:00:00');
|
|
});
|