@@ -4,6 +4,7 @@ import type { Mock } from "vitest"
44
55// Mock dependencies - must come before imports
66vi . mock ( "../../../api/providers/fetchers/modelCache" )
7+ vi . mock ( "../../../api/providers/fetchers/ollama" )
78
89vi . mock ( "../../../integrations/openai-codex/oauth" , ( ) => ( {
910 openAiCodexOAuthManager : {
@@ -25,11 +26,14 @@ import type { ModelRecord } from "@roo-code/types"
2526
2627import { webviewMessageHandler } from "../webviewMessageHandler"
2728import type { ClineProvider } from "../ClineProvider"
28- import { getModels } from "../../../api/providers/fetchers/modelCache"
29+ import { getModels , flushModels } from "../../../api/providers/fetchers/modelCache"
30+ import { discoverOllamaModelsWithSorting } from "../../../api/providers/fetchers/ollama"
2931const { openAiCodexOAuthManager } = await import ( "../../../integrations/openai-codex/oauth" )
3032const { fetchOpenAiCodexRateLimitInfo } = await import ( "../../../integrations/openai-codex/rate-limits" )
3133
3234const mockGetModels = getModels as Mock < typeof getModels >
35+ const mockFlushModels = flushModels as Mock < typeof flushModels >
36+ const mockDiscoverOllamaModels = discoverOllamaModelsWithSorting as Mock < typeof discoverOllamaModelsWithSorting >
3337const mockGetAccessToken = vi . mocked ( openAiCodexOAuthManager . getAccessToken )
3438const mockGetAccountId = vi . mocked ( openAiCodexOAuthManager . getAccountId )
3539const mockFetchOpenAiCodexRateLimitInfo = vi . mocked ( fetchOpenAiCodexRateLimitInfo )
@@ -228,32 +232,40 @@ describe("webviewMessageHandler - requestOllamaModels", () => {
228232 } )
229233
230234 it ( "successfully fetches models from Ollama" , async ( ) => {
231- const mockModels : ModelRecord = {
232- "model-1" : {
233- maxTokens : 4096 ,
234- contextWindow : 8192 ,
235- supportsPromptCache : false ,
236- description : "Test model 1" ,
237- } ,
238- "model-2" : {
239- maxTokens : 8192 ,
240- contextWindow : 16384 ,
241- supportsPromptCache : false ,
242- description : "Test model 2" ,
243- } ,
235+ const mockModelInfo = {
236+ maxTokens : 4096 ,
237+ contextWindow : 8192 ,
238+ supportsPromptCache : false ,
239+ description : "Test model 1" ,
244240 }
245241
246- mockGetModels . mockResolvedValue ( mockModels )
242+ mockFlushModels . mockResolvedValue ( undefined )
243+ mockDiscoverOllamaModels . mockResolvedValue ( {
244+ modelsWithTools : [
245+ { name : "model-1" , modelInfo : mockModelInfo , contextWindow : 8192 , supportsImages : false } ,
246+ ] ,
247+ modelsWithoutTools : [ ] ,
248+ totalCount : 1 ,
249+ } )
247250
248251 await webviewMessageHandler ( mockClineProvider , {
249252 type : "requestOllamaModels" ,
250253 } )
251254
252- expect ( mockGetModels ) . toHaveBeenCalledWith ( { provider : "ollama" , baseUrl : "http://localhost:1234" } )
255+ expect ( mockFlushModels ) . toHaveBeenCalledWith ( { provider : "ollama" , baseUrl : "http://localhost:1234" } , true )
256+ expect ( mockDiscoverOllamaModels ) . toHaveBeenCalledWith (
257+ "http://localhost:1234" ,
258+ undefined ,
259+ expect . objectContaining ( { } ) ,
260+ )
253261
254262 expect ( mockClineProvider . postMessageToWebview ) . toHaveBeenCalledWith ( {
255263 type : "ollamaModels" ,
256- ollamaModels : mockModels ,
264+ ollamaModels : { "model-1" : mockModelInfo } ,
265+ ollamaModelsWithTools : [
266+ { name : "model-1" , modelInfo : mockModelInfo , contextWindow : 8192 , supportsImages : false } ,
267+ ] ,
268+ modelsWithoutTools : [ ] ,
257269 } )
258270 } )
259271} )
0 commit comments