CI-18: selector carries a change through a test that imports another test
checks / unit (pull_request) Successful in 21m20s
infra-pin / fresh (pull_request) Successful in 1s

A test first reached as text (a pattern reader) was never expanded again when a
later path reached it by import, so a test importing it was missed. Expanded and
reached are now tracked apart; the empty diff selects the safety set. Test added.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bdqr7PiaHcBnzPituu2yTC
This commit is contained in:
glenn schrooyen
2026-11-15 21:17:26 +01:00
co-authored by Claude
parent 17b65785b7
commit b2d3066966
2 changed files with 21 additions and 8 deletions
+15 -8
View File
@@ -25,7 +25,8 @@ WHAT IS SELECTED (the union of):
FAILS OPEN. Anything it cannot map selects ALL: a changed file that is not
.py (config.yaml, translations, static, Dockerfile, run-tests.sh, docs, ...),
a deleted or renamed file, a .py nothing references, a file that does not
parse, an empty diff base, a diff it cannot read. Doubt is never "skip".
parse, a base ref that does not exist, a diff it cannot read. Doubt is never "skip". (An EMPTY diff selects the
safety set only: nothing changed.)
OVER-APPROXIMATION IS THE DESIGN. A false edge runs one more file; a missing
edge would skip one. The scan favours false edges (strings, not comments;
@@ -293,7 +294,11 @@ def select(root, changes):
reasons.setdefault(t, []).append(r)
if not changes:
return [], {}, None
for t in SAFETY_SET:
if "goodwe_controller/" + t in tests:
why("goodwe_controller/" + t, "always-run safety set (empty "
"diff): " + SAFETY_SET[t])
return sorted(reasons), reasons, None
changed_py = []
for st, p in changes:
if st not in ("M", "A"):
@@ -320,20 +325,22 @@ def select(root, changes):
# reverse BFS from each changed file
for p in changed_py:
seen = {p: None}
expanded = {p}
queue = [p]
while queue:
cur = queue.pop(0)
for f, r in rev.get(cur, {}).items():
if f in seen:
continue
seen[f] = (cur, r)
if f not in seen:
seen[f] = (cur, r)
# A test that merely READS another file (names it, globs it)
# is affected by it, but is not a dependency of a third test:
# test_inverter reading every test_*.py as text must not make
# everything that imports a module "affected by test_inverter".
if is_test(f) and not r.startswith(IMPORT_KINDS):
continue
queue.append(f)
# Only an import carries the change on through a test file.
if f not in expanded and (not is_test(f)
or r.startswith(IMPORT_KINDS)):
expanded.add(f)
queue.append(f)
hit = [f for f in seen if is_test(f) and f != p]
if not hit and not is_test(p):
return None, None, "changed %s is referenced by no test, " \
+6
View File
@@ -81,6 +81,9 @@ mk(R, {
# reader, not a dependency of anything that imports a module
P + "test_reader.py": "import glob\nfor f in glob.glob('test_*.py'):\n open(f).read()\n",
P + "test_unrelated.py": "print('x')\n",
# a test imported by another test carries the change on (an import runs it)
P + "test_base.py": "from app import lonely\n",
P + "test_chain.py": "import test_base\n",
})
n, why = choose(R, [P + "app/low.py"])
check("a change two imports down chooses the test that imports the top (transitive)",
@@ -89,6 +92,9 @@ check("...and not tests that do not reach it",
n is not None and not {"test_b.py", "test_c.py", "test_unrelated.py"} & set(n))
n, why = choose(R, [P + "app/lonely.py"])
check("a direct importer is chosen", n is not None and "test_b.py" in n)
check("a test that imports another test is chosen with it, even though "
"test_reader (a pattern reader) also reaches test_base as text",
n is not None and "test_chain.py" in n and "test_base.py" in n)
n, why = choose(R, [P + "tools/launched.py"])
check("a tool launched by path in a string chooses the launching test",
n is not None and "test_c.py" in n)