Skip to content

refactor(tests): 测试目录结构性熵减 — 正交分解 + 共享模式提取 - #551

Merged
ThreeFish-AI merged 2 commits into
feature/1.x.xfrom
ThreeFish-AI/istanbul-v4
May 16, 2026
Merged

refactor(tests): 测试目录结构性熵减 — 正交分解 + 共享模式提取#551
ThreeFish-AI merged 2 commits into
feature/1.x.xfrom
ThreeFish-AI/istanbul-v4

Conversation

@ThreeFish-AI

Copy link
Copy Markdown
Owner

背景

  • 本次变更要解决的问题:apps/negentropy/tests 目录中 4 个超大单体测试文件(1,369 / 876 / 840 / 1,403 行)将多个正交概念揉在一起,违反职责单一原则;test_extraction_provider.py 内联了 16 处相同的 FakeClient 类和 50 处重复 monkeypatch.setattr 调用,代码冗余严重。
  • 关联上下文/Issue/文档:Preening Substrate — tests 模块结构性熵减

核心变更

  • 共享模式提取:在 knowledge/conftest.py 新增 FakeMcpClient 参数化工厂 + FakeTextItem / FakeImageContent 辅助类 + patch_extraction_deps 辅助函数,消除 test_extraction_provider.py 中 16 处内联 FakeClient 重复定义和 50 处 monkeypatch 重复调用(1,403 → 1,248 行,-11%)
  • 正交拆分 consolidationtest_consolidation_pipeline.py(1,369 行,10 个 Test 类)→ consolidation/ 子目录 9 个独立文件,共享 _RecordingStep / _new_ctx() 收敛至 conftest
  • 正交拆分 entitytest_kg_entity_service_unit.py(876 行,4 个 Test 类)→ entity/ 子目录 6 个独立文件
  • 正交拆分 graphtest_graph_service.py(840 行)→ graph/ 子目录 5 个独立文件,按 CRUD / build+cancel / result types 三个正交维度分解

风险与回滚

  • 主要风险:纯结构性重构,无功能逻辑变更。所有测试逻辑和断言保持原样。
  • 回滚方式:Git revert 即可完整回滚。

验证证据

  • 单元测试:全量回归 1,661 个测试通过(uv run pytest tests/unit_tests/ -x -q
  • 集成测试:N/A(本次仅涉及单元测试结构重组)
  • E2E/Workflow:N/A
  • 覆盖率/关键截图:覆盖率 55.35% 达标(阈值 50%)

影响范围

  • 前端:无
  • 后端:apps/negentropy/tests/unit_tests/ — 26 个文件变更(+3,077 / -3,502),净减 425 行
  • GitHub Actions / 文档:无

Next Best Action

  • test_extraction_provider.py(1,248 行)进一步拆分为 extraction/ 子目录
  • 测试函数语义规范化:去除 test_negentropy_perceives_provider_ 冗长前缀
  • 其他超大文件(test_source_tracking.py 764 行、test_catalog_dao_unit.py 540 行)的后续清减

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
ThreeFish-AI merged commit 395c4b3 into feature/1.x.x May 16, 2026
7 checks passed
@ThreeFish-AI
ThreeFish-AI deleted the ThreeFish-AI/istanbul-v4 branch May 17, 2026 06:02
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant