Skip to content

fix(describegpt): honor explicit --base-url when value matches default#3893

Merged
jqnatividad merged 3 commits into
masterfrom
fix/describegpt-baseurl-precedence-explicit-default
May 23, 2026
Merged

fix(describegpt): honor explicit --base-url when value matches default#3893
jqnatividad merged 3 commits into
masterfrom
fix/describegpt-baseurl-precedence-explicit-default

Conversation

@jqnatividad
Copy link
Copy Markdown
Collaborator

Summary

  • Removes the docopt [default: ...] from --base-url and --model so flag_base_url / flag_model are Some only when the user explicitly passed the flag.
  • Adds resolve_base_url(args) / resolve_model(args) helpers that apply CLI > env > built-in default manually; replaces the sentinel-based comparisons in get_prompt_file and the api-key localhost check with plain Some/None checks.
  • Adds a regression test describegpt_baseurl_precedence_cli_default_over_env that pins the precedence: QSV_LLM_BASE_URL=fake-env qsv describegpt --base-url http://localhost:1234/v1 ... must honor the explicit CLI value even though it matches the documented default.

Why

Codex review (job 2363, MEDIUM) flagged that the sentinel-based precedence couldn't distinguish an omitted --base-url from an explicit --base-url http://localhost:1234/v1 — both produced flag_base_url == Some(DEFAULT_BASE_URL). As a result, QSV_LLM_BASE_URL silently overrode an explicit-default CLI flag, contradicting the documented precedence (CLI > env > default).

Test plan

  • cargo test -F all_features test_describegpt:: — 72/72 passing
  • Regression test fails on pre-fix code (env URL leaks through), passes after the fix
  • Existing describegpt_baseurl_precedence_cli_over_env and describegpt_baseurl_precedence_env_over_default still pass
  • Help docs regenerated via qsv --generate-help-md

🤖 Generated with Claude Code

Codex review (job 2363, MEDIUM) flagged that the sentinel-based
precedence couldn't distinguish an omitted --base-url from an
explicit --base-url http://localhost:1234/v1: both produced
flag_base_url == Some(DEFAULT_BASE_URL), so QSV_LLM_BASE_URL
silently overrode an explicit-default CLI flag.

Switch to the suggested approach — remove the docopt default for
--base-url (and the matching --model default) and apply
CLI > env > built-in default manually:

- docopt USAGE: drop `[default: ...]` lines for --base-url and
  --model. flag_base_url / flag_model are now Some IFF the user
  explicitly passed the flag.
- New `resolve_base_url(args)` and `resolve_model(args)` helpers
  apply the documented precedence in code. Used at all call
  sites that need a resolved value (check_model, the reqwest
  client builder, the api-key localhost check).
- `get_prompt_file` now uses a plain `if let Some(cli_base_url)`
  check instead of `!= Some(DEFAULT_BASE_URL)`. Same for model.
- DEFAULT_BASE_URL / DEFAULT_MODEL doc comments updated; they
  are no longer sentinels, just the final fallback when neither
  CLI nor env nor the prompt file supplies a value.

Regression test (describegpt_baseurl_precedence_cli_default_over_env):
runs describegpt with QSV_LLM_BASE_URL pointed at an obviously
wrong URL AND --base-url http://localhost:1234/v1 explicit on the
CLI. The new test fails on the pre-fix code (env URL leaks
through) and passes after the fix.

Help docs regenerated via `qsv --generate-help-md` to reflect the
docopt USAGE change.

All 72 describegpt tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread tests/test_describegpt.rs Dismissed
Comment thread src/cmd/describegpt.rs Dismissed
Comment thread src/cmd/describegpt.rs Fixed
Comment thread tests/test_describegpt.rs Dismissed
Comment thread tests/test_describegpt.rs Dismissed
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 23, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics -7 complexity

Metric Results
Complexity -7

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Codex review (job 2372, MEDIUM) flagged that the api-key localhost
gate at run()'s top level now uses `resolve_base_url(&args)`, but
that helper only walks CLI > env > built-in default. With
`--prompt-file` pointing at a non-localhost provider and no
CLI/env base URL, the helper returns "http://localhost:1234/v1",
passes the localhost check, and lets describegpt proceed without
an API key — then send unauthenticated requests to the remote
provider URL stored in the prompt file.

The fix uses the EFFECTIVE base URL (CLI > env > prompt_file >
built-in default) at the gate, by reading
`get_prompt_file(args)?.base_url`. `get_prompt_file` already
applies that precedence and writes the result into
`prompt_file.base_url`, so it's the canonical source.

Also tightened two related call sites:
- `check_model`: the no-`--prompt-file` branch used to call
  `resolve_base_url(args)` which had the same gap. Since
  `get_prompt_file` is already called at the top of the function
  and falls back to the bundled default prompt's base_url, the
  branch collapses to `prompt_file.base_url.clone()` for both
  cases.
- `run_inference_options`: pass the effective URL to
  `create_reqwest_blocking_client` so reqwest's `for_host` retry
  classifier matches the actual request host, not the (possibly
  different) CLI > env > default.

With those call sites switched, `resolve_base_url` and
`resolve_model` are no longer referenced; deleted them. Kept
DEFAULT_BASE_URL / DEFAULT_MODEL under `#[allow(dead_code)]`
because the test helpers still reference them.

Regression test
(describegpt_baseurl_remote_prompt_file_requires_api_key): writes
a prompt TOML with `base_url = "https://api.openai.com/v1"`, runs
describegpt with neither --api-key nor QSV_LLM_APIKEY set. The
new test fails on the pre-fix code (the localhost gate let the
run proceed, hitting BLAKE3 hashing) and passes after the fix
(the api-key error fires before any work begins).

All 73 describegpt tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread src/cmd/describegpt.rs Dismissed
Comment thread src/cmd/describegpt.rs Fixed
Codex review (job 2373, MEDIUM) flagged that my prior fix
(job 2372) made the api-key localhost gate consult the prompt
file's base_url for correctness — but the gate runs ahead of the
--prepare-context branch in run(), so
`qsv describegpt --prepare-context --prompt-file remote.toml`
now errors out asking for credentials even though that mode only
emits prompt/context JSON locally and never calls the LLM API.

Guard the gate with `args.flag_prepare_context`: when set, skip
the localhost / api-key resolution entirely and use an empty
String placeholder for the unused `api_key` variable.
--process-response (a similar no-network mode) already returns
earlier in run() and is unaffected.

Regression test
(describegpt_prepare_context_remote_prompt_file_no_api_key):
runs --prepare-context with a prompt file pointing at
https://api.openai.com/v1 and no API key set — fails on the
pre-fix code, succeeds after the fix.

All 74 describegpt tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread src/cmd/describegpt.rs Dismissed
Comment thread tests/test_describegpt.rs Dismissed
Comment thread tests/test_describegpt.rs Dismissed
Comment thread tests/test_describegpt.rs Dismissed
@jqnatividad jqnatividad merged commit 9eab559 into master May 23, 2026
18 of 19 checks passed
@jqnatividad jqnatividad deleted the fix/describegpt-baseurl-precedence-explicit-default branch May 23, 2026 13:23
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