Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(health): narrow assertion_free_test to tests that really check nothing (#2424)

Raghav Chamadiya6082c64b5b21
diff --git a/docs/layers/CODE_HEALTH.md b/docs/layers/CODE_HEALTH.md
index 82c52d3f9..20507bc77 100644
--- a/docs/layers/CODE_HEALTH.md
+++ b/docs/layers/CODE_HEALTH.md
@@ -454,7 +454,9 @@ whether an assertion observes a double or production output, which is a dataflow
question the pass does not ask — and on the TypeScript sample that one question
accounted for every false positive.
-`assertion_free_test` measures **71%** on TypeScript (31 findings, the complete
+`assertion_free_test` measures at least **71%** on TypeScript — a floor
+rather than a current reading, three false-positive families having been closed
+since the labelling (31 findings, the complete
population of two corpora; an earlier pass published 51% for the larger
pre-change population, which re-labels to 43.1% against this rubric) and **86%** on Python (29 hand-labelled, a systematic
sample of 172), and does not report on Go or Java at all; the per-language
@@ -466,8 +468,11 @@ the TypeScript gap. The marker stays advisory on both: neither population is lar
enough to settle the bar.
It asks a question with a yes-or-no answer rather than a
-threshold, which is why it can be stated plainly: a test case whose assertion
-count and verification count are both zero. A **mock verification counts as an
+threshold, which is why it can be stated plainly: a test case with no oracle of
+any kind — no assertion, no mock verification, no `raise`/`throw` the author
+wrote by hand, and no call to an assertion helper from a position the statement
+scan cannot classify. Four questions, every one of them yes or no and none of
+them a threshold. A **mock verification counts as an
assertion here**, the opposite of the marker above it, because a test whose only
oracle is `verify(...)` does check something. The two markers read the same call
for two different questions; the tiers that keep them apart are in
diff --git a/docs/layers/LANGUAGE_SUPPORT.md b/docs/layers/LANGUAGE_SUPPORT.md
index 2b3d900f7..bec4d821b 100644
--- a/docs/layers/LANGUAGE_SUPPORT.md
+++ b/docs/layers/LANGUAGE_SUPPORT.md
@@ -433,7 +433,10 @@ honestly cannot carry the marker at all:
**Assertion-free test** asks whether a test case checks anything at all, so it
needs two things the other markers do not: a per-function "is this a test case"
-rule, and an assertion count that misses nothing. The rules live in
+rule, and a way to tell that a test checks nothing. The second is deliberately not one
+count: `assertion_count` is calibrated and shared with a scored marker, so the
+shapes it cannot classify — a hand-rolled `throw`, an assertion bound to a name
+— are answered beside it rather than folded into it. The rules live in
`analysis/health/complexity/test_case.py`, one data row per language — a name
prefix for Python, `go test`'s own case-sensitive `TestXxx` rule for Go, the
`it(...)` / `test(...)` callback for JS/TS, and `@Test` and its JUnit siblings
@@ -443,7 +446,13 @@ does not report on them — the shipping set is a constant in the detector.
Measured precision, hand-labelled: **71%** on TypeScript (31 findings, the
complete population of two corpora) and **86%** on Python (29 findings, a
-systematic sample of 172). The marker ships advisory on both: the bar below is a
+systematic sample of 172). **Both are now a floor rather than a current
+reading**, as `mock_saturated_test`'s are a ceiling: three false-positive
+families have been closed since they were labelled, which removed findings
+from the numerator's denominator without re-labelling what survives. On the
+TypeScript population the same 22 true findings now sit in 26 rather than 31,
+which is 84.6% if none of the five removals took a true finding with it — they
+were each read, and none did. The marker ships advisory on both: the bar below is a
property of the marker rather than of one language, and neither reading settles
it on a population this size.
@@ -534,12 +543,15 @@ sample; the 28-point delta is the part carrying the labeller. A second reader on
the same population is the cheapest thing that would settle it. Note also that
22 of 31 is a 95% interval of roughly 53% to 84%, whose lower bound sits below
the 70% bar exactly as Python's 29-item reading does, so neither language
-demonstrates the bar on these populations. The
-four families that remain are a documented no-throw, a wait helper that throws
-rather than asserts, an `expect(...)` the walk does not count because it is
-bound to a name or nested inside another function, and a guard test whose body
-is a bare `throw`. None is reachable by resolving a call, and none was
-introduced by resolving one.
+demonstrates the bar on these populations. Four families accounted for the remainder, and three have since been closed
+by reading the test rather than the call graph — a wait helper that fails by
+throwing, a guard test whose body is a bare `throw`, and an `expect(...)` the
+statement scan declines because it is bound to a name or sits inside a nested
+function. What remains is a documented no-throw, which is a labelling question
+rather than a code one: every test that executes code already fails if that
+code raises, so a comment saying "should not throw" names an oracle the marker
+cannot distinguish from its absence. None of the four was introduced by
+resolving a call.
Python moves on one corpus and not the other, and the split is the point. One
corpus suppresses nothing: its tests keep their oracles inline or in the same
diff --git a/packages/core/src/repowise/core/analysis/execution_graph.py b/packages/core/src/repowise/core/analysis/execution_graph.py
index 5a1a35c5e..2bedd3907 100644
--- a/packages/core/src/repowise/core/analysis/execution_graph.py
+++ b/packages/core/src/repowise/core/analysis/execution_graph.py
@@ -115,6 +115,7 @@ class ExecutionGraphIndex:
"_call_only",
"_callers_with_site_metadata",
"_ranges",
+ "_span_end",
"calls",
"declares",
"forward",
@@ -232,6 +233,7 @@ class ExecutionGraphIndex:
self._callers_with_site_metadata = frozenset(callers_with_site_metadata)
self._by_file_line = {key: min(values) for key, values in by_file_line_candidates.items()}
self._ranges = {path: tuple(values) for path, values in ranges.items()}
+ self._span_end = {node_id: end for values in ranges.values() for _, end, node_id in values}
self.in_degree = {node: len(callers) for node, callers in self.reverse.items()}
@staticmethod
@@ -267,17 +269,35 @@ class ExecutionGraphIndex:
callers_with_site_metadata.add(source)
_append_unique(by_caller_line, (source, line), target, caller_line_seen)
- def resolve_function(self, path: str, func_start: int) -> str | None:
- """Resolve a function definition, tolerating decorator line offsets."""
+ def resolve_function(
+ self, path: str, func_start: int, *, func_end: int | None = None
+ ) -> str | None:
+ """Resolve a function definition, tolerating decorator line offsets.
+
+ Without *func_end* the fallback returns the innermost symbol whose range
+ contains *func_start*, which is what a caller attributing a fact to
+ whatever encloses it wants. Pass *func_end* to ask for the function
+ itself: a symbol that outlives it is then rejected rather than returned
+ as a stand-in. A TS ``const suite = describe(...)`` is one symbol
+ spanning every ``it`` callback inside it, so containment alone would
+ answer the same node for all of them.
+ """
if func_start == 0:
module = module_node_id(path)
return module if module in self.nodes else None
exact = self._by_file_line.get((path, func_start))
- if exact is not None:
+ if exact is not None and (func_end is None or self._span_end.get(exact, func_end) <= func_end):
+ # Bounded here too: sharing a start line is not being the function.
+ # ``const suite = describe('outer', () => { it(...)`` puts the
+ # wrapper and the first callback on one line, and without this the
+ # exact hit would hand back the wrapper and the fallback below --
+ # the whole point of ``func_end`` -- would never run.
return exact
best: str | None = None
best_start = -1
for start, end, node_id in self._ranges.get(path, ()):
+ if func_end is not None and end > func_end:
+ continue
if start <= func_start <= end and (
start > best_start or (start == best_start and (best is None or node_id < best))
):
diff --git a/packages/core/src/repowise/core/analysis/health/asserts/lexicon.py b/packages/core/src/repowise/core/analysis/health/asserts/lexicon.py
index 9ff391992..9aaaa8d39 100644
--- a/packages/core/src/repowise/core/analysis/health/asserts/lexicon.py
+++ b/packages/core/src/repowise/core/analysis/health/asserts/lexicon.py
@@ -18,9 +18,11 @@ walk, and they are deliberately not the same count:
that marker's denominator. Same call, opposite treatment, two questions.
That split is the reason a row here can never move a score, and it is the only
-reason this file is safe to edit freely.
+reason a row here is safe to edit freely. :data:`NARROW_PREFIXES` and
+:data:`STUB_EXCEPTIONS` are not rows: both are read by
+``asserts/predicate.py``, which decides findings.
-Names are matched **exactly**, never as prefixes. SonarQube keeps a wide list
+Dialect names are matched **exactly**, never as prefixes. SonarQube keeps a wide list
and a narrow one for the same reason we keep two, but its wide list matches
name prefixes; measured across three test corpora, the ambiguous English verbs
in that shape (``check``, ``validate``, ``approve``, ``fail``) matched
@@ -50,6 +52,17 @@ from dataclasses import dataclass, field
#: count with these and nothing else.
NARROW_PREFIXES: tuple[str, ...] = ("assert", "expect")
+#: Exception names whose raise declares a method unimplemented rather than
+#: checking anything. ``raise NotImplementedError`` is the Python abstract-stub
+#: idiom; counting it would make every unimplemented base-class method an
+#: oracle, which then suppresses -- by name, the receiver being dropped -- any
+#: test calling a same-named method on a subclass that does implement it.
+#: Matched against the head of the raised expression's identifier chain, so
+#: only the unqualified spelling. **No JS/TS entry exists**, that idiom being
+#: ``throw new Error('not implemented')``, a message rather than a type, which
+#: nothing here can tell from a real guard.
+STUB_EXCEPTIONS = frozenset({"notimplementederror"})
+
@dataclass(frozen=True)
class AssertVocabulary:
diff --git a/packages/core/src/repowise/core/analysis/health/asserts/oracle_reach.py b/packages/core/src/repowise/core/analysis/health/asserts/oracle_reach.py
index 6c3fe5bba..428d4477c 100644
--- a/packages/core/src/repowise/core/analysis/health/asserts/oracle_reach.py
+++ b/packages/core/src/repowise/core/analysis/health/asserts/oracle_reach.py
@@ -1,7 +1,8 @@
"""Cross-file oracle resolution for ``assertion_free_test``.
-A test whose own assertion count is zero has still checked something if it
-handed the job to a helper that asserts. ``_asserting_names`` resolves that
+A test with no oracle of its own -- ``asserts/predicate.checks_something``
+answers that, and it is four questions rather than an assertion count -- has
+still checked something if it handed the job to a helper that has one. ``_asserting_names`` resolves that
within one file; a JS/TS suite keeps its helpers in another module and a
class-based suite inherits them from a base class, so the same delegation is
invisible to a same-file rule by construction.
@@ -23,6 +24,13 @@ handed to ``it(...)``; the graph has **no node for it at all**, and the calls
inside it are attributed to the enclosing module. Resolving from the module node
would make one delegating test suppress every other test in its file, so:
+Resolution asks for the function, never for whatever encloses it:
+``resolve_function``'s containment fallback exists to tolerate a decorator
+offset, and read as identity it would answer one wrapper symbol for every
+callback inside it. Declining falls through to the file lane, which is
+per-function. The sentence above is therefore true of the shapes that reach the
+file lane *because* of that bound, not independently of it.
+
* **call-edge** -- the test resolves to a symbol; walk its own outgoing edges.
Precise attribution, bounded depth. Python, Go, Java.
* **file-edge** -- the test does not resolve; require both that *this file* has
@@ -84,6 +92,7 @@ from typing import TYPE_CHECKING, Any
from ....test_paths import is_test_related_path
from ...execution_graph import ExecutionGraphIndex, file_of_symbol, reachable_to_sink
from ..coverage import is_test_file
+from .predicate import checks_something
if TYPE_CHECKING:
from ..complexity import FileComplexity
@@ -189,9 +198,9 @@ def collect_cross_file_oracles(
if not is_test_related_path(path, pf.file_info.language):
continue
for fn in fcx.functions:
- if not (fn.assertion_count or fn.verification_count):
+ if not checks_something(fn):
continue
- sid = index.resolve_function(path, fn.start_line)
+ sid = index.resolve_function(path, fn.start_line, func_end=fn.end_line)
if sid is not None:
oracle_name.setdefault(sid, fn.name)
if not oracle_name:
@@ -223,7 +232,13 @@ def _resolve_one(
oracle_name: dict[str, str],
by_file_name: dict[str, dict[str, set[str]]],
) -> OracleReach | None:
- sid = index.resolve_function(path, fn.start_line)
+ # ``func_end`` asks for this function rather than for whatever encloses it.
+ # The containment fallback answers the innermost symbol spanning the start
+ # line, and a symbol wrapped around several test callbacks spans all of
+ # them, so without the bound one delegating test would resolve to the same
+ # node as its silent siblings and suppress them. Unresolved here falls
+ # through to the file-edge lane, whose two conjuncts are per-function.
+ sid = index.resolve_function(path, fn.start_line, func_end=fn.end_line)
if sid is not None:
info = reach.get(sid)
# ``distance == 0`` means this node IS an oracle, which happens when a
@@ -311,8 +326,4 @@ def _candidates(pf: Any, fcx: FileComplexity) -> list[Any]:
"""Test cases in a test file that check nothing themselves."""
if not is_test_file(pf.file_info.path):
return []
- return [
- fn
- for fn in fcx.functions
- if fn.is_test_case and not (fn.assertion_count or fn.verification_count)
- ]
+ return [fn for fn in fcx.functions if fn.is_test_case and not checks_something(fn)]
diff --git a/packages/core/src/repowise/core/analysis/health/asserts/predicate.py b/packages/core/src/repowise/core/analysis/health/asserts/predicate.py
new file mode 100644
index 000000000..5efdbd420
--- /dev/null
+++ b/packages/core/src/repowise/core/analysis/health/asserts/predicate.py
@@ -0,0 +1,47 @@
+"""Does this function check anything -- the one predicate both lanes ask.
+
+Split out of ``lexicon.py`` because it is not vocabulary: it is language
+agnostic, it reads a walker output rather than a name, and editing it moves
+findings, which a dialect row can never do.
+"""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
+from .lexicon import NARROW_PREFIXES
+
+if TYPE_CHECKING:
+ from ..complexity.models import FunctionComplexity
+
+
+def checks_something(fn: FunctionComplexity) -> bool:
+ """Whether a walked function carries an oracle of any kind.
+
+ Four things fail a test: a state assertion, a mock verification, a
+ ``raise`` / ``throw`` the author wrote by hand, and an assertion call in a
+ position ``_assertion_tier`` never classifies.
+
+ The third is in no assertion vocabulary, because a throw is a statement and
+ the vocabularies match callee names, so a helper built on ``if (!ok) throw
+ new Error(...)`` reads as checking nothing unless this is asked.
+
+ The fourth is a floor under ``assertion_count``, not a second opinion on
+ it. ``_assertion_tier`` classifies statements, so ``const e = expect(x)``
+ is a declaration it declines and ``return expect(x).toBe(1)`` is a return
+ it declines, while ``called_names`` records the call either way. Asking the
+ name is coarser and can only ever say "checked something", never how much;
+ counting those positions properly means admitting more statement kinds into
+ ``_assertion_tier``, which moves every calibrated marker reading that
+ count. Reading names also bounds the nested-body descent behind it: it
+ finds a call, so an ``expect(...)`` inside an inline helper is seen and a
+ Python ``assert`` there, having no callee, is not. Unobserved in anything
+ labelled, so it is a stated limit rather than a thing to build for.
+
+ Read only by ``assertion_free_test`` and the oracle resolution behind it,
+ both as a boolean. Calibrated markers count ``assertion_count`` alone and
+ are untouched by the last two terms.
+ """
+ if fn.assertion_count or fn.verification_count or fn.raise_count:
+ return True
+ return any(name.lstrip("_").startswith(NARROW_PREFIXES) for name in fn.called_names)
diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/assertion_free_test.py b/packages/core/src/repowise/core/analysis/health/biomarkers/assertion_free_test.py
index f3a3ab771..4dc47dc4a 100644
--- a/packages/core/src/repowise/core/analysis/health/biomarkers/assertion_free_test.py
+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/assertion_free_test.py
@@ -7,7 +7,9 @@ never fails the refactor it was written to protect. Meszaros names the smell
It is the one marker in this family that is objectively decidable. The others
ask a question of degree and need a threshold nobody has calibrated; this one
-asks whether a count is zero.
+asks whether the test has an oracle at all. That is four questions rather than
+one count -- ``asserts/predicate.checks_something`` -- but every one of them is
+yes or no, and none of them is a threshold.
**A mock verification counts as an assertion here, and this is deliberately the
opposite of ``mock_saturated_test``.** Zhu et al. (FSE 2025,
@@ -20,6 +22,14 @@ marker measures verification itself and so must exclude it from its denominator.
Same call, opposite treatment, two different questions. The tiers that keep them
apart are in ``complexity/assertions.py``.
+**A hand-rolled ``throw`` counts as an oracle too.** A test that ends
+``if (!ok) throw new Error(...)``, and a wait helper that gives up by throwing
+rather than by asserting, both fail their test on the property the author named.
+No assertion vocabulary reaches either, because a ``throw`` is a statement and
+the vocabularies match callee names. ``asserts/lexicon.checks_something`` is the
+predicate; it is deliberately not folded into ``assertion_count``, which is
+calibrated.
+
**This marker is advisory and never deducts.** See ``ADVISORY_DIMENSION`` in
``scoring.py``, and LANGUAGE_SUPPORT.md#code-health-coverage for the measured
per-language precision and the false positives it does not separate.
@@ -27,6 +37,7 @@ per-language precision and the false positives it does not separate.
from __future__ import annotations
+from ..asserts.predicate import checks_something
from ..coverage import is_test_file
from ..models import Severity
from .base import BiomarkerResult, FileContext
@@ -61,7 +72,7 @@ class AssertionFreeTestDetector:
# is asking precisely the functions that have none.
if not fn.is_test_case:
continue
- if fn.assertion_count or fn.verification_count:
+ if checks_something(fn):
continue
if fn.called_names & oracles:
continue
@@ -97,8 +108,10 @@ def _asserting_names(ctx: FileContext) -> frozenset[str]:
method on a test-local double suppresses against a module-level function of
that name. Both directions hide a real finding rather than invent one,
which is the tolerable way round for an advisory marker, but neither is
- free. A helper nested inside the test body is not collected as a function
- at all, so it suppresses nothing.
+ free. A helper nested inside the test body is still not collected as a
+ function at all, so it suppresses nothing *by name* -- but its calls now
+ roll up into the enclosing test's own ``called_names``, so the test it
+ sits in is answered directly rather than through this set.
Same file only, and by name. The cross-file half of the same question --
a shared JS fixture, an inherited base-class helper -- is answered from the
@@ -107,11 +120,7 @@ def _asserting_names(ctx: FileContext) -> frozenset[str]:
still cannot see it lists itself; ``super().test_x(...)`` is one of them,
the resolver having no ``super()`` receiver handling.
"""
- return frozenset(
- fn.name.lower()
- for fn in ctx.all_functions
- if fn.assertion_count or fn.verification_count
- )
+ return frozenset(fn.name.lower() for fn in ctx.all_functions if checks_something(fn))
BIOMARKER = AssertionFreeTestDetector()
diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/mock_saturated_test.py b/packages/core/src/repowise/core/analysis/health/biomarkers/mock_saturated_test.py
index e2f5158be..db394664a 100644
--- a/packages/core/src/repowise/core/analysis/health/biomarkers/mock_saturated_test.py
+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/mock_saturated_test.py
@@ -52,7 +52,13 @@ class MockSaturatedTestDetector:
asserts = fn.assertion_count
# No assertion at all is a different finding, not this one: it is
# usually a fixture or a helper, and where it is a real test
- # ``assertion_free_test`` is the marker that says so.
+ # ``assertion_free_test`` is usually the marker that says so.
+ # Not always: the two stopped asking the same question. This one
+ # gates on ``assertion_count``, that one on
+ # ``asserts/predicate.checks_something``, so a mock-heavy test
+ # whose only oracle is a hand-rolled ``throw`` is reported by
+ # neither. That is the price of keeping ``raise_count`` out of
+ # ``assertion_count`` so this denominator cannot move.
if mocks < self._MIN_MOCK_SETUP or asserts < 1:
continue
if prefixes and not fn.name.lower().startswith(prefixes):
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/assertions.py b/packages/core/src/repowise/core/analysis/health/complexity/assertions.py
index 0530f8f89..1b4ac7d8c 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/assertions.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/assertions.py
@@ -8,7 +8,7 @@ count. Opt-in per language via the ``LanguageNodeMap`` ``assert_kinds`` /
``duplicated_assertion_block`` biomarkers, and by ``mock_saturated_test``,
which divides mock setup by the total.
-Two tiers are counted in one walk, and which marker reads which is the whole
+Four counts come out of one walk, and which marker reads which is the whole
design (``asserts/lexicon.py`` carries the vocabulary and the evidence):
* ``blocks`` counts the **narrow** tier only — an ``assert``/``expect`` callee
@@ -24,14 +24,27 @@ design (``asserts/lexicon.py`` carries the vocabulary and the evidence):
verification is an oracle, so it counts there; ``mock_saturated_test``
measures verification itself, so counting it in that marker's denominator
would blind it. The same call is read two ways on purpose.
+* ``raises`` counts the hand-rolled oracles no vocabulary can reach, a
+ ``raise`` / ``throw`` being a statement where the tiers match callee names.
+ Read only by ``asserts/predicate.py`` and only as a boolean, so it is in
+ none of the three counts above and moves nothing calibrated.
+
+``called_names`` rides along on the same traversal. Alone among these it is
+collected **through** nested function bodies, because nothing else ever
+collects them.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
-from ..asserts.lexicon import NARROW_PREFIXES, AssertDialect
-from .ast_utils import _IDENTIFIER_SUFFIX, _callee_names, _receiver_method_verdict
+from ..asserts.lexicon import NARROW_PREFIXES, STUB_EXCEPTIONS, AssertDialect
+from .ast_utils import (
+ _IDENTIFIER_SUFFIX,
+ _callee_names,
+ _identifier_chain,
+ _receiver_method_verdict,
+)
from .languages import LanguageNodeMap
if TYPE_CHECKING:
@@ -261,10 +274,30 @@ def _is_assertion_statement(
return _assertion_tier(stmt, lmap, dialect) in (_NARROW, _BROAD)
+def _is_oracle_raise(node: Node) -> bool:
+ """Whether a raise statement is the author checking something.
+
+ Two that are not, read off the first named child -- the raised expression,
+ the rest of the statement being a ``from`` clause:
+
+ * an abstract-stub exception, ``STUB_EXCEPTIONS``. Only the unqualified
+ spelling is matched, since the chain is read from its head.
+ * no raised expression at all. A Python bare ``raise`` re-raises whatever
+ is in flight, which is the enclosing ``except`` deciding not to swallow
+ it rather than a check the author wrote.
+ """
+ for child in node.children:
+ if not child.is_named:
+ continue
+ chain = _identifier_chain(child)
+ return bool(chain) and chain[0] not in STUB_EXCEPTIONS
+ return False
+
+
def _collect_assertion_facts(
body_node: Node, lmap: LanguageNodeMap, dialect: AssertDialect | None = None
-) -> tuple[list[tuple[int, int, int]], int, int, frozenset[str], frozenset[str]]:
- """``(blocks, total, verifications, called)`` facts for one function body.
+) -> tuple[list[tuple[int, int, int]], int, int, int, frozenset[str], frozenset[str]]:
+ """``(blocks, total, verifications, raises, called, bare)`` for one body.
*blocks* are runs of ≥2 consecutive **narrow-tier** assertion statements,
each recorded as ``(start_line, end_line, count)``. Runs are found per
@@ -292,19 +325,33 @@ def _collect_assertion_facts(
actually bind; a qualified one names a method on something else that
happens to share the name.
- *called* is every name called directly in this body, lowercased, excluding
- nested function bodies on the same rule the assertion scan uses. It rides
- along on this traversal because the traversal already reaches every call
- node; collecting it separately would mean walking every function body
- twice. It counts nothing and so cannot move a calibrated marker. Empty
- under the early return above, which is fine only because the one reader
- ships no language that takes it.
+ *raises* counts the ``raise`` / ``throw`` statements ``_is_oracle_raise``
+ admits, in this body only -- not in a nested function and not in a nested
+ lambda -- wherever the traversal reaches one rather than only at block
+ level: an unbraced ``if (x) throw
+ ...`` guard is a hand-rolled oracle too, and its only reader asks whether
+ the count is zero. In no other count, so no calibrated marker moves.
+
+ *called* is every name called directly in this body, lowercased,
+ **including nested function bodies**, which is where it parts company with
+ the counts beside it. Those stop at a nested function because its
+ assertions are its own. A name does not work that way here, because a
+ function nested inside an already-collected one is never collected as an
+ entry of its own -- ``ast_utils._collect_function_nodes`` does not descend
+ past a function -- so stopping would attribute its calls to nobody at all,
+ and an ``expect`` inside an inline ``function`` helper would be recorded
+ nowhere. It rides along on this traversal because the traversal already
+ reaches every call node; collecting it separately would mean walking every
+ function body twice. It counts nothing and so cannot move a calibrated
+ marker. Empty under the early return above, which is fine only because the
+ one reader ships no language that takes it.
"""
if not lmap.assert_kinds and not lmap.assert_call_kinds:
- return [], 0, 0, frozenset(), frozenset()
+ return [], 0, 0, 0, frozenset(), frozenset()
blocks: list[tuple[int, int, int]] = []
total = 0
verifications = 0
+ raises = 0
called: set[str] = set()
bare: set[str] = set()
call_kinds = lmap.call_kinds or lmap.assert_call_kinds
@@ -335,7 +382,8 @@ def _collect_assertion_facts(
if run_count >= 2:
blocks.append((run_start, run_end, run_count))
- def _visit(node: Node) -> None:
+ def _visit(node: Node, *, under_lambda: bool = False) -> None:
+ nonlocal raises
# Lambda kinds join the block kinds because an expression-bodied arrow
# has no statement at all: ``waitFor(() => expect(x).toBe(1))`` keeps
# its assertion directly under the arrow. Run detection below is
@@ -346,6 +394,16 @@ def _collect_assertion_facts(
or node.type in lmap.lambda_kinds
)
_scan_siblings(node, count_total=counts_here)
+ # ``under_lambda`` keeps the raise count on this body only. The
+ # assertion counts deliberately cross a lambda, because
+ # ``waitFor(() => expect(x).toBe(1))`` runs its assertion as part of
+ # this test. A raise does not follow: ``registry.add(() => { throw x })``
+ # hands the code under test something whose job is to fail *it*, and
+ # reading that as this test's oracle suppresses a real finding. Nested
+ # named functions are already excluded below; a lambda is the sibling
+ # shape, one token apart in JS and not covered by that branch.
+ if node.type in lmap.raise_kinds and not under_lambda and _is_oracle_raise(node):
+ raises += 1
if node.type in call_kinds:
names = _callee_names(node)
if names is not None:
@@ -353,9 +411,25 @@ def _collect_assertion_facts(
if not names[1]:
bare.add(names[0])
for child in node.children:
+ child_under_lambda = under_lambda or child.type in lmap.lambda_kinds
if child.type in lmap.function_kinds:
- continue # nested fn, not collected as its own entry either
- _visit(child)
+ # Counts stop here: a nested function's assertions are its own,
+ # and so is a raise it makes -- a callable handed to the code
+ # under test to make it fail is not this body's oracle. Names
+ # do not stop, because nothing else collects them.
+ _visit_names_only(child)
+ continue
+ _visit(child, under_lambda=child_under_lambda)
+
+ def _visit_names_only(node: Node) -> None:
+ if node.type in call_kinds:
+ names = _callee_names(node)
+ if names is not None:
+ called.add(names[0])
+ if not names[1]:
+ bare.add(names[0])
+ for child in node.children:
+ _visit_names_only(child)
_visit(body_node)
# A lambda with an expression body holds no statement: ``it("x", () =>
@@ -371,4 +445,4 @@ def _collect_assertion_facts(
verifications += 1
elif tier != _NOT_ASSERTION:
total += 1
- return blocks, total, verifications, frozenset(called), frozenset(bare)
+ return blocks, total, verifications, raises, frozenset(called), frozenset(bare)
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/models.py b/packages/core/src/repowise/core/analysis/health/complexity/models.py
index e9770e65c..f134cdf97 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/models.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/models.py
@@ -59,14 +59,33 @@ class FunctionComplexity:
# Mock verifications in the body, counted apart from ``assertion_count``.
# Why they are separate: ``asserts/lexicon.py``.
verification_count: int = 0
+ # ``raise`` / ``throw`` statements this body checks with, taken from the
+ # node map's ``raise_kinds`` -- which is a CFG-terminator mapping, so it is
+ # Rust's ``?`` there rather than a throw; harmless while the reader ships
+ # four languages, load-bearing if that widens. 0 for a language with no
+ # assertion opt-in, like the counts above. Excludes an abstract stub
+ # (``asserts/lexicon.STUB_EXCEPTIONS``), a bare re-raise, and anything in a
+ # nested function or lambda: a callable handed to the code under test to
+ # make *it* fail is not this body's oracle. A
+ # hand-rolled oracle -- ``if (!ok) throw new Error(...)`` -- fails its test
+ # exactly as an assertion does, but no assertion vocabulary names it. Kept
+ # in its own field rather than folded into ``assertion_count`` because that
+ # count is calibrated and this one is not: only ``assertion_free_test`` and
+ # the oracle resolution behind it read this, and both read it as a
+ # boolean. Counted wherever the traversal reaches one rather than at block
+ # level, so an unbraced ``if (x) throw ...`` guard is seen.
+ raise_count: int = 0
# Mock-setup statements in the body, decorators included. 0 for a language
# with no entry in ``analysis/health/mocks/lexicon.py``.
mock_setup_count: int = 0
# True when this function is a test case its framework would run, as
# opposed to a helper or fixture beside it. ``complexity/test_case.py``.
is_test_case: bool = False
- # Every name called directly in this function's own body, lowercased,
- # excluding nested function bodies. Empty for a language with no assertion
+ # Every name called in this function's body, lowercased, **including**
+ # nested function bodies -- where it parts company with the counts above,
+ # which stop at one. A function nested inside an already-collected one is
+ # never collected as an entry of its own, so stopping would attribute its
+ # calls to nobody. Empty for a language with no assertion
# vocabulary row, because it rides on that traversal. It answers one
# question: did this function hand its work to something else in the file?
called_names: frozenset[str] = frozenset()
@@ -75,7 +94,10 @@ class FunctionComplexity:
# cross-file oracle pass, which pairs a name with a file-scoped call edge:
# a qualified call names a method on something else that happens to share
# the name, and pairing it with the file's edge would let one delegating
- # test license every same-named call beside it.
+ # test license every same-named call beside it. It widened with
+ # ``called_names``, so a name may now come from a nested body -- which is
+ # a suppression path, and means a registered-but-never-invoked callback
+ # contributes. In the direction that lane already errs.
bare_called_names: frozenset[str] = frozenset()
def __post_init__(self) -> None:
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/walker.py b/packages/core/src/repowise/core/analysis/health/complexity/walker.py
index a36a70a3b..b260ee5d3 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/walker.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/walker.py
@@ -165,6 +165,7 @@ def walk_file(
assertion_blocks,
assertion_count,
verifications,
+ raises,
called,
bare_called,
) = _collect_assertion_facts(body, lmap, asserts)
@@ -183,6 +184,7 @@ def walk_file(
assertion_blocks=assertion_blocks,
assertion_count=assertion_count,
verification_count=verifications,
+ raise_count=raises,
mock_setup_count=_count_mock_setup(fn_node, body, lmap, mock_dialect, asserts),
is_test_case=is_test_case(fn_node, name, language),
called_names=called,
diff --git a/packages/core/src/repowise/core/analysis/health/engine.py b/packages/core/src/repowise/core/analysis/health/engine.py
index 325ddff8c..5584a72dc 100644
--- a/packages/core/src/repowise/core/analysis/health/engine.py
+++ b/packages/core/src/repowise/core/analysis/health/engine.py
@@ -110,6 +110,37 @@ log = structlog.get_logger(__name__)
# walk itself is unchanged, but this stamp keys the walk and duplication-token
# caches, so bumping it re-walks and re-tokenizes anyway.
#
+# v20: ``assertion_free_test`` stops reading a containing symbol as the test.
+# ``ExecutionGraphIndex.resolve_function`` falls back to the innermost symbol
+# whose range holds the start line, which tolerates a decorator offset but also
+# answers a wrapper declaration -- a TS ``const suite = describe(...)`` spans
+# every callback inside it -- for every test in it at once. One delegating test
+# then suppressed its silent siblings through that wrapper's edge. The oracle
+# pass now asks for the function rather than its enclosure, so those findings
+# come back, and nothing re-mints the rows a v19 store suppressed except this
+# stamp.
+#
+# v20 also reads a hand-rolled ``raise`` / ``throw`` as an oracle, for which the
+# walker records one new ``FunctionComplexity`` field, ``raise_count``, that a
+# cached v19 walk does not carry at all. It is its own field rather than a term
+# in ``assertion_count`` precisely so that it moves nothing calibrated:
+# ``mock_saturated_test`` and ``large_assertion_block`` read ``assertion_count``
+# and ``assertion_blocks`` directly and are untouched. Only
+# ``assertion_free_test`` and the oracle pass behind it read the new field, both
+# through ``asserts/lexicon.checks_something``, and both as a boolean.
+#
+# v20 finally reads an assertion call from a position ``_assertion_tier`` never
+# classifies, because that pass classifies statements: a ``const e =
+# expect(x)`` is a declaration and a ``return expect(x).toBe(1)`` is a return,
+# and neither reaches it. ``checks_something`` asks ``called_names`` for a
+# callee under ``NARROW_PREFIXES`` as a floor under the count, and the walker
+# now collects those names through nested function bodies rather than stopping
+# at them -- a function nested in an already-collected one is never collected
+# as an entry of its own, so its calls were recorded nowhere at all. The
+# *counts* still stop at a nested function, so ``assertion_count`` is
+# bit-identical to v19; only the name sets widen, and a cached v19 walk carries
+# the narrower ones. No score moves; the marker is advisory.
+#
# v19: ``assertion_free_test`` resolves a test's oracle across file
# boundaries, on a call edge rather than by name, so a test that delegates its
# checks to a helper in another module is no longer called assertion-free. The
@@ -182,7 +213,7 @@ log = structlog.get_logger(__name__)
# forms. Files that were counted untested and are not become tested, which
# moves untested-hotspot findings and the scores that carry them, on every
# language with a prefix or spec convention rather than Ruby alone.
-HEALTH_ANALYZER_VERSION = 19
+HEALTH_ANALYZER_VERSION = 20
def walked_functions(
diff --git a/packages/ui/src/health/biomarker-glossary.ts b/packages/ui/src/health/biomarker-glossary.ts
index 1f8459dde..8822b216a 100644
--- a/packages/ui/src/health/biomarker-glossary.ts
+++ b/packages/ui/src/health/biomarker-glossary.ts
@@ -206,7 +206,7 @@ export const BIOMARKER_GLOSSARY: Record<string, BiomarkerInfo> = {
label: "Assertion free test",
category: "test_quality",
description:
- "A test case that runs the code under test and then checks nothing, so it passes whatever that code does. A mock verification counts as a check, and so does handing the check to a helper this test calls, in this file or, when the call graph resolves the call, in another one. Advisory: it costs this file no points.",
+ "A test case that runs the code under test and then checks nothing, so it passes whatever that code does. A mock verification counts as a check, so does a `throw` the author wrote by hand, and so does handing the check to a helper this test calls, in this file or, when the call graph resolves the call, in another one. Advisory: it costs this file no points.",
},
mock_saturated_test: {
label: "Mock saturated test",
diff --git a/tests/unit/health/test_assertion_free_test.py b/tests/unit/health/test_assertion_free_test.py
index a975b91dd..9b8e1ed7f 100644
--- a/tests/unit/health/test_assertion_free_test.py
+++ b/tests/unit/health/test_assertion_free_test.py
@@ -548,3 +548,194 @@ def test_resolution_is_by_name_and_a_second_class_shares_it() -> None:
" self._check(g())\n"
)
assert _flagged(source) == []
+
+
+# --------------------------------------------------------------------------
+# A hand-rolled throw is an oracle
+# --------------------------------------------------------------------------
+
+
+def test_a_guard_test_that_reports_a_misconfiguration_by_throwing_is_not_assertion_free() -> None:
+ """``if (!ok) throw`` fails the test on a named property. No vocabulary
+ reaches it, because a throw is a statement and the vocabularies match
+ callee names."""
+ _require("typescript")
+ src = (
+ "it('the fixture directory is configured', () => {\n"
+ " if (!process.env.FIXTURES) {\n"
+ " throw new Error('FIXTURES is unset');\n"
+ " }\n"
+ "});\n"
+ "it('checks nothing', () => {\n"
+ " run();\n"
+ "});\n"
+ )
+ assert _flagged(src, "src/thing.test.ts", "typescript") == ["it callback"]
+
+
+def test_an_unbraced_throw_guard_counts_too() -> None:
+ """The count is taken wherever the traversal finds a throw, not only at
+ block level, so the brace-less form of the same guard is not a blind spot."""
+ _require("typescript")
+ src = "it('guards', () => {\n if (!cfg) throw new Error('no cfg');\n run();\n});\n"
+ assert _flagged(src, "src/thing.test.ts", "typescript") == []
+
+
+def test_a_python_test_that_raises_on_a_bad_state_is_not_assertion_free() -> None:
+ _require("python")
+ src = (
+ "def test_backend_is_reachable():\n"
+ " if not ping():\n"
+ " raise RuntimeError('backend down')\n"
+ "\n"
+ "def test_checks_nothing():\n"
+ " run()\n"
+ )
+ assert _flagged(src) == ["test_checks_nothing"]
+
+
+def test_a_raise_inside_the_code_under_test_is_not_the_test_s_own_oracle() -> None:
+ """The count is per body and stops at a nested definition, so a callable
+ handed to the code under test purely to make it fail is not read as this
+ test having checked anything."""
+ _require("python")
+ src = (
+ "def test_registers_a_failing_callback():\n"
+ " def boom():\n"
+ " raise ValueError('nope')\n"
+ " registry.add(boom)\n"
+ )
+ assert _flagged(src) == ["test_registers_a_failing_callback"]
+
+
+def test_an_abstract_stub_raising_notimplementederror_is_not_an_oracle() -> None:
+ """``raise NotImplementedError`` declares a method unimplemented; it checks
+ nothing. Counting it would make every abstract base-class method an oracle,
+ and the same-file lane matches helper names with the receiver dropped, so
+ one unimplemented stub would then answer for every same-named method on
+ every subclass that does implement it."""
+ _require("python")
+ src = (
+ "class BaseStorageTests:\n"
+ " def create_backend(self):\n"
+ " raise NotImplementedError('subclasses must set this')\n"
+ "\n"
+ " def test_get(self):\n"
+ " raise NotImplementedError\n"
+ "\n"
+ "\n"
+ "class ConcreteTests(BaseStorageTests):\n"
+ " def test_closes_cleanly(self):\n"
+ " self.create_backend().close()\n"
+ )
+ assert _flagged(src) == ["test_closes_cleanly", "test_get"]
+
+
+# --------------------------------------------------------------------------
+# Assertion calls the statement scan cannot classify
+# --------------------------------------------------------------------------
+
+
+def test_an_expect_bound_to_a_const_still_counts_as_checking_something() -> None:
+ """``_assertion_tier`` classifies statements, and a declaration is not one.
+
+ The awaited-rejection idiom has to bind the expectation before advancing
+ the clock, so the only assertion in the test sits where the statement scan
+ never looks. ``called_names`` records the call wherever it sits."""
+ _require("typescript")
+ src = (
+ "it('times out', async () => {\n"
+ " const expectation = expect(client.command('x')).rejects.toThrow('timed out');\n"
+ " await vi.advanceTimersByTimeAsync(30001);\n"
+ " await expectation;\n"
+ "});\n"
+ "it('checks nothing', () => {\n"
+ " run();\n"
+ "});\n"
+ )
+ assert _flagged(src, "src/thing.test.ts", "typescript") == ["it callback"]
+
+
+def test_an_assertion_inside_a_nested_function_helper_is_not_lost() -> None:
+ """A function nested in a test body is collected as nobody's entry.
+
+ ``_collect_function_nodes`` does not descend past a function, so an inline
+ ``function`` helper is never a walked function of its own, and the counts
+ stop at it. Its calls would otherwise be recorded nowhere at all."""
+ _require("typescript")
+ src = (
+ "it('checks in a helper', () => {\n"
+ " function verifyRow(row) {\n"
+ " expect(row.id).toBeDefined();\n"
+ " }\n"
+ " rows.forEach(verifyRow);\n"
+ "});\n"
+ "it('checks nothing', () => {\n"
+ " run();\n"
+ "});\n"
+ )
+ assert _flagged(src, "src/thing.test.ts", "typescript") == ["it callback"]
+
+
+def test_descending_for_names_does_not_move_the_assertion_count() -> None:
+ """The counts must stay where they were. Only the name set widened."""
+ _require("typescript")
+ src = (
+ "it('outer', () => {\n"
+ " function inner() {\n"
+ " expect(1).toBe(1);\n"
+ " }\n"
+ " inner();\n"
+ "});\n"
+ )
+ counts = _counts(src, "src/thing.test.ts", "typescript")
+ assert counts["it callback"][0] == 0, counts
+
+
+def test_a_throw_inside_a_callback_handed_to_the_code_under_test_is_not_the_oracle() -> None:
+ """The JS sibling of the nested-function case, one token apart.
+
+ The assertion counts deliberately cross a lambda, because
+ ``waitFor(() => expect(x).toBe(1))`` runs its assertion as part of the
+ test. A raise does not follow it across: a callback handed to the code
+ under test exists to fail *that*, and the bare re-throw below checks
+ nothing at all."""
+ _require("typescript")
+ src = (
+ "it('registers a failing callback', () => {\n"
+ " registry.add(() => { throw new Error('nope'); });\n"
+ " run();\n"
+ "});\n"
+ "it('rethrows', () => {\n"
+ " return load().catch(err => { throw err; });\n"
+ "});\n"
+ )
+ assert _flagged(src, "src/thing.test.ts", "typescript") == ["it callback", "it callback"]
+
+
+def test_a_throw_in_the_test_s_own_body_still_counts_beside_those() -> None:
+ """The bound is the lambda, not the shape of the statement around it."""
+ _require("typescript")
+ src = (
+ "it('guards', () => {\n"
+ " if (!cfg) {\n"
+ " throw new Error('no cfg');\n"
+ " }\n"
+ " registry.add(() => { throw new Error('nope'); });\n"
+ "});\n"
+ )
+ assert _flagged(src, "src/thing.test.ts", "typescript") == []
+
+
+def test_a_bare_python_reraise_is_not_an_oracle() -> None:
+ """``except X: raise`` declines to swallow what is already in flight. It
+ is not a property the author checked."""
+ _require("python")
+ src = (
+ "def test_reraises():\n"
+ " try:\n"
+ " run()\n"
+ " except ValueError:\n"
+ " raise\n"
+ )
+ assert _flagged(src) == ["test_reraises"]
diff --git a/tests/unit/health/test_cross_file_oracle.py b/tests/unit/health/test_cross_file_oracle.py
index 1f9e99903..43d17c4f3 100644
--- a/tests/unit/health/test_cross_file_oracle.py
+++ b/tests/unit/health/test_cross_file_oracle.py
@@ -197,6 +197,137 @@ def test_a_receiver_qualified_call_does_not_borrow_a_sibling_test_s_edge(
assert 7 not in lines, f"a qualified call must not borrow the file's edge: {lines}"
+_WRAPPED_SUITE = {
+ "tests/helpers.ts": ("export function checkOk(v: string) {\n expect(v).toBe('ok');\n}\n"),
+ # ``const suite = describe(...)`` is a named declaration, so the graph holds
+ # one symbol spanning every callback inside it. Both ``it`` bodies sit in
+ # its line range and the import edge is attributed to it, not to either of
+ # them.
+ "tests/thing.test.ts": (
+ "import { checkOk } from './helpers';\n"
+ "export const suite = describe('outer', () => {\n"
+ " it('delegates', () => {\n"
+ " checkOk(run());\n"
+ " });\n"
+ " it('checks nothing', () => {\n"
+ " run();\n"
+ " });\n"
+ "});\n"
+ ),
+}
+
+
+def test_a_symbol_wrapped_around_the_suite_does_not_answer_for_a_test_inside_it(
+ tmp_path: Path,
+) -> None:
+ """A containing symbol is not the test, and must not speak for it.
+
+ ``resolve_function`` falls back to the innermost symbol whose range
+ contains the start line, which exists to tolerate a decorator offset. A
+ wrapper around the whole suite contains every callback in it, so reading
+ that fallback as identity would let the wrapper's one edge to an asserting
+ helper suppress every test beside the one that made it -- the same
+ one-test-licenses-its-siblings failure the file lane's two conjuncts
+ prevent, arriving through the other lane.
+ """
+ _require("typescript")
+ walked, graph = _build(tmp_path, _WRAPPED_SUITE)
+ resolved = collect_cross_file_oracles(walked, graph)
+ lines = resolved.get("tests/thing.test.ts", {})
+ assert 6 not in lines, f"the silent callback borrowed the wrapper's edge: {lines}"
+ assert _flagged(walked, graph, "tests/thing.test.ts") == ["it callback"]
+
+
+def test_a_delegating_test_inside_such_a_wrapper_still_resolves(tmp_path: Path) -> None:
+ """The mirror: rejecting the wrapper must not cost the real delegation.
+
+ Declining the containing symbol has to fall through to the file-edge lane
+ rather than answer ``None``. Without that, tightening the call-edge lane
+ would trade a false suppression for a false finding on the very test the
+ feature exists for.
+ """
+ _require("typescript")
+ walked, graph = _build(tmp_path, _WRAPPED_SUITE)
+ resolved = collect_cross_file_oracles(walked, graph)
+ lines = resolved.get("tests/thing.test.ts", {})
+ assert 3 in lines, f"the delegating callback resolved nothing: {lines}"
+ assert lines[3].basis == "file-edge"
+ assert lines[3].oracle == "tests/helpers.ts::checkOk"
+
+
+def test_a_wait_helper_that_gives_up_by_throwing_is_an_oracle(tmp_path: Path) -> None:
+ """A helper that fails its caller by throwing checks as much as one that
+ asserts. ``waitFor(events, p)`` that throws when the predicate never
+ matches is the common shape, and no assertion vocabulary names ``throw``,
+ so without counting it the helper reads as checking nothing and every test
+ delegating to it is reported."""
+ _require("typescript")
+ walked, graph = _build(
+ tmp_path,
+ {
+ "tests/wait.ts": (
+ "export function waitForEvent(events: string[], want: string) {\n"
+ " if (!events.includes(want)) {\n"
+ " throw new Error(`never saw ${want}`);\n"
+ " }\n"
+ "}\n"
+ ),
+ "tests/thing.test.ts": (
+ "import { waitForEvent } from './wait';\n"
+ "\n"
+ "it('waits', () => {\n"
+ " waitForEvent(collect(), 'done');\n"
+ "});\n"
+ "\n"
+ "it('checks nothing', () => {\n"
+ " run();\n"
+ "});\n"
+ ),
+ },
+ )
+ resolved = collect_cross_file_oracles(walked, graph)
+ lines = resolved.get("tests/thing.test.ts", {})
+ assert 3 in lines, f"the throwing helper was not read as an oracle: {lines}"
+ assert lines[3].oracle == "tests/wait.ts::waitForEvent"
+ assert 7 not in lines
+ assert _flagged(walked, graph, "tests/thing.test.ts") == ["it callback"]
+
+
+def test_a_wrapper_sharing_a_start_line_with_its_first_callback_is_still_declined(
+ tmp_path: Path,
+) -> None:
+ """The bound has to cover the exact lookup, not only the fallback.
+
+ ``resolve_function`` answers an exact start-line match before it reaches
+ the containment scan. Put the wrapper and its first callback on one
+ physical line and the wrapper wins that match, so without the same bound
+ on it the fix would be defeated by formatting alone.
+ """
+ _require("typescript")
+ walked, graph = _build(
+ tmp_path,
+ {
+ "tests/helpers.ts": (
+ "export function checkOk(v: string) {\n expect(v).toBe('ok');\n}\n"
+ ),
+ "tests/thing.test.ts": (
+ "import { checkOk } from './helpers';\n"
+ "export const suite = describe('outer', () => "
+ "{ it('delegates', () => { checkOk(run()); });\n"
+ " it('checks nothing', () => {\n"
+ " run();\n"
+ " });\n"
+ "});\n"
+ ),
+ },
+ )
+ resolved = collect_cross_file_oracles(walked, graph)
+ lines = resolved.get("tests/thing.test.ts", {})
+ assert 3 not in lines, f"the silent callback borrowed the wrapper's edge: {lines}"
+ assert 2 in lines, f"the delegating callback resolved nothing: {lines}"
+ assert lines[2].basis == "file-edge"
+
+
# --------------------------------------------------------------------------
# The negative cases: what must still fire
# --------------------------------------------------------------------------
diff --git a/tests/unit/health/test_model_version_coupling.py b/tests/unit/health/test_model_version_coupling.py
index 06ed9b260..04bbbbcd4 100644
--- a/tests/unit/health/test_model_version_coupling.py
+++ b/tests/unit/health/test_model_version_coupling.py
@@ -22,7 +22,7 @@ from repowise.core.analysis.health.refactoring.identity import (
# The three stamps as they stand together. Moving either identity model means
# moving the analyzer with it, and updating this tuple in the same commit.
-_STAMPS = (19, 2, 2)
+_STAMPS = (20, 2, 2)
def test_the_identity_models_and_the_analyzer_stamp_are_pinned_together() -> None: