summaryrefslogtreecommitdiff
path: root/.github/scripts/tests/test_native_cache_policy.py
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
committerChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
commitffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch)
tree1269efa852935b183daae4bb33a58d1b4d2ffb53 /.github/scripts/tests/test_native_cache_policy.py
parent059831534c7e884f0a607ed86b582fd00d821731 (diff)
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to '.github/scripts/tests/test_native_cache_policy.py')
-rw-r--r--.github/scripts/tests/test_native_cache_policy.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/.github/scripts/tests/test_native_cache_policy.py b/.github/scripts/tests/test_native_cache_policy.py
new file mode 100644
index 00000000..274344c6
--- /dev/null
+++ b/.github/scripts/tests/test_native_cache_policy.py
@@ -0,0 +1,86 @@
+import importlib.util
+import pathlib
+import os
+import subprocess
+import sys
+import re
+import unittest
+
+ROOT = pathlib.Path(__file__).resolve().parents[3]
+SPEC = importlib.util.spec_from_file_location(
+ "summary", ROOT / ".github/scripts/summarize-native-caches.py")
+summary = importlib.util.module_from_spec(SPEC)
+SPEC.loader.exec_module(summary)
+
+
+class NativeCachePolicyTests(unittest.TestCase):
+ def test_compiler_only_command(self):
+ result = subprocess.run(
+ [sys.executable, str(SPEC.origin), "--compiler"],
+ env={**os.environ, "CACHE_STEPS": "{}", "COLD_BUILD": "true"},
+ capture_output=True, text=True, check=True)
+ self.assertIn("| Compiler objects | bypassed (cold build) | not run |", result.stdout)
+
+ def test_unknown_dependency_is_rejected(self):
+ result = subprocess.run(
+ [sys.executable, str(SPEC.origin), "unknown"],
+ env={**os.environ, "CACHE_STEPS": "{}"},
+ capture_output=True, text=True)
+ self.assertEqual(result.returncode, 2)
+ self.assertIn("unknown dependency: unknown", result.stderr)
+
+ def test_restore_outcomes(self):
+ cases = [
+ ({}, "not run"),
+ ({"outcome": "failure"}, "failure"),
+ ({"outcome": "cancelled"}, "cancelled"),
+ ({"outcome": "success", "outputs": {"cache-hit": "true"}}, "exact hit"),
+ ({"outcome": "success", "outputs": {"cache-hit": "false", "cache-matched-key": "older"}}, "fallback restore"),
+ ({"outcome": "success", "outputs": {"cache-hit": ""}}, "miss"),
+ ]
+ for step, expected in cases:
+ with self.subTest(expected=expected):
+ self.assertEqual(summary.restore_status(step, False), expected)
+ self.assertEqual(summary.restore_status({}, True), "bypassed (cold build)")
+
+ def test_failed_rebuild_and_forced_recompilation_are_distinct(self):
+ report = summary.render({
+ "qt-cache": {"outcome": "success"},
+ "qt-build": {"outcome": "failure"},
+ "ccache": {"outcome": "success", "outputs": {"cache-hit": "true"}},
+ "compile": {"outcome": "skipped"},
+ }, ["qt"], recache=True, compiler=True)
+ self.assertIn("| Qt | miss | failure |", report)
+ self.assertIn("| Compiler objects | exact hit | not run; forced recompilation requested |", report)
+
+ def test_cold_build_blocks_every_workflow_cache_restore_and_save(self):
+ for platform in ["macos", "windows"]:
+ text = (ROOT / f".github/workflows/build-{platform}.yml").read_text()
+ self.assertEqual(len(re.findall(r"^ cold_build:", text, re.M)), 2)
+ for step in re.split(r"^ - ", text, flags=re.M)[1:]:
+ if "uses: actions/cache/" in step:
+ self.assertIn("!inputs.cold_build", step)
+ self.assertIn("CCACHE_DIR=$(mktemp -d", text)
+ self.assertIn("id: compile", text)
+ windows = (ROOT / ".github/workflows/build-windows.yml").read_text()
+ self.assertIn("cache: ${{ !inputs.cold_build }}", windows)
+ self.assertIn("cold_build: ${{ inputs.cold_build }}", windows)
+ action = (ROOT / ".github/actions/build-windows-deps/action.yml").read_text()
+ for step in re.split(r"^ - ", action, flags=re.M)[1:]:
+ if "uses: actions/cache/" in step:
+ self.assertIn("inputs.cold_build != 'true'", step)
+
+ def test_summaries_run_after_failures(self):
+ paths = [".github/workflows/build-macos.yml", ".github/workflows/build-windows.yml",
+ ".github/actions/warm-macos-deps/action.yml", ".github/actions/build-windows-deps/action.yml"]
+ for path in paths:
+ text = (ROOT / path).read_text()
+ for step in re.split(r"^\s+- name: ", text, flags=re.M)[1:]:
+ if step.startswith("Summarize"):
+ self.assertIn("if: always()", step)
+ warmer = (ROOT / ".github/workflows/warm-dependency-caches.yml").read_text()
+ self.assertIn(" summary:\n if: always()", warmer)
+
+
+if __name__ == "__main__":
+ unittest.main()