@@ -70,6 +70,14 @@ function createOllamaFetchMock(params: {
7070 } ) ;
7171}
7272
73+ function mockCall ( mock : { mock : { calls : unknown [ ] [ ] } } , index = 0 ) {
74+ return mock . mock . calls . at ( index ) ;
75+ }
76+
77+ function mockCallArg ( mock : { mock : { calls : unknown [ ] [ ] } } , index = 0 , argIndex = 0 ) {
78+ return mockCall ( mock , index ) ?. at ( argIndex ) ;
79+ }
80+
7381function createLocalPrompter ( ) : WizardPrompter {
7482 return {
7583 select : vi . fn ( ) . mockResolvedValueOnce ( "local-only" ) ,
@@ -151,7 +159,7 @@ describe("ollama setup", () => {
151159 prompter,
152160 } ) ;
153161
154- const baseUrlPrompt = text . mock . calls [ 0 ] ?. [ 0 ] as {
162+ const baseUrlPrompt = mockCallArg ( text ) as {
155163 message ?: string ;
156164 initialValue ?: string ;
157165 placeholder ?: string ;
@@ -164,7 +172,7 @@ describe("ollama setup", () => {
164172 validate : baseUrlPrompt . validate ,
165173 } ) ;
166174 expect ( typeof baseUrlPrompt . validate ) . toBe ( "function" ) ;
167- expect ( fetchMock . mock . calls [ 0 ] ?. [ 0 ] ) . toBe ( "http://host.docker.internal:11434/api/tags" ) ;
175+ expect ( mockCallArg ( fetchMock ) ) . toBe ( "http://host.docker.internal:11434/api/tags" ) ;
168176 expect ( result . config . models ?. providers ?. ollama ?. baseUrl ) . toBe (
169177 "http://host.docker.internal:11434" ,
170178 ) ;
@@ -485,8 +493,8 @@ describe("ollama setup", () => {
485493 } ) ;
486494
487495 expect ( fetchMock ) . toHaveBeenCalledTimes ( 2 ) ;
488- expect ( fetchMock . mock . calls [ 1 ] [ 0 ] ) . toContain ( "/api/pull" ) ;
489- const pullInit = fetchMock . mock . calls [ 1 ] [ 1 ] ;
496+ expect ( mockCallArg ( fetchMock , 1 ) ) . toContain ( "/api/pull" ) ;
497+ const pullInit = mockCallArg ( fetchMock , 1 , 1 ) as RequestInit | undefined ;
490498 expect ( pullInit ?. signal ) . toBeInstanceOf ( AbortSignal ) ;
491499 expect ( pullInit ?. signal ?. aborted ) . toBe ( false ) ;
492500
@@ -522,7 +530,7 @@ describe("ollama setup", () => {
522530 prompter,
523531 } ) . catch ( ( err : unknown ) => err ) ;
524532
525- await vi . waitFor ( ( ) => expect ( fetchMock . mock . calls [ 1 ] ?. [ 0 ] ) . toContain ( "/api/pull" ) ) ;
533+ await vi . waitFor ( ( ) => expect ( mockCallArg ( fetchMock , 1 ) ) . toContain ( "/api/pull" ) ) ;
526534
527535 await vi . advanceTimersByTimeAsync ( 300_000 ) ;
528536 const pullError = await pullPromise ;
@@ -595,8 +603,8 @@ describe("ollama setup", () => {
595603 prompter,
596604 } ) ;
597605
598- expect ( fetchMock . mock . calls [ 0 ] ?. [ 0 ] ) . toBe ( "http://127.0.0.1:11435/api/tags" ) ;
599- expect ( fetchMock . mock . calls [ 1 ] ?. [ 0 ] ) . toBe ( "http://127.0.0.1:11435/api/pull" ) ;
606+ expect ( mockCallArg ( fetchMock ) ) . toBe ( "http://127.0.0.1:11435/api/tags" ) ;
607+ expect ( mockCallArg ( fetchMock , 1 ) ) . toBe ( "http://127.0.0.1:11435/api/pull" ) ;
600608 } ) ;
601609
602610 it ( "skips pull for cloud models" , async ( ) => {
@@ -680,7 +688,7 @@ describe("ollama setup", () => {
680688 runtime,
681689 } ) ;
682690
683- const pullRequest = fetchMock . mock . calls [ 1 ] ?. [ 1 ] ;
691+ const pullRequest = mockCallArg ( fetchMock , 1 , 1 ) as RequestInit | undefined ;
684692 expect ( JSON . parse ( requestBodyText ( pullRequest ?. body ) ) ) . toEqual ( { name : "llama3.2:latest" } ) ;
685693 expect ( result . agents ?. defaults ?. model ) . toEqual ( { primary : "ollama/llama3.2:latest" } ) ;
686694 } ) ;
0 commit comments