Skip to content

fix(QUA-576): route -p and positional args through configured cliAgent#102

Closed
Desperado wants to merge 1 commit into
mainfrom
Desperado/qua-576-p-flag-backend
Closed

fix(QUA-576): route -p and positional args through configured cliAgent#102
Desperado wants to merge 1 commit into
mainfrom
Desperado/qua-576-p-flag-backend

Conversation

@Desperado
Copy link
Copy Markdown
Contributor

Summary

Fixes QUA-576.

Before this change, both non-interactive entry paths in main.go called ag.Run (the Anthropic API agent) unconditionally — silently ignoring backend=cc (and backend=codex). Every CI / scripting / cloud-session invocation that used qmax-code -p "..." or qmax-code "..." was bypassing the cc backend and hitting the Anthropic API directly.

Repro (pre-fix)

$ qmax-code config           # shows backend = "cc" (claude found: …)
$ qmax-code -backend cc -p "hi"
Error: API call failed: API error 401: invalid x-api-key

The 401 comes from a stale keychain key being sent to Anthropic — not from any actual CC backend invocation.

Repro (post-fix)

$ qmax-code -backend cc -p "Reply with exactly one word: alpha"
alpha

Fix

  • Single runOneShot dispatcher shared by both -p and positional-arg modes.
  • If cliAgent is set (cc/codex), the prompt goes through it (cliAgent.Run) with its own streaming output via a Terminal created on demand.
  • If cliAgent is nil, fall back to ag.Run exactly as before.

This also restores doc-comment accuracy: README/CONTRIBUTING/cc_agent.go all claim "no Anthropic API key needed when backend=cc" — that statement is now true for non-interactive mode, not just the REPL.

Tests

  • main_oneshot_test.go (new) — fakeCLIAgent + 3 assertions:
    • CLIAgent is preferred when set
    • API path is used as fallback when CLIAgent is nil
    • Errors from the CLIAgent propagate (so main.go exits non-zero)
  • Full suite green: go test ./... -short -count=1.

Test plan

  • qmax-code -backend cc -p "..." returns through claude, no Anthropic 401.
  • qmax-code -backend cc "..." (positional) same behaviour.
  • qmax-code -backend api -p "..." still uses the API path (or errors cleanly if no key).
  • qmax-code -backend codex -p "..." routes through codex CLI.
  • CI integration (relevant to QUA-404): cloud sessions driving qmax-code -p now actually use the configured backend.

🤖 Generated with Claude Code

Before this change, both `qmax-code -p "..."` and `qmax-code "..."`
called `ag.Run` (the Anthropic API agent) unconditionally — silently
ignoring `backend=cc` and `backend=codex`. Every CI / scripting /
cloud-session invocation bypassed the cc backend and hit the
Anthropic API directly (often producing a 401 from a stale keychain
key, masking the real issue). The doc claims that the cc backend
needs no Anthropic API key were also false for these paths.

The fix introduces a single `runOneShot` dispatcher shared by both
non-interactive entry points: if `cliAgent` is configured, prompts
go through it (claude/codex CLI) with its own streaming output; only
when there is no CLI backend do we fall back to `ag.Run`.

Regression tests (main_oneshot_test.go) mirror the dispatch contract
with a fake CLIAgent and assert (1) CLI takes precedence, (2) API
is used as the fallback, (3) CLI errors propagate.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@qualitymaxapp
Copy link
Copy Markdown

qualitymaxapp Bot commented May 15, 2026

✅ QualityMax Pipeline

Gate Result
🔍 AI Review ✅ Clean
🧪 Repo Tests ✅ 288/288 passed (go)
🤖 AI Tests ✅ 28/32 passed

Powered by QualityMax — AI-Powered Test Automation

@Desperado
Copy link
Copy Markdown
Contributor Author

Included and merged via #103 (db91e5d). Closing this stale duplicate PR to avoid re-merging the same change.

@Desperado Desperado closed this May 15, 2026
@Desperado Desperado deleted the Desperado/qua-576-p-flag-backend branch May 15, 2026 21:54
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