fix(ai): 修 ruff lint 三处错误——CI 由红转绿
CI / ai-gates (push) Successful in 31s

`4762358` 与 `86d63ab` 两次 CI 均因 `ruff check` 失败而红。

**根因是我的门禁自查方法错了**:用 `ruff check . | tail -1; echo $?` 读到的是
`tail` 的退出码而不是 ruff 的,于是把一次真实的 lint 失败读成了通过——先前声称
的「四道门禁全绿」是基于这个坏掉的检查得出的。已在 ci.yml 的 Gates 步骤就地注明
此坑,并改为逐条分开跑读各自退出码。

三处都是实际问题,非误报:
- `client.py:138` PYI034:`__enter__` 的返回注解硬编码为类名,应为 `Self`
  (子类化后注解会失准)
- `test_video.py:58` C408:`dict()` 调用改字面量
- `test_layering.py:85` PIE810:两次 `endswith` 合并为一次元组调用

修复后在与 CI 同构的隔离 venv(同镜像源、同 requirements-dev.txt,实测 ruff
版本与本地一致 0.16.8)逐道复验:secret-scan / format / lint / pytest 四道
退出码均为 0,100 测试全过。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-20 12:36:17 +08:00
parent 86d63ab1cb
commit db87d66403
4 changed files with 13 additions and 9 deletions
+4
View File
@@ -51,6 +51,10 @@ jobs:
if [ -f requirements.txt ]; then pip install -q -r requirements.txt; fi if [ -f requirements.txt ]; then pip install -q -r requirements.txt; fi
# 与本地门禁同一套命令。ruff 兼任 format 检查与 lint, # 与本地门禁同一套命令。ruff 兼任 format 检查与 lint,
# 对应 patbond-flutter 的 dart format + flutter analyze 两步。 # 对应 patbond-flutter 的 dart format + flutter analyze 两步。
#
# 本地自查时注意:`ruff check . | tail -1; echo $?` 读到的是 **tail** 的
# 退出码,不是 ruff 的——这样会把一次真实的 lint 失败读成通过(本仓已因此
# 红过一次)。逐条分开跑,或用 ${PIPESTATUS[0]}。
- name: Gates - name: Gates
run: | run: |
python --version python --version
+2 -2
View File
@@ -12,7 +12,7 @@ client,而不是各自再抄一遍鉴权与错误解包——这是把它单
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any from typing import Any, Self
import httpx import httpx
@@ -135,7 +135,7 @@ class ArkClient:
if self._owns_client: if self._owns_client:
self._client.close() self._client.close()
def __enter__(self) -> ArkClient: def __enter__(self) -> Self:
return self return self
def __exit__(self, *exc_info: object) -> None: def __exit__(self, *exc_info: object) -> None:
+6 -6
View File
@@ -55,12 +55,12 @@ def provider_with(handler, **kwargs) -> SeedanceVideoProvider:
def video_request(**kwargs) -> GenerationRequest: def video_request(**kwargs) -> GenerationRequest:
defaults = dict( defaults = {
job_id="job-1", "job_id": "job-1",
media_kind=MediaKind.VIDEO, "media_kind": MediaKind.VIDEO,
model="doubao-seedance-x", "model": "doubao-seedance-x",
prompt="一只猫", "prompt": "一只猫",
) }
return GenerationRequest(**{**defaults, **kwargs}) return GenerationRequest(**{**defaults, **kwargs})
+1 -1
View File
@@ -82,7 +82,7 @@ class TestTransportStaysBusinessAgnostic:
offenders = { offenders = {
name name
for name in imports_of(APP / "providers" / "volcengine" / "client.py") for name in imports_of(APP / "providers" / "volcengine" / "client.py")
if name.endswith((".video", ".image")) or name.endswith("models") if name.endswith((".video", ".image", "models"))
} }
assert not offenders, f"传输层不应依赖具体业务模块:{offenders}" assert not offenders, f"传输层不应依赖具体业务模块:{offenders}"