StepHandler abstraction (app/Support/VideoWorkflow/StepHandlers/) plugs into WorkflowEngine without coupling it to how any given step type is actually executed: - ScriptGenerationHandler: builds a prompt from the project's title/ description (or an explicit outline/tone/keywords/target length in step input), generates via an active OpenAI AiProvider, stores the result as a 'script' asset. - TtsVoiceoverHandler: voices step.input.text, or falls back to the project's latest script asset, via an active ElevenLabs AiProvider; voice_id/model_id are configurable per step. No direct "speed" control — ElevenLabs' base TTS endpoint doesn't expose one. RunWorkflowStepJob resolves a step's handler by type and runs it on the queue, matching the existing PublishPostJob pattern (including a stale-dispatch guard: no-op if the step isn't 'in_progress' anymore). UI, under its own /video-projects routes and nav entry — separate from /projects per the earlier decision: - VideoProjects/Index (#43): list projects with status and step progress, create new ones. - VideoProjects/Show (#44): start a project from a WorkflowTemplate or a hardcoded default 8-step pipeline; per-step Run/Approve/Reject/ Retry/Skip actions; auto-queues the next step after any transition when a handler exists for its type (steps with no handler yet just sit in_progress rather than auto-failing); lists project assets. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
130 lines
4.7 KiB
PHP
130 lines
4.7 KiB
PHP
<?php
|
|
|
|
use App\Jobs\RunWorkflowStepJob;
|
|
use App\Livewire\VideoProjects\Show;
|
|
use App\Models\VideoProject;
|
|
use App\Models\WorkflowTemplate;
|
|
use App\Support\VideoWorkflow\WorkflowEngine;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Livewire\Livewire;
|
|
|
|
test('starting the default pipeline creates steps and queues the first handled one', function () {
|
|
Queue::fake();
|
|
$project = VideoProject::factory()->create();
|
|
|
|
Livewire::test(Show::class, ['videoProject' => $project])
|
|
->call('startDefault');
|
|
|
|
expect($project->fresh()->status)->toBe('in_progress');
|
|
expect($project->steps()->count())->toBe(8);
|
|
expect($project->steps()->orderBy('order')->first()->type)->toBe('script_generation');
|
|
|
|
Queue::assertPushed(RunWorkflowStepJob::class, function ($job) use ($project) {
|
|
$step = $project->steps()->orderBy('order')->first();
|
|
|
|
return $job->stepId === $step->id;
|
|
});
|
|
});
|
|
|
|
test('starting from a template uses its steps and does not queue unhandled types', function () {
|
|
Queue::fake();
|
|
$template = WorkflowTemplate::factory()->create(['steps' => [
|
|
['type' => 'video_generation'],
|
|
['type' => 'youtube_publish'],
|
|
]]);
|
|
$project = VideoProject::factory()->create();
|
|
|
|
Livewire::test(Show::class, ['videoProject' => $project])
|
|
->set('workflowTemplateId', $template->id)
|
|
->call('startWithTemplate');
|
|
|
|
expect($project->fresh()->workflow_template_id)->toBe($template->id);
|
|
expect($project->steps()->count())->toBe(2);
|
|
|
|
// video_generation has no handler yet, so nothing should be queued
|
|
Queue::assertNotPushed(RunWorkflowStepJob::class);
|
|
});
|
|
|
|
test('startWithTemplate shows a notice when no template is selected', function () {
|
|
$project = VideoProject::factory()->create();
|
|
|
|
Livewire::test(Show::class, ['videoProject' => $project])
|
|
->call('startWithTemplate')
|
|
->assertSee('Pick a template first.');
|
|
|
|
expect($project->fresh()->status)->toBe('draft');
|
|
});
|
|
|
|
test('runStep dispatches the job for the given step', function () {
|
|
Queue::fake();
|
|
$project = VideoProject::factory()->create();
|
|
$step = (new WorkflowEngine)->start($project, [['type' => 'script_generation']]);
|
|
|
|
Livewire::test(Show::class, ['videoProject' => $project])
|
|
->call('runStep', $step->id);
|
|
|
|
Queue::assertPushed(RunWorkflowStepJob::class, fn ($job) => $job->stepId === $step->id);
|
|
});
|
|
|
|
test('approving a step advances and queues the next handled step', function () {
|
|
Queue::fake();
|
|
$project = VideoProject::factory()->create();
|
|
$engine = new WorkflowEngine;
|
|
$step = $engine->start($project, [
|
|
['type' => 'script_generation', 'requires_approval' => true],
|
|
['type' => 'tts_voiceover'],
|
|
]);
|
|
$engine->completeStep($step, ['script' => 'draft']);
|
|
|
|
Livewire::test(Show::class, ['videoProject' => $project])
|
|
->call('approveStep', $step->id);
|
|
|
|
$next = $project->steps()->where('order', 1)->first();
|
|
expect($next->status)->toBe('in_progress');
|
|
Queue::assertPushed(RunWorkflowStepJob::class, fn ($job) => $job->stepId === $next->id);
|
|
});
|
|
|
|
test('rejecting a step blocks the pipeline', function () {
|
|
$project = VideoProject::factory()->create();
|
|
$engine = new WorkflowEngine;
|
|
$step = $engine->start($project, [['type' => 'script_generation', 'requires_approval' => true]]);
|
|
$engine->completeStep($step, ['script' => 'bad']);
|
|
|
|
Livewire::test(Show::class, ['videoProject' => $project])
|
|
->call('rejectStep', $step->id);
|
|
|
|
expect($step->fresh()->status)->toBe('rejected');
|
|
});
|
|
|
|
test('retrying a failed step re-queues it', function () {
|
|
Queue::fake();
|
|
$project = VideoProject::factory()->create();
|
|
$engine = new WorkflowEngine;
|
|
$step = $engine->start($project, [['type' => 'script_generation']]);
|
|
$engine->failStep($step, 'boom');
|
|
|
|
Livewire::test(Show::class, ['videoProject' => $project])
|
|
->call('retryStep', $step->id);
|
|
|
|
expect($step->fresh()->status)->toBe('in_progress');
|
|
Queue::assertPushed(RunWorkflowStepJob::class, fn ($job) => $job->stepId === $step->id);
|
|
});
|
|
|
|
test('skipping a step advances and queues the next handled step', function () {
|
|
Queue::fake();
|
|
$project = VideoProject::factory()->create();
|
|
$engine = new WorkflowEngine;
|
|
$step = $engine->start($project, [
|
|
['type' => 'video_generation'],
|
|
['type' => 'script_generation'],
|
|
]);
|
|
|
|
Livewire::test(Show::class, ['videoProject' => $project])
|
|
->call('skipStep', $step->id);
|
|
|
|
$next = $project->steps()->where('order', 1)->first();
|
|
expect($step->fresh()->status)->toBe('skipped');
|
|
expect($next->status)->toBe('in_progress');
|
|
Queue::assertPushed(RunWorkflowStepJob::class, fn ($job) => $job->stepId === $next->id);
|
|
});
|