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>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?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' => 'video_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');
|
||||
});
|
||||
Reference in New Issue
Block a user