refactor(chain): P2 结构治理 — 拆 ChainBase 上帝基类为 6 域内聚 Mixin(审计 #16) - #96
Merged
Conversation
按域将 ChainBase 的 88 个方法拆入 6 个 in-file Mixin 类(缓存/识别/搜索/下载转移/ 通知/元数据分类),ChainBase 继承之;__init__ 与 12 个 name-mangling 分发内核方法 (__execute_*/__handle_*/__*_entries/__is_valid_empty/run_module/async_run_module) 保留本类(mangling 簇与调用方须同类,不可拆)。28 子类 + 市场插件零改动:公共 API、 from app.chain import ChainBase 导入路径、方法名/签名全不变。 选 in-file 而非分文件:测试有 ~21 处直接 patch chain 模块命名空间的协作者 (app.chain.MoviePilotServerHelper/MessageTemplateHelper),分文件会使这些 mock 注入点失效需逐一重定向;in-file 让模块级符号留原命名空间→零测试改动、零 patch 失效。 验证:88 方法体与重构前逐字节一致(纯移动);方法集经 name-mangling 改写后等价 (88=88,零丢失/新增);全量 1970 passed/19 skipped(=基线);ruff 净;无 __dict__/vars/__mro__ 内省依赖;对抗审查无新回归 —— 行为保持。
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.
背景
P2 结构治理续作(PR #95 拆分 message.py 上帝文件后),处理审计 §6 路线图旗舰项 #16 拆 ChainBase 上帝基类。
变更
app/chain/__init__.py的ChainBase(1827 行 / 88 方法)按域拆为 6 个 in-file Mixin:_CacheChainMixin_RecognizeMediaChainMixin_SearchChainMixin_DownloadTransferChainMixin_NotificationChainMixin_MetadataCategoryChainMixinclass ChainBase(<6 Mixin>, metaclass=ABCMeta)继承之;__init__与 12 个 name-mangling 分发内核方法(__execute_*/__handle_*/__*_entries/__is_valid_empty/run_module/async_run_module)保留本类——name-mangling 簇须与调用方同类,不可跨类拆分。为何 in-file 而非分文件
测试有 ~21 处
patch("app.chain.MoviePilotServerHelper…" / "app.chain.MessageTemplateHelper…")直接 patch chain 模块命名空间的协作者。分文件会使这些 mock 注入点失效(符号查找移到子模块),须逐一重定向、churn 大、易错。in-file Mixin 让模块级符号留原命名空间 → 零测试改动、零 patch 失效,同时完成上帝类按域内聚拆分(审计 #16 核心诉求)。行为保持证明
pytestruff F401__dict__/vars/__mro__内省依赖28 子类 + 插件
公共 API、
from app.chain import ChainBase导入路径、方法名/签名全不变;27 个子类 +PluginChian(ChainBase)零改动。P2 剩余