"""Flag tests whose only assertion can never actually fail.
The biggest LLM test-writing failure this skill's other checks miss:
`.skip`/`.only` catch a committed shortcut, but nothing catches a test that
runs and "passes" while asserting nothing meaningful — `expect(true).toBe(true)`
or an empty test body. (An unawaited-async-assertion check was considered
and dropped: a reliable regex for "this expect() call's promise is never
awaited or chained" would need real AST scope tracking, not text matching —
a `ts-morph`/`ast-grep` upgrade, not a grep heuristic. Flagging it here
would just be a false-confidence check.)
Usage: check_assertion_quality.py FILE [FILE ...]
Exit 0 = no flagged pattern in any file. Exit 1 = at least one flagged
pattern found. Exit 2 = usage/file error.
TAUTOLOGY_RE = re.compile(
r"expect\(\s*(true|1|'a'|\"a\")\s*\)\.(toBe|toEqual)\(\s*(true|1|'a'|\"a\")\s*\)"
EMPTY_BODY_RE = re.compile(
r"\b(it|test)\(\s*['\"][^'\"]*['\"]\s*,\s*(?:async\s*)?\(\s*\)\s*=>\s*\{\s*\}\s*\)"
def check_file(path: str) -> list[str]:
text = open(path, encoding="utf-8").read()
for m in TAUTOLOGY_RE.finditer(text):
line = text[: m.start()].count("\n") + 1
findings.append(f"{path}:{line}: tautological assertion (asserts a literal against itself, can never fail)")
for m in EMPTY_BODY_RE.finditer(text):
line = text[: m.start()].count("\n") + 1
findings.append(f"{path}:{line}: empty test body — asserts nothing")
print("Usage: check_assertion_quality.py FILE [FILE ...]", file=sys.stderr)
for path in sys.argv[1:]:
findings = check_file(path)
print(f"ERROR: cannot read {path}: {e}", file=sys.stderr)
print(f"✅ {path}: no tautological or empty-body assertions found")
if __name__ == "__main__":