88 it ,
99} from 'bun:test'
1010
11- // Import the entire module to spy on its exports
12- import * as checkNewFilesNecessaryModule from '../find-files/check-new-files-necessary'
1311import * as OriginalRequestFilesPromptModule from '../find-files/request-files-prompt'
1412import * as geminiWithFallbacksModule from '../llm-apis/gemini-with-fallbacks'
1513
@@ -18,17 +16,6 @@ import type { CodebuffMessage } from '@codebuff/common/types/message'
1816import type { ProjectFileContext } from '@codebuff/common/util/file'
1917import type { Mock } from 'bun:test'
2018
21- // Restore module-level mocks using bunMockFn for the mock implementations
22- bunMockFn . module ( '../find-files/check-new-files-necessary' , ( ) => ( {
23- checkNewFilesNecessary : bunMockFn ( ( ) =>
24- Promise . resolve ( {
25- newFilesNecessary : true ,
26- response : 'YES' ,
27- duration : 100 ,
28- } ) ,
29- ) ,
30- } ) )
31-
3219bunMockFn . module ( '../llm-apis/gemini-with-fallbacks' , ( ) => ( {
3320 promptFlashWithFallbacks : bunMockFn ( ( ) =>
3421 Promise . resolve ( 'file1.ts\nfile2.ts' ) ,
@@ -121,18 +108,6 @@ describe('requestRelevantFiles', () => {
121108 'getCustomFilePickerConfigForOrg' ,
122109 ) . mockResolvedValue ( null )
123110
124- // Reset behavior and clear call history for module mocks
125- const checkNewFilesNecessaryMock =
126- checkNewFilesNecessaryModule . checkNewFilesNecessary as Mock <
127- typeof checkNewFilesNecessaryModule . checkNewFilesNecessary
128- >
129- checkNewFilesNecessaryMock . mockResolvedValue ( {
130- newFilesNecessary : true ,
131- response : 'YES' ,
132- duration : 100 ,
133- } )
134- checkNewFilesNecessaryMock . mockClear ( )
135-
136111 const promptFlashWithFallbacksMock =
137112 geminiWithFallbacksModule . promptFlashWithFallbacks as Mock <
138113 typeof geminiWithFallbacksModule . promptFlashWithFallbacks
@@ -265,35 +240,4 @@ describe('requestRelevantFiles', () => {
265240 )
266241 expect ( getCustomFilePickerConfigForOrgSpy ) . toHaveBeenCalled ( )
267242 } )
268-
269- it ( 'should return null if checkNewFilesNecessary returns false' , async ( ) => {
270- // Override the module mock for this specific test case
271- ; (
272- checkNewFilesNecessaryModule . checkNewFilesNecessary as Mock <
273- typeof checkNewFilesNecessaryModule . checkNewFilesNecessary
274- >
275- ) . mockResolvedValue ( {
276- newFilesNecessary : false ,
277- response : 'NO' ,
278- duration : 50 ,
279- } )
280-
281- const result = await OriginalRequestFilesPromptModule . requestRelevantFiles (
282- { messages : mockMessages , system : mockSystem } ,
283- mockFileContext ,
284- mockAssistantPrompt ,
285- mockAgentStepId ,
286- mockClientSessionId ,
287- mockFingerprintId ,
288- mockUserInputId ,
289- mockUserId ,
290- mockRepoId ,
291- )
292-
293- expect ( result ) . toBeNull ( )
294- expect (
295- geminiWithFallbacksModule . promptFlashWithFallbacks ,
296- ) . not . toHaveBeenCalled ( )
297- expect ( getCustomFilePickerConfigForOrgSpy ) . toHaveBeenCalled ( )
298- } )
299243} )
0 commit comments