From 867356c882e5d34524b5b771f2a5ff802a4945e9 Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Wed, 22 Jan 2025 13:34:51 -0500 Subject: [PATCH] test: add some additional tests --- .../src/pytest_taskgraph/fixtures/gen.py | 4 ++ test/test_transforms_run_run_task.py | 56 +++++++++++++++++-- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/packages/pytest-taskgraph/src/pytest_taskgraph/fixtures/gen.py b/packages/pytest-taskgraph/src/pytest_taskgraph/fixtures/gen.py index 038a5ca2..989a2103 100644 --- a/packages/pytest-taskgraph/src/pytest_taskgraph/fixtures/gen.py +++ b/packages/pytest-taskgraph/src/pytest_taskgraph/fixtures/gen.py @@ -193,14 +193,18 @@ def target_tasks_method(full_task_graph, parameters, graph_config): @pytest.fixture def make_transform_config(parameters, graph_config): + default_graph_config = graph_config + def inner( kind_config=None, kind_dependencies_tasks=None, + graph_config=None, extra_params=None, extra_graph_config=None, ): kind_config = kind_config or {} kind_dependencies_tasks = kind_dependencies_tasks or {} + graph_config = graph_config or default_graph_config if extra_params: parameters.update(extra_params) if extra_graph_config: diff --git a/test/test_transforms_run_run_task.py b/test/test_transforms_run_run_task.py index 3f2d9323..fef490d3 100644 --- a/test/test_transforms_run_run_task.py +++ b/test/test_transforms_run_run_task.py @@ -236,14 +236,18 @@ def inner(task, **kwargs): caches = result["worker"][key] caches = [c for c in caches if "cache-name" in c] - print("Dumping for copy/paste:") + print("Dumping caches for copy/paste:") pprint(caches, indent=2) + env = result["worker"]["env"] + print("Dumping env for copy/paste:") + pprint(env, indent=2) + # Create a new schema object with just the part relevant to caches. partial_schema = Schema(payload_builders[impl].schema.schema[key]) validate_schema(partial_schema, caches, "validation error") - return caches + return caches, env return inner @@ -254,12 +258,16 @@ def test_caches_enabled(run_caches): "use-caches": True, } } - caches = run_caches(task) + caches, env = run_caches(task) assert len(caches) == len(CACHES) cache_names = {c["cache-name"] for c in caches} for name, cfg in CACHES.items(): if "cache_name" in cfg: continue + + if "env" in cfg: + assert cfg["env"] in env + assert env[cfg["env"]] == f"{{task_workdir}}/.task-cache/{name}" assert name in cache_names @@ -269,7 +277,7 @@ def test_caches_disabled(run_caches): "use-caches": False, } } - assert run_caches(task) == [] + assert run_caches(task)[0] == [] def test_caches_explicit(run_caches): @@ -278,7 +286,7 @@ def test_caches_explicit(run_caches): "use-caches": ["cargo"], } } - assert run_caches(task) == [ + assert run_caches(task)[0] == [ {"cache-name": "cargo", "directory": ".task-cache/cargo"} ] @@ -287,5 +295,41 @@ def test_caches_project_explicit(run_caches): caches = run_caches( {}, extra_graph_config={"taskgraph": {"run": {"use-caches": ["cargo"]}}}, - ) + )[0] assert caches == [{"cache-name": "cargo", "directory": ".task-cache/cargo"}] + + +def test_checkout_cache_name_multiple_repos(graph_config, run_caches): + graph_config._config["taskgraph"]["repositories"] = { + "foo": { + "name": "Foo", + "project-regex": "some-project", + "default-repository": True, + "default-ref": "foo", + "type": "git", + }, + "bar": { + "name": "Bar", + "project-regex": "other-project", + "default-repository": False, + "default-ref": "bar", + "type": "git", + }, + } + caches = run_caches( + {"run": {"checkout": {"foo": {}}, "use-caches": ["checkout"]}}, + graph_config=graph_config, + )[0] + assert caches == [ + { + "cache-name": "checkouts-repos-299b346080c0dca622b70ba47481fc6d79931c4ccaf9e13d7a2ccf6ce4eb9b2a", + "directory": "checkouts", + } + ] + + +def test_checkout_cache_name_sparse(run_caches): + caches = run_caches({"run": {"sparse-profile": "foo", "use-caches": ["checkout"]}})[ + 0 + ] + assert caches == [{"cache-name": "checkouts-sparse", "directory": "checkouts"}]