TenantAtlas/tests/Feature/OpsUx/RunDetailPollingStopsOnTerminalTest.php
ahmido 4db73e872e Spec 123: operations auto-refresh pass (#149)
## Summary
- add conditional polling support for the tenantless operation run viewer and tenant review pack card
- add focused Pest coverage for active vs terminal polling behavior and related review pack access regressions
- add the full Spec Kit artifacts for Spec 123, including spec, plan, research, data model, contracts, quickstart, tasks, and checklist

## Testing
- `vendor/bin/sail artisan test --compact tests/Feature/OpsUx/RunDetailPollingStopsOnTerminalTest.php tests/Feature/Operations/TenantlessOperationRunViewerTest.php tests/Feature/ReviewPack/ReviewPackWidgetTest.php tests/Feature/ReviewPack/ReviewPackGenerationTest.php tests/Feature/ReviewPack/ReviewPackRbacTest.php`
- `vendor/bin/sail bin pint --dirty --format agent`

## Notes
- Manual QA task `T014` in the Spec Kit checklist remains to be completed outside this automated flow.
- Livewire v4.0+ compliance is unchanged.
- No panel provider changes were made; provider registration remains in `bootstrap/providers.php`.
- No global-search behavior was changed.
- No destructive actions were added or modified.
- No new Filament assets were introduced; existing deployment expectations for `php artisan filament:assets` remain unchanged.

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #149
2026-03-08 11:11:26 +00:00

79 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\OperationRun;
use App\Support\OperationRunOutcome;
use App\Support\OperationRunStatus;
use App\Support\OpsUx\RunDetailPolling;
use Illuminate\Support\Carbon;
it('returns the expected interval for active runs based on age', function (string $status, int $ageSeconds, string $expectedInterval): void {
$referenceTime = now();
Carbon::setTestNow($referenceTime);
try {
$run = OperationRun::factory()->make([
'status' => $status,
'outcome' => OperationRunOutcome::Pending->value,
'created_at' => $referenceTime->copy()->subSeconds($ageSeconds),
]);
expect(RunDetailPolling::interval($run))->toBe($expectedInterval);
} finally {
Carbon::setTestNow();
}
})->with([
'queued runs younger than 10 seconds poll every second' => [
OperationRunStatus::Queued->value,
9,
'1s',
],
'queued runs at 10 seconds slow to 5 seconds' => [
OperationRunStatus::Queued->value,
10,
'5s',
],
'running runs younger than 60 seconds poll every 5 seconds' => [
OperationRunStatus::Running->value,
59,
'5s',
],
'running runs at 60 seconds slow to 10 seconds' => [
OperationRunStatus::Running->value,
60,
'10s',
],
])->group('ops-ux');
it('disables run-detail polling once the run is terminal or unrecognized', function (string $status, string $outcome): void {
$run = OperationRun::factory()->make([
'status' => $status,
'outcome' => $outcome,
]);
expect(RunDetailPolling::interval($run))->toBeNull();
})->with([
'completed succeeded' => [
OperationRunStatus::Completed->value,
OperationRunOutcome::Succeeded->value,
],
'completed partially succeeded' => [
OperationRunStatus::Completed->value,
OperationRunOutcome::PartiallySucceeded->value,
],
'completed failed' => [
OperationRunStatus::Completed->value,
OperationRunOutcome::Failed->value,
],
'legacy failed status' => [
'failed',
OperationRunOutcome::Pending->value,
],
'unknown status fallback' => [
'stalled',
OperationRunOutcome::Pending->value,
],
])->group('ops-ux');