diff --git a/src/platform/tests/Bridge/DockerModelRunner/Completions/ResultConverterTest.php b/src/platform/tests/Bridge/DockerModelRunner/Completions/ResultConverterTest.php index 38c9c37e2..73d683434 100644 --- a/src/platform/tests/Bridge/DockerModelRunner/Completions/ResultConverterTest.php +++ b/src/platform/tests/Bridge/DockerModelRunner/Completions/ResultConverterTest.php @@ -13,11 +13,16 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; use Symfony\AI\Platform\Bridge\DockerModelRunner\Completions; use Symfony\AI\Platform\Bridge\DockerModelRunner\Completions\ResultConverter; use Symfony\AI\Platform\Bridge\OpenAi\Gpt\ResultConverter as OpenAiResultConverter; +use Symfony\AI\Platform\Exception\ModelNotFoundException; +use Symfony\AI\Platform\Exception\RuntimeException; +use Symfony\AI\Platform\Result\RawHttpResult; +use Symfony\Contracts\HttpClient\ResponseInterface; #[CoversClass(ResultConverter::class)] #[UsesClass(Completions::class)] @@ -31,4 +36,43 @@ public function testItSupportsCompletionsModel() $this->assertTrue($converter->supports(new Completions('test-model'))); } + + #[TestWith(['Model not found'])] + #[TestWith(['MODEL NOT FOUND'])] + public function testItThrowsModelNotFoundExceptionWhen404WithModelNotFoundMessage(string $message) + { + $response = $this->createMock(ResponseInterface::class); + $response + ->method('getStatusCode') + ->willReturn(404); + $response + ->method('getContent') + ->with(false) + ->willReturn($message); + + $this->expectException(ModelNotFoundException::class); + $this->expectExceptionMessage($message); + + (new ResultConverter())->convert(new RawHttpResult($response)); + } + + public function testItDoesNotThrowModelNotFoundExceptionWhen404WithoutModelNotFoundMessage() + { + $response = $this->createMock(ResponseInterface::class); + $response + ->method('getStatusCode') + ->willReturn(404); + $response + ->method('getContent') + ->with(false) + ->willReturn('Not found'); + $response + ->method('toArray') + ->willReturn(['error' => 'some other error']); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Response does not contain choices.'); + + (new ResultConverter())->convert(new RawHttpResult($response)); + } } diff --git a/src/platform/tests/Bridge/DockerModelRunner/Embeddings/ResultConverterTest.php b/src/platform/tests/Bridge/DockerModelRunner/Embeddings/ResultConverterTest.php index b294532c5..efe737837 100644 --- a/src/platform/tests/Bridge/DockerModelRunner/Embeddings/ResultConverterTest.php +++ b/src/platform/tests/Bridge/DockerModelRunner/Embeddings/ResultConverterTest.php @@ -13,10 +13,12 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; use Symfony\AI\Platform\Bridge\DockerModelRunner\Embeddings; use Symfony\AI\Platform\Bridge\DockerModelRunner\Embeddings\ResultConverter; +use Symfony\AI\Platform\Exception\ModelNotFoundException; use Symfony\AI\Platform\Exception\RuntimeException; use Symfony\AI\Platform\Result\RawHttpResult; use Symfony\AI\Platform\Result\VectorResult; @@ -86,4 +88,43 @@ public function testItSupportsEmbeddingsModel() $this->assertTrue($converter->supports(new Embeddings('test-model'))); } + + #[TestWith(['Model not found'])] + #[TestWith(['MODEL NOT FOUND'])] + public function testItThrowsModelNotFoundExceptionWhen404WithModelNotFoundMessage(string $message) + { + $response = $this->createMock(ResponseInterface::class); + $response + ->method('getStatusCode') + ->willReturn(404); + $response + ->method('getContent') + ->with(false) + ->willReturn($message); + + $this->expectException(ModelNotFoundException::class); + $this->expectExceptionMessage($message); + + (new ResultConverter())->convert(new RawHttpResult($response)); + } + + public function testItDoesNotThrowModelNotFoundExceptionWhen404WithoutModelNotFoundMessage() + { + $response = $this->createMock(ResponseInterface::class); + $response + ->method('getStatusCode') + ->willReturn(404); + $response + ->method('getContent') + ->with(false) + ->willReturn('Not found'); + $response + ->method('toArray') + ->willReturn(['error' => 'some other error']); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Response does not contain data.'); + + (new ResultConverter())->convert(new RawHttpResult($response)); + } }