From 5e14615dceff274fbbf1081423e81235abc4b9f9 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 16 Oct 2026 15:49:36 +0800 Subject: [PATCH] refactor(types): govern raw plugin metadata mappings --- app/runtime/extensions/plugin/metadata.py | 8 ++++---- docs/code-quality.md | 2 +- docs/refactor/optimization-checklist.md | 2 +- mypy.ini | 1 + tests/fixtures/architecture/mypy-baseline.json | 3 --- tests/test_plugin_catalog_runtime.py | 7 +++++++ tests/test_plugin_catalog_service.py | 1 + 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/runtime/extensions/plugin/metadata.py b/app/runtime/extensions/plugin/metadata.py index 454ffb790..aed2c48f7 100644 --- a/app/runtime/extensions/plugin/metadata.py +++ b/app/runtime/extensions/plugin/metadata.py @@ -17,10 +17,10 @@ class PluginMetadataMapper: *, plugin_instance: Callable[[str], Optional[Any]], plugin_class: Callable[[str], Optional[Any]], - annotate_system_version: Callable[[dict], dict], + annotate_system_version: Callable[[dict[str, object]], dict[str, object]], annotate_runtime_compatibility: Callable[[dict[str, Any]], dict[str, Any]], - is_package_compatible: Callable[[dict, str], bool], - auth_checker: Callable[[Plugin, dict], bool], + is_package_compatible: Callable[[dict[str, object], str], bool], + auth_checker: Callable[[Plugin, dict[str, object]], bool], version_compare: Callable[[str, str, str], bool], log: Any, ) -> None: @@ -37,7 +37,7 @@ class PluginMetadataMapper: def map( self, plugin_id: str, - plugin_info: dict, + plugin_info: dict[str, object], market: str, installed_plugins: list[str], add_time: int, diff --git a/docs/code-quality.md b/docs/code-quality.md index 93de36992..d8b8248b2 100644 --- a/docs/code-quality.md +++ b/docs/code-quality.md @@ -75,7 +75,7 @@ uv run --locked --no-sync python scripts/architecture/complexity.py 回调和返回值类型;全仓错误计数为零并不保证单独纳入 strict frontier 后也为零。 2026-10-16 开始逐文件清理类型债务,`app/domain/title.py` 通过局部可空类型声明保留 -既有搜索解析行为,并纳入严格清单;当前清单共 76 个文件(75 个生产文件和 1 个脚本)。 +既有搜索解析行为,并纳入严格清单;当前清单共 77 个文件(76 个生产文件和 1 个脚本)。 每个治理提交聚焦一个生产文件及其必要测试、门禁配置、真实下降基线和指标文档。 验收同时检查完整严格清单与全宿主 Linux 分析,避免 `follow_imports = skip` 隐藏依赖 签名冲突;不通过忽略诊断或放宽类型合同接受回退。最新文件清单以 `mypy.ini` 为准, diff --git a/docs/refactor/optimization-checklist.md b/docs/refactor/optimization-checklist.md index 27caee7aa..0065120a2 100644 --- a/docs/refactor/optimization-checklist.md +++ b/docs/refactor/optimization-checklist.md @@ -108,7 +108,7 @@ ARCH-201 至 ARCH-204 均达到实现、验证、提交、推送和远端门禁 | Event Contract | 53 | 均已有 payload model,但当前全部是 diagnostic enforcement | | Python 源码量 | 372,178 行 | 本次重新扫描物理行数,排除 `app/plugins/**`;74 个文件超过 1,000 行,12 个超过 2,000 行;源码尺寸仅作观察 | | 长方法 | 309 个超过 80 行 | 本次 AST 扫描排除 `app/plugins/**`;61 个超过 150 行,17 个超过 250 行;新增函数仍受 C901/嵌套深度门禁约束 | -| 全量 mypy 历史债务 | 8,942 / 476 文件 | 通知排版补齐 Slack 消息块类型,历史债务减少 2 项;工作流资源过滤改用领域对象调用过滤链,恢复的节点输出在消费前归一化,并收紧可空资源列表的类型低水位;消息媒体交互类型债务已清零,canonical Facade 与 endpoint 类型边界已补齐,低水位只允许继续下降;微信 ClawBot 入站 item_list 媒体解析改为按子项键名分派后,类型错误减少 4 项;站点解析器分享率改用浮点初值,类型错误减少 20 项;本次下载与文件安全修复再减少 3 项;Transmission 进度回退值归一化再减少 2 项,逐文件逐错误码无增长 | +| 全量 mypy 历史债务 | 8,938 / 475 文件 | 通知排版补齐 Slack 消息块类型,历史债务减少 2 项;工作流资源过滤改用领域对象调用过滤链,恢复的节点输出在消费前归一化,并收紧可空资源列表的类型低水位;消息媒体交互类型债务已清零,canonical Facade 与 endpoint 类型边界已补齐,低水位只允许继续下降;微信 ClawBot 入站 item_list 媒体解析改为按子项键名分派后,类型错误减少 4 项;站点解析器分享率改用浮点初值,类型错误减少 20 项;本次下载与文件安全修复再减少 3 项;Transmission 进度回退值归一化再减少 2 项,逐文件逐错误码无增长 | | Ruff 历史诊断 | 100 | 低水位门禁通过,但规则集只覆盖 `E4/E7/E9/F/I` | | 覆盖率固定基线 | Application 80.00%,Domain 80.00% | Chain、Runtime、Agent、Adapter、Startup 未进入包级覆盖率门禁 | diff --git a/mypy.ini b/mypy.ini index 84aea078f..a897ce475 100644 --- a/mypy.ini +++ b/mypy.ini @@ -49,6 +49,7 @@ files = app/runtime/extensions/plugin/admission.py, app/runtime/extensions/plugin/clone.py, app/runtime/extensions/plugin/lifecycle.py, + app/runtime/extensions/plugin/metadata.py, app/runtime/extensions/plugin/storage.py, app/runtime/extensions/service.py, app/runtime/compat/diagnostics.py, diff --git a/tests/fixtures/architecture/mypy-baseline.json b/tests/fixtures/architecture/mypy-baseline.json index 20c30fa52..69fa0dd70 100644 --- a/tests/fixtures/architecture/mypy-baseline.json +++ b/tests/fixtures/architecture/mypy-baseline.json @@ -2404,9 +2404,6 @@ "no-untyped-def": 11, "type-arg": 10 }, - "app/runtime/extensions/plugin/metadata.py": { - "type-arg": 4 - }, "app/runtime/extensions/plugin/monitor.py": { "index": 1, "type-arg": 3 diff --git a/tests/test_plugin_catalog_runtime.py b/tests/test_plugin_catalog_runtime.py index 5a7b9cfc9..bfcf6bcf7 100644 --- a/tests/test_plugin_catalog_runtime.py +++ b/tests/test_plugin_catalog_runtime.py @@ -51,7 +51,9 @@ async def test_async_online_normalizes_market_configuration(monkeypatch) -> None requested_markets: list[str] = [] class FakeMarketCatalog: + """记录真实目录入口请求的市场列表,替代外部市场访问。""" async def async_collect(self, **kwargs): + """捕获规范化后的市场参数并返回空目录。""" requested_markets.extend(kwargs["markets"]) return [] @@ -93,6 +95,7 @@ async def test_async_online_normalizes_market_configuration(monkeypatch) -> None def test_installed_catalog_keeps_plugins_that_are_not_loaded(): """已安装清单中的插件即使缺依赖或源码也必须保留可观察卡片。""" class ActivePlugin: + """提供已加载插件元数据,与缺依赖和缺源码的占位条目对照。""" plugin_name = "已运行插件" plugin_version = "1.0.0" plugin_order = 0 @@ -148,6 +151,7 @@ def test_local_repository_failure_does_not_break_catalog_projection(): warnings: list[str] = [] def local_candidates(): + """模拟本地仓损坏,使目录验证异常隔离与显式抛错两种入口。""" raise RuntimeError("invalid local package") facade = PluginCatalogFacade( @@ -189,6 +193,7 @@ def test_local_projects_effective_log_level_for_virtual_instance( set_plugin_instance_log_level("CatalogOverlayVirtual", "DEBUG") class DemoPlugin: + """为虚拟实例的日志等级覆盖提供最小源插件元数据。""" plugin_name = "Demo" plugin_order = 0 @@ -214,6 +219,7 @@ def test_local_reports_no_log_override_when_instance_follows_global_level( ): """没有覆盖的分身实例不应带任何日志等级徽标信息。""" class DemoPlugin: + """为沿用全局日志等级的虚拟实例提供最小源插件元数据。""" plugin_name = "Demo" plugin_order = 0 @@ -245,6 +251,7 @@ def test_local_projects_effective_log_level_for_physical_plugin( set_plugin_instance_log_level("CatalogOverlayHost", "WARNING") class DemoPlugin: + """为物理插件日志等级覆盖提供最小插件元数据。""" plugin_name = "Demo" plugin_order = 0 diff --git a/tests/test_plugin_catalog_service.py b/tests/test_plugin_catalog_service.py index c1f7b09f3..644e862ca 100644 --- a/tests/test_plugin_catalog_service.py +++ b/tests/test_plugin_catalog_service.py @@ -201,6 +201,7 @@ async def test_async_collect_preserves_each_repository_update_candidate(): service = _service() async def loader(market: str, package_version: str | None, _force: bool): + """按仓库返回不同版本,验证来源保留模式不会提前跨仓去重。""" if package_version is None: return [] version = "2.0.0" if market == "https://market-bound" else "3.0.0"