@@ -11,16 +11,12 @@ const mockedAxios = axios as any
1111// Mock @lmstudio /sdk
1212const mockGetModelInfo = vi . fn ( )
1313const mockListLoaded = vi . fn ( )
14- const mockListDownloadedModels = vi . fn ( )
1514vi . mock ( "@lmstudio/sdk" , ( ) => {
1615 return {
1716 LMStudioClient : vi . fn ( ) . mockImplementation ( ( ) => ( {
1817 llm : {
1918 listLoaded : mockListLoaded ,
2019 } ,
21- system : {
22- listDownloadedModels : mockListDownloadedModels ,
23- } ,
2420 } ) ) ,
2521 }
2622} )
@@ -32,7 +28,6 @@ describe("LMStudio Fetcher", () => {
3228 MockedLMStudioClientConstructor . mockClear ( )
3329 mockListLoaded . mockClear ( )
3430 mockGetModelInfo . mockClear ( )
35- mockListDownloadedModels . mockClear ( )
3631 } )
3732
3833 describe ( "parseLMStudioModel" , ( ) => {
@@ -93,40 +88,8 @@ describe("LMStudio Fetcher", () => {
9388 trainedForToolUse : false , // Added
9489 }
9590
96- it ( "should fetch downloaded models using system.listDownloadedModels" , async ( ) => {
97- const mockLLMInfo : LLMInfo = {
98- type : "llm" as const ,
99- modelKey : "mistralai/devstral-small-2505" ,
100- format : "safetensors" ,
101- displayName : "Devstral Small 2505" ,
102- path : "mistralai/devstral-small-2505" ,
103- sizeBytes : 13277565112 ,
104- architecture : "mistral" ,
105- vision : false ,
106- trainedForToolUse : false ,
107- maxContextLength : 131072 ,
108- }
109-
110- mockedAxios . get . mockResolvedValueOnce ( { data : { status : "ok" } } )
111- mockListDownloadedModels . mockResolvedValueOnce ( [ mockLLMInfo ] )
112-
113- const result = await getLMStudioModels ( baseUrl )
114-
115- expect ( mockedAxios . get ) . toHaveBeenCalledTimes ( 1 )
116- expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl } /v1/models` )
117- expect ( MockedLMStudioClientConstructor ) . toHaveBeenCalledTimes ( 1 )
118- expect ( MockedLMStudioClientConstructor ) . toHaveBeenCalledWith ( { baseUrl : lmsUrl } )
119- expect ( mockListDownloadedModels ) . toHaveBeenCalledTimes ( 1 )
120- expect ( mockListDownloadedModels ) . toHaveBeenCalledWith ( "llm" )
121- expect ( mockListLoaded ) . toHaveBeenCalled ( ) // we now call it to get context data
122-
123- const expectedParsedModel = parseLMStudioModel ( mockLLMInfo )
124- expect ( result ) . toEqual ( { [ mockLLMInfo . path ] : expectedParsedModel } )
125- } )
126-
127- it ( "should fall back to listLoaded when listDownloadedModels fails" , async ( ) => {
91+ it ( "should fetch only loaded models and use model.path as key" , async ( ) => {
12892 mockedAxios . get . mockResolvedValueOnce ( { data : { status : "ok" } } )
129- mockListDownloadedModels . mockRejectedValueOnce ( new Error ( "Method not available" ) )
13093 mockListLoaded . mockResolvedValueOnce ( [ { getModelInfo : mockGetModelInfo } ] )
13194 mockGetModelInfo . mockResolvedValueOnce ( mockRawModel )
13295
@@ -136,11 +99,11 @@ describe("LMStudio Fetcher", () => {
13699 expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl } /v1/models` )
137100 expect ( MockedLMStudioClientConstructor ) . toHaveBeenCalledTimes ( 1 )
138101 expect ( MockedLMStudioClientConstructor ) . toHaveBeenCalledWith ( { baseUrl : lmsUrl } )
139- expect ( mockListDownloadedModels ) . toHaveBeenCalledTimes ( 1 )
140102 expect ( mockListLoaded ) . toHaveBeenCalledTimes ( 1 )
141103
142104 const expectedParsedModel = parseLMStudioModel ( mockRawModel )
143- expect ( result ) . toEqual ( { [ mockRawModel . modelKey ] : expectedParsedModel } )
105+ // Now using model.path as the key instead of modelKey
106+ expect ( result ) . toEqual ( { [ mockRawModel . path ] : expectedParsedModel } )
144107 } )
145108
146109 it ( "should use default baseUrl if an empty string is provided" , async ( ) => {
@@ -212,7 +175,7 @@ describe("LMStudio Fetcher", () => {
212175 consoleInfoSpy . mockRestore ( )
213176 } )
214177
215- it ( "should return an empty object and log error if listDownloadedModels fails" , async ( ) => {
178+ it ( "should return an empty object and log error if listLoaded fails" , async ( ) => {
216179 const consoleErrorSpy = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
217180 const listError = new Error ( "LMStudio SDK internal error" )
218181
0 commit comments