Skip to content

test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851

Closed

Description

@dan-petty

Context & Rationale

AGENTS.md:15-17 makes agents fold asserts into tuple equality because 'every assert adds +1 to McCabe'. That is true only of the in-house counter. ruff C901, which #586 will enforce, does not count asserts. This item is the only plan to retire the mandate.

An AST scan of tests/ at 308a71f, covering 5,389 test functions, found:

  • about 60 tests whose every check is a presence check (is not None, isinstance, hasattr, callable). About 30 of these are re-export checks, for example tests/test_fast_dispatch.py:62.
  • 9 tests that assert only bare truthiness (assert x).
  • 32 tuple asserts that hide a presence element, for example tests/test_ai_client_retries.py:127.

Ruff PT018 was assigned to #421, which closed without it.

Scope & Deliverables

  • Deliverable:
    • Drop the mandate from AGENTS.md:15-17 and instruction_generator.py. Boolean checks become separate asserts.
    • Add one AST check inside the same test function as the blind-raise scan, so it shares that function's parse of tests/. It fails on:
      • a tuple-equality assert that compares presence calls with bool literals;
      • a test whose every assert is a presence check, bare truthiness included.
    • The names that count as presence checks live in config/constants.py.
    • Rewrite the existing sites with no allowlist. Re-export tests assert identity with the defining object; the rest compare values.
    • Decide whether to select PT018, and record the reason either way.
  • Acceptance criteria:
    • The check fails with file:line on each of these fixtures:
      • a test whose only check is assert x is not None;
      • a test whose only check is assert x;
      • a test whose only check is assert (isinstance(x, Y),) == (True,).
    • Tests that delegate to a same-module helper that asserts are not flagged, for example tests/test_security_sarif.py:1439.
    • The check passes on the rewritten tree and adds at most 1 s to the test function it joins, recorded from --durations.
  • Key questions:
    • Should no-assertion 'does not raise' tests be flagged? (proposed) No. Forcing assert f() is None adds no fault detection.
  • Constraint: No allowlist.

Strategic Alignment

Owner decisions (2026-10-01)

From the agentic quality assessment (https://claude.ai/artifact/K7S7AkKJymFydhjwexigiN), decided by the owner. These replace any matching proposed answer above.

Test design (2026-10-07)

Strategic alignment (added).

Proposed design

Problem statement

The issue addresses the need to retire the tuple-assert mandate that required all assertions in tests to be expressed as tuple equality checks. This mandate was based on an outdated concern about McCabe complexity from in-house tools, which no longer applies with the adoption of ruff C901 that does not count asserts or with-blocks. The change also involves detecting and flagging tests that perform only presence checks (like 'is not None', isinstance, hasattr) or bare truthiness assertions ('assert x'), as well as tuple-asserts that hide presence elements.

Acceptance criteria

  • Criterion 1: The mandate requiring tuple-equality asserts in tests is removed from documentation and code generation logic.
    Verification: Verify that AGENTS.md no longer contains the mandate and that instruction_generator.py does not reference it.
  • Criterion 2: An AST check is added to detect tests with only presence checks or bare truthiness assertions, and flags them at file:line level.
    Verification: Run the new AST check on test files; it should report file:line for each of these fixtures: a test whose only check is assert x is not None, a test whose only check is assert x, and a test whose only check is assert (isinstance(x, Y),) == (True,).
  • Criterion 3: The check does not flag tests that delegate to same-module helpers that assert.
    Verification: Run the AST check on a test like tests/test_security_sarif.py:1439 and confirm it is not flagged.
  • Criterion 4: Tests are rewritten to comply with new rules, using identity checks for re-exports and value comparisons otherwise.
    Verification: Verify that existing test sites have been rewritten appropriately without an allowlist.
  • Criterion 5: The check passes on the rewritten tree and adds at most 1 second to test function duration.
    Verification: Run tests with --durations and confirm the check adds no more than 1 second per function.

Key questions

  • Should no-assertion 'does not raise' tests be flagged?: No. Forcing assert f() is None adds no fault detection. (proposed)

Open questions

  • Does the tuple-assert mandate need to be removed from AGENTS.md and instruction_generator.py? (missing verified source)
  • What constitutes presence checks for the AST check? (missing verified source)
  • Where are the names that count as presence checks defined? (missing verified source)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p2-mediumscope/clitype/test

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions