runner: never embed a fossil screenshot from a collided run dir
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
!testme gitea PR #10 (drone build 35, 2026-10-05) rendered a summary card whose app screenshot was custom-html-tiny's — a fossil from a May-31 run dir with the same number. Root cause chain: - /var/lib/cc-ci-runs/ keeps old-era run dirs numbered up to 1377; drone's build counter restarted when its DB was re-created (2026-09-27), so new builds collide with old dirs (35 was one). - the run reused the collided dir without cleaning it: fresh results.json/ summary.* landed NEXT TO the old screenshot.png. - screenshot.capture()'s SCREENSHOT-hook branch skipped the actual snap when out_path already existed ('the hook may have saved it' — no hook does), so capture() 'succeeded' without writing and the card embedded the fossil. Fix, cosmetics-only (R7 — verdict logic untouched): - results.fresh_artifact_dir(): at run start, remove ONLY the files/dirs this run owns (results.json, summary.*, badge.svg, lint.txt, screenshot.png, junit/) from its artifact dir; anything else is left alone; never raises. - run_recipe_ci calls it right after computing run_artifact_dir. - screenshot.capture(): the hook branch ALWAYS snaps (same settle/blank-retry path as the default branch) — a pre-existing file is never trusted. Unit tests: fresh_artifact_dir (owned-only removal, dir creation, odd entries) + capture() fake-playwright regression proving a fossil out_path is overwritten.
This commit is contained in:
@@ -27,6 +27,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
from . import level as level_mod
|
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.
|
# The dashboard serves these read-only at /runs/<run_id>/... (U0.4). Overridable for tests.
|
||||||
RUNS_DIR_DEFAULT = "/var/lib/cc-ci-runs"
|
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:
|
def runs_dir() -> str:
|
||||||
return os.environ.get("CCCI_RUNS_DIR", RUNS_DIR_DEFAULT)
|
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"
|
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:
|
def junit_file(junit_dir: str, tier: str, source: str, path: str) -> str:
|
||||||
"""Deterministic per-(tier,source,file) JUnit XML path under junit_dir."""
|
"""Deterministic per-(tier,source,file) JUnit XML path under junit_dir."""
|
||||||
base = os.path.splitext(os.path.basename(path))[0]
|
base = os.path.splitext(os.path.basename(path))[0]
|
||||||
|
|||||||
@@ -142,11 +142,12 @@ def capture(domain: str, out_path: str, *, recipe_meta: dict | None = None) -> s
|
|||||||
page = context.new_page()
|
page = context.new_page()
|
||||||
if hook is not None:
|
if hook is not None:
|
||||||
# Recipe-specific safe view (post-login etc.). The hook owns navigation +
|
# Recipe-specific safe view (post-login etc.). The hook owns navigation +
|
||||||
# the no-secret-page guarantee; it should call page.screenshot itself, but if
|
# the no-secret-page guarantee; we ALWAYS snap the page after it returns.
|
||||||
# it doesn't, we still snap the resulting page below. SCREENSHOT(page, ctx) —
|
# Never trust a pre-existing out_path: a recycled run artifact dir (drone
|
||||||
# the uniform ctx convention (rcust P3).
|
# build numbers restarted 2026-09-27 while old-era dirs linger) must not get
|
||||||
|
# its fossil screenshot embedded (observed 2026-10-05, !testme gitea #10
|
||||||
|
# build 35). SCREENSHOT(page, ctx) — the uniform ctx convention (rcust P3).
|
||||||
hook(page, meta_mod.hook_ctx(domain, recipe_meta))
|
hook(page, meta_mod.hook_ctx(domain, recipe_meta))
|
||||||
if not os.path.exists(out_path):
|
|
||||||
_snap_with_blank_retry(page, out_path)
|
_snap_with_blank_retry(page, out_path)
|
||||||
else:
|
else:
|
||||||
# Default: landing page. Accept any rendered status (200 or an auth redirect to a
|
# Default: landing page. Accept any rendered status (200 or an auth redirect to a
|
||||||
|
|||||||
@@ -1184,6 +1184,10 @@ def main() -> int:
|
|||||||
# {tier,source,file,rc,junit} record; after the run we assemble results.json (per-stage/per-test +
|
# {tier,source,file,rc,junit} record; after the run we assemble results.json (per-stage/per-test +
|
||||||
# level) into the artifact dir. Best-effort — never changes the verdict (R7).
|
# level) into the artifact dir. Best-effort — never changes the verdict (R7).
|
||||||
run_artifact_dir = os.path.join(results_mod.runs_dir(), results_mod.run_id())
|
run_artifact_dir = os.path.join(results_mod.runs_dir(), results_mod.run_id())
|
||||||
|
# Collision guard (2026-10-05): drone build numbers restarted when its DB was re-created while
|
||||||
|
# old-era run dirs (same numbers, other recipes' artifacts — e.g. a fossil screenshot.png) are
|
||||||
|
# still on disk. Wipe the files THIS run owns so nothing stale survives into the card.
|
||||||
|
results_mod.fresh_artifact_dir(run_artifact_dir)
|
||||||
junit_dir = os.path.join(run_artifact_dir, "junit")
|
junit_dir = os.path.join(run_artifact_dir, "junit")
|
||||||
records: list[dict] = []
|
records: list[dict] = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user