diff --git a/src/taskgraph/transforms/cached_tasks.py b/src/taskgraph/transforms/cached_tasks.py index d6668d06d..86d580e91 100644 --- a/src/taskgraph/transforms/cached_tasks.py +++ b/src/taskgraph/transforms/cached_tasks.py @@ -75,6 +75,11 @@ def cache_task(config, tasks): if task.get("worker", {}).get("chain-of-trust"): digest_data.append(str(task["worker"]["chain-of-trust"])) + # The worker type can affect the environment the task runs in (e.g + # platform or architecture), so it should influence the cache digest. + if task.get("worker-type"): + digest_data.append(task["worker-type"]) + add_optimization( config, task, diff --git a/test/test_transforms_cached_tasks.py b/test/test_transforms_cached_tasks.py index c69112a5b..3dcaa6c4b 100644 --- a/test/test_transforms_cached_tasks.py +++ b/test/test_transforms_cached_tasks.py @@ -105,6 +105,13 @@ def assert_chain_of_trust_influences_digest(tasks): assert digest_0 != digest_1 +def assert_worker_type_influences_digest(tasks): + assert len(tasks) == 3 + tasks = sorted(tasks, key=lambda t: t["label"]) # no-wt, wt-a, wt-b + digests = [t["attributes"]["cached_task"]["digest"] for t in tasks] + assert len(set(digests)) == 3 + + @pytest.mark.parametrize( "tasks, kind_config, deps", ( @@ -233,6 +240,42 @@ def assert_chain_of_trust_influences_digest(tasks): {}, id="chain_of_trust_influences_digest", ), + pytest.param( + # tasks + [ + { + "cache": { + "type": "cached-task.v2", + "name": "cache-foo", + "digest-data": ["abc"], + }, + "label": "no-wt", + }, + { + "cache": { + "type": "cached-task.v2", + "name": "cache-foo", + "digest-data": ["abc"], + }, + "label": "wt-a", + "worker-type": "a", + }, + { + "cache": { + "type": "cached-task.v2", + "name": "cache-foo", + "digest-data": ["abc"], + }, + "label": "wt-b", + "worker-type": "b", + }, + ], + # kind config + {}, + # kind deps + {}, + id="worker_type_influences_digest", + ), ), ) def test_transforms(