refactor(tests): 测试目录结构性熵减 — 正交分解 + 共享模式提取 - #551
Merged
Conversation
1. conftest.py 新增 FakeMcpClient 工厂、FakeTextItem/FakeImageContent 辅助类 及 patch_extraction_deps 辅助函数,消除 test_extraction_provider.py 中 16 处内联 FakeClient 重复定义和 50 处 monkeypatch 重复调用; 2. test_extraction_provider.py 1,403→1,248 行(净减 155 行,-11%); 3. test_consolidation_pipeline.py 1,369 行单体文件按 10 个 Test 类正交分解为 consolidation/ 子目录下 9 个独立文件(conftest + 8 个测试文件), 每个文件职责单一、边界清晰; 4. 全量回归 1,661 测试通过,无破坏性变更。 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
1. test_kg_entity_service_unit.py (876 行) → entity/ 子目录 6 文件: 按 4 个 Test 类正交分解为 test_sync_entity / test_sync_relation / test_batch_sync / test_get_top_entities + conftest; 2. test_graph_service.py (840 行) → graph/ 子目录 5 文件: 按 CRUD / build+cancel / result types 三个正交维度分解, 共享 Fake Repository 和 patch helper 收敛至 conftest; 3. 全量回归 1,661 测试通过,无破坏性变更。 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
ThreeFish-AI
added a commit
that referenced
this pull request
May 17, 2026
…为权威实现收敛 123 处冲突; - 基准 merge-base: bc6f173(chore(merge): 回流 master c0bb18f) - master-only commits(均为 feature/1.x.x 演进的子集回流): * 94a709e release(feature/1.x.x): #462 Memory P1-7 + KG P1-5 + Skills P1-2; * a34bf19 Merge branch 'feature/1.x.x'; * 8de1089 chore(release): 同步 PR #417/#418 至 master; - 策略: -X ours 解析 123 处冲突 + checkout HEAD 复原 9 处 auto-merge(消除 instrumentation.py 等重复定义); - 残留治理: * git rm: docs/issue.md(已迁至 docs/agents/issue.md)+ 2 个测试单文件(已被 #551 正交分解)+ test_consolidation_pipeline.py(已被 #551 拆分至 consolidation/); * git rm: 5 个调试截图(master 端 #462 squash 误回 + #4e10a54e 已声明移除); - 合并后工作树与 feature/1.x.x HEAD 完全一致(git diff HEAD → 空),merge commit 仅记录拓扑; 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
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.
背景
apps/negentropy/tests目录中 4 个超大单体测试文件(1,369 / 876 / 840 / 1,403 行)将多个正交概念揉在一起,违反职责单一原则;test_extraction_provider.py内联了 16 处相同的FakeClient类和 50 处重复monkeypatch.setattr调用,代码冗余严重。核心变更
knowledge/conftest.py新增FakeMcpClient参数化工厂 +FakeTextItem/FakeImageContent辅助类 +patch_extraction_deps辅助函数,消除test_extraction_provider.py中 16 处内联FakeClient重复定义和 50 处monkeypatch重复调用(1,403 → 1,248 行,-11%)test_consolidation_pipeline.py(1,369 行,10 个 Test 类)→consolidation/子目录 9 个独立文件,共享_RecordingStep/_new_ctx()收敛至 conftesttest_kg_entity_service_unit.py(876 行,4 个 Test 类)→entity/子目录 6 个独立文件test_graph_service.py(840 行)→graph/子目录 5 个独立文件,按 CRUD / build+cancel / result types 三个正交维度分解风险与回滚
验证证据
uv run pytest tests/unit_tests/ -x -q)影响范围
apps/negentropy/tests/unit_tests/— 26 个文件变更(+3,077 / -3,502),净减 425 行Next Best Action
test_extraction_provider.py(1,248 行)进一步拆分为extraction/子目录test_negentropy_perceives_provider_冗长前缀test_source_tracking.py764 行、test_catalog_dao_unit.py540 行)的后续清减