@@ -13,8 +13,6 @@ describe("remoteSource", () => {
1313 let cloneStub : sinon . SinonStub ;
1414 let fetchStub : sinon . SinonStub ;
1515 let checkoutStub : sinon . SinonStub ;
16- let initSparseStub : sinon . SinonStub ;
17- let setSparseStub : sinon . SinonStub ;
1816 let mockGitClient : GitClient ;
1917
2018 beforeEach ( ( ) => {
@@ -24,14 +22,10 @@ describe("remoteSource", () => {
2422 cloneStub = sinon . stub ( ) . returns ( { status : 0 } ) ;
2523 fetchStub = sinon . stub ( ) . returns ( { status : 0 } ) ;
2624 checkoutStub = sinon . stub ( ) . returns ( { status : 0 } ) ;
27- initSparseStub = sinon . stub ( ) . returns ( { status : 0 } ) ;
28- setSparseStub = sinon . stub ( ) . returns ( { status : 0 } ) ;
2925 mockGitClient = {
3026 clone : cloneStub ,
3127 fetch : fetchStub ,
3228 checkout : checkoutStub ,
33- initSparseCheckout : initSparseStub ,
34- setSparsePaths : setSparseStub ,
3529 } as unknown as GitClient ;
3630 } ) ;
3731
@@ -66,24 +60,69 @@ describe("remoteSource", () => {
6660
6761 it ( "should validate subdirectory exists after clone" , async ( ) => {
6862 isGitAvailableStub . returns ( true ) ;
69- setSparseStub . returns ( {
70- status : 1 ,
71- stderr : "fatal: pathspec 'subdir' did not match any files" ,
63+ // Simulate that the subdirectory does not exist
64+ existsSyncStub . callsFake ( ( p : fs . PathLike ) => {
65+ const s = String ( p ) ;
66+ if ( / [ / \\ ] s u b d i r $ / . test ( s ) ) return false ; // dir missing
67+ if ( s . endsWith ( "functions.yaml" ) ) return true ; // avoid manifest error masking
68+ return true ;
7269 } ) ;
73-
7470 await expect (
7571 cloneRemoteSource ( "https://github.com/org/repo" , "main" , "subdir" , mockGitClient ) ,
7672 ) . to . be . rejectedWith ( FirebaseError , / D i r e c t o r y ' s u b d i r ' n o t f o u n d / ) ;
7773 } ) ;
7874
7975 it ( "should validate functions.yaml exists" , async ( ) => {
8076 isGitAvailableStub . returns ( true ) ;
81- existsSyncStub . withArgs ( sinon . match ( / f i r e b a s e - f u n c t i o n s - r e m o t e / ) ) . returns ( true ) ;
82- existsSyncStub . withArgs ( sinon . match ( / f u n c t i o n s \. y a m l $ / ) ) . returns ( false ) ;
77+ // Everything exists except the manifest file
78+ existsSyncStub . callsFake ( ( p : fs . PathLike ) => ! String ( p ) . endsWith ( "functions.yaml" ) ) ;
8379
8480 await expect (
8581 cloneRemoteSource ( "https://github.com/org/repo" , "main" , undefined , mockGitClient ) ,
8682 ) . to . be . rejectedWith ( FirebaseError , / m i s s i n g a r e q u i r e d d e p l o y m e n t m a n i f e s t / ) ;
8783 } ) ;
84+
85+ it ( "should successfully clone a repository without a subdirectory" , async ( ) => {
86+ isGitAvailableStub . returns ( true ) ;
87+ // Pass manifest check by returning true for any path ending with functions.yaml
88+ existsSyncStub . callsFake ( ( p : fs . PathLike ) => String ( p ) . endsWith ( "functions.yaml" ) ) ;
89+
90+ const sourceDir = await cloneRemoteSource (
91+ "https://github.com/org/repo" ,
92+ "main" ,
93+ undefined ,
94+ mockGitClient ,
95+ ) ;
96+
97+ expect ( cloneStub . calledOnceWith ( "https://github.com/org/repo" , sinon . match . string ) ) . to . be
98+ . true ;
99+ expect ( fetchStub . calledOnceWith ( "main" , sinon . match . string ) ) . to . be . true ;
100+ expect ( checkoutStub . calledOnceWith ( "FETCH_HEAD" , sinon . match . string ) ) . to . be . true ;
101+ // No sparse-checkout in MVP path
102+ expect ( sourceDir ) . to . be . a ( "string" ) ;
103+ } ) ;
104+
105+ it ( "should successfully clone a repository with a subdirectory" , async ( ) => {
106+ isGitAvailableStub . returns ( true ) ;
107+ existsSyncStub . callsFake ( ( p : fs . PathLike ) => {
108+ const s = String ( p ) ;
109+ if ( / [ / \\ ] f u n c t i o n s $ / . test ( s ) ) return true ; // subdir exists
110+ if ( s . endsWith ( "functions.yaml" ) ) return true ; // manifest exists
111+ return false ;
112+ } ) ;
113+
114+ const dir = "functions" ;
115+ const sourceDir = await cloneRemoteSource (
116+ "https://github.com/org/repo" ,
117+ "main" ,
118+ dir ,
119+ mockGitClient ,
120+ ) ;
121+
122+ expect ( fetchStub . calledOnceWith ( "main" , sinon . match . string ) ) . to . be . true ;
123+ expect ( checkoutStub . calledOnceWith ( "FETCH_HEAD" , sinon . match . string ) ) . to . be . true ;
124+ expect ( sourceDir ) . to . be . a ( "string" ) ;
125+ expect ( / [ / \\ ] f u n c t i o n s $ / . test ( sourceDir ) ) . to . be . true ;
126+ } ) ;
88127 } ) ;
89128} ) ;
0 commit comments