TenantAtlas/tests/Feature/TrackOperationRunMiddlewareTest.php
ahmido 845d21db6d feat: harden operation lifecycle monitoring (#190)
## 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
2026-03-23 21:53:19 +00:00

79 lines
2.5 KiB
PHP

<?php
use App\Jobs\Middleware\TrackOperationRun;
use App\Models\OperationRun;
use App\Services\OperationRunService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
it('does not mark an operation run completed when the job is released', function () {
[$user, $tenant] = createUserWithTenant(role: 'owner');
/** @var OperationRunService $operationRunService */
$operationRunService = app(OperationRunService::class);
$operationRun = $operationRunService->ensureRun(
tenant: $tenant,
type: 'test.release',
inputs: ['foo' => 'bar'],
initiator: $user,
);
$job = new class($operationRun) implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(public OperationRun $operationRun)
{
$this->withFakeQueueInteractions();
}
};
$middleware = new TrackOperationRun;
$middleware->handle($job, function ($job): void {
$job->release(60);
});
$operationRun->refresh();
expect($operationRun->status)->toBe('running');
expect($operationRun->outcome)->toBe('pending');
});
it('marks an operation run failed when the wrapped job throws inside middleware execution', function () {
[$user, $tenant] = createUserWithTenant(role: 'owner');
/** @var OperationRunService $operationRunService */
$operationRunService = app(OperationRunService::class);
$operationRun = $operationRunService->ensureRun(
tenant: $tenant,
type: 'test.exception',
inputs: ['foo' => 'bar'],
initiator: $user,
);
$job = new class($operationRun) implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(public OperationRun $operationRun)
{
$this->withFakeQueueInteractions();
}
};
$middleware = new TrackOperationRun;
expect(fn () => $middleware->handle($job, function (): void {
throw new RuntimeException('wrapped job failure');
}))->toThrow(RuntimeException::class);
$operationRun->refresh();
expect($operationRun->status)->toBe('completed')
->and($operationRun->outcome)->toBe('failed')
->and(data_get($operationRun->failure_summary, '0.code'))->toBe('exception.unhandled');
});