Skip to content

Commit 505eca2

Browse files
committed
feat(test): coverage selection summary line
1 parent ea0343e commit 505eca2

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

toolchain/mfc/test/coverage.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,13 @@ def get_changed_files(root_dir, compare_branch="master", explicit: Optional[str]
152152
return {f for f in diff.stdout.splitlines() if f.strip()}
153153
except (subprocess.TimeoutExpired, OSError):
154154
return None
155+
156+
157+
def format_summary(*, ran, total, reason, meta, now) -> str:
158+
if meta and meta.get("built_at"):
159+
built = datetime.datetime.fromisoformat(meta["built_at"])
160+
age_days = (datetime.datetime.fromisoformat(now) - built).days
161+
age = f"map age {age_days}d"
162+
else:
163+
age = "map age unknown"
164+
return f"Coverage selection: ran {ran}/{total} tests · {age} · {reason}"

toolchain/mfc/test/test_coverage_unit.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from unittest.mock import patch
55

6-
from mfc.test.coverage import get_changed_files, is_always_run_all, load_map, param_hash, save_map, select_tests
6+
from mfc.test.coverage import format_summary, get_changed_files, is_always_run_all, load_map, param_hash, save_map, select_tests
77

88

99
def test_param_hash_is_order_independent():
@@ -168,3 +168,25 @@ def fake_run(cmd, **kw):
168168

169169
with patch("subprocess.run", fake_run):
170170
assert get_changed_files("/repo", "master") is None
171+
172+
173+
def test_summary_mentions_counts_age_reason():
174+
s = format_summary(
175+
ran=47,
176+
total=610,
177+
reason="selected 47/610 by coverage overlap",
178+
meta={"built_at": "2026-05-20T00:00:00+00:00"},
179+
now="2026-05-29T00:00:00+00:00",
180+
)
181+
assert "47/610" in s and "9d" in s and "coverage overlap" in s
182+
183+
184+
def test_summary_handles_missing_meta():
185+
s = format_summary(
186+
ran=610,
187+
total=610,
188+
reason="rung1: changed-file list unavailable",
189+
meta=None,
190+
now="2026-05-29T00:00:00+00:00",
191+
)
192+
assert "610/610" in s and "map age unknown" in s

0 commit comments

Comments
 (0)