diff --git a/app/adapters/web/correlation.py b/app/adapters/web/correlation.py index 76a74be26..7d6afc715 100644 --- a/app/adapters/web/correlation.py +++ b/app/adapters/web/correlation.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import Any +from starlette.types import ASGIApp, Message, Receive, Scope, Send from app.runtime.correlation import ( CORRELATION_ID_HEADER, @@ -14,11 +14,11 @@ from app.runtime.correlation import ( class CorrelationIdMiddleware: """验证入口 ID、绑定请求上下文并把同一 ID 写回响应。""" - def __init__(self, app: Any) -> None: + def __init__(self, app: ASGIApp) -> None: """保存下游 ASGI 应用。""" self._app = app - async def __call__(self, scope: dict, receive: Any, send: Any) -> None: + async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: """只治理 HTTP scope,并让绑定覆盖完整流式响应生命周期。""" if scope.get("type") != "http": await self._app(scope, receive, send) @@ -30,7 +30,7 @@ class CorrelationIdMiddleware: ) scope.setdefault("state", {})["request_id"] = correlation_id - async def send_with_correlation(message: dict) -> None: + async def send_with_correlation(message: Message) -> None: """在响应开始帧中覆盖为当前请求的安全关联 ID。""" if message.get("type") == "http.response.start": headers = list(message.get("headers") or []) diff --git a/docs/code-quality.md b/docs/code-quality.md index e285c2eab..3670ffc64 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` 通过局部可空类型声明保留 -既有搜索解析行为,并纳入严格清单;当前清单共 49 个文件(48 个生产文件和 1 个脚本)。 +既有搜索解析行为,并纳入严格清单;当前清单共 50 个文件(49 个生产文件和 1 个脚本)。 每个治理提交只修改一个生产文件及其必要测试、门禁配置、真实下降基线和指标文档。 验收同时检查完整严格清单与全宿主 Linux 分析,避免 `follow_imports = skip` 隐藏依赖 签名冲突;不通过忽略诊断或放宽类型合同接受回退。最新文件清单以 `mypy.ini` 为准, diff --git a/docs/refactor/optimization-checklist.md b/docs/refactor/optimization-checklist.md index f3f30f87b..64bb0664b 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 源码量 | 371,923 行 | 本次重新扫描物理行数,排除 `app/plugins/**`;74 个文件超过 1,000 行,12 个超过 2,000 行;源码尺寸仅作观察 | | 长方法 | 309 个超过 80 行 | 本次 AST 扫描排除 `app/plugins/**`;61 个超过 150 行,17 个超过 250 行;新增函数仍受 C901/嵌套深度门禁约束 | -| 全量 mypy 历史债务 | 9,117 / 504 文件 | 通知排版补齐 Slack 消息块类型,历史债务减少 2 项;工作流资源过滤改用领域对象调用过滤链,恢复的节点输出在消费前归一化,并收紧可空资源列表的类型低水位;消息媒体交互类型债务已清零,canonical Facade 与 endpoint 类型边界已补齐,低水位只允许继续下降;微信 ClawBot 入站 item_list 媒体解析改为按子项键名分派后,类型错误减少 4 项;站点解析器分享率改用浮点初值,类型错误减少 20 项;本次下载与文件安全修复再减少 3 项,逐文件逐错误码无增长 | +| 全量 mypy 历史债务 | 9,115 / 503 文件 | 通知排版补齐 Slack 消息块类型,历史债务减少 2 项;工作流资源过滤改用领域对象调用过滤链,恢复的节点输出在消费前归一化,并收紧可空资源列表的类型低水位;消息媒体交互类型债务已清零,canonical Facade 与 endpoint 类型边界已补齐,低水位只允许继续下降;微信 ClawBot 入站 item_list 媒体解析改为按子项键名分派后,类型错误减少 4 项;站点解析器分享率改用浮点初值,类型错误减少 20 项;本次下载与文件安全修复再减少 3 项,逐文件逐错误码无增长 | | 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 c6e666cbe..b02e601d4 100644 --- a/mypy.ini +++ b/mypy.ini @@ -15,6 +15,7 @@ files = app/domain/meta/infopath.py, app/foundation/url.py, app/adapters/network/cloudflare.py, + app/adapters/web/correlation.py, app/runtime/correlation.py, app/runtime/coalesce.py, app/runtime/log.py, diff --git a/tests/fixtures/architecture/mypy-baseline.json b/tests/fixtures/architecture/mypy-baseline.json index 8db81097f..eafebf3bb 100644 --- a/tests/fixtures/architecture/mypy-baseline.json +++ b/tests/fixtures/architecture/mypy-baseline.json @@ -104,9 +104,6 @@ "app/adapters/system/stdio.py": { "override": 1 }, - "app/adapters/web/correlation.py": { - "type-arg": 2 - }, "app/adapters/web/metrics.py": { "no-any-return": 1, "type-arg": 3,