fix(backend): address CodeRabbit review comments for KB permission resolver#25
Merged
cocowh merged 1 commit intoweagent/kb-permission-extensionfrom Apr 23, 2026
Conversation
…solver
- kb_permissions.py: change `if result:` to explicit `if result is None`
check and add warning log when extension wrap() returns None, so
misconfigured extensions are surfaced instead of silently discarded
- knowledge_service.py: guard get_accessible_kb_ids() call in try/except
so extension runtime errors degrade gracefully to ext_kb_ids=[] rather
than breaking the entire KB listing path
- test_kb_permission_resolver.py:
- rewrite tautological test to call the real _create_resolver() with
monkeypatched SERVICE_EXTENSION="" rather than patching the function
itself (test was asserting on its own mock, not the real code)
- remove dead return_value assignment that was immediately overridden by
side_effect (Ruff/mock semantics: side_effect takes precedence)
- rename unused variable `role` to `_role` to signal intent (Ruff RUF059)
- fix stale docstring references kbPermissionResolver -> kb_permission_resolver
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.
修改内容
针对 PR wecode-ai#1025 中 CodeRabbit 的 5 条 review 意见逐一修复。
修复详情
1.
kb_permissions.py—wrap()返回None时静默降级,难以诊断配置错误2.
knowledge_service.py— extension 运行时异常会中断整个 KB 列表查询3.
test_kb_permission_resolver.py— tautological 测试(mock 了函数再断言 mock 返回值)原测试 patch 了
_create_resolver然后直接调用 mock,永远通过,完全没有覆盖真实逻辑。4.
test_kb_permission_resolver.py— 死赋值被side_effect立即覆盖5.
test_kb_permission_resolver.py— 未使用变量role触发 Ruff RUF059Test Plan
uv run pytest tests/services/readers/test_kb_permission_resolver.py— 10 passeduv run black --check— 全量通过uv run isort --check— 全量通过