Skip to content

test(cli): every test asserts its outcome, and each pytest.raises of a built-in exception names the message #2171

Closed

Description

@dan-petty

What happened

Some tests do not check what they claim. The test-suite audit of 2026-10-24 at df8e2ee found two kinds:

Tests with no assertion (10). Each one passes as long as the code raises nothing:

  • tests/test_argo.py:34 test_valid_k8s_label_names and :66 test_valid_k8s_resource_names
  • tests/test_docker_engine.py:1116 test_remove_container_tolerates_already_reaped
  • tests/test_http.py:12 test_public_https_url_allowed and :21 test_public_http_url_allowed
  • tests/test_http_connection_pool.py:177 test_closing_an_empty_registry_is_harmless
  • tests/test_k8s_security_stream.py:234 test_render_security_alerts_empty
  • tests/test_output.py:756 test_print_panel_fallback_on_exception
  • tests/test_review_runner.py:51 test_rendering_helpers (40 lines)
  • tests/test_vault_cmd.py:95 test_validate_vault_path_valid

pytest.raises(<built-in exception>) with no match= (39 sites). A built-in exception such as KeyError, AttributeError, RuntimeError or SystemExit can come from any line, so the test passes when the code fails for another reason. The sites are in tests/test_ai_client_providers_and_embeddings.py:525-535 (6), tests/test_fast_dispatch.py:97, :124, :131, :140, :177, tests/test_personas.py:32, :35, :43, tests/test_ai_agent_capabilities.py:229, :232, tests/test_github_rate_limiter.py:821, :1529, tests/test_config_commands.py:359, tests/test_roadmap_intake.py:1758, tests/test_validation.py:456, :501, :519, tests/test_http_egress.py:611, :613, tests/test_pydantic_ai_mcp.py:166, tests/test_process.py:85, :108, tests/test_isolation_tripwire.py:132, tests/test_docs.py:697, :726, tests/test_consolidation_dry_run_decorator.py:77, tests/test_memory_profiler.py:201, tests/test_rag_query_telemetry.py:365, tests/test_telemetry.py:423, tests/test_review_pipeline.py:153, tests/test_rag_embeddings.py:716 and tests/test_devcontainer.py:1994.

What should happen

  • Each test asserts the outcome that its name states, as a whole value where it can (docs/TESTING.md, "Names and assertions").
  • Each pytest.raises of a built-in exception passes match= with the message that only the expected failure gives, or checks the exit code of a SystemExit.
  • Checks stop new cases. Ruff's PT011, with raises-require-match-for set to the built-in exceptions, flags a pytest.raises with no match=, and the lint row runs it. An ast-grep rule in .ast-grep/rules/, run by the constructs row, flags a test function with no assert, no pytest.raises and no fake check.

Evidence

  • .data/agent/scratch/audit/full_list.txt of the 2026-10-24 audit, sections 4.no-assertion and 4.builtin-raises-without-match. Every line exists at b170358.
  • pyproject.toml:124: PT011 is selected, with the default raises-require-match-for list. tests/test_architectural_invariants.py:1393 already bans pytest.raises(Exception).

Acceptance criteria

  • Each of the 10 tests asserts its outcome, or it is deleted when another test already asserts it. The pull request names the other test.
  • Each of the 39 sites passes match= or checks the exit code.
  • A check in devops ci fails a new test with no assertion and a new pytest.raises of a built-in exception with no match=. The pull request shows both failing on a scratch case.
  • Each changed test fails when the behaviour it checks is broken. The pull request shows this for three of them.
  • uv run devops ci passes.

The tests that check only mock calls (126 in the audit) are not in scope: each child of #1307 replaces those doubles with shared fakes and asserts whole values (#1307, Q7).

Proposed design

Problem statement

Ten tests pass without checking any outcome, and 39 pytest.raises sites catch a built-in exception without a match= or exit-code check. A test that raises nothing, or raises the wrong exception, still passes. The project needs each test to assert the value it claims, each built-in-exception raises to name the expected message, and two lint rules to stop new cases.

Acceptance criteria

  • Criterion 1: Each of the 10 no-assertion tests asserts the outcome its name states, or is deleted with the covering test named in the pull request.
    Verification: Run uv run pytest on each of the 10 named tests. Confirm each has an assert on a whole value, or is absent with the replacement test named in the PR description.
  • Criterion 2: Each of the 39 pytest.raises sites of a built-in exception passes match= with the expected message, or checks the SystemExit code.
    Verification: Run grep -rn 'pytest.raises' tests/ | grep -E 'KeyError|AttributeError|RuntimeError|SystemExit' and confirm every hit has a match= argument or an exc.value.code check.
  • Criterion 3: Ruff PT011 with raises-require-match-for set to the built-in exceptions flags a new pytest.raises with no match=.
    Verification: Add a scratch test with pytest.raises(KeyError) and no match=. Run uv run ruff check --select PT011 on it. Confirm it fails. Delete the scratch test.
  • Criterion 4: An ast-grep rule in .ast-grep/rules/ flags a test function with no assert, no pytest.raises and no fake check.
    Verification: Add a scratch test function with no assertion. Run the constructs row of uv run devops ci. Confirm it fails. Delete the scratch test.
  • Criterion 5: Each changed test fails when the behaviour it checks is broken.
    Verification: For three of the changed tests, temporarily break the behaviour they assert. Run the test. Confirm it fails. Restore the behaviour.
  • Criterion 6: The full CI suite passes after all changes.
    Verification: Run uv run devops ci. Confirm it exits 0.

Key questions

  • Which built-in exceptions go in the raises-require-match-for list?: KeyError, AttributeError, RuntimeError and SystemExit, as named in the issue body. (proposed)
  • How is SystemExit handled differently from the other built-in exceptions?: A SystemExit site checks the exit code via exc.value.code instead of passing match=, because SystemExit carries an integer code, not a message string. (proposed)
  • Where is PT011 currently configured?: PT011 is selected in pyproject.toml at line 126, with the default raises-require-match-for list. The change adds an explicit raises-require-match-for setting. [sources: pyproject.toml:126]
  • Are the 126 mock-call-only tests in scope?: No. The body states they are out of scope. Each child of test(cli): tests double only process edges and mirror the source tree #1307 replaces those doubles with shared fakes and asserts whole values. (proposed)

Open questions

  • Where do the ast-grep rules live and which CI row runs them? (missing verified source)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/test
    on Oct 24, 2026
  2. dan-petty commented on Oct 24, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/test. The candidate focuses on improving test quality and assertions, which is a test type task.
    • Priority: P1-High. Tests without assertions or proper exception matching can lead to false positives in the test suite.
    • Value: High. Improving test assertions and exception handling increases confidence in test results and code quality.
    • Effort: High. The candidate requires auditing and fixing a large number of tests, which is time-intensive.
  3. dan-petty commented on Oct 27, 2026

    @dan-petty
    OwnerAuthor

    Refine cannot set this item to Ready at 0abf552 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • Where do the ast-grep rules live and which CI row runs them? (missing verified source)
  4. added
    priority/p1-high
    status/new
    effort/high
    value/high
    scope/cli
    status/in-progress
    and removed
    status/new
    on Oct 28, 2026
  5. added a commit that references this issue on Oct 31, 2026
    a29dff6
  6. removed
    status/in-progress
    on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p1-highscope/clisource/agenttype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions