@@ -209,7 +209,6 @@ test("sync target can unwrap single root directory", async () => {
209209 const cacheDir = path . join ( tmpRoot , ".docs" ) ;
210210 const repoDir = path . join ( tmpRoot , "repo" ) ;
211211 const configPath = path . join ( tmpRoot , "docs.config.json" ) ;
212- const targetDir = path . join ( tmpRoot , "target" ) ;
213212
214213 const config = {
215214 $schema :
@@ -218,12 +217,15 @@ test("sync target can unwrap single root directory", async () => {
218217 {
219218 id : "local" ,
220219 repo : "https://example.com/repo.git" ,
221- targetDir : "target" ,
220+ include : [ "17/umbraco-forms/**" ] ,
222221 unwrapSingleRootDir : true ,
223222 } ,
224223 ] ,
225224 } ;
226225 await writeFile ( configPath , `${ JSON . stringify ( config , null , 2 ) } \n` , "utf8" ) ;
226+ const repoFile = path . join ( repoDir , "17" , "umbraco-forms" , "README.md" ) ;
227+ await mkdir ( path . dirname ( repoFile ) , { recursive : true } ) ;
228+ await writeFile ( repoFile , "hello" , "utf8" ) ;
227229
228230 await runSync (
229231 {
@@ -244,26 +246,85 @@ test("sync target can unwrap single root directory", async () => {
244246 repoDir,
245247 cleanup : async ( ) => undefined ,
246248 } ) ,
247- materializeSource : async ( { cacheDir : cacheRoot , sourceId } ) => {
248- const outDir = path . join ( cacheRoot , sourceId , "umbraco-forms" ) ;
249- await mkdir ( outDir , { recursive : true } ) ;
250- await writeFile (
251- path . join ( cacheRoot , sourceId , ".manifest.jsonl" ) ,
252- `${ JSON . stringify ( { path : "umbraco-forms/README.md" , size : 5 } ) } \n` ,
253- ) ;
254- await writeFile ( path . join ( outDir , "README.md" ) , "hello" , "utf8" ) ;
255- return { bytes : 5 , fileCount : 1 } ;
256- } ,
257249 } ,
258250 ) ;
259251
260- assert . equal ( await exists ( path . join ( targetDir , "README.md" ) ) , true ) ;
252+ assert . equal ( await exists ( path . join ( cacheDir , "local" , "README.md" ) ) , true ) ;
261253 assert . equal (
262- await exists ( path . join ( targetDir , "umbraco-forms" , "README.md" ) ) ,
254+ await exists (
255+ path . join ( cacheDir , "local" , "17" , "umbraco-forms" , "README.md" ) ,
256+ ) ,
263257 false ,
264258 ) ;
265259} ) ;
266260
261+ test ( "sync re-materializes when unwrapSingleRootDir changes" , async ( ) => {
262+ const tmpRoot = path . join (
263+ tmpdir ( ) ,
264+ `docs-cache-unwrap-toggle-${ Date . now ( ) . toString ( 36 ) } ` ,
265+ ) ;
266+ await mkdir ( tmpRoot , { recursive : true } ) ;
267+ const cacheDir = path . join ( tmpRoot , ".docs" ) ;
268+ const repoDir = path . join ( tmpRoot , "repo" ) ;
269+ const configPath = path . join ( tmpRoot , "docs.config.json" ) ;
270+
271+ const repoFile = path . join ( repoDir , "17" , "umbraco-forms" , "README.md" ) ;
272+ await mkdir ( path . dirname ( repoFile ) , { recursive : true } ) ;
273+ await writeFile ( repoFile , "hello" , "utf8" ) ;
274+
275+ const writeConfigWithUnwrap = async ( unwrapSingleRootDir ) => {
276+ const config = {
277+ $schema :
278+ "https://raw.githubusercontent.com/fbosch/docs-cache/main/docs.config.schema.json" ,
279+ sources : [
280+ {
281+ id : "local" ,
282+ repo : "https://example.com/repo.git" ,
283+ include : [ "17/umbraco-forms/**" ] ,
284+ unwrapSingleRootDir,
285+ } ,
286+ ] ,
287+ } ;
288+ await writeFile ( configPath , `${ JSON . stringify ( config , null , 2 ) } \n` , "utf8" ) ;
289+ } ;
290+
291+ const run = async ( ) =>
292+ runSync (
293+ {
294+ configPath,
295+ cacheDirOverride : cacheDir ,
296+ json : false ,
297+ lockOnly : false ,
298+ offline : false ,
299+ failOnMiss : false ,
300+ } ,
301+ {
302+ resolveRemoteCommit : async ( ) => ( {
303+ repo : "https://example.com/repo.git" ,
304+ ref : "HEAD" ,
305+ resolvedCommit : "abc123" ,
306+ } ) ,
307+ fetchSource : async ( ) => ( {
308+ repoDir,
309+ cleanup : async ( ) => undefined ,
310+ } ) ,
311+ } ,
312+ ) ;
313+
314+ await writeConfigWithUnwrap ( false ) ;
315+ await run ( ) ;
316+ assert . equal (
317+ await exists (
318+ path . join ( cacheDir , "local" , "17" , "umbraco-forms" , "README.md" ) ,
319+ ) ,
320+ true ,
321+ ) ;
322+
323+ await writeConfigWithUnwrap ( true ) ;
324+ await run ( ) ;
325+ assert . equal ( await exists ( path . join ( cacheDir , "local" , "README.md" ) ) , true ) ;
326+ } ) ;
327+
267328test ( "sync offline allows missing optional sources" , async ( ) => {
268329 const tmpRoot = path . join (
269330 tmpdir ( ) ,
0 commit comments