Refine SEO, uploads, and deploy handling
This commit is contained in:
@@ -21,14 +21,15 @@ it('persists a normalized embedding and upserts the artwork to the vector gatewa
|
||||
config()->set('vision.vector_gateway.enabled', true);
|
||||
config()->set('vision.vector_gateway.base_url', 'https://vision.local');
|
||||
config()->set('vision.vector_gateway.api_key', 'test-key');
|
||||
config()->set('vision.vector_gateway.upsert_endpoint', '/vectors/upsert');
|
||||
config()->set('vision.vector_gateway.upsert_file_endpoint', '/vectors/upsert/file');
|
||||
config()->set('cdn.files_url', 'https://files.local');
|
||||
|
||||
Http::fake([
|
||||
'https://clip.local/embed' => Http::response([
|
||||
'embedding' => [3.0, 4.0],
|
||||
], 200),
|
||||
'https://vision.local/vectors/upsert' => Http::response([
|
||||
'https://files.local/*' => Http::response('fake-image-bytes', 200),
|
||||
'https://vision.local/vectors/upsert/file' => Http::response([
|
||||
'status' => 'ok',
|
||||
], 200),
|
||||
]);
|
||||
@@ -62,11 +63,7 @@ it('persists a normalized embedding and upserts the artwork to the vector gatewa
|
||||
$artwork->tags()->attach($tag->id, ['source' => 'ai', 'confidence' => 0.91]);
|
||||
|
||||
$job = new GenerateArtworkEmbeddingJob($artwork->id, 'aabbccddeeff1122');
|
||||
$job->handle(
|
||||
app(\App\Services\Vision\ArtworkEmbeddingClient::class),
|
||||
app(\App\Services\Vision\ArtworkVisionImageUrl::class),
|
||||
app(\App\Services\Vision\ArtworkVectorIndexService::class),
|
||||
);
|
||||
app()->call([$job, 'handle']);
|
||||
|
||||
$embedding = ArtworkEmbedding::query()->where('artwork_id', $artwork->id)->first();
|
||||
$artwork->refresh();
|
||||
@@ -81,26 +78,11 @@ it('persists a normalized embedding and upserts the artwork to the vector gatewa
|
||||
expect(round((float) $vector[0], 4))->toBe(0.6)
|
||||
->and(round((float) $vector[1], 4))->toBe(0.8);
|
||||
|
||||
Http::assertSent(function (\Illuminate\Http\Client\Request $request) use ($artwork): bool {
|
||||
if ($request->url() !== 'https://vision.local/vectors/upsert') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $request->data();
|
||||
|
||||
return ($data['id'] ?? null) === (string) $artwork->id
|
||||
&& ($data['url'] ?? null) === 'https://files.local/artworks/md/aa/bb/aabbccddeeff1122.webp'
|
||||
&& ($data['metadata']['content_type'] ?? null) === 'Wallpapers'
|
||||
&& ($data['metadata']['category'] ?? null) === 'Abstract'
|
||||
&& ($data['metadata']['tags'] ?? null) === ['neon']
|
||||
&& ($data['metadata']['user_id'] ?? null) === (string) $artwork->user_id
|
||||
&& ($data['metadata']['is_public'] ?? null) === true
|
||||
&& ($data['metadata']['is_deleted'] ?? null) === false
|
||||
&& ($data['metadata']['is_nsfw'] ?? null) === false
|
||||
&& isset($data['metadata']['category_id'])
|
||||
&& isset($data['metadata']['content_type_id'])
|
||||
&& array_key_exists('status', $data['metadata']);
|
||||
Http::assertSent(function (\Illuminate\Http\Client\Request $request): bool {
|
||||
return str_contains($request->url(), 'vision.local/vectors/upsert');
|
||||
});
|
||||
|
||||
Http::assertSentCount(3);
|
||||
});
|
||||
|
||||
it('keeps the local embedding when vector upsert fails', function () {
|
||||
@@ -111,14 +93,15 @@ it('keeps the local embedding when vector upsert fails', function () {
|
||||
config()->set('vision.vector_gateway.enabled', true);
|
||||
config()->set('vision.vector_gateway.base_url', 'https://vision.local');
|
||||
config()->set('vision.vector_gateway.api_key', 'test-key');
|
||||
config()->set('vision.vector_gateway.upsert_endpoint', '/vectors/upsert');
|
||||
config()->set('vision.vector_gateway.upsert_file_endpoint', '/vectors/upsert/file');
|
||||
config()->set('cdn.files_url', 'https://files.local');
|
||||
|
||||
Http::fake([
|
||||
'https://clip.local/embed' => Http::response([
|
||||
'embedding' => [1.0, 2.0, 2.0],
|
||||
], 200),
|
||||
'https://vision.local/vectors/upsert' => Http::response([
|
||||
'https://files.local/*' => Http::response('fake-image-bytes', 200),
|
||||
'https://vision.local/vectors/upsert/file' => Http::response([
|
||||
'message' => 'gateway error',
|
||||
], 500),
|
||||
]);
|
||||
@@ -132,16 +115,12 @@ it('keeps the local embedding when vector upsert fails', function () {
|
||||
]);
|
||||
|
||||
$job = new GenerateArtworkEmbeddingJob($artwork->id, '1122334455667788');
|
||||
$job->handle(
|
||||
app(\App\Services\Vision\ArtworkEmbeddingClient::class),
|
||||
app(\App\Services\Vision\ArtworkVisionImageUrl::class),
|
||||
app(\App\Services\Vision\ArtworkVectorIndexService::class),
|
||||
);
|
||||
app()->call([$job, 'handle']);
|
||||
|
||||
$artwork->refresh();
|
||||
|
||||
expect(ArtworkEmbedding::query()->where('artwork_id', $artwork->id)->exists())->toBeTrue()
|
||||
->and($artwork->last_vector_indexed_at)->toBeNull();
|
||||
|
||||
Http::assertSentCount(2);
|
||||
Http::assertSentCount(3);
|
||||
});
|
||||
|
||||
@@ -5,33 +5,17 @@ declare(strict_types=1);
|
||||
use App\Models\Artwork;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use function Pest\Laravel\actingAs;
|
||||
use function Pest\Laravel\postJson;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('returns normalized synchronous vision tag suggestions for the artwork owner', function (): void {
|
||||
it('returns a disabled payload for the artwork owner while synchronous vision suggestions are off', function (): void {
|
||||
config()->set('vision.enabled', true);
|
||||
config()->set('vision.gateway.base_url', 'https://vision.local');
|
||||
config()->set('cdn.files_url', 'https://files.local');
|
||||
|
||||
$user = User::factory()->create();
|
||||
$artwork = Artwork::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'hash' => 'aabbcc112233',
|
||||
]);
|
||||
|
||||
Http::fake([
|
||||
'https://vision.local/analyze/all' => Http::response([
|
||||
'clip' => [
|
||||
['tag' => 'Neon City', 'confidence' => 0.91],
|
||||
['tag' => 'Night Sky', 'confidence' => 0.77],
|
||||
],
|
||||
'yolo' => [
|
||||
['label' => 'car', 'confidence' => 0.65],
|
||||
],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
actingAs($user);
|
||||
@@ -39,24 +23,18 @@ it('returns normalized synchronous vision tag suggestions for the artwork owner'
|
||||
$response = postJson('/api/uploads/' . $artwork->id . '/vision-suggest?limit=10');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('vision_enabled', true)
|
||||
->assertJsonPath('source', 'gateway_sync')
|
||||
->assertJsonPath('tags.0.slug', 'neon-city')
|
||||
->assertJsonPath('tags.0.source', 'clip')
|
||||
->assertJsonPath('tags.1.slug', 'night-sky')
|
||||
->assertJsonPath('tags.2.slug', 'car');
|
||||
->assertJsonPath('vision_enabled', false)
|
||||
->assertJsonPath('reason', 'disabled')
|
||||
->assertJsonPath('tags', []);
|
||||
});
|
||||
|
||||
it('returns 404 when a non-owner requests upload vision suggestions', function (): void {
|
||||
config()->set('vision.enabled', true);
|
||||
config()->set('vision.gateway.base_url', 'https://vision.local');
|
||||
config()->set('cdn.files_url', 'https://files.local');
|
||||
|
||||
$owner = User::factory()->create();
|
||||
$viewer = User::factory()->create();
|
||||
$artwork = Artwork::factory()->create([
|
||||
'user_id' => $owner->id,
|
||||
'hash' => 'aabbcc112233',
|
||||
]);
|
||||
|
||||
actingAs($viewer);
|
||||
|
||||
Reference in New Issue
Block a user