From db87d6640338535fc75686c8d6ecb537ddbdcf5a Mon Sep 17 00:00:00 2001 From: Lixi20 Date: Sun, 20 Sep 2026 12:36:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(ai):=20=E4=BF=AE=20ruff=20lint=20=E4=B8=89?= =?UTF-8?q?=E5=A4=84=E9=94=99=E8=AF=AF=E2=80=94=E2=80=94CI=20=E7=94=B1?= =?UTF-8?q?=E7=BA=A2=E8=BD=AC=E7=BB=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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) --- .gitea/workflows/ci.yml | 4 ++++ app/providers/volcengine/client.py | 4 ++-- tests/providers/volcengine/test_video.py | 12 ++++++------ tests/test_layering.py | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index fc3176d..6b29e1a 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -51,6 +51,10 @@ jobs: if [ -f requirements.txt ]; then pip install -q -r requirements.txt; fi # 与本地门禁同一套命令。ruff 兼任 format 检查与 lint, # 对应 patbond-flutter 的 dart format + flutter analyze 两步。 + # + # 本地自查时注意:`ruff check . | tail -1; echo $?` 读到的是 **tail** 的 + # 退出码,不是 ruff 的——这样会把一次真实的 lint 失败读成通过(本仓已因此 + # 红过一次)。逐条分开跑,或用 ${PIPESTATUS[0]}。 - name: Gates run: | python --version diff --git a/app/providers/volcengine/client.py b/app/providers/volcengine/client.py index 82402f9..02c27e4 100644 --- a/app/providers/volcengine/client.py +++ b/app/providers/volcengine/client.py @@ -12,7 +12,7 @@ client,而不是各自再抄一遍鉴权与错误解包——这是把它单 from __future__ import annotations import logging -from typing import Any +from typing import Any, Self import httpx @@ -135,7 +135,7 @@ class ArkClient: if self._owns_client: self._client.close() - def __enter__(self) -> ArkClient: + def __enter__(self) -> Self: return self def __exit__(self, *exc_info: object) -> None: diff --git a/tests/providers/volcengine/test_video.py b/tests/providers/volcengine/test_video.py index ce286eb..439a756 100644 --- a/tests/providers/volcengine/test_video.py +++ b/tests/providers/volcengine/test_video.py @@ -55,12 +55,12 @@ def provider_with(handler, **kwargs) -> SeedanceVideoProvider: def video_request(**kwargs) -> GenerationRequest: - defaults = dict( - job_id="job-1", - media_kind=MediaKind.VIDEO, - model="doubao-seedance-x", - prompt="一只猫", - ) + defaults = { + "job_id": "job-1", + "media_kind": MediaKind.VIDEO, + "model": "doubao-seedance-x", + "prompt": "一只猫", + } return GenerationRequest(**{**defaults, **kwargs}) diff --git a/tests/test_layering.py b/tests/test_layering.py index 8c76e29..f86ad9e 100644 --- a/tests/test_layering.py +++ b/tests/test_layering.py @@ -82,7 +82,7 @@ class TestTransportStaysBusinessAgnostic: offenders = { name 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}"