@@ -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 ,
@@ -157,3 +174,29 @@ describe("buildApiHandler", () => {
157174 expect ( handler ) . toBeInstanceOf ( AnthropicHandler )
158175 } )
159176} )
177+
178+ // fetchModels is optional on ApiHandler, so this replaces the old fetcher switch's
179+ // exhaustiveness check: every RouterName must build a handler that implements it.
180+ describe ( "buildApiHandler model catalog coverage" , ( ) => {
181+ const routerNames : RouterName [ ] = [ ...dynamicProviders , ...localProviders ]
182+
183+ it ( "covers at least one router" , ( ) => {
184+ expect ( routerNames . length ) . toBeGreaterThan ( 0 )
185+ } )
186+
187+ it . each ( routerNames ) ( "returns a handler implementing fetchModels for %s" , ( apiProvider ) => {
188+ const handler = buildApiHandler ( { apiProvider } )
189+
190+ expect ( handler ) . not . toBeInstanceOf ( AnthropicHandler )
191+ expect ( typeof handler . fetchModels ) . toBe ( "function" )
192+ expect ( typeof handler . getModelCacheScope ) . toBe ( "function" )
193+ } )
194+
195+ it ( "does not expose fetchModels on the default fallback handler" , ( ) => {
196+ const handler = buildApiHandler ( {
197+ apiProvider : "unsupported-provider" as ProviderNameWithRetired ,
198+ } )
199+
200+ expect ( handler . fetchModels ) . toBeUndefined ( )
201+ } )
202+ } )
0 commit comments