docs(plan): 去注解引号 + Task7 lint 只查改动文件(基线558既有ruff错)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
guke
2026-07-06 11:16:00 +08:00
parent 9354588ba2
commit 822c2ca2a6
@@ -179,12 +179,12 @@ from app.core.config import settings
# 有界事件队列(懒创建,见 get_queue):首次取用时在运行中的 loop 里建,避免 import 期
# 无 loop 的边角问题;put_nowait/get_nowait 不需运行中的 loop → 可在无 loop 下测试。
_queue: "asyncio.Queue[dict] | None" = None
_queue: asyncio.Queue[dict] | None = None
# 队列满时的丢弃计数,worker 定期取出打日志。
_dropped = 0
def get_queue() -> "asyncio.Queue[dict]":
def get_queue() -> asyncio.Queue[dict]:
"""返回全局有界事件队列(懒创建)。测试可 monkeypatch 模块级 _queue 换成小队列。"""
global _queue
if _queue is None:
@@ -512,7 +512,7 @@ from app.core.observe import get_queue, take_dropped
logger = logging.getLogger("shagua.observe")
# 上报用的 httpx client,start 时建、stop 时关。
_client: "httpx.AsyncClient | None" = None
_client: httpx.AsyncClient | None = None
async def _collect_batch() -> list[dict]:
@@ -568,7 +568,7 @@ async def _run_loop(client: httpx.AsyncClient) -> None:
raise
def start_observe_worker() -> "asyncio.Task | None":
def start_observe_worker() -> asyncio.Task | None:
"""启动上报 worker。未配置观测 → 返回 None(no-op)。"""
global _client
if not settings.observe_configured:
@@ -587,7 +587,7 @@ def start_observe_worker() -> "asyncio.Task | None":
return asyncio.create_task(_run_loop(_client), name="observe-worker")
async def stop_observe_worker(task: "asyncio.Task | None") -> None:
async def stop_observe_worker(task: asyncio.Task | None) -> None:
"""收尾:cancel worker → best-effort 发最后一批 → 关 client。"""
global _client
if task is None:
@@ -866,10 +866,13 @@ Expected: 稍等 ≤5sflush 间隔),OpenObserve UI 的 Logs → `app_requ
在 OpenObserve UI 分别粘贴 README 里的 QPS / P95 / 错误率 SQL,确认能出数。
- [ ] **Step 5: 全量 lint + 测试**
- [ ] **Step 5: lint(仅本改动涉及文件)+ 全量测试**
Run: `ruff check . && pytest -q`
Expected: ruff 无错;测试全 PASS
> 说明:仓库基线有 ~558 个既有 ruff 错误、且未强制 ruff 通过。不要去清历史欠债(范围蔓延)。只要求**本次新增/改动的文件**零 ruff 错误。
Run: `ruff check app/core/observe.py app/core/observe_worker.py tests/test_observe.py && python -m pytest -q`
Expected: 上述三个新文件 ruff 无错;测试里 `tests/test_observe.py` 全 PASS,且**全量失败数不超过基线的 4 个**(test_compare_proxy ×2 / test_coupon_proxy ×1 / test_invite ×1,均与本功能无关)。
额外确认我对既有文件的改动没有引入**新的** ruff 错误:`ruff check app/core/config.py app/main.py`(数量应与基线一致,不因本改动增加)。
- [ ] **Step 6: 关观测复跑一次,确认降级**