From 5c3f2c71466e25ef857daf5b2a474f7065f381b6 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 22 Nov 2026 01:54:03 +0100 Subject: [PATCH] fix: key coverage cache on the given collection --- scripts/sitegen/coverage.py | 17 +++++++++++------ tests/test_coverage_cache.py | 30 +++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/scripts/sitegen/coverage.py b/scripts/sitegen/coverage.py index 2f80dbfa9..b87dde981 100644 --- a/scripts/sitegen/coverage.py +++ b/scripts/sitegen/coverage.py @@ -9,6 +9,7 @@ from pathlib import Path from core.cli import InputMissing from core.paths import DB_FILE, EMULATORS_DIR, REPO_ROOT +from model import siteinputs from model.largefiles import LARGE_FILES_CACHE from model.platforms import load_platform_config from model.profiles import load_emulator_profiles @@ -117,8 +118,12 @@ def _coverage_inputs(db_path: Path, platforms_dir: str, emulators_dir: str) -> s digest.update(path.read_bytes() if path.is_file() else b"") add_file(db_path.resolve()) + # The repository's manifests and bios/, and those beside a given database. + beside = db_path.resolve().parent + manifests = dict.fromkeys((REPO_ROOT / "install", siteinputs.manifests_dir().resolve())) for root, pattern in ((Path(platforms_dir), "*"), (Path(emulators_dir), "*.yml"), - (REPO_ROOT / "scripts", "*.py"), (REPO_ROOT / "install", "*.json"), + (REPO_ROOT / "scripts", "*.py"), + *((folder, "*.json") for folder in manifests), (REPO_ROOT / "recipes", "*.json")): for path in sorted(p for p in root.resolve().rglob(pattern) if p.is_file()): add_file(path) @@ -132,11 +137,11 @@ def _coverage_inputs(db_path: Path, platforms_dir: str, emulators_dir: str) -> s if path.is_file(): stat = path.stat() digest.update(f"{path.name}\0{stat.st_size}\0{stat.st_mtime_ns}\n".encode()) - bios = REPO_ROOT / "bios" - for path in sorted(bios.rglob("*")): - if path.is_file(): - stat = path.stat() - digest.update(f"{path.relative_to(bios)}\0{stat.st_size}\0{stat.st_mtime_ns}\n".encode()) + for bios in dict.fromkeys((REPO_ROOT / "bios", beside / "bios")): + for path in sorted(bios.rglob("*")): + if path.is_file(): + stat = path.stat() + digest.update(f"{path.relative_to(bios)}\0{stat.st_size}\0{stat.st_mtime_ns}\n".encode()) return digest.hexdigest() diff --git a/tests/test_coverage_cache.py b/tests/test_coverage_cache.py index d7b96f479..2b867c499 100644 --- a/tests/test_coverage_cache.py +++ b/tests/test_coverage_cache.py @@ -33,11 +33,12 @@ class CoverageCache(unittest.TestCase): self.db = self.work / "database.json" self.db.write_text("{}") self.calls: list[str] = [] - patches = [ - mock.patch.object(coverage, "COVERAGE_CACHE_DIR", self.work / "cache"), - mock.patch.object(coverage, "compute_coverage", self._compute), - ] - for patch in patches: + replaced: tuple[tuple[str, object], ...] = ( + ("COVERAGE_CACHE_DIR", self.work / "cache"), + ("compute_coverage", self._compute), + ) + for name, value in replaced: + patch = mock.patch.object(coverage, name, value) patch.start() self.addCleanup(patch.stop) @@ -80,6 +81,25 @@ class CoverageCache(unittest.TestCase): self._run() self.assertEqual(self.calls, ["alpha", "beta"]) + def test_a_change_in_the_given_collection_computes_again(self): + """A site built from another collection kept the coverage of its + first run after its bios/ or its manifests changed.""" + from model import siteinputs + + siteinputs.use(siteinputs.SiteInputs(db=self.db)) + self.addCleanup(siteinputs.use, siteinputs.SiteInputs()) + (self.work / "bios").mkdir() + (self.work / "install").mkdir() + self._run() + for change in ( + lambda: (self.work / "bios" / "a.bin").write_bytes(b"a"), + lambda: (self.work / "install" / "alpha.json").write_text("{}"), + ): + self.calls.clear() + change() + self._run() + self.assertEqual(self.calls, ["alpha", "beta"]) + def test_another_platform_list_computes_again(self): self._run() self.calls.clear()