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
+37
View File
@@ -27,6 +27,7 @@ from __future__ import annotations
import json
import os
import shutil
import xml.etree.ElementTree as ET
from . import level as level_mod
@@ -35,6 +36,17 @@ from . import level as level_mod
# The dashboard serves these read-only at /runs/<run_id>/... (U0.4). Overridable for tests.
RUNS_DIR_DEFAULT = "/var/lib/cc-ci-runs"
# The artifact files/dirs a run OWNS in its run dir (written fresh every run).
_OWNED_ARTIFACTS = (
"results.json",
"summary.html",
"summary.png",
"badge.svg",
"lint.txt",
"screenshot.png",
"junit",
)
def runs_dir() -> str:
return os.environ.get("CCCI_RUNS_DIR", RUNS_DIR_DEFAULT)
@@ -49,6 +61,31 @@ def run_id() -> str:
return os.environ.get("CCCI_APP_DOMAIN") or os.environ.get("CCCI_RUN_ID") or "manual"
def fresh_artifact_dir(path: str) -> str:
"""Ensure the run artifact dir holds no stale artifacts from a PREVIOUS run with the same id.
Drone build numbers restarted when its DB was re-created (2026-09-27) while /var/lib/cc-ci-runs
still holds old-era dirs numbered into the thousands — a new build reusing an old number would
otherwise mix old artifacts into the new run's card (observed 2026-10-05: !testme gitea build 35
collided with a May-31 run 35 and embedded custom-html-tiny's fossil screenshot.png, because
screenshot.capture() skips its snap when out_path already exists). Removes ONLY the files/dirs
this run owns (see _OWNED_ARTIFACTS); anything else in the dir is left untouched. Best-effort
(R7): never raises into the run."""
os.makedirs(path, exist_ok=True)
for name in _OWNED_ARTIFACTS:
p = os.path.join(path, name)
if os.path.isdir(p):
shutil.rmtree(p, ignore_errors=True)
else:
try:
os.remove(p)
except FileNotFoundError:
pass
except OSError:
pass # R7: a stuck file must never fail the run — the card is best-effort anyway
return path
def junit_file(junit_dir: str, tier: str, source: str, path: str) -> str:
"""Deterministic per-(tier,source,file) JUnit XML path under junit_dir."""
base = os.path.splitext(os.path.basename(path))[0]