Skip to content

fix(test): the ast-grep hook fails on main for test_ai_chat_helpers_print_thought_and_tool #2874

Closed as not planned

Description

@dan-petty

Problem

On origin/main the commit hook ast-grep scan fails for every commit. The rule test-function-has-assertion reports tests/commands/test_ai_cmd.py:252, the test test_ai_chat_helpers_print_thought_and_tool. It calls two print functions and asserts nothing.

Evidence

Run git commit on any branch based on origin/main 330e9fa. The hook ast-grep scan (network constructs and working-directory reads in src, elapsed-time bounds in tests) prints error[test-function-has-assertion] and exits 1. The hook scans the whole tree, so it blocks every commit, not only commits that touch this file.

Two merged pull requests caused it together: #2863 added the test, and #2864 added the rule. Each passed on its own.

Expected

The test asserts what the helpers print, and the hook passes. A check that runs when a rule lands also runs on the tests that exist then.

Found by

The work on #2868.

Proposed design

Problem statement

The ast-grep rule test-function-has-assertion reports tests/commands/test_ai_cmd.py:252. The test test_ai_chat_helpers_print_thought_and_tool calls two print functions without asserting on the captured output. This blocks every commit on branches based on origin/main. The test was added in #2863 and the rule in #2864. Each passed on its own, but together they conflict.

Acceptance criteria

Requirement: test-asserts-captured-output

The test test_ai_chat_helpers_print_thought_and_tool SHALL assert on the output captured by the capsys fixture.

Scenario: ast-grep-rule-passes

  • WHEN The ast-grep rule test-function-has-assertion is run against tests/commands/test_ai_cmd.py
  • THEN The rule reports no error at line 252.

Requirement: hook-exits-zero

The pre-commit hook ast-grep scan SHALL exit 0 on a branch based on origin/main.

Scenario: commit-succeeds

  • WHEN A developer runs git commit on a branch based on origin/main 330e9fa
  • THEN The hook exits with code 0 and prints no error[test-function-has-assertion].

Existing Tool Considered

No check has run. The need is to add assertions to an existing test function. This is a code edit, not a tool or library need. The ast-grep rule test-function-has-assertion is already in the repository.

Key questions

  • What should the test assert to satisfy the rule?: The test SHALL assert on the output captured by the capsys fixture, verifying that the print functions produce the expected output. (best practice) [sources: tests/commands/test_ai_cmd.py:252]
    • Chosen: Assert on captured stdout via capsys.readouterr(). The test uses the capsys fixture to capture output. Asserting on it verifies the print behavior and satisfies the rule.
    • Rejected: Suppress the rule for this test. This defeats the purpose of the rule, which exists to ensure tests verify behavior.
    • Rejected: Remove the test. This loses test coverage for the print helpers.

Open questions

  • Does the CI pipeline run the ast-grep scan in addition to the local pre-commit hook? (missing verified source)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/high
    effort/low
    on Oct 31, 2026
  2. dan-petty commented on Oct 31, 2026

    @dan-petty
    OwnerAuthor

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

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: none. The title has the scope test, and .github/labels.yml declares no scope/test label. Add the label to the file to give the scope to this item.
    • Priority: P1-High. The hook blocks every commit on main, halting all development.
    • Value: High. Every developer is blocked from committing until this is fixed.
    • Effort: Low. Adding one assertion to a single test function is minimal work.
    • Related: ci(gate): checks of committed files and tool configuration run as devops ci rows, not as pytest tests that start the tool #2164, which asks for a different change. Both concern ast-grep checks in the test tree, but #2164 moves checks out of pytest into devops ci rows while this candidate fixes one test to satisfy an existing rule.
  3. added
    priority/p1-high
    on Oct 31, 2026
  4. dan-petty commented on Oct 31, 2026

    @dan-petty
    OwnerAuthor

    Main at 03d3dc5 holds two asserts in tests/commands/test_ai_cmd.py::test_ai_chat_helpers_print_thought_and_tool. The first one reads capsys.readouterr().out. This read empties the capture. The second one then reads an empty capture, so it gets (False, False, False). The test fails on main with assert (False, False, False) == (True, True, True).

    Evidence: a merge of origin/main into a topic branch with no change to this file fails the test, and the same file text is in git show origin/main:tests/commands/test_ai_cmd.py.

    Found while shipping #2865. The fix is to keep one of the two reads.

  5. dan-petty commented on Oct 31, 2026

    @dan-petty
    OwnerAuthor

    Superseded by PR #2873 (commit c53bcec), which added assertions to test_ai_chat_helpers_print_thought_and_tool.

  6. removed
    status/new
    on Oct 31, 2026
  7. devops-cli-service commented on Oct 31, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 03d3dc5 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.

    • Does the CI pipeline run the ast-grep scan in addition to the local pre-commit hook? (missing verified source)
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/lowpriority/p1-highsource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions