Repository navigation
Description
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 exampletests/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-17andinstruction_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.
- Drop the mandate from
- 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,).
- a test whose only check is
- 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.
- The check fails with file:line on each of these fixtures:
- Key questions:
- Should no-assertion 'does not raise' tests be flagged? (proposed) No. Forcing
assert f() is Noneadds no fault detection.
- Should no-assertion 'does not raise' tests be flagged? (proposed) No. Forcing
- Constraint: No allowlist.
Strategic Alignment
- Milestone: Backlog
- Depends on: feat(cli): enforce the complexity cap with ruff C901 and an inline baseline that only shrinks #586
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.
- D1, the tuple-assert mandate. It is settled here together with feat(cli): enforce the complexity cap with ruff C901 and an inline baseline that only shrinks #586's switch to ruff C901. That switch stops counting asserts and with-blocks, which removes the complexity reason the mandate rests on.
Test design (2026-10-07)
-
docs(cli): docs/TESTING.md holds the test conventions, ADR 0005 records that tests double only process edges, and AGENTS.md and the contributor docs point to them #1308 removes the AGENTS.md copy of the mandate (
AGENTS.md:15-16, and its echo at:103) together with the other test rules and.devops/review.md:91-92, so this item no longer edits those files. This item keepsai/instruction_generator.py, the AST check and the site rewrites. -
Correction.
ai/instruction_generator.pyholds no copy of the mandate, at 308a71f or at 5c45b1e, so its part here is only to confirm that none appears. -
The review's copies go with refactor(review): the model verifier, the hallucination catalog and the model-claim guards are deleted, and person-recorded verdicts become suppressions #1150. The review still enforces the mandate in
src:- the built-in hallucination entry
HALLUCINATION-STRUCTURAL-TUPLE-EQUALITY(ai/review/common_hallucinations.json:731); _check_structural_tuple_equality_hallucination(ai/review/verification.py:1171-1198, run at:1476), which cites the mandate to invalidate review findings about tuple asserts in test files.
refactor(review): the model verifier, the hallucination catalog and the model-claim guards are deleted, and person-recorded verdicts become suppressions #1150 deletes both, with the hallucination catalog and the verifier's guards; this item does not touch them.
- the built-in hallucination entry
Strategic alignment (added).
- Parent: test(cli): tests double only process edges and mirror the source tree #1307 (phase A).
- Related: docs(cli): docs/TESTING.md holds the test conventions, ADR 0005 records that tests double only process edges, and AGENTS.md and the contributor docs point to them #1308 (removes the AGENTS.md and
.devops/review.mdcopies); refactor(review): the model verifier, the hallucination catalog and the model-claim guards are deleted, and person-recorded verdicts become suppressions #1150 (deletes the review's tuple-equality entry and guard).
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 isassert x is not None, a test whose only check isassert x, and a test whose only check isassert (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 liketests/test_security_sarif.py:1439and 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--durationsand 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 Noneadds 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
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity