fix(ci): 单测环境注入哑 LLM key,修复 openai>=3 构造期凭据校验导致的 CI 红 - #12
Open
leaderwm wants to merge 1 commit into
Open
Conversation
openai 3.x 起 AsyncOpenAI() 构造时即校验凭据(2.x 延迟到首次请求), 且仅 api_key=None 时才回退读环境变量;config 默认空串被原样传入 → DeepSeekLLM/QwenLLM/DoubaoLLM 构造即抛 'Missing credentials', test_batch3_infra 3 例失败(main CI 自 2026-09-03 起红)。 conftest 在 Settings 实例化前 setdefault 三个 provider key 为哑值: 单测中所有 LLM 请求均被 mock,不会真实外发;对 openai 2.x/3.x 均兼容。
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.
问题
main 的 CI(
tests与CI两个工作流)自 2026-09-03 起持续红,失败集固定为tests/test_batch3_infra.py3 例(test_chat_with_usage_returns_real_tokens/test_chat_with_usage_no_usage_returns_none/test_chat_str_contract_unchanged),并连带所有 open PR 的 CI 显示失败。根因:requirements 中
openai>=2.0无上界,CI 安装到 openai 3.7.0。3.x 起AsyncOpenAI()构造时即校验凭据(2.x 延迟到首次请求才查),且 SDK 仅在api_key=None时才回退读OPENAI_API_KEY环境变量;而config.py中DEEPSEEK_API_KEY等默认值是空串(非 None),被原样传入 →DeepSeekLLM()/QwenLLM()/DoubaoLLM()在单测环境(无真实 key)构造即抛OpenAIError: Missing credentials。三个测试都是「先构造 provider 再 mockclient.chat.completions.create」的写法,构造一步就挂。改动(仅测试环境,零生产代码变更)
tests/conftest.py在app.config.Settings实例化之前,对三个 provider keysetdefault哑值(sk-test-dummy):setdefault不覆盖真实环境变量,本地有真 key 的开发者行为不变;验证
test_batch3_infra.py3 failed / 11 passed;全量 3 failed, 864 passedtest_batch3_infra.py14 passed;全量 867 passed, 0 failed(CI 同款命令pytest tests/ -q --ignore=tests/test_api.py -m "not integration")python scripts/validate_golden.py通过(109 条)