Skip to content

test: cover run_chat's REPL loop and run_setup's interactive flow - #150

Open
shrdgn wants to merge 1 commit into
mainfrom
claude/cli-repl-test-coverage
Open

test: cover run_chat's REPL loop and run_setup's interactive flow#150
shrdgn wants to merge 1 commit into
mainfrom
claude/cli-repl-test-coverage

Conversation

@shrdgn

@shrdgn shrdgn commented Aug 17, 2026

Copy link
Copy Markdown
Owner

What & why

run_chat() (~107 lines: the entire REPL — /help, /models, /clear, /preset, /tokens, /key, unknown-command fallback, KeyboardInterrupt/EOFError exit, the exception-recovery handler with its 401/credit hint, and the interactive first-run key prompt) and run_setup() (the overwrite-confirmation prompt, empty-key bailout, and preset choice) had zero direct test coverage. tests/test_cli.py only asserted that main() 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 /tokens REPL-cap bug fixed in #145 lived inside this exact untested run_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, /preset valid+invalid, /tokens valid+invalid, /key, unknown command), EOFError/KeyboardInterrupt on 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_chat locally and confirming the corresponding new test fails, then reverted.

How it was tested

  • ruff check . passes
  • pytest -q passes (no live network) — full suite: 506 passed
  • New behavior has a test — this PR is entirely new tests, no production code changed
  • Docs updated if config / request surface / defaults changed — not applicable, no behavior change
  • No secrets, prompts, or response bodies added to logs or metrics
  • Quality/cost claims backed by a reproducible bench/run.py number — not applicable

Notes for reviewers

Found via an automated repo-review scheduled task. Test-only change — zero production code touched. tests/test_cli.py isn't in mypy's CI scope (only openfusion/ is checked, and cli.py itself is currently excluded from mypy), so no mypy run was needed here.


Generated by Claude Code

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants