trypost/tests/Feature/Automation/Command/PruneDryRunAutomationRunsTest.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

36 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\AutomationNodeRun;
use App\Models\AutomationRun;
it('prunes terminal dry-run rows older than the grace window', function () {
$old = AutomationRun::factory()->create(['is_dry_run' => true, 'finished_at' => now()->subHour()]);
$recent = AutomationRun::factory()->create(['is_dry_run' => true, 'finished_at' => now()->subMinute()]);
$realOld = AutomationRun::factory()->create(['is_dry_run' => false, 'finished_at' => now()->subHour()]);
$this->artisan('automation:prune-dry-runs')->assertExitCode(0);
expect(AutomationRun::find($old->id))->toBeNull();
expect(AutomationRun::find($recent->id))->not->toBeNull();
expect(AutomationRun::find($realOld->id))->not->toBeNull();
});
it('leaves dry-run rows that have not finished yet', function () {
$unfinished = AutomationRun::factory()->create(['is_dry_run' => true, 'finished_at' => null, 'updated_at' => now()->subHour()]);
$this->artisan('automation:prune-dry-runs')->assertExitCode(0);
expect(AutomationRun::find($unfinished->id))->not->toBeNull();
});
it('deletes the node runs belonging to pruned dry runs', function () {
$old = AutomationRun::factory()->create(['is_dry_run' => true, 'finished_at' => now()->subHour()]);
$nodeRun = AutomationNodeRun::factory()->create(['run_id' => $old->id]);
$this->artisan('automation:prune-dry-runs')->assertExitCode(0);
expect(AutomationRun::find($old->id))->toBeNull();
expect(AutomationNodeRun::find($nodeRun->id))->toBeNull();
});