Skip to content

fix(config): hide Baidu web search key when disabled#7992

Merged
RC-CHN merged 2 commits intoAstrBotDevs:masterfrom
RhoninSeiei:fix/websearch-baidu-key-condition
May 6, 2026
Merged

fix(config): hide Baidu web search key when disabled#7992
RC-CHN merged 2 commits intoAstrBotDevs:masterfrom
RhoninSeiei:fix/websearch-baidu-key-condition

Conversation

@RhoninSeiei
Copy link
Copy Markdown
Contributor

@RhoninSeiei RhoninSeiei commented May 4, 2026

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 / 运行截图或测试结果

image image astrbotbug1 1

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.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.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:

  • Hide the Baidu web search key configuration when web search is disabled, consistent with other providers.

Tests:

  • Add a regression test ensuring the Baidu web search key field is only active when Baidu is selected and web search is enabled.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label May 4, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/unit/test_config.py Outdated
Comment on lines +54 to +66
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,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

目前的回归测试仅针对百度搜索的 Key 进行了校验。为了更好地实现“防止该条件后续再次遗漏”的目标,建议将测试逻辑通用化,遍历 websearch 组下的所有配置项(除开关本身外),确保它们都包含了 provider_settings.web_search: True 的显示条件。这样可以确保所有搜索提供商的配置项在行为上保持一致,并能自动覆盖未来可能新增的配置项。

Suggested change
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
  1. When implementing similar functionality for different cases, refactor the logic into a shared helper function to avoid code duplication.

Comment thread tests/unit/test_config.py
Copy link
Copy Markdown
Member

@Soulter Soulter May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, this pr does not need any tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已移除,只保留default.py的单行更改。

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 6, 2026
@RC-CHN RC-CHN merged commit b4e1181 into AstrBotDevs:master May 6, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 关闭网页搜索后百度 AI 搜索 Key 配置项仍显示

3 participants