@@ -14,17 +14,29 @@ vi.mock('glob', () => ({
1414 glob : vi . fn ( ) ,
1515} ) ) ;
1616
17+ // Mock fs/promises so tests don't touch the real filesystem.
18+ // By default, stat resolves as a directory; individual tests can override this.
19+ vi . mock ( 'fs/promises' , ( ) => ( {
20+ default : {
21+ stat : vi . fn ( ) . mockResolvedValue ( { isDirectory : ( ) => true } ) ,
22+ } ,
23+ } ) ) ;
24+
1725import { isPathAValidGitRepoRoot , getOriginUrl , isUrlAValidGitRepo } from './git.js' ;
1826import { glob } from 'glob' ;
27+ import fs from 'fs/promises' ;
1928
2029const mockedGlob = vi . mocked ( glob ) ;
2130const mockedIsPathAValidGitRepoRoot = vi . mocked ( isPathAValidGitRepoRoot ) ;
2231const mockedGetOriginUrl = vi . mocked ( getOriginUrl ) ;
2332const mockedIsUrlAValidGitRepo = vi . mocked ( isUrlAValidGitRepo ) ;
33+ const mockedFsStat = vi . mocked ( fs . stat ) ;
2434
2535describe ( 'compileGenericGitHostConfig_file' , ( ) => {
2636 beforeEach ( ( ) => {
2737 vi . clearAllMocks ( ) ;
38+ // Default: all paths exist and are directories. Override per-test as needed.
39+ mockedFsStat . mockResolvedValue ( { isDirectory : ( ) => true } as any ) ;
2840 } ) ;
2941
3042 afterEach ( ( ) => {
@@ -47,6 +59,22 @@ describe('compileGenericGitHostConfig_file', () => {
4759 expect ( result . warnings [ 0 ] ) . toContain ( '/path/to/nonexistent/repo' ) ;
4860 } ) ;
4961
62+ test ( 'should return warning when path is a file, not a directory' , async ( ) => {
63+ mockedGlob . mockResolvedValue ( [ '/path/to/a-file.txt' ] ) ;
64+ mockedFsStat . mockResolvedValue ( { isDirectory : ( ) => false } as any ) ;
65+
66+ const config = {
67+ type : 'git' as const ,
68+ url : 'file:///path/to/a-file.txt' ,
69+ } ;
70+
71+ const result = await compileGenericGitHostConfig_file ( config , 1 ) ;
72+
73+ expect ( result . repoData ) . toHaveLength ( 0 ) ;
74+ expect ( result . warnings . length ) . toBeGreaterThanOrEqual ( 1 ) ;
75+ expect ( result . warnings . some ( w => w . includes ( 'not a directory' ) ) ) . toBe ( true ) ;
76+ } ) ;
77+
5078 test ( 'should return warning when path is not a valid git repo' , async ( ) => {
5179 mockedGlob . mockResolvedValue ( [ '/path/to/not-a-repo' ] ) ;
5280 mockedIsPathAValidGitRepoRoot . mockResolvedValue ( false ) ;
0 commit comments