@@ -9,25 +9,42 @@ vitest.mock("vscode", () => ({
99 } ,
1010} ) )
1111
12- // Handler constructors can require credentials or initialize SDK clients. Replace them
13- // with inert classes so these tests exercise only the factory's routing behavior.
12+ // Replace handlers with inert classes (no-op constructors) that keep the real prototype
13+ // chain, so tests exercise routing and can still inspect methods such as fetchModels.
14+ const { inertClass } = vitest . hoisted ( ( ) => ( {
15+ inertClass : ( actual : unknown ) : unknown => {
16+ if ( typeof actual !== "function" || ! actual . prototype ) {
17+ return actual
18+ }
19+ const Inert = class { }
20+ Object . setPrototypeOf ( Inert . prototype , actual . prototype )
21+ return Inert
22+ } ,
23+ } ) )
24+
1425vitest . mock ( "../providers" , async ( ) => {
1526 const providers = await vitest . importActual < Record < string , unknown > > ( "../providers" )
1627
17- return Object . fromEntries ( Object . keys ( providers ) . map ( ( name ) => [ name , class { } ] ) )
28+ return Object . fromEntries ( Object . entries ( providers ) . map ( ( [ name , actual ] ) => [ name , inertClass ( actual ) ] ) )
1829} )
1930
20- vitest . mock ( "../providers/native-ollama" , ( ) => ( {
21- NativeOllamaHandler : class { } ,
22- } ) )
31+ vitest . mock ( "../providers/native-ollama" , async ( ) => {
32+ const actual = await vitest . importActual < typeof import ( "../providers/native-ollama" ) > ( "../providers/native-ollama" )
33+
34+ return { NativeOllamaHandler : inertClass ( actual . NativeOllamaHandler ) }
35+ } )
2336
2437import {
38+ dynamicProviders ,
39+ localProviders ,
2540 providerIdentifiers ,
2641 retiredProviderIdentifiers ,
2742 type ProviderName ,
2843 type ProviderNameWithRetired ,
2944} from "@roo-code/types"
3045
46+ import type { RouterName } from "../../shared/api"
47+
3148import { buildApiHandler } from "../index"
3249import {
3350 AnthropicHandler ,
@@ -155,3 +172,29 @@ describe("buildApiHandler", () => {
155172 expect ( handler ) . toBeInstanceOf ( AnthropicHandler )
156173 } )
157174} )
175+
176+ // fetchModels is optional on ApiHandler, so this replaces the old fetcher switch's
177+ // exhaustiveness check: every RouterName must build a handler that implements it.
178+ describe ( "buildApiHandler model catalog coverage" , ( ) => {
179+ const routerNames : RouterName [ ] = [ ...dynamicProviders , ...localProviders ]
180+
181+ it ( "covers at least one router" , ( ) => {
182+ expect ( routerNames . length ) . toBeGreaterThan ( 0 )
183+ } )
184+
185+ it . each ( routerNames ) ( "returns a handler implementing fetchModels for %s" , ( apiProvider ) => {
186+ const handler = buildApiHandler ( { apiProvider } )
187+
188+ expect ( handler ) . not . toBeInstanceOf ( AnthropicHandler )
189+ expect ( typeof handler . fetchModels ) . toBe ( "function" )
190+ expect ( typeof handler . getModelCacheScope ) . toBe ( "function" )
191+ } )
192+
193+ it ( "does not expose fetchModels on the default fallback handler" , ( ) => {
194+ const handler = buildApiHandler ( {
195+ apiProvider : "unsupported-provider" as ProviderNameWithRetired ,
196+ } )
197+
198+ expect ( handler . fetchModels ) . toBeUndefined ( )
199+ } )
200+ } )
0 commit comments