@@ -236,14 +236,18 @@ def inner(task, **kwargs):
236236
237237 caches = result ["worker" ][key ]
238238 caches = [c for c in caches if "cache-name" in c ]
239- print ("Dumping for copy/paste:" )
239+ print ("Dumping caches for copy/paste:" )
240240 pprint (caches , indent = 2 )
241241
242+ env = result ["worker" ]["env" ]
243+ print ("Dumping env for copy/paste:" )
244+ pprint (env , indent = 2 )
245+
242246 # Create a new schema object with just the part relevant to caches.
243247 partial_schema = Schema (payload_builders [impl ].schema .schema [key ])
244248 validate_schema (partial_schema , caches , "validation error" )
245249
246- return caches
250+ return caches , env
247251
248252 return inner
249253
@@ -254,12 +258,16 @@ def test_caches_enabled(run_caches):
254258 "use-caches" : True ,
255259 }
256260 }
257- caches = run_caches (task )
261+ caches , env = run_caches (task )
258262 assert len (caches ) == len (CACHES )
259263 cache_names = {c ["cache-name" ] for c in caches }
260264 for name , cfg in CACHES .items ():
261265 if "cache_name" in cfg :
262266 continue
267+
268+ if "env" in cfg :
269+ assert cfg ["env" ] in env
270+ assert env [cfg ["env" ]] == f"{{task_workdir}}/.task-cache/{ name } "
263271 assert name in cache_names
264272
265273
@@ -269,7 +277,7 @@ def test_caches_disabled(run_caches):
269277 "use-caches" : False ,
270278 }
271279 }
272- assert run_caches (task ) == []
280+ assert run_caches (task )[ 0 ] == []
273281
274282
275283def test_caches_explicit (run_caches ):
@@ -278,7 +286,7 @@ def test_caches_explicit(run_caches):
278286 "use-caches" : ["cargo" ],
279287 }
280288 }
281- assert run_caches (task ) == [
289+ assert run_caches (task )[ 0 ] == [
282290 {"cache-name" : "cargo" , "directory" : ".task-cache/cargo" }
283291 ]
284292
@@ -287,5 +295,41 @@ def test_caches_project_explicit(run_caches):
287295 caches = run_caches (
288296 {},
289297 extra_graph_config = {"taskgraph" : {"run" : {"use-caches" : ["cargo" ]}}},
290- )
298+ )[ 0 ]
291299 assert caches == [{"cache-name" : "cargo" , "directory" : ".task-cache/cargo" }]
300+
301+
302+ def test_checkout_cache_name_multiple_repos (graph_config , run_caches ):
303+ graph_config ._config ["taskgraph" ]["repositories" ] = {
304+ "foo" : {
305+ "name" : "Foo" ,
306+ "project-regex" : "some-project" ,
307+ "default-repository" : True ,
308+ "default-ref" : "foo" ,
309+ "type" : "git" ,
310+ },
311+ "bar" : {
312+ "name" : "Bar" ,
313+ "project-regex" : "other-project" ,
314+ "default-repository" : False ,
315+ "default-ref" : "bar" ,
316+ "type" : "git" ,
317+ },
318+ }
319+ caches = run_caches (
320+ {"run" : {"checkout" : {"foo" : {}}, "use-caches" : ["checkout" ]}},
321+ graph_config = graph_config ,
322+ )[0 ]
323+ assert caches == [
324+ {
325+ "cache-name" : "checkouts-repos-1d0c10d2cdc5a6f1acd71c0b363719b15805bcdd809ad7b459a43796203ff2c4" ,
326+ "directory" : "checkouts" ,
327+ }
328+ ]
329+
330+
331+ def test_checkout_cache_name_sparse (run_caches ):
332+ caches = run_caches ({"run" : {"sparse-profile" : "foo" , "use-caches" : ["checkout" ]}})[
333+ 0
334+ ]
335+ assert caches == [{"cache-name" : "checkouts-sparse" , "directory" : "checkouts" }]
0 commit comments