Files
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

114 lines
4.1 KiB
PHP

<?php
use App\Models\VideoProject;
use App\Models\WorkflowStep;
use App\Support\AssetStorage\AssetStorage;
use Illuminate\Support\Facades\Storage;
beforeEach(function () {
Storage::fake();
$this->storage = new AssetStorage;
});
test('storing content writes the file and creates an asset record', function () {
$project = VideoProject::factory()->create();
$asset = $this->storage->store($project, 'script', 'Once upon a time...', 'txt', mimeType: 'text/plain');
expect($asset->type)->toBe('script');
expect($asset->version)->toBe(1);
expect($asset->size_bytes)->toBe(strlen('Once upon a time...'));
expect($asset->mime_type)->toBe('text/plain');
expect($asset->video_project_id)->toBe($project->id);
Storage::assertExists($asset->disk_path);
expect(Storage::get($asset->disk_path))->toBe('Once upon a time...');
});
test('storing the same slot again increments the version instead of overwriting', function () {
$project = VideoProject::factory()->create();
$v1 = $this->storage->store($project, 'script', 'draft one', 'txt');
$v2 = $this->storage->store($project, 'script', 'draft two', 'txt');
expect($v1->version)->toBe(1);
expect($v2->version)->toBe(2);
expect($v1->disk_path)->not->toBe($v2->disk_path);
Storage::assertExists($v1->disk_path);
Storage::assertExists($v2->disk_path);
expect(Storage::get($v1->disk_path))->toBe('draft one');
expect(Storage::get($v2->disk_path))->toBe('draft two');
});
test('versioning is scoped per workflow step when one is given', function () {
$project = VideoProject::factory()->create();
$stepA = WorkflowStep::factory()->for($project)->create(['order' => 0]);
$stepB = WorkflowStep::factory()->for($project)->create(['order' => 1]);
$a = $this->storage->store($project, 'script', 'from step A', 'txt', step: $stepA);
$b = $this->storage->store($project, 'script', 'from step B', 'txt', step: $stepB);
expect($a->version)->toBe(1);
expect($b->version)->toBe(1);
});
test('contents retrieves the stored file', function () {
$project = VideoProject::factory()->create();
$asset = $this->storage->store($project, 'script', 'hello', 'txt');
expect($this->storage->contents($asset))->toBe('hello');
});
test('url returns the authenticated streaming route for an existing file, null for a missing one', function () {
$project = VideoProject::factory()->create();
$asset = $this->storage->store($project, 'script', 'hello', 'txt');
expect($this->storage->url($asset))->toBe(route('video-projects.assets.show', [$project->id, $asset->id]));
Storage::delete($asset->disk_path);
expect($this->storage->url($asset))->toBeNull();
});
test('delete removes the file and the asset record', function () {
$project = VideoProject::factory()->create();
$asset = $this->storage->store($project, 'script', 'hello', 'txt');
$this->storage->delete($asset);
Storage::assertMissing($asset->disk_path);
expect(\App\Models\Asset::find($asset->id))->toBeNull();
});
test('pruneOldVersions keeps only the newest N versions', function () {
$project = VideoProject::factory()->create();
$versions = collect(range(1, 5))->map(
fn ($i) => $this->storage->store($project, 'script', "draft {$i}", 'txt')
);
$pruned = $this->storage->pruneOldVersions($project, 'script', keep: 2);
expect($pruned)->toBe(3);
$remaining = $project->assets()->where('type', 'script')->pluck('version')->sort()->values();
expect($remaining->all())->toBe([4, 5]);
Storage::assertMissing($versions[0]->disk_path);
Storage::assertMissing($versions[1]->disk_path);
Storage::assertMissing($versions[2]->disk_path);
Storage::assertExists($versions[3]->disk_path);
Storage::assertExists($versions[4]->disk_path);
});
test('pruneOldVersions does nothing when there are fewer versions than the keep count', function () {
$project = VideoProject::factory()->create();
$this->storage->store($project, 'script', 'only draft', 'txt');
$pruned = $this->storage->pruneOldVersions($project, 'script', keep: 3);
expect($pruned)->toBe(0);
expect($project->assets()->count())->toBe(1);
});