Skip to content

test(cli): each test of an error path checks the error code, the exit code or the message, not only the error type #2177

Closed

Description

@dan-petty

What happened

docs/TESTING.md says: "A test of an error path checks the DevOpsCLIError subclass raised, with its exit code and machine-readable error code." At b170358, 200 pytest.raises calls in 85 test files name a project or library error type, pass no match=, and keep no handle to the error, so they check only the type. A test of an error path then passes when the code raises the right type for the wrong reason.

The most common types: ValidationError (33), SSRFBlockedError (24), typer.Exit (23), SecurityError (15), AIClientError (7), ServiceAddressError (7), asyncio.CancelledError (6), SandboxNotFoundError (5). The files with the most sites: tests/test_validation.py (21), tests/test_process.py (15), tests/test_http_egress.py (10), tests/test_http_broker.py (7), tests/test_ai_client_providers_and_embeddings.py (6).

What should happen

  • A pytest.raises of a DevOpsCLIError subclass keeps the error (as raised) and checks its error_code, and its exit code where the command layer maps one.
  • A pytest.raises of a library error passes match= with the message that only the expected failure gives. A typer.Exit check reads its exit code.
  • A check stops new cases: ruff's PT011, with raises-require-match-for extended to these types, or an ast-grep rule in the constructs row.

Evidence

  • An AST pass over tests/ at b170358: pytest.raises(X) where X is not a built-in exception, with no match= keyword and no as target. 200 sites in 85 files. The script and its list are in .data/agent/scratch/audit-issues/ of the 2026-10-24 audit.
  • docs/TESTING.md, "Names and assertions".

Acceptance criteria

  • Each of the 200 sites checks the error_code (and exit code) of a DevOpsCLIError, the message of a library error, or the code of a typer.Exit.
  • A check in devops ci fails a new pytest.raises that checks only the type. The pull request shows it failing on a scratch case.
  • The tests patch nothing new and import no private name.
  • uv run devops ci passes.

Related: #2171 owns the tests with no assertion and the built-in pytest.raises with no match=. #1307's children change these files for other reasons; a site that a child rewrites first leaves this item.

Source: #2171

Proposed design

Problem statement

200 pytest.raises calls in 85 test files check only the exception type. They do not verify the error code, exit code, or message. A test then passes when the code raises the right type for the wrong reason. The fix adds the missing assertion at each site. It also adds a static check that fails a new bare pytest.raises.

Acceptance criteria

  • Criterion 1: Each of the 200 sites checks the error_code of a DevOpsCLIError, the message of a library error, or the code of a typer.Exit.
    Verification: Run the AST audit over tests/ and confirm zero sites with a project or library error type, no match=, and no as target.
  • Criterion 2: A static check in devops ci fails a new pytest.raises that checks only the type.
    Verification: Add a scratch test with a bare pytest.raises(ValidationError) and confirm uv run devops ci fails on it.
  • Criterion 3: The tests add no new patch and import no private name.
    Verification: uv run devops ci passes, including the invariants that check for new patches and private imports.
  • Criterion 4: uv run devops ci passes.
    Verification: Run uv run devops ci and confirm all checks pass.

Key questions

  • What attributes does DevOpsCLIError expose for the assertion?: It has an error_code and an exit code. TESTING.md states the test checks the subclass with its exit code and machine-readable error code. [sources: docs/TESTING.md]
  • Which static check mechanism prevents new violations?: Either ruff PT011 with raises-require-match-for extended to the project error types, or an ast-grep rule in the constructs row. The repository already runs ast-grep rules such as test-elapsed-upper-bound in .ast-grep/rules/. (proposed) [sources: docs/TESTING.md]
  • How does a test check a typer.Exit?: It keeps the exception with as raised and asserts on raised.code. [sources: tests/test_validation.py]
  • How does a test check a library error such as asyncio.CancelledError that has no distinctive message?: The test passes match= with the message the failure gives, or keeps the exception with as and asserts on a distinguishing attribute. The surrounding test context and post-conditions already distinguish the expected failure. (proposed) [sources: tests/test_process.py]

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 proposes changes to test assertions for error paths, which is a test-related task.
    • Priority: P2-Medium. This change improves test accuracy and reliability but does not fix a critical issue or add a major feature.
    • Value: High. Improving test quality helps prevent false positives in error handling and strengthens the project's reliability.
    • Effort: Medium. The change requires modifying 200 test cases across multiple files, but it follows a clear pattern that can be automated.
    • Related: refactor(cli): exceptions carry their codes as class data, and one exit seam replaces 19 hand-rolled exits #1006, which asks for a different change. Both items work on error handling but item 1006 focuses on mapping exceptions to exit codes and consolidating the error classes while this candidate checks more thoroughly in tests.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at bb46660 (see proposed design in issue body).

  4. added
    priority/p2-medium
    status/ready
    effort/medium
    value/high
    scope/cli
    status/in-progress
    and removed
    status/ready
    on Oct 28, 2026
  5. added a commit that references this issue on Oct 31, 2026
    8ea8765
  6. added
    status/in-review
    and removed
    status/in-progress
    on Oct 31, 2026
  7. added a commit that references this issue on Oct 31, 2026
    b6a7fd3
  8. removed
    status/in-review
    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/mediumpriority/p2-mediumscope/clisource/agenttype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions