trypost/tests/Feature/Automation/Command/RecoverStuckAutomationRunsTest.php
Paulo Castellano 4efaa0bf99 Harden automations module: full-post generation, reliable runs, editor UX
Generation
- Generate node now produces the full post (text + AI image + carousel)
  via a shared PostImagePipeline extracted from StreamPostCreation
- Generate config UI mirrors the /posts/create wizard (carousel slide
  count, include-image toggle); drop the decorative format/unsplash keys

Flow correctness
- RSS/HTTP nodes expose named has-items (default) and no-items output
  handles, labeled and colored like the Condition node
- AdvanceAutomationRun records a no_matching_edge terminal instead of
  completing silently; "0 new items" feedback in the test panel
- Manual/test runs no longer persist the production dedup watermark

Run reliability
- Pause truly halts in-flight runs (production only; manual test runs
  always run regardless of automation status)
- ProcessAutomationNode::failed() marks the run failed
- automation:recover-stuck-runs and automation:prune-dry-runs commands

Webhook / HTTP
- Branded User-Agent (config-driven) on outbound webhook + http_request
- Webhook fails on invalid JSON instead of silently sending {}
- HTTP custom headers editor; CodeMirror-based CodeEditor for JSON

Editor UX
- Header Test button only opens the panel; the panel has a Run button
  (saves first) and owns the with-real-data toggle
- Clicking a node closes the test panel and opens its config
- Node cards: max-width + truncate so long URLs don't grow the node
2026-06-10 20:45:01 -03:00

44 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Enums\Automation\Run\Status as RunStatus;
use App\Models\AutomationRun;
it('fails runs stuck running past the threshold', function () {
$stuck = AutomationRun::factory()->create(['status' => RunStatus::Running, 'started_at' => now()->subHours(3), 'updated_at' => now()->subHours(3)]);
$this->artisan('automation:recover-stuck-runs')->assertExitCode(0);
$stuck->refresh();
expect($stuck->status)->toBe(RunStatus::Failed);
expect(data_get($stuck->error, 'reason'))->toBe('stuck');
expect($stuck->finished_at)->not->toBeNull();
});
it('fails runs stuck pending past the threshold', function () {
$stuck = AutomationRun::factory()->create(['status' => RunStatus::Pending, 'updated_at' => now()->subHours(3)]);
$this->artisan('automation:recover-stuck-runs')->assertExitCode(0);
$stuck->refresh();
expect($stuck->status)->toBe(RunStatus::Failed);
expect(data_get($stuck->error, 'reason'))->toBe('stuck');
expect($stuck->finished_at)->not->toBeNull();
});
it('leaves recent running runs alone', function () {
$recent = AutomationRun::factory()->create(['status' => RunStatus::Running, 'started_at' => now()->subMinute(), 'updated_at' => now()->subMinute()]);
$this->artisan('automation:recover-stuck-runs');
expect($recent->fresh()->status)->toBe(RunStatus::Running);
});
it('does not touch waiting runs', function () {
$waiting = AutomationRun::factory()->create(['status' => RunStatus::Waiting, 'updated_at' => now()->subDay(), 'next_action_at' => now()->addDay()]);
$this->artisan('automation:recover-stuck-runs');
expect($waiting->fresh()->status)->toBe(RunStatus::Waiting);
});