fix(backend): fix CI failures in KB permission resolver PR#23
Merged
cocowh merged 1 commit intoweagent/kb-permission-extensionfrom Apr 23, 2026
Merged
Conversation
- Apply Black formatting to knowledge_service.py (trailing comma style) - Rename kbPermissionResolver to kb_permission_resolver (PEP 8 snake_case) - Fix test mock paths: use importlib.import_module() to obtain the real module object instead of the same-named instance exported by app.services.share.__init__.py, which caused AttributeError when patch() tried to resolve is_organization_namespace and is_restricted_analyst - Update all consumers of kb_permission_resolver (readers/__init__.py, knowledge_service.py, knowledge_share_service.py)
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 存在以下 CI 失败:
1. Lint Backend (Black)
knowledge_service.py中函数调用尾随逗号格式不合规,需要 Black 重排为多行风格。2. Test Backend (3.10 & 3.12) — 根本原因:mock 路径解析歧义
测试使用字符串路径
patch("app.services.share.knowledge_share_service.is_organization_namespace"),Python 的unittest.mock.patch在解析该路径时:app.services.share包getattr(app.services.share, "knowledge_share_service")app/services/share/__init__.py通过from ... import knowledge_share_service将 同名实例 导出到包命名空间,属性查找返回的是KnowledgeShareService()实例,而非模块is_organization_namespace→AttributeError3. 命名规范
kbPermissionResolver使用 camelCase,违反 PEP 8 snake_case 规范。修复内容
knowledge_service.pykb_permissions.pykbPermissionResolver→kb_permission_resolverreaders/__init__.pyknowledge_service.pyknowledge_share_service.pytest_kb_permission_resolver.pyimportlib.import_module()获取真实模块对象替代import ... as的属性遍历方式;改用patch.object(_kss_module, ...)关键修复逻辑:
Test Plan
uv run pytest tests/services/readers/test_kb_permission_resolver.py— 10 passeduv run black --check app/— all 553 files unchangeduv run isort --check app/— pass