- Implement Fake repositories and services for testing purposes. - Create tests for Article API including creation, validation, and listing. - Develop ProcessTicketJobFlowTest to validate ticket processing logic. - Add QuickReplyAdminTest for creating and updating quick replies. - Implement TicketAndArticleModelTest to ensure proper cascading deletes and credential encryption. - Create TicketIngestionTest for ticket creation and job dispatching. - Add TicketShowPageTest to verify rendering of quick replies and tool calls. - Implement unit tests for ClassifierPromptBuilder, EmbeddingService, LlmJsonDecoder, QuickReplyResolver, SupportReplyService, TicketResultPayloadBuilder, TicketToolCallService, and ToolCallRequestValidator.
71 lines
2.0 KiB
PHP
71 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Exceptions\OllamaUnavailableException;
|
|
use App\Models\EmbeddingCache;
|
|
use App\Services\AppSettingsService;
|
|
use App\Services\EmbeddingService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\Fakes\FakeLlmClient;
|
|
use Tests\TestCase;
|
|
|
|
class EmbeddingServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_it_returns_cached_embedding_without_new_llm_call(): void
|
|
{
|
|
$settings = $this->fakeSettings();
|
|
$llm = new FakeLlmClient;
|
|
$service = new EmbeddingService($llm, $settings);
|
|
|
|
EmbeddingCache::query()->create([
|
|
'provider_instance_id' => 'instance-1',
|
|
'embedding_model' => 'embed-model',
|
|
'text_hash' => hash('sha256', 'abc'),
|
|
'text' => 'abc',
|
|
'embedding' => [0.9, 0.8],
|
|
]);
|
|
|
|
$embedding = $service->embed('abc');
|
|
$this->assertSame([0.9, 0.8], $embedding);
|
|
$this->assertCount(0, $llm->generatedPrompts);
|
|
}
|
|
|
|
public function test_it_throws_when_embedding_is_empty(): void
|
|
{
|
|
$settings = $this->fakeSettings();
|
|
$llm = new FakeLlmClient;
|
|
$llm->embeddings['abc'] = [];
|
|
$service = new EmbeddingService($llm, $settings);
|
|
|
|
$this->expectException(OllamaUnavailableException::class);
|
|
$service->embed('abc');
|
|
}
|
|
|
|
private function fakeSettings(): AppSettingsService
|
|
{
|
|
return new class extends AppSettingsService {
|
|
public function activeProviderInstance(): array
|
|
{
|
|
return ['id' => 'instance-1', 'embedding_model' => 'embed-model'];
|
|
}
|
|
|
|
public function activeProviderInstanceId(): string
|
|
{
|
|
return 'instance-1';
|
|
}
|
|
|
|
public function get(string $key, ?string $default = null): ?string
|
|
{
|
|
if ($key === 'llm.models.embedding') {
|
|
return 'embed-model';
|
|
}
|
|
|
|
return $default;
|
|
}
|
|
};
|
|
}
|
|
}
|