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>
101 lines
4.1 KiB
PHP
101 lines
4.1 KiB
PHP
<?php
|
|
|
|
use App\Models\AiProvider;
|
|
use App\Models\VideoProject;
|
|
use App\Support\AiProviders\AiProviderManager;
|
|
use App\Support\AssetStorage\AssetStorage;
|
|
use App\Support\VideoWorkflow\StepHandlers\StoryboardHandler;
|
|
use App\Support\VideoWorkflow\WorkflowEngine;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
beforeEach(function () {
|
|
Storage::fake();
|
|
$this->engine = new WorkflowEngine;
|
|
$this->assets = new AssetStorage;
|
|
$this->handler = new StoryboardHandler(app(AiProviderManager::class), $this->assets);
|
|
});
|
|
|
|
test('it breaks the script into scenes, stores them, and completes the step', function () {
|
|
$scenesJson = json_encode(['scenes' => [
|
|
['scene_number' => 1, 'description' => 'Intro shot', 'visual_prompt' => 'a bright kitchen'],
|
|
['scene_number' => 2, 'description' => 'Demo', 'visual_prompt' => 'a chef cooking'],
|
|
]]);
|
|
Http::fake(['api.openai.com/*' => Http::response(['choices' => [['message' => ['content' => $scenesJson]]]])]);
|
|
AiProvider::factory()->create(['provider' => 'openai']);
|
|
|
|
$project = VideoProject::factory()->create();
|
|
$this->assets->store($project, 'script', 'A script about cooking.', 'txt');
|
|
$step = $this->engine->start($project, [['type' => 'storyboard']]);
|
|
|
|
$this->handler->handle($step, $this->engine);
|
|
|
|
$fresh = $step->fresh();
|
|
expect($fresh->status)->toBe('completed');
|
|
expect($fresh->output['scene_count'])->toBe(2);
|
|
|
|
$asset = \App\Models\Asset::find($fresh->output['asset_id']);
|
|
expect($asset->type)->toBe('other');
|
|
expect($asset->metadata['kind'])->toBe('storyboard');
|
|
$stored = json_decode(Storage::get($asset->disk_path), true);
|
|
expect($stored['scenes'])->toHaveCount(2);
|
|
|
|
Http::assertSent(function ($request) {
|
|
return str_contains($request['messages'][0]['content'], 'A script about cooking.')
|
|
&& ($request['response_format']['type'] ?? null) === 'json_object';
|
|
});
|
|
});
|
|
|
|
test('a style hint is included in the prompt when given', function () {
|
|
Http::fake(['api.openai.com/*' => Http::response(['choices' => [['message' => ['content' => json_encode(['scenes' => [['scene_number' => 1, 'description' => 'x', 'visual_prompt' => 'y']]])]]]])]);
|
|
AiProvider::factory()->create(['provider' => 'openai']);
|
|
|
|
$project = VideoProject::factory()->create();
|
|
$step = $this->engine->start($project, [['type' => 'storyboard']]);
|
|
$step->update(['input' => ['script' => 'a script', 'style' => 'noir black and white']]);
|
|
|
|
$this->handler->handle($step->fresh(), $this->engine);
|
|
|
|
Http::assertSent(fn ($request) => str_contains($request['messages'][0]['content'], 'noir black and white'));
|
|
});
|
|
|
|
test('it fails when there is no script to storyboard', function () {
|
|
AiProvider::factory()->create(['provider' => 'openai']);
|
|
|
|
$project = VideoProject::factory()->create();
|
|
$step = $this->engine->start($project, [['type' => 'storyboard']]);
|
|
|
|
$this->handler->handle($step, $this->engine);
|
|
|
|
expect($step->fresh())
|
|
->status->toBe('failed')
|
|
->error->toContain('No script available');
|
|
});
|
|
|
|
test('it fails when no active OpenAI provider is configured', function () {
|
|
$project = VideoProject::factory()->create();
|
|
$this->assets->store($project, 'script', 'a script', 'txt');
|
|
$step = $this->engine->start($project, [['type' => 'storyboard']]);
|
|
|
|
$this->handler->handle($step, $this->engine);
|
|
|
|
expect($step->fresh())
|
|
->status->toBe('failed')
|
|
->error->toContain('No active OpenAI provider');
|
|
});
|
|
|
|
test('it fails when the AI response has no usable scenes', function () {
|
|
Http::fake(['api.openai.com/*' => Http::response(['choices' => [['message' => ['content' => '{"not_scenes": []}']]]])]);
|
|
AiProvider::factory()->create(['provider' => 'openai']);
|
|
|
|
$project = VideoProject::factory()->create();
|
|
$this->assets->store($project, 'script', 'a script', 'txt');
|
|
$step = $this->engine->start($project, [['type' => 'storyboard']]);
|
|
|
|
$this->handler->handle($step, $this->engine);
|
|
|
|
expect($step->fresh())
|
|
->status->toBe('failed')
|
|
->error->toContain('unusable storyboard');
|
|
});
|