11import { finetunedVertexModels } from '@codebuff/common/old-constants'
2+ import { TEST_AGENT_RUNTIME_IMPL } from '@codebuff/common/testing/impl/agent-runtime'
23import {
34 clearMockedModules ,
45 mockModule ,
@@ -18,10 +19,13 @@ import * as OriginalRequestFilesPromptModule from '../find-files/request-files-p
1819import * as geminiWithFallbacksModule from '../llm-apis/gemini-with-fallbacks'
1920
2021import type { CostMode } from '@codebuff/common/old-constants'
22+ import type { AgentRuntimeDeps } from '@codebuff/common/types/contracts/agent-runtime'
2123import type { Message } from '@codebuff/common/types/messages/codebuff-message'
2224import type { ProjectFileContext } from '@codebuff/common/util/file'
2325import type { Mock } from 'bun:test'
2426
27+ let agentRuntimeImpl : AgentRuntimeDeps
28+
2529describe ( 'requestRelevantFiles' , ( ) => {
2630 const mockMessages : Message [ ] = [ { role : 'user' , content : 'test prompt' } ]
2731 const mockSystem = 'test system'
@@ -58,12 +62,6 @@ describe('requestRelevantFiles', () => {
5862 const mockUserId = 'user1'
5963 const mockCostMode : CostMode = 'normal'
6064 const mockRepoId = 'owner/repo'
61- const logger = {
62- debug : ( ) => { } ,
63- info : ( ) => { } ,
64- warn : ( ) => { } ,
65- error : ( ) => { } ,
66- }
6765
6866 let getCustomFilePickerConfigForOrgSpy : any // Explicitly typed as any
6967
@@ -81,15 +79,6 @@ describe('requestRelevantFiles', () => {
8179 } ) ) ,
8280 } ) )
8381
84- mockModule ( '@codebuff/backend/util/logger' , ( ) => ( {
85- logger : {
86- info : bunMockFn ( ( ) => { } ) ,
87- error : bunMockFn ( ( ) => { } ) ,
88- warn : bunMockFn ( ( ) => { } ) ,
89- debug : bunMockFn ( ( ) => { } ) ,
90- } ,
91- } ) )
92-
9382 mockModule ( '@codebuff/common/db' , ( ) => ( {
9483 default : {
9584 insert : bunMockFn ( ( ) => ( {
@@ -109,6 +98,8 @@ describe('requestRelevantFiles', () => {
10998 } )
11099
111100 beforeEach ( ( ) => {
101+ agentRuntimeImpl = { ...TEST_AGENT_RUNTIME_IMPL }
102+
112103 // If the spy was created in a previous test, restore it
113104 if (
114105 getCustomFilePickerConfigForOrgSpy &&
@@ -134,6 +125,7 @@ describe('requestRelevantFiles', () => {
134125
135126 it ( 'should use default file counts and maxFiles when no custom config' , async ( ) => {
136127 await OriginalRequestFilesPromptModule . requestRelevantFiles ( {
128+ ...agentRuntimeImpl ,
137129 messages : mockMessages ,
138130 system : mockSystem ,
139131 fileContext : mockFileContext ,
@@ -144,7 +136,6 @@ describe('requestRelevantFiles', () => {
144136 userInputId : mockUserInputId ,
145137 userId : mockUserId ,
146138 repoId : mockRepoId ,
147- logger,
148139 } )
149140 expect (
150141 geminiWithFallbacksModule . promptFlashWithFallbacks ,
@@ -161,6 +152,7 @@ describe('requestRelevantFiles', () => {
161152 getCustomFilePickerConfigForOrgSpy ! . mockResolvedValue ( customConfig as any )
162153
163154 await OriginalRequestFilesPromptModule . requestRelevantFiles ( {
155+ ...agentRuntimeImpl ,
164156 messages : mockMessages ,
165157 system : mockSystem ,
166158 fileContext : mockFileContext ,
@@ -171,7 +163,6 @@ describe('requestRelevantFiles', () => {
171163 userInputId : mockUserInputId ,
172164 userId : mockUserId ,
173165 repoId : mockRepoId ,
174- logger,
175166 } )
176167 expect (
177168 geminiWithFallbacksModule . promptFlashWithFallbacks ,
@@ -187,6 +178,7 @@ describe('requestRelevantFiles', () => {
187178 getCustomFilePickerConfigForOrgSpy ! . mockResolvedValue ( customConfig as any )
188179
189180 const result = await OriginalRequestFilesPromptModule . requestRelevantFiles ( {
181+ ...agentRuntimeImpl ,
190182 messages : mockMessages ,
191183 system : mockSystem ,
192184 fileContext : mockFileContext ,
@@ -197,7 +189,6 @@ describe('requestRelevantFiles', () => {
197189 userInputId : mockUserInputId ,
198190 userId : mockUserId ,
199191 repoId : mockRepoId ,
200- logger,
201192 } )
202193 expect ( result ) . toBeArray ( )
203194 if ( result ) {
@@ -213,6 +204,7 @@ describe('requestRelevantFiles', () => {
213204 getCustomFilePickerConfigForOrgSpy ! . mockResolvedValue ( customConfig as any )
214205
215206 await OriginalRequestFilesPromptModule . requestRelevantFiles ( {
207+ ...agentRuntimeImpl ,
216208 messages : mockMessages ,
217209 system : mockSystem ,
218210 fileContext : mockFileContext ,
@@ -223,7 +215,6 @@ describe('requestRelevantFiles', () => {
223215 userInputId : mockUserInputId ,
224216 userId : mockUserId ,
225217 repoId : mockRepoId ,
226- logger,
227218 } )
228219 expect (
229220 geminiWithFallbacksModule . promptFlashWithFallbacks ,
@@ -242,6 +233,7 @@ describe('requestRelevantFiles', () => {
242233 getCustomFilePickerConfigForOrgSpy ! . mockResolvedValue ( customConfig as any )
243234
244235 await OriginalRequestFilesPromptModule . requestRelevantFiles ( {
236+ ...agentRuntimeImpl ,
245237 messages : mockMessages ,
246238 system : mockSystem ,
247239 fileContext : mockFileContext ,
@@ -252,7 +244,6 @@ describe('requestRelevantFiles', () => {
252244 userInputId : mockUserInputId ,
253245 userId : mockUserId ,
254246 repoId : mockRepoId ,
255- logger,
256247 } )
257248 const expectedModel = finetunedVertexModels . ft_filepicker_010
258249 expect (
0 commit comments