qwen-code/packages
John London b2ab751087
fix(cli): correct model precedence — argv > settings > auth env vars (#3645)
* fix(cli): correct OPENAI_MODEL precedence without breaking /model selection

Fixes model precedence regression from #3567 (reverted in #3633):

- argv.model > settings.model.name > OPENAI_MODEL > QWEN_MODEL
- settings.model.name wins over OPENAI_MODEL when it matches a provider
- OPENAI_MODEL only used as fallback when no explicit model is configured
- Added tests proving both paths: settings wins, and OPENAI_MODEL fallback works

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(cli): separate model selection from provider lookup to prevent env override

The previous implementation iterated through candidates [argv.model, settings.model.name,
OPENAI_MODEL, QWEN_MODEL] and picked the first matching provider. This caused
settings.model.name to be overridden by OPENAI_MODEL when the former didn't
match any provider.

Fix by:
1. First resolve target model using strict precedence
2. Only look up provider for that specific model
3. Filter OPENAI_MODEL/QWEN_MODEL from env when model was resolved
   from settings or argv, preventing the core resolver from picking
   up these env vars

Also fixes Edge Case 5 test (was testing buggy behavior) and adds
integration test verifying settings.model.name wins over OPENAI_MODEL.

* fix(types): remove unused type annotation from mock

The mockImplementation used ModelConfigSourcesInput type which
wasn't properly resolved. Remove the type annotation
to fix TypeScript and ESLint errors.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* trigger CI

* chore: trigger clean CI build

* fix(test): make mock compatible with CI type checking

The mockImplementation was causing TS2345 in CI because
the return type didn't match ModelConfigResolutionResult.
Fixed by using optional chaining and removing type annotations
that caused CI build failures.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(test): make mock compatible with CI type checking

The mock of resolveModelConfig returned sources as { model: string }
instead of { model: ConfigSource }, causing a type error in CI only
(where strictBuild is enabled). Use proper ConfigSource objects.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(test): update mock to match reviewer suggestion

Use proper ConfigSource objects with path/envKey details as suggested
in the review, matching what resolveModelConfig actually returns.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* test(cli): add regression tests for model precedence

Adds [Regression] tests that guard against the original bug where
OPENAI_MODEL incorrectly overrode settings.model.name. Tests cover:
- settings.model.name precedence over OPENAI_MODEL
- OPENAI_MODEL used when settings.model.name not set
- argv.model overriding both settings and env
- QWEN_MODEL as fallback when OPENAI_MODEL not set
- Non-OpenAI auth ignoring OPENAI_MODEL

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(cli): address reviewer feedback on model precedence PR

- Add missing assertion in Non-OpenAI auth test to verify OPENAI_MODEL
  is filtered from env passed to resolveModelConfig
- Clean up modelProvider lookup comment to clarify the old bug is fixed

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(cli): address review feedback on model precedence PR

- Sanitize OPENAI_MODEL/QWEN_MODEL in beforeEach to prevent flaky tests
- Remove stray "// trigger rebuild" comment
- Add AUTH_ENV_MODEL_VARS mapping for all auth types (not just OpenAI)
- Fix filteredEnv logic to strip ALL model env vars when model not from env
- Use sourceEnvVar tracking to only keep the env var that was actually used

Fixes the blocking test failure when OPENAI_MODEL is set in shell env.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(cli): fix test assertion for filtered env, add source-based filtering comments

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
2026-04-30 09:17:22 +08:00
..
channels chore(release): bump version to 0.15.3 (#3708) 2026-04-28 21:04:52 +08:00
cli fix(cli): correct model precedence — argv > settings > auth env vars (#3645) 2026-04-30 09:17:22 +08:00
core fix(core): replay DeepSeek reasoning_content on all assistant turns (#3747) 2026-04-30 07:43:16 +08:00
sdk-java fix(sdk-java): pass custom env to CLI process (#3543) 2026-04-24 10:37:52 +08:00
sdk-python feat(SDK) Add Python SDK implementation for #3010 (#3494) 2026-04-25 07:02:58 +08:00
sdk-typescript chore(release): sdk-typescript v0.1.7 (#3688) 2026-04-28 14:59:13 +08:00
vscode-ide-companion chore(release): bump version to 0.15.3 (#3708) 2026-04-28 21:04:52 +08:00
web-templates chore(release): bump version to 0.15.3 (#3708) 2026-04-28 21:04:52 +08:00
webui chore(release): bump version to 0.15.3 (#3708) 2026-04-28 21:04:52 +08:00
zed-extension chore(zed-extension): update package version to 0.10.0 2026-02-06 14:26:01 +08:00