runner: never embed a fossil screenshot from a collided run dir (#45)
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit was merged in pull request #45.
This commit is contained in:
2026-10-05 17:46:25 +00:00
parent 5cec3e0e31
commit 35ba99768c
5 changed files with 169 additions and 5 deletions
+47
View File
@@ -489,3 +489,50 @@ def test_write_results_roundtrip(tmp_path):
assert path.endswith("/42/results.json")
with open(path) as f:
assert json.load(f)["level"] == 3
def test_fresh_artifact_dir_removes_owned_stale_artifacts(tmp_path):
"""Run-dir collision guard (2026-10-05): drone build numbers restarted while old-era run dirs
linger in /var/lib/cc-ci-runs — a new build reusing an old number must not mix the old run's
artifacts (fossil screenshot.png from ANOTHER recipe) into its card. Only OWNED artifacts go."""
d = tmp_path / "35"
d.mkdir()
(d / "results.json").write_text('{"old": true}')
(d / "screenshot.png").write_bytes(b"stale-fossil")
(d / "summary.png").write_bytes(b"stale")
(d / "badge.svg").write_text("<svg/>")
(d / "lint.txt").write_text("old")
(d / "summary.html").write_text("<html/>")
(d / "junit").mkdir()
(d / "junit" / "old.xml").write_text("<x/>")
(d / "untracked-thing.bin").write_bytes(b"keep me") # NOT owned — must survive
R.fresh_artifact_dir(str(d))
for name in (
"results.json",
"screenshot.png",
"summary.png",
"badge.svg",
"lint.txt",
"summary.html",
):
assert not (d / name).exists(), f"stale owned artifact {name} survived"
assert not (d / "junit").exists(), "stale junit dir survived"
assert (d / "untracked-thing.bin").read_bytes() == b"keep me", "unowned file was deleted"
def test_fresh_artifact_dir_creates_missing_dir(tmp_path):
d = tmp_path / "36"
out = R.fresh_artifact_dir(str(d))
assert out == str(d) and d.is_dir()
def test_fresh_artifact_dir_tolerant_of_odd_entries(tmp_path):
"""R7: never raise into the run — a dir where an owned name is itself a dir must still work."""
d = tmp_path / "37"
d.mkdir()
(d / "screenshot.png").mkdir() # perverse: a DIRECTORY named screenshot.png
(d / "junit").mkdir()
R.fresh_artifact_dir(str(d))
assert not (d / "screenshot.png").exists() and not (d / "junit").exists()