refactor(chain): P2 结构治理 — 拆分 message.py 上帝文件,MediaInteractionChain 独立成模块(审计 #61) - #95
Merged
Merged
Conversation
…立成模块(审计 #61) 将 MediaInteractionChain(1461 行)从 app/chain/message.py 抽出为新模块 app/chain/media_interaction.py,类体逐字节不变(纯移动)。message.py 由 3369 行降至 1900 行(<2000 行上帝文件阈值),ruff F401 核验删除随类移出后不再使用的 17 个 import;经再导出保持 from app.chain.message import MediaInteractionChain 对外导入路径不变,并供 MessageChain 内部实例化。 tests/test_media_interaction.py:7 处 mock patch 目标从 app.chain.message 重定向 至 app.chain.media_interaction(DirectoryHelper/DownloadChain 协作者随类迁移, mock 须打在名字被查找的模块)。 验证:全量 1970 passed/19 skipped(与基线一致);MediaInteractionChain 类体与 MessageChain 体均逐字节不变;ruff 净;3 维度对抗审查 0 新回归 —— 行为保持。 P2 其余项:#60 双轨已于 2cc5ccf6 完成;#16 拆 ChainBase(可行为保持但需重排 ~1300 行核心基类、28 子类依赖,diff 大)按分析建议留独立 PR;#9 拆 Scheduler/ Monitor 与 #38 扩展点登记表存在无法行为保持的特例,本轮不做。
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.
背景
延续 P0(安全加固,PR #93)、P1(架构债)之后,处理
docs/architecture-audit-v3python.md§6 路线图的 P2 结构治理。本轮先用多 agent workflow(5 个 ecc:code-architect 并行精读,约 33 万 token)对 5 个 P2 项逐项评估「当前状态 / 是否已完成 / 能否行为保持 / 风险」,再据证据确定唯一可安全落地的子集,避免审计自身反复警示的「最该警惕的是优化本身」。
本 PR 范围:审计 #61 —— 拆分 message.py 上帝文件
app/chain/message.py原 3369 行,含两个独立的ChainBase子类。将其中MediaInteractionChain(1461 行)抽出为新模块app/chain/media_interaction.py:diff对原 message.py:1909-3369 验证一致)。message.py3369 → 1900 行(降至 <2000 行上帝文件阈值),ruff F401核验删除随类移出后不再使用的 17 个 import。from app.chain.message import MediaInteractionChain的对外导入路径不变,且供MessageChain内部实例化。tests/test_media_interaction.py:7 处 mock patch 目标从app.chain.message.{DirectoryHelper,DownloadChain}重定向至app.chain.media_interaction.*——协作者随类迁移,mock 必须打在名字被查找的模块。行为保持证明
MediaInteractionChain类体MessageChain类体ruff check --select F401P2 其余项的 scope 决策(证据见 workflow 分析)
_Class__xxx跨类显式 demangle 耦合或单一内聚类,不可安全拆分,逐一 skip2cc5ccf6(分发内核统一)落地,无残留测试计划
pytest:1970 passed / 19 skippedruff静态检查通过