test: cover run_chat's REPL loop and run_setup's interactive flow - #150
Open
shrdgn wants to merge 1 commit into
Open
test: cover run_chat's REPL loop and run_setup's interactive flow#150shrdgn wants to merge 1 commit into
shrdgn wants to merge 1 commit into
Conversation
Both were previously untested: test_main_dispatches_chat_to_run_chat and test_main_dispatches_setup_to_run_setup only assert that main() dispatches to them, with the actual functions monkeypatched away. The bug PR #145 fixes (the /tokens ratchet) lived inside this exact blind spot. Adds coverage for run_chat's config-load/API-key error paths, the missing-key interactive prompt, every slash command (/help, /models, /clear, /preset, /tokens, /key, unknown), EOF/KeyboardInterrupt exit, and the message-turn success/error/cancel paths (including the 401/credit hint). Adds coverage for run_setup's overwrite-confirmation prompt, empty-key bailout, and both preset choices. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EdA4xCCD6tTs2Z1atpfdB7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
run_chat()(~107 lines: the entire REPL —/help,/models,/clear,/preset,/tokens,/key, unknown-command fallback,KeyboardInterrupt/EOFErrorexit, the exception-recovery handler with its 401/credit hint, and the interactive first-run key prompt) andrun_setup()(the overwrite-confirmation prompt, empty-key bailout, and preset choice) had zero direct test coverage.tests/test_cli.pyonly asserted thatmain()dispatches to them (test_main_dispatches_chat_to_run_chat/test_main_dispatches_setup_to_run_setup), with both functions monkeypatched away.This is a real blind spot, not a hypothetical one: the
/tokensREPL-cap bug fixed in #145 lived inside this exact untestedrun_chat()body.Added tests cover:
run_chat: config-load error exit, no-API-key exit (interactive and non-interactive), the interactive missing-key prompt (and that it saves the key), every slash command (/help,/models,/clear,/presetvalid+invalid,/tokensvalid+invalid,/key, unknown command),EOFError/KeyboardInterrupton the prompt, and a message turn's success/error/cancel paths (including the 401-vs-generic-error hint distinction).run_setup: declining the overwrite prompt, an empty key bailing out without writing a file, both preset choices (default/budget and quality), and accepting an overwrite.I verified these aren't rubber-stamp tests by deliberately breaking the 401-hint condition in
run_chatlocally and confirming the corresponding new test fails, then reverted.How it was tested
ruff check .passespytest -qpasses (no live network) — full suite: 506 passedbench/run.pynumber — not applicableNotes for reviewers
Found via an automated repo-review scheduled task. Test-only change — zero production code touched.
tests/test_cli.pyisn't in mypy's CI scope (onlyopenfusion/is checked, andcli.pyitself is currently excluded from mypy), so no mypy run was needed here.Generated by Claude Code