@@ -227,3 +227,203 @@ func TestEngineNames_Nil(t *testing.T) {
227227 t .Fatalf ("expected nil engine names on nil receiver, got %v" , names )
228228 }
229229}
230+
231+ func TestEngineCapability_SupportsAPIFormat (t * testing.T ) {
232+ ec := & EngineCapability {
233+ Name : EngineTypeVLLM ,
234+ APIFormats : []APIFormat {
235+ APIFormatOpenAIChat ,
236+ APIFormatOpenAIResponses ,
237+ APIFormatAnthropicMessages ,
238+ },
239+ }
240+ if ! ec .SupportsAPIFormat (APIFormatOpenAIChat ) {
241+ t .Error ("expected vllm to support openai-chat" )
242+ }
243+ if ! ec .SupportsAPIFormat (APIFormatOpenAIResponses ) {
244+ t .Error ("expected vllm to support openai-responses" )
245+ }
246+ if ! ec .SupportsAPIFormat (APIFormatAnthropicMessages ) {
247+ t .Error ("expected vllm to support anthropic-messages" )
248+ }
249+ }
250+
251+ func TestEngineCapability_SupportsAPIFormat_EmptyDefaultsToChat (t * testing.T ) {
252+ ec := & EngineCapability {
253+ Name : EngineTypeVLLM ,
254+ APIFormats : []APIFormat {},
255+ }
256+ if ! ec .SupportsAPIFormat (APIFormatOpenAIChat ) {
257+ t .Error ("expected empty APIFormats to default to supporting openai-chat" )
258+ }
259+ if ec .SupportsAPIFormat (APIFormatOpenAIResponses ) {
260+ t .Error ("expected empty APIFormats to NOT support openai-responses" )
261+ }
262+ if ec .SupportsAPIFormat (APIFormatAnthropicMessages ) {
263+ t .Error ("expected empty APIFormats to NOT support anthropic-messages" )
264+ }
265+ }
266+
267+ func TestEngineCapability_SupportsAPIFormat_NilFormats (t * testing.T ) {
268+ ec := & EngineCapability {Name : EngineTypeVLLM }
269+ if ! ec .SupportsAPIFormat (APIFormatOpenAIChat ) {
270+ t .Error ("expected nil APIFormats to default to supporting openai-chat" )
271+ }
272+ if ec .SupportsAPIFormat (APIFormatAnthropicMessages ) {
273+ t .Error ("expected nil APIFormats to NOT support anthropic-messages" )
274+ }
275+ }
276+
277+ func TestEngineCapability_SupportsAPIFormat_Nil (t * testing.T ) {
278+ var ec * EngineCapability
279+ if ec .SupportsAPIFormat (APIFormatOpenAIChat ) {
280+ t .Error ("expected nil receiver to return false" )
281+ }
282+ }
283+
284+ func TestEngineCapability_EffectiveAPIFormats (t * testing.T ) {
285+ ec := & EngineCapability {
286+ Name : EngineTypeVLLM ,
287+ APIFormats : []APIFormat {
288+ APIFormatOpenAIChat ,
289+ APIFormatAnthropicMessages ,
290+ },
291+ }
292+ formats := ec .EffectiveAPIFormats ()
293+ if len (formats ) != 2 {
294+ t .Fatalf ("expected 2 formats, got %d" , len (formats ))
295+ }
296+ if formats [0 ] != APIFormatOpenAIChat {
297+ t .Errorf ("expected first format openai-chat, got %s" , formats [0 ])
298+ }
299+ if formats [1 ] != APIFormatAnthropicMessages {
300+ t .Errorf ("expected second format anthropic-messages, got %s" , formats [1 ])
301+ }
302+ }
303+
304+ func TestEngineCapability_EffectiveAPIFormats_EmptyMaterializesChat (t * testing.T ) {
305+ ec := & EngineCapability {Name : EngineTypeVLLM }
306+ formats := ec .EffectiveAPIFormats ()
307+ if len (formats ) != 1 {
308+ t .Fatalf ("expected 1 default format, got %d" , len (formats ))
309+ }
310+ if formats [0 ] != APIFormatOpenAIChat {
311+ t .Errorf ("expected default format openai-chat, got %s" , formats [0 ])
312+ }
313+ }
314+
315+ func TestEngineCapability_EffectiveAPIFormats_Nil (t * testing.T ) {
316+ var ec * EngineCapability
317+ formats := ec .EffectiveAPIFormats ()
318+ if formats != nil {
319+ t .Fatalf ("expected nil on nil receiver, got %v" , formats )
320+ }
321+ }
322+
323+ func TestProviderCapabilities_SupportsAPIFormat (t * testing.T ) {
324+ caps := & ProviderCapabilities {
325+ Engines : []EngineCapability {
326+ {
327+ Name : EngineTypeVLLM ,
328+ APIFormats : []APIFormat {
329+ APIFormatOpenAIChat ,
330+ APIFormatOpenAIResponses ,
331+ APIFormatAnthropicMessages ,
332+ },
333+ },
334+ {
335+ Name : EngineTypeLlamaCpp ,
336+ APIFormats : []APIFormat {
337+ APIFormatOpenAIChat ,
338+ },
339+ },
340+ },
341+ }
342+
343+ if ! caps .SupportsAPIFormat (EngineTypeVLLM , APIFormatAnthropicMessages ) {
344+ t .Error ("expected vllm to support anthropic-messages via ProviderCapabilities" )
345+ }
346+ if caps .SupportsAPIFormat (EngineTypeLlamaCpp , APIFormatAnthropicMessages ) {
347+ t .Error ("expected llamacpp to NOT support anthropic-messages" )
348+ }
349+ if caps .SupportsAPIFormat (EngineTypeSGLang , APIFormatOpenAIChat ) {
350+ t .Error ("expected missing engine to not support any format" )
351+ }
352+ }
353+
354+ func TestProviderCapabilities_EffectiveAPIFormats (t * testing.T ) {
355+ caps := & ProviderCapabilities {
356+ Engines : []EngineCapability {
357+ {Name : EngineTypeVLLM },
358+ },
359+ }
360+ formats := caps .EffectiveAPIFormats (EngineTypeVLLM )
361+ if len (formats ) != 1 || formats [0 ] != APIFormatOpenAIChat {
362+ t .Errorf ("expected [openai-chat] default, got %v" , formats )
363+ }
364+ formats = caps .EffectiveAPIFormats (EngineTypeSGLang )
365+ if formats != nil {
366+ t .Errorf ("expected nil for missing engine, got %v" , formats )
367+ }
368+ }
369+
370+ func TestValidateAPIFormatsForEngine (t * testing.T ) {
371+ if err := ValidateAPIFormatsForEngine (EngineTypeVLLM , []APIFormat {
372+ APIFormatOpenAIChat , APIFormatOpenAIResponses , APIFormatAnthropicMessages ,
373+ }); err != nil {
374+ t .Errorf ("expected no error for valid vllm formats, got %v" , err )
375+ }
376+
377+ if err := ValidateAPIFormatsForEngine (EngineTypeSGLang , []APIFormat {
378+ APIFormatOpenAIChat , APIFormatAnthropicMessages ,
379+ }); err != nil {
380+ t .Errorf ("expected no error for valid sglang formats, got %v" , err )
381+ }
382+
383+ if err := ValidateAPIFormatsForEngine (EngineTypeLlamaCpp , []APIFormat {
384+ APIFormatOpenAIChat ,
385+ }); err != nil {
386+ t .Errorf ("expected no error for valid llamacpp formats, got %v" , err )
387+ }
388+
389+ if err := ValidateAPIFormatsForEngine (EngineTypeTRTLLM , []APIFormat {
390+ APIFormatOpenAIChat , APIFormatOpenAIResponses ,
391+ }); err != nil {
392+ t .Errorf ("expected no error for valid trtllm formats, got %v" , err )
393+ }
394+
395+ // Empty formats should pass (no invalid entries)
396+ if err := ValidateAPIFormatsForEngine (EngineTypeVLLM , []APIFormat {}); err != nil {
397+ t .Errorf ("expected no error for empty formats, got %v" , err )
398+ }
399+ }
400+
401+ func TestValidateAPIFormatsForEngine_Invalid (t * testing.T ) {
402+ err := ValidateAPIFormatsForEngine (EngineTypeTRTLLM , []APIFormat {
403+ APIFormatOpenAIChat , APIFormatAnthropicMessages ,
404+ })
405+ if err == nil {
406+ t .Error ("expected error for trtllm with anthropic-messages" )
407+ }
408+
409+ err = ValidateAPIFormatsForEngine (EngineTypeSGLang , []APIFormat {
410+ APIFormatOpenAIResponses ,
411+ })
412+ if err == nil {
413+ t .Error ("expected error for sglang with openai-responses" )
414+ }
415+
416+ err = ValidateAPIFormatsForEngine (EngineTypeLlamaCpp , []APIFormat {
417+ APIFormatOpenAIChat , APIFormatAnthropicMessages ,
418+ })
419+ if err == nil {
420+ t .Error ("expected error for llamacpp with anthropic-messages" )
421+ }
422+ }
423+
424+ func TestValidateAPIFormatsForEngine_UnknownEngine (t * testing.T ) {
425+ err := ValidateAPIFormatsForEngine (EngineType ("unknown" ), []APIFormat {APIFormatOpenAIChat })
426+ if err == nil {
427+ t .Error ("expected error for unknown engine type" )
428+ }
429+ }
0 commit comments