fix(config): hide Baidu web search key when disabled#7992
fix(config): hide Baidu web search key when disabled#7992RC-CHN merged 2 commits intoAstrBotDevs:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the configuration metadata for Baidu AI search by adding a requirement that the web search toggle must be enabled. It also introduces a unit test to verify this condition. A review comment suggests generalizing this test to iterate through all web search configuration items, ensuring consistent behavior across different providers and better coverage for future additions.
| def test_baidu_web_search_key_requires_web_search_enabled(self): | ||
| websearch_items = CONFIG_METADATA_3["ai_group"]["metadata"]["websearch"][ | ||
| "items" | ||
| ] | ||
|
|
||
| condition = websearch_items[ | ||
| "provider_settings.websearch_baidu_app_builder_key" | ||
| ]["condition"] | ||
|
|
||
| assert condition == { | ||
| "provider_settings.websearch_provider": "baidu_ai_search", | ||
| "provider_settings.web_search": True, | ||
| } |
There was a problem hiding this comment.
目前的回归测试仅针对百度搜索的 Key 进行了校验。为了更好地实现“防止该条件后续再次遗漏”的目标,建议将测试逻辑通用化,遍历 websearch 组下的所有配置项(除开关本身外),确保它们都包含了 provider_settings.web_search: True 的显示条件。这样可以确保所有搜索提供商的配置项在行为上保持一致,并能自动覆盖未来可能新增的配置项。
| def test_baidu_web_search_key_requires_web_search_enabled(self): | |
| websearch_items = CONFIG_METADATA_3["ai_group"]["metadata"]["websearch"][ | |
| "items" | |
| ] | |
| condition = websearch_items[ | |
| "provider_settings.websearch_baidu_app_builder_key" | |
| ]["condition"] | |
| assert condition == { | |
| "provider_settings.websearch_provider": "baidu_ai_search", | |
| "provider_settings.web_search": True, | |
| } | |
| def test_web_search_items_conditions(self): | |
| websearch_items = CONFIG_METADATA_3["ai_group"]["metadata"]["websearch"]["items"] | |
| # 检查所有网页搜索相关的配置项是否都包含了启用网页搜索的条件 | |
| for key, item in websearch_items.items(): | |
| if key == "provider_settings.web_search": | |
| continue | |
| condition = item.get("condition", {}) | |
| assert condition.get("provider_settings.web_search") is True, f"{key} 缺少 web_search 启用条件" | |
| # 验证百度搜索 Key 的特定提供商条件 | |
| baidu_key = "provider_settings.websearch_baidu_app_builder_key" | |
| assert websearch_items[baidu_key]["condition"]["provider_settings.websearch_provider"] == "baidu_ai_search" |
References
- When implementing similar functionality for different cases, refactor the logic into a shared helper function to avoid code duplication.
There was a problem hiding this comment.
hi, this pr does not need any tests
There was a problem hiding this comment.
已移除,只保留default.py的单行更改。
Fixes #7985.
Modifications / 改动点
This is NOT a breaking change. / 这不是一个破坏性变更。
为
provider_settings.websearch_baidu_app_builder_key补充provider_settings.web_search: True显示条件。使百度 AI 搜索 Key 配置项与 Tavily、BoCha、Brave、Firecrawl 的 Key 配置项行为一致:关闭网页搜索后隐藏对应 Key 输入框。
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Align Baidu web search key configuration visibility with other web search providers and guard it with tests.
Bug Fixes:
Tests: