@@ -50,6 +50,22 @@ vi.mock("../../plugins/provider-runtime.js", () => ({
5050
5151let resolveModelAsync : typeof import ( "./model.js" ) . resolveModelAsync ;
5252
53+ function expectWorkspaceHookCall ( mock : { mock : { calls : unknown [ ] [ ] } } ) {
54+ expect ( mock . mock . calls ) . toHaveLength ( 1 ) ;
55+ const [ arg ] = mock . mock . calls [ 0 ] ?? [ ] ;
56+ expect ( arg ) . toBeTruthy ( ) ;
57+ if ( ! arg || typeof arg !== "object" ) {
58+ throw new Error ( "Expected runtime hook call argument" ) ;
59+ }
60+ const call = arg as { context ?: unknown ; workspaceDir ?: unknown } ;
61+ expect ( call . workspaceDir ) . toBe ( "/tmp/workspace" ) ;
62+ expect ( call . context ) . toBeTruthy ( ) ;
63+ if ( ! call . context || typeof call . context !== "object" ) {
64+ throw new Error ( "Expected runtime hook context" ) ;
65+ }
66+ expect ( ( call . context as { workspaceDir ?: unknown } ) . workspaceDir ) . toBe ( "/tmp/workspace" ) ;
67+ }
68+
5369beforeEach ( async ( ) => {
5470 vi . clearAllMocks ( ) ;
5571 ( { resolveModelAsync } = await import ( "./model.js" ) ) ;
@@ -63,34 +79,18 @@ describe("resolveModelAsync skipPiDiscovery runtime hooks", () => {
6379 } ) ;
6480
6581 expect ( result . error ) . toBeUndefined ( ) ;
66- expect ( result . model ) . toMatchObject ( {
67- provider : "ollama" ,
68- id : "llama3.2:latest" ,
69- api : "ollama" ,
70- } ) ;
82+ expect ( result . model ) . toBeDefined ( ) ;
83+ if ( ! result . model ) {
84+ throw new Error ( "Expected resolved model" ) ;
85+ }
86+ expect ( result . model . provider ) . toBe ( "ollama" ) ;
87+ expect ( result . model . id ) . toBe ( "llama3.2:latest" ) ;
88+ expect ( result . model . api ) . toBe ( "ollama" ) ;
7189 expect ( mocks . discoverAuthStorage ) . not . toHaveBeenCalled ( ) ;
7290 expect ( mocks . discoverModels ) . not . toHaveBeenCalled ( ) ;
73- expect ( mocks . prepareProviderDynamicModel ) . toHaveBeenCalledTimes ( 1 ) ;
74- expect ( mocks . prepareProviderDynamicModel ) . toHaveBeenCalledWith (
75- expect . objectContaining ( {
76- workspaceDir : "/tmp/workspace" ,
77- context : expect . objectContaining ( { workspaceDir : "/tmp/workspace" } ) ,
78- } ) ,
79- ) ;
80- expect ( mocks . runProviderDynamicModel ) . toHaveBeenCalledTimes ( 1 ) ;
81- expect ( mocks . runProviderDynamicModel ) . toHaveBeenCalledWith (
82- expect . objectContaining ( {
83- workspaceDir : "/tmp/workspace" ,
84- context : expect . objectContaining ( { workspaceDir : "/tmp/workspace" } ) ,
85- } ) ,
86- ) ;
87- expect ( mocks . normalizeProviderResolvedModelWithPlugin ) . toHaveBeenCalledTimes ( 1 ) ;
88- expect ( mocks . normalizeProviderResolvedModelWithPlugin ) . toHaveBeenCalledWith (
89- expect . objectContaining ( {
90- workspaceDir : "/tmp/workspace" ,
91- context : expect . objectContaining ( { workspaceDir : "/tmp/workspace" } ) ,
92- } ) ,
93- ) ;
91+ expectWorkspaceHookCall ( mocks . prepareProviderDynamicModel ) ;
92+ expectWorkspaceHookCall ( mocks . runProviderDynamicModel ) ;
93+ expectWorkspaceHookCall ( mocks . normalizeProviderResolvedModelWithPlugin ) ;
9494 expect ( mocks . applyProviderResolvedModelCompatWithPlugins ) . not . toHaveBeenCalled ( ) ;
9595 expect ( mocks . applyProviderResolvedTransportWithPlugin ) . not . toHaveBeenCalled ( ) ;
9696 expect ( mocks . normalizeProviderTransportWithPlugin ) . not . toHaveBeenCalled ( ) ;
0 commit comments