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): count AVA's t.* assertions in JS/TS tests (#3674)

Yunus Ozenb8c58bd7e581
diff --git a/docs/architecture/language-support.md b/docs/architecture/language-support.md
index 675e6fd9b..83918900c 100644
--- a/docs/architecture/language-support.md
+++ b/docs/architecture/language-support.md
@@ -1043,8 +1043,9 @@ language with no row produces no signal.
and `validate` match production functions, not assertions). Oracles that are
not plain assertion statements are counted at the broad tier too:
`with pytest.raises(...)`, Java's split `object` + `name` call shape, chai
- property chains (`expect(x).to.be.null`), expression-bodied test lambdas and
- private `_assert_*` helpers.
+ property chains (`expect(x).to.be.null`), AVA's `t.is` / `t.deepEqual` /
+ `t.throwsAsync` methods on the test handle, expression-bodied test lambdas
+ and private `_assert_*` helpers.
- **Mock saturation** (`analysis/health/mocks/lexicon.py`, `MOCK_DIALECTS`) has
rows for Python and JS/TS only. Go has no mock vocabulary. Java is held out
because Mockito states its checks as `verify(...)`, which counts toward
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 1eb6e78a6..dfbafeccd 100644
--- a/packages/core/src/repowise/core/analysis/health/asserts/lexicon.py
+++ b/packages/core/src/repowise/core/analysis/health/asserts/lexicon.py
@@ -151,11 +151,40 @@ _PY = AssertDialect(
)
+# AVA's assertions, which are methods on the test handle ``t`` rather than
+# ``assert``/``expect`` calls. Matched by receiver name like the Go row above;
+# ``t`` is the AVA convention. ``plan`` / ``teardown`` / ``timeout`` / ``log`` /
+# ``try`` / ``context`` are deliberately absent: they set a test up or report on
+# it, they don't check anything.
+_AVA_ASSERTIONS = frozenset(
+ {
+ "is",
+ "not",
+ "deepequal",
+ "notdeepequal",
+ "like",
+ "true",
+ "false",
+ "truthy",
+ "falsy",
+ "throws",
+ "throwsasync",
+ "notthrows",
+ "notthrowsasync",
+ "regex",
+ "notregex",
+ "snapshot",
+ "pass",
+ "fail",
+ }
+)
+
_JS_TS = AssertDialect(
# should.js / chai's BDD chain, as the receiver root of the matcher call:
# ``result.should.equal(x)``. The property form (``x.should.be.true``) is
# not a call and stays uncounted, an undercount in the safe direction.
assert_names=frozenset({"should"}),
+ receiver_methods={"t": _AVA_ASSERTIONS},
)
diff --git a/tests/unit/health/test_assertion_free_test.py b/tests/unit/health/test_assertion_free_test.py
index e7699a59e..541478844 100644
--- a/tests/unit/health/test_assertion_free_test.py
+++ b/tests/unit/health/test_assertion_free_test.py
@@ -169,6 +169,30 @@ def test_silent_when_the_test_asserts() -> None:
assert _flagged("def test_ok():\n assert 1 == 1\n") == []
+def test_silent_on_an_ava_test_that_asserts_on_the_handle() -> None:
+ _require("typescript")
+ source = """
+import test from 'ava';
+test('base url', async t => {
+ t.is(1, 1);
+ t.deepEqual([1], [1]);
+ await t.throwsAsync(() => f());
+});
+"""
+ assert _flagged(source, "test/base-url.ts", "typescript") == []
+
+
+def test_fires_on_an_ava_test_that_only_logs() -> None:
+ _require("typescript")
+ source = """
+import test from 'ava';
+test('logs only', t => {
+ t.log('nothing checked');
+});
+"""
+ assert _flagged(source, "test/logs.ts", "typescript") == ["test callback"]
+
+
def test_silent_on_a_production_file() -> None:
_require("python")
assert _flagged("def test_bare():\n do_thing()\n", "src/pkg/module.py", "python") == []
diff --git a/tests/unit/health/test_assertion_vocabulary.py b/tests/unit/health/test_assertion_vocabulary.py
index 7e59c52fb..62f67f8d1 100644
--- a/tests/unit/health/test_assertion_vocabulary.py
+++ b/tests/unit/health/test_assertion_vocabulary.py
@@ -123,6 +123,59 @@ describe("thing", () => {
assert _counts(source, "tests/thing.test.ts", "typescript")["it callback"][0] == 2
+# ---------------------------------------------------------------------------
+# JavaScript / TypeScript — AVA's assertions on the test handle
+# ---------------------------------------------------------------------------
+
+AVA_TEST = """
+import test from 'ava';
+test('base url', async t => {
+ t.is(1, 1);
+ t.deepEqual([1], [1]);
+ await t.throwsAsync(() => f());
+});
+"""
+
+
+ ("path", "language"),
+ [
+ ("test/base-url.ts", "typescript"),
+ ("test/base-url.js", "javascript"),
+ ("test/base-url.tsx", "tsx"),
+ ],
+)
+def test_ava_test_handle_methods_are_assertions(path: str, language: str) -> None:
+ """``t.is`` / ``t.deepEqual`` / ``t.throwsAsync`` are how AVA asserts."""
+ _require(language)
+ assert _counts(AVA_TEST, path, language)["test callback"][0] == 3
+
+
+def test_ava_setup_methods_are_not_assertions() -> None:
+ """``t.log`` / ``t.plan`` share the handle and check nothing."""
+ _require("typescript")
+ source = """
+import test from 'ava';
+test('setup only', t => {
+ t.log('diagnostic');
+ t.plan(1);
+});
+"""
+ assert _counts(source, "test/setup.ts", "typescript")["test callback"][0] == 0
+
+
+def test_ava_unknown_test_handle_method_is_not_an_assertion() -> None:
+ """The ``t`` row is an exact method list, not the whole receiver."""
+ _require("typescript")
+ source = """
+import test from 'ava';
+test('unknown', t => {
+ t.foo(1);
+});
+"""
+ assert _counts(source, "test/unknown.ts", "typescript")["test callback"][0] == 0
+
+
def test_typescript_should_prefixed_callee_is_not_an_assertion() -> None:
"""``shouldRetry(cfg)`` is the code under test.