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\Tenant;
use App\Models\AiEditingSetting;
use App\Models\AiEditOutput;
use App\Models\AiEditRequest;
use App\Models\AiStyle;
use App\Models\AiUsageLedger;
@@ -11,6 +12,7 @@ use App\Models\EventPackage;
use App\Models\EventPackageAddon;
use App\Models\Package;
use App\Models\Photo;
use Illuminate\Support\Facades\Storage;
use Tests\Feature\Tenant\TenantTestCase;
class TenantAiEditControllerTest extends TenantTestCase
@@ -835,6 +837,63 @@ class TenantAiEditControllerTest extends TenantTestCase
->assertJsonPath('data.budget.hard_stop_enabled', true);
}
public function test_tenant_show_serializes_local_output_url_when_storage_path_is_present(): void
{
$event = Event::factory()->create([
'tenant_id' => $this->tenant->id,
'status' => 'published',
]);
$this->attachEntitledEventPackage($event);
$photo = Photo::factory()->for($event)->create([
'tenant_id' => $this->tenant->id,
'status' => 'approved',
]);
$style = AiStyle::query()->create([
'key' => 'tenant-output-url-style',
'name' => 'Tenant Output URL',
'provider' => 'runware',
'provider_model' => 'runware-default',
'requires_source_image' => true,
'is_active' => true,
]);
$request = AiEditRequest::query()->create([
'tenant_id' => $this->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' => 'tenant-output-url-1',
'queued_at' => now()->subMinute(),
'completed_at' => now(),
]);
$storagePath = 'events/demo-event/ai-edits/output-tenant-1.jpg';
AiEditOutput::query()->create([
'request_id' => $request->id,
'provider_asset_id' => 'tenant-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(),
]);
$response = $this->authenticatedRequest('GET', "/api/v1/tenant/events/{$event->slug}/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([