Repository navigation
Description
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
dan-petty commentedon Oct 31, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.test, and .github/labels.yml declares no scope/test label. Add the label to the file to give the scope to this item.The hook blocks every commit on main, halting all development.Every developer is blocked from committing until this is fixed.Adding one assertion to a single test function is minimal work.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.dan-petty commentedon Oct 31, 2026
Main at 03d3dc5 holds two asserts in
tests/commands/test_ai_cmd.py::test_ai_chat_helpers_print_thought_and_tool. The first one readscapsys.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 withassert (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.
fix(test): the chat helper test asserts what the helpers print (#2874)
dan-petty commentedon Oct 31, 2026
Superseded by PR #2873 (commit c53bcec), which added assertions to test_ai_chat_helpers_print_thought_and_tool.
devops-cli-service commentedon Oct 31, 2026
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.