## Summary - harden operation-run lifecycle handling with explicit reconciliation policy, stale-run healing, failed-job bridging, and monitoring visibility - refactor audit log event inspection into a Filament slide-over and remove the stale inline detail/header-action coupling - align panel theme asset resolution and supporting Filament UI updates, including the rounded 2xl theme token regression fix ## Testing - ran focused Pest coverage for the affected audit-log inspection flow and related visibility tests - ran formatting with `vendor/bin/sail bin pint --dirty --format agent` - manually verified the updated audit-log slide-over flow in the integrated browser ## Notes - branch includes the Spec 160 artifacts under `specs/160-operation-lifecycle-guarantees/` - the full test suite was not rerun as part of this final commit/PR step Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #190
99 lines
3.8 KiB
PHP
99 lines
3.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\OperationRun;
|
|
use App\Services\Operations\OperationLifecycleReconciler;
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\OperationRunStatus;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('reconciles stale queued and running covered runs while leaving fresh runs untouched', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$staleQueued = OperationRun::factory()->create([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'user_id' => (int) $user->getKey(),
|
|
'type' => 'policy.sync',
|
|
'status' => OperationRunStatus::Queued->value,
|
|
'outcome' => OperationRunOutcome::Pending->value,
|
|
'started_at' => null,
|
|
'created_at' => now()->subMinutes(15),
|
|
]);
|
|
|
|
$staleRunning = OperationRun::factory()->create([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'user_id' => (int) $user->getKey(),
|
|
'type' => 'inventory_sync',
|
|
'status' => OperationRunStatus::Running->value,
|
|
'outcome' => OperationRunOutcome::Pending->value,
|
|
'started_at' => now()->subMinutes(30),
|
|
'created_at' => now()->subMinutes(30),
|
|
]);
|
|
|
|
$freshRunning = OperationRun::factory()->create([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'user_id' => (int) $user->getKey(),
|
|
'type' => 'inventory_sync',
|
|
'status' => OperationRunStatus::Running->value,
|
|
'outcome' => OperationRunOutcome::Pending->value,
|
|
'started_at' => now()->subMinutes(2),
|
|
'created_at' => now()->subMinutes(2),
|
|
]);
|
|
|
|
$result = app(OperationLifecycleReconciler::class)->reconcile([
|
|
'types' => ['policy.sync', 'inventory_sync'],
|
|
'tenant_ids' => [(int) $tenant->getKey()],
|
|
'dry_run' => false,
|
|
]);
|
|
|
|
expect($result['reconciled'])->toBe(2)
|
|
->and($result['skipped'])->toBe(1);
|
|
|
|
expect($staleQueued->fresh()->status)->toBe(OperationRunStatus::Completed->value)
|
|
->and($staleQueued->fresh()->outcome)->toBe(OperationRunOutcome::Failed->value)
|
|
->and(data_get($staleQueued->fresh()->context, 'reconciliation.reason_code'))->toBe('run.stale_queued');
|
|
|
|
expect($staleRunning->fresh()->status)->toBe(OperationRunStatus::Completed->value)
|
|
->and($staleRunning->fresh()->outcome)->toBe(OperationRunOutcome::Failed->value)
|
|
->and(data_get($staleRunning->fresh()->context, 'reconciliation.reason_code'))->toBe('run.stale_running');
|
|
|
|
expect($freshRunning->fresh()->status)->toBe(OperationRunStatus::Running->value)
|
|
->and($freshRunning->fresh()->outcome)->toBe(OperationRunOutcome::Pending->value);
|
|
});
|
|
|
|
it('is idempotent when the reconciler is run repeatedly', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$run = OperationRun::factory()->create([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'user_id' => (int) $user->getKey(),
|
|
'type' => 'policy.sync',
|
|
'status' => OperationRunStatus::Queued->value,
|
|
'outcome' => OperationRunOutcome::Pending->value,
|
|
'created_at' => now()->subMinutes(20),
|
|
]);
|
|
|
|
$reconciler = app(OperationLifecycleReconciler::class);
|
|
|
|
$first = $reconciler->reconcile([
|
|
'types' => ['policy.sync'],
|
|
'tenant_ids' => [(int) $tenant->getKey()],
|
|
]);
|
|
|
|
$second = $reconciler->reconcile([
|
|
'types' => ['policy.sync'],
|
|
'tenant_ids' => [(int) $tenant->getKey()],
|
|
]);
|
|
|
|
expect($first['reconciled'])->toBe(1)
|
|
->and($second['reconciled'])->toBe(0)
|
|
->and($run->fresh()->status)->toBe(OperationRunStatus::Completed->value);
|
|
});
|