@@ -146,6 +146,80 @@ describe("cloneRepo", () => {
146146 expect ( mockGitInstance . checkout ) . toHaveBeenCalledWith ( "v1.0.0" ) ;
147147 } ) ;
148148
149+ it ( "sparse + tag + sparsePathOverrides: fetches override branch and checks out paths" , async ( ) => {
150+ const overrideConfig : RepoConfig = {
151+ ...sparseConfig ,
152+ sparsePathOverrides : [
153+ {
154+ paths : [
155+ "docs/developer_versioned_docs/version-v1.0.0" ,
156+ "docs/static/api" ,
157+ ] ,
158+ branch : "next" ,
159+ } ,
160+ ] ,
161+ } ;
162+ mockExistsSync . mockReturnValue ( false ) ;
163+ mockGitInstance . clone . mockResolvedValue ( undefined ) ;
164+ mockGitInstance . raw . mockResolvedValue ( undefined ) ;
165+ mockGitInstance . fetch . mockResolvedValue ( undefined ) ;
166+ mockGitInstance . checkout . mockResolvedValue ( undefined ) ;
167+
168+ const result = await cloneRepo ( overrideConfig ) ;
169+ expect ( result ) . toContain ( "Cloned aztec-packages" ) ;
170+
171+ // Normal tag checkout happens first
172+ expect ( mockGitInstance . checkout ) . toHaveBeenCalledWith ( "v1.0.0" ) ;
173+
174+ // Then override: fetch the branch and checkout paths from it
175+ expect ( mockGitInstance . fetch ) . toHaveBeenCalledWith ( [
176+ "--depth=1" ,
177+ "origin" ,
178+ "next" ,
179+ ] ) ;
180+ expect ( mockGitInstance . checkout ) . toHaveBeenCalledWith ( [
181+ "origin/next" ,
182+ "--" ,
183+ "docs/developer_versioned_docs/version-v1.0.0" ,
184+ "docs/static/api" ,
185+ ] ) ;
186+ } ) ;
187+
188+ it ( "sparse + tag + sparsePathOverrides: throws descriptive error with GitHub links on failure" , async ( ) => {
189+ const overrideConfig : RepoConfig = {
190+ ...sparseConfig ,
191+ sparsePathOverrides : [
192+ {
193+ paths : [
194+ "docs/developer_versioned_docs/version-v1.0.0" ,
195+ "docs/static/aztec-nr-api/devnet" ,
196+ "docs/static/typescript-api/devnet" ,
197+ ] ,
198+ branch : "next" ,
199+ } ,
200+ ] ,
201+ } ;
202+ mockExistsSync . mockReturnValue ( false ) ;
203+ mockGitInstance . clone . mockResolvedValue ( undefined ) ;
204+ mockGitInstance . raw . mockResolvedValue ( undefined ) ;
205+ mockGitInstance . fetch . mockResolvedValue ( undefined ) ;
206+ // Tag checkout succeeds, override checkout fails
207+ mockGitInstance . checkout
208+ . mockResolvedValueOnce ( undefined ) // tag checkout
209+ . mockRejectedValueOnce ( new Error ( "pathspec did not match" ) ) ;
210+
211+ try {
212+ await cloneRepo ( overrideConfig ) ;
213+ expect . unreachable ( "should have thrown" ) ;
214+ } catch ( e : any ) {
215+ expect ( e . message ) . toMatch ( / s p a r s e P a t h O v e r r i d e s f a i l e d f o r b r a n c h " n e x t " / ) ;
216+ expect ( e . message ) . toContain ( "docs/developer_versioned_docs/version-v1.0.0" ) ;
217+ expect ( e . message ) . toContain ( "https://github.com/AztecProtocol/aztec-packages/tree/next/docs/developer_versioned_docs" ) ;
218+ expect ( e . message ) . toContain ( "https://github.com/AztecProtocol/aztec-packages/tree/next/docs/static/aztec-nr-api" ) ;
219+ expect ( e . message ) . toContain ( "https://github.com/AztecProtocol/aztec-packages/tree/next/docs/static/typescript-api" ) ;
220+ }
221+ } ) ;
222+
149223 it ( "sparse + commit: clones with sparse flags, fetches commit" , async ( ) => {
150224 const commitConfig : RepoConfig = {
151225 ...sparseConfig ,
0 commit comments