Skip to content

Commit 216e04c

Browse files
committed
feat(test): add stable param_hash key for coverage selection
1 parent 5aa4e4a commit 216e04c

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

toolchain/mfc/test/coverage.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Execution-coverage-based test selection (PR path).
2+
3+
Selection is sound (only over-includes) and its failures are loud. See
4+
docs/superpowers/specs/2026-05-29-coverage-test-selection-design.md.
5+
"""
6+
7+
import hashlib
8+
import json
9+
10+
11+
def param_hash(params: dict) -> str:
12+
"""Stable 16-hex key identifying a test by its defining params.
13+
14+
Independent of dict ordering and of the human-readable trace, so cosmetic
15+
cases.py edits don't change the key; a real param change does.
16+
"""
17+
canonical = json.dumps(params, sort_keys=True, separators=(",", ":"), default=str)
18+
return hashlib.sha256(canonical.encode("utf-8")).hexdigest()[:16]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from mfc.test.coverage import param_hash
2+
3+
4+
def test_param_hash_is_order_independent():
5+
a = param_hash({"m": 100, "weno_order": 5, "bubbles_euler": "T"})
6+
b = param_hash({"weno_order": 5, "bubbles_euler": "T", "m": 100})
7+
assert a == b
8+
9+
10+
def test_param_hash_changes_with_value():
11+
a = param_hash({"weno_order": 5})
12+
b = param_hash({"weno_order": 3})
13+
assert a != b
14+
15+
16+
def test_param_hash_is_hex_and_short():
17+
h = param_hash({"m": 1})
18+
assert len(h) == 16 and all(c in "0123456789abcdef" for c in h)
19+
20+
21+
def test_param_hash_nested_order_independent():
22+
a = param_hash({"patch": {"x": 1, "y": 2}})
23+
b = param_hash({"patch": {"y": 2, "x": 1}})
24+
assert a == b

0 commit comments

Comments
 (0)