@@ -187,11 +187,11 @@ describe("LLMRouter", () => {
187187 expect ( options . headers ) . not . toHaveProperty ( "Authorization" ) ;
188188 } ) ;
189189
190- it ( "should parse MiniMax response content and usage correctly" , async ( ) => {
191- const config : LLMProviderConfig = {
192- name : "minimax" ,
193- baseUrl : "https://api.minimax.io/anthropic/v1" ,
194- apiKey : "test-minimax-key" ,
190+ it ( "should parse MiniMax response content and usage correctly" , async ( ) => {
191+ const config : LLMProviderConfig = {
192+ name : "minimax" ,
193+ baseUrl : "https://api.minimax.io/anthropic/v1" ,
194+ apiKey : "test-minimax-key" ,
195195 model : "MiniMax-M2.7-highspeed" ,
196196 maxTokens : 4096 ,
197197 } ;
@@ -206,15 +206,36 @@ describe("LLMRouter", () => {
206206 const result = await router . complete ( [ { role : "user" , content : "hello" } ] ) ;
207207
208208 expect ( result . content ) . toBe ( "MiniMax response" ) ;
209- expect ( result . promptTokens ) . toBe ( 20 ) ;
210- expect ( result . completionTokens ) . toBe ( 10 ) ;
211- } ) ;
212-
213- it ( "should route to completions endpoint when apiType is undefined" , async ( ) => {
214- const config : LLMProviderConfig = { ...baseConfig } ;
215- fetchSpy . mockResolvedValueOnce (
216- createJSONResponse ( {
217- choices : [ { message : { content : "hello" } } ] ,
209+ expect ( result . promptTokens ) . toBe ( 20 ) ;
210+ expect ( result . completionTokens ) . toBe ( 10 ) ;
211+ } ) ;
212+
213+ it ( "should reject Anthropic-compatible responses without text content" , async ( ) => {
214+ const config : LLMProviderConfig = {
215+ name : "minimax" ,
216+ baseUrl : "https://api.minimax.io/anthropic/v1" ,
217+ apiKey : "test-minimax-key" ,
218+ model : "MiniMax-M2.7-highspeed" ,
219+ maxTokens : 4096 ,
220+ } ;
221+ fetchSpy . mockResolvedValueOnce (
222+ createJSONResponse ( {
223+ content : [ { type : "tool_use" , id : "call-1" , name : "lookup" , input : { } } ] ,
224+ } ) ,
225+ ) ;
226+
227+ const router = new LLMRouter ( config ) ;
228+
229+ await expect (
230+ router . complete ( [ { role : "user" , content : "hello" } ] ) ,
231+ ) . rejects . toThrow ( "LLM 响应格式异常: 缺少 text content 字段" ) ;
232+ } ) ;
233+
234+ it ( "should route to completions endpoint when apiType is undefined" , async ( ) => {
235+ const config : LLMProviderConfig = { ...baseConfig } ;
236+ fetchSpy . mockResolvedValueOnce (
237+ createJSONResponse ( {
238+ choices : [ { message : { content : "hello" } } ] ,
218239 usage : { prompt_tokens : 10 , completion_tokens : 5 } ,
219240 } ) ,
220241 ) ;
0 commit comments