Files
muninn/tests/Feature/Jobs/RunWorkflowStepJobTest.php
T
m105andClaude Sonnet 5 c249a14d78 Add storyboard/video-gen/video-editing handlers and asset previews (#37-39, #45, #46)
StoryboardHandler (#37): breaks the project's script into a numbered
scene-by-scene breakdown (description + image prompt per scene) via
OpenAI in JSON mode (added json_mode support to OpenAiDriver for
reliable structured output), stored as a JSON asset.

VideoGenerationHandler (#38): generates one still image per storyboard
scene via StabilityAI — the scene *visuals*, not motion/video clips
(no text-to-video model integrated; see the task comment for why).

VideoEditingHandler (#39): the step that actually produces a video
file — assembles the scene stills into an MP4 via ffmpeg's concat
demuxer, timed to the voiceover audio's duration (probed via ffprobe)
or a fixed per-scene duration if there's no audio, then muxes the
audio track in. Verified against the real ffmpeg/ffprobe binaries on
this box, not just Process::fake().

Asset previews (#45, #46): a reusable partial renders each asset
inline by type — image/audio/video get real playback elements, text/
JSON gets a truncated <pre> block, everything else a download link.
Wired into both the awaiting_approval step view (so approving/
rejecting is an actual content review, not just a word count) and a
general project assets grid.

Also fixes a latent bug in AssetStorage::url(), found while wiring up
previews: it called Storage::url() on the default 'local' disk, which
has no configured URL driver and throws in production — only worked
before because Storage::fake() is more permissive than the real local
driver. Now serves assets through a new authenticated streaming route
instead (VideoProjectAssetController).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-06 21:15:31 +03:00

78 lines
2.7 KiB
PHP

<?php
use App\Jobs\RunWorkflowStepJob;
use App\Models\AiProvider;
use App\Models\VideoProject;
use App\Support\AiProviders\AiProviderManager;
use App\Support\VideoWorkflow\StepHandlers\StepHandlerManager;
use App\Support\VideoWorkflow\WorkflowEngine;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
beforeEach(function () {
Storage::fake();
$this->engine = new WorkflowEngine;
});
test('it runs the matching handler and completes the step', function () {
Http::fake(['api.openai.com/*' => Http::response(['choices' => [['message' => ['content' => 'a script']]]])]);
AiProvider::factory()->create(['provider' => 'openai']);
$project = VideoProject::factory()->create();
$step = $this->engine->start($project, [['type' => 'script_generation']]);
(new RunWorkflowStepJob($step->id))->handle(app(StepHandlerManager::class), $this->engine);
expect($step->fresh()->status)->toBe('completed');
});
test('it fails the step when no handler is registered for its type', function () {
$project = VideoProject::factory()->create();
$step = $this->engine->start($project, [['type' => 'thumbnail_generation']]);
(new RunWorkflowStepJob($step->id))->handle(app(StepHandlerManager::class), $this->engine);
expect($step->fresh())
->status->toBe('failed')
->error->toContain('No handler registered');
});
test('it does nothing for a step that is no longer in_progress', function () {
$project = VideoProject::factory()->create();
$step = $this->engine->start($project, [['type' => 'script_generation']]);
$this->engine->skipStep($step);
(new RunWorkflowStepJob($step->id))->handle(app(StepHandlerManager::class), $this->engine);
expect($step->fresh()->status)->toBe('skipped');
});
test('it does nothing for a missing step', function () {
(new RunWorkflowStepJob(999999))->handle(app(StepHandlerManager::class), $this->engine);
})->throwsNoExceptions();
test('it fails the step when the handler throws unexpectedly', function () {
$badHandler = new class implements \App\Support\VideoWorkflow\StepHandlers\StepHandler
{
public function type(): string
{
return 'script_generation';
}
public function handle(\App\Models\WorkflowStep $step, WorkflowEngine $engine): void
{
throw new \RuntimeException('boom');
}
};
$manager = new StepHandlerManager([$badHandler]);
$project = VideoProject::factory()->create();
$step = $this->engine->start($project, [['type' => 'script_generation']]);
(new RunWorkflowStepJob($step->id))->handle($manager, $this->engine);
expect($step->fresh())
->status->toBe('failed')
->error->toBe('boom');
});