1313
1414use PHPUnit \Framework \TestCase ;
1515use Symfony \AI \Platform \Bridge \Anthropic \ResultConverter ;
16+ use Symfony \AI \Platform \Exception \RuntimeException ;
1617use Symfony \AI \Platform \Result \RawHttpResult ;
1718use Symfony \AI \Platform \Result \ToolCallResult ;
1819use Symfony \Component \HttpClient \MockHttpClient ;
1920use Symfony \Component \HttpClient \Response \JsonMockResponse ;
21+ use Symfony \Component \HttpClient \Response \MockResponse ;
2022
2123final class ResultConverterTest extends TestCase
2224{
@@ -42,4 +44,34 @@ public function testConvertThrowsExceptionWhenContentIsToolUseAndLacksText()
4244 $ this ->assertSame ('xxx_tool ' , $ result ->getContent ()[0 ]->getName ());
4345 $ this ->assertSame (['action ' => 'get_data ' ], $ result ->getContent ()[0 ]->getArguments ());
4446 }
47+
48+ public function testModelNotFoundError ()
49+ {
50+ $ httpClient = new MockHttpClient ([
51+ new MockResponse ('{"type":"error","error":{"type":"not_found_error","message":"model: claude-3-5-sonnet-20241022"}} ' ),
52+ ]);
53+
54+ $ response = $ httpClient ->request ('POST ' , 'https://api.anthropic.com/v1/messages ' );
55+ $ converter = new ResultConverter ();
56+
57+ $ this ->expectException (RuntimeException::class);
58+ $ this ->expectExceptionMessage ('API Error [not_found_error]: "model: claude-3-5-sonnet-20241022" ' );
59+
60+ $ converter ->convert (new RawHttpResult ($ response ));
61+ }
62+
63+ public function testUnknownError ()
64+ {
65+ $ httpClient = new MockHttpClient ([
66+ new MockResponse ('{"type":"error"} ' ),
67+ ]);
68+
69+ $ response = $ httpClient ->request ('POST ' , 'https://api.anthropic.com/v1/messages ' );
70+ $ converter = new ResultConverter ();
71+
72+ $ this ->expectException (RuntimeException::class);
73+ $ this ->expectExceptionMessage ('API Error [Unknown]: "An unknown error occurred." ' );
74+
75+ $ converter ->convert (new RawHttpResult ($ response ));
76+ }
4577}
0 commit comments