1- import * as geminiWithFallbacksModule from '@codebuff/agent-runtime/llm-api/gemini-with-fallbacks'
21import { finetunedVertexModels } from '@codebuff/common/old-constants'
32import {
43 TEST_AGENT_RUNTIME_IMPL ,
54 TEST_AGENT_RUNTIME_SCOPED_IMPL ,
65} from '@codebuff/common/testing/impl/agent-runtime'
7- import {
8- clearMockedModules ,
9- mockModule ,
10- } from '@codebuff/common/testing/mock-modules'
11- import {
12- afterAll ,
13- beforeAll ,
14- beforeEach ,
15- mock as bunMockFn ,
16- describe ,
17- expect ,
18- it ,
19- } from 'bun:test'
6+ import { beforeEach , describe , expect , it , mock } from 'bun:test'
207
21- import * as OriginalRequestFilesPromptModule from '../find-files /request-files-prompt'
8+ import { requestRelevantFiles } from '../request-files-prompt'
229
23- import type { CostMode } from '@codebuff/common/old-constants'
2410import type { AgentRuntimeDeps } from '@codebuff/common/types/contracts/agent-runtime'
2511import type { Message } from '@codebuff/common/types/messages/codebuff-message'
2612import type { ProjectFileContext } from '@codebuff/common/util/file'
27- import type { Mock } from 'bun:test'
2813
2914let agentRuntimeImpl : AgentRuntimeDeps
3015
@@ -62,54 +47,17 @@ describe('requestRelevantFiles', () => {
6247 const mockFingerprintId = 'fingerprint1'
6348 const mockUserInputId = 'input1'
6449 const mockUserId = 'user1'
65- const mockCostMode : CostMode = 'normal'
6650 const mockRepoId = 'owner/repo'
6751
68- beforeAll ( ( ) => {
69- mockModule ( '@codebuff/backend/llm-apis/gemini-with-fallbacks' , ( ) => ( {
70- promptFlashWithFallbacks : bunMockFn ( ( ) =>
71- Promise . resolve ( 'file1.ts\nfile2.ts' ) ,
72- ) ,
73- } ) )
74-
75- mockModule ( '@codebuff/backend/websockets/request-context' , ( ) => ( {
76- getRequestContext : bunMockFn ( ( ) => ( {
77- approvedOrgIdForRepo : 'org123' ,
78- isRepoApprovedForUserInOrg : true ,
79- } ) ) ,
80- } ) )
81-
82- mockModule ( '@codebuff/common/db' , ( ) => ( {
83- default : {
84- insert : bunMockFn ( ( ) => ( {
85- values : bunMockFn ( ( ) => ( {
86- onConflictDoNothing : bunMockFn ( ( ) => Promise . resolve ( ) ) ,
87- } ) ) ,
88- } ) ) ,
89- } ,
90- } ) )
91- mockModule ( '@codebuff/bigquery' , ( ) => ( {
92- insertTrace : bunMockFn ( ( ) => Promise . resolve ( ) ) ,
93- } ) )
94- } )
95-
96- afterAll ( ( ) => {
97- clearMockedModules ( )
98- } )
99-
10052 beforeEach ( ( ) => {
101- agentRuntimeImpl = { ...TEST_AGENT_RUNTIME_IMPL }
102-
103- const promptFlashWithFallbacksMock =
104- geminiWithFallbacksModule . promptFlashWithFallbacks as Mock <
105- typeof geminiWithFallbacksModule . promptFlashWithFallbacks
106- >
107- promptFlashWithFallbacksMock . mockResolvedValue ( 'file1.ts\nfile2.ts' )
108- promptFlashWithFallbacksMock . mockClear ( )
53+ agentRuntimeImpl = {
54+ ...TEST_AGENT_RUNTIME_IMPL ,
55+ promptAiSdk : mock ( ( ) => Promise . resolve ( 'file1.ts\nfile2.ts' ) ) ,
56+ }
10957 } )
11058
11159 it ( 'should use default file counts and maxFiles when no custom config' , async ( ) => {
112- await OriginalRequestFilesPromptModule . requestRelevantFiles ( {
60+ await requestRelevantFiles ( {
11361 ...agentRuntimeImpl ,
11462 ...TEST_AGENT_RUNTIME_SCOPED_IMPL ,
11563 messages : mockMessages ,
@@ -123,9 +71,7 @@ describe('requestRelevantFiles', () => {
12371 userId : mockUserId ,
12472 repoId : mockRepoId ,
12573 } )
126- expect (
127- geminiWithFallbacksModule . promptFlashWithFallbacks ,
128- ) . toHaveBeenCalled ( )
74+ expect ( agentRuntimeImpl . promptAiSdk ) . toHaveBeenCalled ( )
12975 } )
13076
13177 it ( 'should use custom file counts from config' , async ( ) => {
@@ -135,7 +81,7 @@ describe('requestRelevantFiles', () => {
13581 maxFilesPerRequest : 10 ,
13682 }
13783
138- await OriginalRequestFilesPromptModule . requestRelevantFiles ( {
84+ await requestRelevantFiles ( {
13985 ...agentRuntimeImpl ,
14086 ...TEST_AGENT_RUNTIME_SCOPED_IMPL ,
14187 messages : mockMessages ,
@@ -149,9 +95,7 @@ describe('requestRelevantFiles', () => {
14995 userId : mockUserId ,
15096 repoId : mockRepoId ,
15197 } )
152- expect (
153- geminiWithFallbacksModule . promptFlashWithFallbacks ,
154- ) . toHaveBeenCalled ( )
98+ expect ( agentRuntimeImpl . promptAiSdk ) . toHaveBeenCalled ( )
15599 } )
156100
157101 it ( 'should use custom maxFilesPerRequest from config' , async ( ) => {
@@ -160,7 +104,7 @@ describe('requestRelevantFiles', () => {
160104 maxFilesPerRequest : 3 ,
161105 }
162106
163- const result = await OriginalRequestFilesPromptModule . requestRelevantFiles ( {
107+ const result = await requestRelevantFiles ( {
164108 ...agentRuntimeImpl ,
165109 ...TEST_AGENT_RUNTIME_SCOPED_IMPL ,
166110 messages : mockMessages ,
@@ -185,7 +129,7 @@ describe('requestRelevantFiles', () => {
185129 modelName : 'ft_filepicker_010' ,
186130 }
187131
188- await OriginalRequestFilesPromptModule . requestRelevantFiles ( {
132+ await requestRelevantFiles ( {
189133 ...agentRuntimeImpl ,
190134 ...TEST_AGENT_RUNTIME_SCOPED_IMPL ,
191135 messages : mockMessages ,
@@ -199,9 +143,7 @@ describe('requestRelevantFiles', () => {
199143 userId : mockUserId ,
200144 repoId : mockRepoId ,
201145 } )
202- expect (
203- geminiWithFallbacksModule . promptFlashWithFallbacks ,
204- ) . toHaveBeenCalledWith (
146+ expect ( agentRuntimeImpl . promptAiSdk ) . toHaveBeenCalledWith (
205147 expect . objectContaining ( {
206148 useFinetunedModel : finetunedVertexModels . ft_filepicker_010 ,
207149 } ) ,
@@ -213,7 +155,7 @@ describe('requestRelevantFiles', () => {
213155 modelName : 'invalid-model-name' ,
214156 }
215157
216- await OriginalRequestFilesPromptModule . requestRelevantFiles ( {
158+ await requestRelevantFiles ( {
217159 ...agentRuntimeImpl ,
218160 ...TEST_AGENT_RUNTIME_SCOPED_IMPL ,
219161 messages : mockMessages ,
@@ -228,9 +170,7 @@ describe('requestRelevantFiles', () => {
228170 repoId : mockRepoId ,
229171 } )
230172 const expectedModel = finetunedVertexModels . ft_filepicker_010
231- expect (
232- geminiWithFallbacksModule . promptFlashWithFallbacks ,
233- ) . toHaveBeenCalledWith (
173+ expect ( agentRuntimeImpl . promptAiSdk ) . toHaveBeenCalledWith (
234174 expect . objectContaining ( {
235175 useFinetunedModel : expectedModel ,
236176 } ) ,
0 commit comments