feat(ai-edits): add output storage backfill flow and coverage
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-02-07 10:10:45 +01:00
parent fb45d1f6ab
commit 8cc0918881
18 changed files with 1610 additions and 18 deletions

View File

@@ -3,6 +3,7 @@
namespace Tests\Feature\Api\Event;
use App\Models\AiEditingSetting;
use App\Models\AiEditOutput;
use App\Models\AiEditRequest;
use App\Models\AiStyle;
use App\Models\AiUsageLedger;
@@ -13,6 +14,7 @@ use App\Models\Package;
use App\Models\Photo;
use App\Services\EventJoinTokenService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class EventAiEditControllerTest extends TestCase
@@ -802,6 +804,67 @@ class EventAiEditControllerTest extends TestCase
->assertJsonPath('error.meta.allowed_style_keys.0', $allowed->key);
}
public function test_guest_show_serializes_local_output_url_when_storage_path_is_present(): void
{
$event = Event::factory()->create([
'status' => 'published',
]);
$this->attachEntitledEventPackage($event);
$photo = Photo::factory()->for($event)->create([
'tenant_id' => $event->tenant_id,
'status' => 'approved',
]);
$style = AiStyle::query()->create([
'key' => 'guest-output-url-style',
'name' => 'Guest Output URL',
'provider' => 'runware',
'provider_model' => 'runware-default',
'requires_source_image' => true,
'is_active' => true,
]);
$request = AiEditRequest::query()->create([
'tenant_id' => $event->tenant_id,
'event_id' => $event->id,
'photo_id' => $photo->id,
'style_id' => $style->id,
'provider' => 'runware',
'provider_model' => 'runware-default',
'status' => AiEditRequest::STATUS_SUCCEEDED,
'safety_state' => 'passed',
'prompt' => 'Create edit.',
'idempotency_key' => 'guest-output-url-1',
'queued_at' => now()->subMinute(),
'completed_at' => now(),
]);
$storagePath = 'events/demo-event/ai-edits/output-1.jpg';
AiEditOutput::query()->create([
'request_id' => $request->id,
'provider_asset_id' => 'guest-output-asset-1',
'storage_disk' => 'public',
'storage_path' => $storagePath,
'provider_url' => 'https://provider.example/output.jpg',
'mime_type' => 'image/jpeg',
'is_primary' => true,
'safety_state' => 'passed',
'generated_at' => now(),
]);
$token = app(EventJoinTokenService::class)
->createToken($event, ['label' => 'guest-output-url'])
->getAttribute('plain_token');
$response = $this->withHeaders(['X-Device-Id' => 'guest-device-output-url'])
->getJson("/api/v1/events/{$token}/ai-edits/{$request->id}");
$response->assertOk()
->assertJsonPath('data.outputs.0.storage_path', $storagePath)
->assertJsonPath('data.outputs.0.url', Storage::disk('public')->url($storagePath));
}
private function attachEntitledEventPackage(Event $event): EventPackage
{
$package = Package::factory()->endcustomer()->create([