@@ -58,20 +58,20 @@ vi.mock("openai", () => {
5858 }
5959} )
6060
61- // Mock LM Studio fetcher
62- vi . mock ( "../fetchers/lmstudio " , ( ) => ( {
63- getLMStudioModels : vi . fn ( ) ,
61+ // Mock model cache
62+ vi . mock ( "../fetchers/modelCache " , ( ) => ( {
63+ getModels : vi . fn ( ) ,
6464} ) )
6565
6666import type { Anthropic } from "@anthropic-ai/sdk"
6767import type { ModelInfo } from "@roo-code/types"
6868
6969import { LmStudioHandler } from "../lm-studio"
7070import type { ApiHandlerOptions } from "../../../shared/api"
71- import { getLMStudioModels } from "../fetchers/lmstudio "
71+ import { getModels } from "../fetchers/modelCache "
7272
7373// Get the mocked function
74- const mockGetLMStudioModels = vi . mocked ( getLMStudioModels )
74+ const mockGetModels = vi . mocked ( getModels )
7575
7676describe ( "LmStudioHandler" , ( ) => {
7777 let handler : LmStudioHandler
@@ -98,7 +98,7 @@ describe("LmStudioHandler", () => {
9898 }
9999 handler = new LmStudioHandler ( mockOptions )
100100 mockCreate . mockClear ( )
101- mockGetLMStudioModels . mockClear ( )
101+ mockGetModels . mockClear ( )
102102 } )
103103
104104 describe ( "constructor" , ( ) => {
@@ -190,7 +190,7 @@ describe("LmStudioHandler", () => {
190190
191191 it ( "should return fetched model info when available" , async ( ) => {
192192 // Mock the fetched models
193- mockGetLMStudioModels . mockResolvedValueOnce ( {
193+ mockGetModels . mockResolvedValueOnce ( {
194194 "local-model" : mockModelInfo ,
195195 } )
196196
@@ -204,7 +204,7 @@ describe("LmStudioHandler", () => {
204204
205205 it ( "should fallback to default when model not found in fetched models" , async ( ) => {
206206 // Mock fetched models without our target model
207- mockGetLMStudioModels . mockResolvedValueOnce ( {
207+ mockGetModels . mockResolvedValueOnce ( {
208208 "other-model" : mockModelInfo ,
209209 } )
210210
@@ -219,32 +219,21 @@ describe("LmStudioHandler", () => {
219219
220220 describe ( "fetchModel" , ( ) => {
221221 it ( "should fetch models successfully" , async ( ) => {
222- mockGetLMStudioModels . mockResolvedValueOnce ( {
222+ mockGetModels . mockResolvedValueOnce ( {
223223 "local-model" : mockModelInfo ,
224224 } )
225225
226226 const result = await handler . fetchModel ( )
227227
228- expect ( mockGetLMStudioModels ) . toHaveBeenCalledWith ( mockOptions . lmStudioBaseUrl )
228+ expect ( mockGetModels ) . toHaveBeenCalledWith ( { provider : "lmstudio" } )
229229 expect ( result . id ) . toBe ( mockOptions . lmStudioModelId )
230230 expect ( result . info ) . toEqual ( mockModelInfo )
231231 } )
232232
233233 it ( "should handle fetch errors gracefully" , async ( ) => {
234- const consoleSpy = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
235- mockGetLMStudioModels . mockRejectedValueOnce ( new Error ( "Connection failed" ) )
234+ mockGetModels . mockRejectedValueOnce ( new Error ( "Connection failed" ) )
236235
237- const result = await handler . fetchModel ( )
238-
239- expect ( consoleSpy ) . toHaveBeenCalledWith (
240- "Failed to fetch LM Studio models, using defaults:" ,
241- expect . any ( Error ) ,
242- )
243- expect ( result . id ) . toBe ( mockOptions . lmStudioModelId )
244- expect ( result . info . maxTokens ) . toBe ( - 1 )
245- expect ( result . info . contextWindow ) . toBe ( 128_000 )
246-
247- consoleSpy . mockRestore ( )
236+ await expect ( handler . fetchModel ( ) ) . rejects . toThrow ( "Connection failed" )
248237 } )
249238 } )
250239} )
0 commit comments