fix: key coverage cache on the given collection

This commit is contained in:
Abdessamad Derraz committed 2026-11-22 02:26:44 +01:00
1 parent 9979f1856d
commit 5c3f2c7146
2 files changed
+36 -11

No files matched your search

+11 -6
View File
@@ -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"<absent>")
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()
+25 -5
View File
@@ -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()