From 31cf08c6cb467098c31cdbb32cd5f83fcceebd1e Mon Sep 17 00:00:00 2001 From: im47cn-bot Date: Wed, 18 Nov 2026 17:09:35 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20commitlint=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=94=B9=20.cjs=EF=BC=8C=E8=A7=84=E9=81=BF=E4=B8=8A=E5=B1=82?= =?UTF-8?q?=20package.json=20type:module=20=E8=AF=AF=E5=88=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .factory/factory-local.json | 4 ++-- .factory/factory_lib.py | 3 +++ .factory/hosting.py | 9 +++++++- .factory/tests/test_factory_lib.py | 10 +++++++++ .factory/tests/test_hosting.py | 22 +++++++++++++++++++ .factory/upstream-lock.json | 4 ++-- commitlint.config.js => commitlint.config.cjs | 0 7 files changed, 47 insertions(+), 5 deletions(-) rename commitlint.config.js => commitlint.config.cjs (100%) diff --git a/.factory/factory-local.json b/.factory/factory-local.json index be9dd18..d4945cf 100644 --- a/.factory/factory-local.json +++ b/.factory/factory-local.json @@ -35,8 +35,8 @@ "review_basis": "CONTRIBUTING.md 规格引用(wop-specs/docs/specs/wop-sdk-spec.md)+ 既有测试形态", "final_gate_cmd": "scripts/run_tests.sh --no-lock", "pr_review_skills": [], - "upstream_repo": "im47cn/awesome-rules", - "upstream_path": "~/sources/awesome-rules", + "upstream_repo": "im47cn/awesome-factory", + "upstream_path": "~/sources/awesome-factory", "port_point": "011d8d8c", "feedback_branch_prefix": "feedback/wop-python-sdk" } diff --git a/.factory/factory_lib.py b/.factory/factory_lib.py index 48a7b87..23929d7 100755 --- a/.factory/factory_lib.py +++ b/.factory/factory_lib.py @@ -1444,6 +1444,9 @@ def main(argv: list[str]) -> int: # 不可读/内容畸形 = 死(SIGKILL 残锁过期同判)。退出码 0=活 1=死 # 2=参数错。PG 形态(SUPABASE_DB)租约在库中,调用方不得用本 # 命令的输出断言死活(保守 unknown)。 + if len(argv) < 3: + print("lease-fresh: 缺锁文件路径参数", file=sys.stderr) + return 2 lock = Path(argv[2]) try: line = lock.read_text(encoding="utf-8").strip().splitlines()[0] diff --git a/.factory/hosting.py b/.factory/hosting.py index cab30b9..cdd540f 100755 --- a/.factory/hosting.py +++ b/.factory/hosting.py @@ -1097,10 +1097,17 @@ def _add_label_lock(self, p, name): time.sleep(0.05) continue break - with contextlib.suppress(OSError): + try: with open(os.path.join(lock_dir, "pid"), "w", encoding="ascii") as fh: fh.write(str(os.getpid())) + except OSError as e: + # 无 pid 残锁会被判陈旧致另一进程接管(双写):释放并拒持锁 + shutil.rmtree(lock_dir, ignore_errors=True) + raise HostingError( + f"add {name}: 锁 pid 写入失败({e}),fail-closed 拒持锁", + code=1, + ) from e try: yield finally: diff --git a/.factory/tests/test_factory_lib.py b/.factory/tests/test_factory_lib.py index b8c0e2f..ef02ae5 100644 --- a/.factory/tests/test_factory_lib.py +++ b/.factory/tests/test_factory_lib.py @@ -621,3 +621,13 @@ def test_multi_suite_roundtrip_read_d(self, capsys): assert raw.endswith("\0") assert raw[:-1].split("\0") == [ "skills/api-guard/scripts", "skills/doc review/scripts"] + + +class TestLeaseFreshArgv: + """lease-fresh 缺锁路径参数 → exit 2(文档承诺 0=活 1=死 2=参数错): + 裸 IndexError 走 exit 1 会被调用方当「锁死」接管活锁(awesome- + rules@80ce34ad 血统既有检查移植;wop-skills#25 审查实证)。""" + + def test_missing_lock_path_returns_2(self, capsys): + assert main(["factory_lib.py", "lease-fresh"]) == 2 + assert "缺锁文件路径参数" in capsys.readouterr().err diff --git a/.factory/tests/test_hosting.py b/.factory/tests/test_hosting.py index 766ef05..a309791 100644 --- a/.factory/tests/test_hosting.py +++ b/.factory/tests/test_hosting.py @@ -1123,6 +1123,28 @@ def test_pidless_crash_dir_reclaimed_after_grace(self, monkeypatch, tmp_path): assert os.path.isdir(lock_dir) assert not os.path.isdir(lock_dir) + def test_pid_write_failure_refuses_lock(self, monkeypatch, tmp_path): + """pid 写失败 → 释放锁目录 + HostingError fail-closed 拒持锁: + 无 pid 裸持锁越过年龄宽限即被他进程判死接管 = 双写,且先者的 + finally 清理会误删后继活锁(awesome-rules@80ce34ad 血统既有 + 保护移植;wop-skills#25 审查以 suppress 形态实证接管窗口)。""" + monkeypatch.setenv("FACTORY_LOCK_DIR", str(tmp_path)) + ad = hosting.CodeupAdapter() + lock_dir = hosting._label_lock_dir(".", 7, "factory:needs-review") + real_open = open + + def flaky_open(path, *a, **k): + if str(path).endswith("/pid"): + raise OSError("模拟写盘失败") + return real_open(path, *a, **k) + + monkeypatch.setattr("builtins.open", flaky_open) + with pytest.raises(hosting.HostingError) as e: + with ad._add_label_lock(7, "factory:needs-review"): + pass + assert e.value.code == 1 + assert not os.path.isdir(lock_dir) # 拒持锁前已释放,不留无 pid 残锁 + def test_parallel_add_posts_exactly_once(self, monkeypatch, tmp_path): """并发回归(核心契约):两独立适配器实例(双进程/双链形态) 同仓同 PR 同名 add 并发——锁串行化 + 后到者锁内重预检幂等跳过, diff --git a/.factory/upstream-lock.json b/.factory/upstream-lock.json index 091dded..562233a 100644 --- a/.factory/upstream-lock.json +++ b/.factory/upstream-lock.json @@ -1,5 +1,5 @@ { - "anchor": "181618c32492fb41f5a2a14f52515449fdc1c9eb", + "anchor": "36a8749c9385dba755ef495e523f6a4358d483f9", "upstream": "/Users/dreambt/sources/awesome-factory", - "synced_at": "2026-11-01T03:45:40+00:00" + "synced_at": "2026-11-09T05:51:11+00:00" } diff --git a/commitlint.config.js b/commitlint.config.cjs similarity index 100% rename from commitlint.config.js rename to commitlint.config.cjs From 04063bfc46dca9e88bedf38613a384962aee4648 Mon Sep 17 00:00:00 2001 From: im47cn-bot Date: Wed, 18 Nov 2026 17:09:39 +0800 Subject: [PATCH 2/4] =?UTF-8?q?ci:=20=E6=8E=A5=E5=85=A5=20ruff=20=E9=9D=99?= =?UTF-8?q?=E6=80=81=E6=A3=80=E6=9F=A5=E5=B9=B6=E6=B8=85=E7=90=86=E6=9C=AA?= =?UTF-8?q?=E7=94=A8=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 14 ++++++++++++++ pyproject.toml | 13 +++++++++++++ src/wop_sdk/config/_loader.py | 2 +- src/wop_sdk/config/_parser.py | 2 +- src/wop_sdk/transport_discovery.py | 2 +- tests/test_bdd.py | 1 - tests/test_config.py | 4 +--- tests/test_config_loading.py | 1 - tests/test_suites.py | 2 +- 9 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8eaed41..4e860cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -149,3 +149,17 @@ jobs: run: pip install griffe==1.14.0 - name: API snapshot gate (regenerate to temp file, git diff --exit-code) run: python3 scripts/check-api-snapshot.py + + # ruff 静态检查(E4/E7/E9/F;配置见 pyproject.toml [tool.ruff],vendored .factory + # 已排除)。版本锁定保证检查集稳定;纯静态、秒级。 + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Install pinned ruff + run: pip install ruff==0.17.3 + - name: ruff check + run: ruff check . diff --git a/pyproject.toml b/pyproject.toml index e118297..b8d37d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,3 +64,16 @@ branch = true [tool.coverage.report] show_missing = true precision = 2 + +[tool.ruff] +target-version = "py39" +line-length = 120 +# .factory:从上游同步的 vendored 工厂副本,不在本仓维护,排除以免同步覆盖与噪声 +extend-exclude = [".factory"] + +[tool.ruff.lint] +# E4/E7/E9/F:语法/未定义名/未用导入变量/重定义等真实错误。 +# E741/E702/E731 是历史代码纯风格(歧义单字母名、分号多语句、lambda 赋值——后者 +# 是模块级公共 API `request_id_generator`,改为 def 会动 griffe API 快照),基线忽略。 +select = ["E4", "E7", "E9", "F"] +ignore = ["E741", "E702", "E731"] diff --git a/src/wop_sdk/config/_loader.py b/src/wop_sdk/config/_loader.py index 2669240..4b222ba 100644 --- a/src/wop_sdk/config/_loader.py +++ b/src/wop_sdk/config/_loader.py @@ -6,7 +6,7 @@ import threading from importlib import resources from pathlib import Path -from typing import Callable, Dict, Optional, Union +from typing import Callable, Dict, Union from ..errors import ConfigurationError from ._models import WopSdkConfig diff --git a/src/wop_sdk/config/_parser.py b/src/wop_sdk/config/_parser.py index 88c25b6..3e68501 100644 --- a/src/wop_sdk/config/_parser.py +++ b/src/wop_sdk/config/_parser.py @@ -4,7 +4,7 @@ import json import math -from typing import Any, Dict, List, Mapping, MutableMapping, Tuple +from typing import Any, Dict, List, Mapping, Tuple from ..errors import ConfigurationError from ._models import DEFAULT_EXPIRED_SECONDS, HttpClientSettings, WopSdkConfig diff --git a/src/wop_sdk/transport_discovery.py b/src/wop_sdk/transport_discovery.py index bf0c04c..2e7dc9e 100644 --- a/src/wop_sdk/transport_discovery.py +++ b/src/wop_sdk/transport_discovery.py @@ -4,7 +4,7 @@ import importlib.util import os -from typing import Dict, List +from typing import Dict, List # noqa: F401 — List 是 wildcard 导出的 API 别名(tests/api_snapshot.json 记录),非内部使用 from .errors import ConfigurationError from .transports import Transport, UrllibTransport diff --git a/tests/test_bdd.py b/tests/test_bdd.py index 26eafcc..535a461 100644 --- a/tests/test_bdd.py +++ b/tests/test_bdd.py @@ -10,7 +10,6 @@ import base64 import hashlib import json -import os import re import pytest diff --git a/tests/test_config.py b/tests/test_config.py index dbd3bf0..a47fd24 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -3,15 +3,13 @@ from __future__ import annotations import json -import os import threading from pathlib import Path -from unittest import mock import pytest from wop_sdk.client import WopClient, WopConfig -from wop_sdk.config import HttpClientSettings, WopSdkConfig, clear_cache, load, load_default +from wop_sdk.config import WopSdkConfig, clear_cache, load, load_default from wop_sdk.config._parser import parse_config_json from wop_sdk.config._validator import join_url, validate_api_path, validate_gateway_url from wop_sdk.errors import ConfigurationError, WopGatewayResponseError diff --git a/tests/test_config_loading.py b/tests/test_config_loading.py index 7a3a008..9287289 100644 --- a/tests/test_config_loading.py +++ b/tests/test_config_loading.py @@ -5,7 +5,6 @@ transport_discovery 59%),PR 新增加载链未带测试。本文件按 term-missing 行号逐段闭合。 """ import json -import sys from pathlib import Path import pytest diff --git a/tests/test_suites.py b/tests/test_suites.py index e008192..f85e9b0 100644 --- a/tests/test_suites.py +++ b/tests/test_suites.py @@ -3,7 +3,7 @@ import pytest from wop_sdk.errors import SuiteParseError, UnsupportedSuiteError -from wop_sdk.suites import Suite, parse_suite +from wop_sdk.suites import parse_suite class TestParsePositive: From 88e3fc2951c39bcc42990a756f39fc87629783af Mon Sep 17 00:00:00 2001 From: im47cn-bot Date: Wed, 18 Nov 2026 17:09:54 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E9=92=A9=E5=AD=90=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=BC=95=E7=94=A8=20commitlint.config.cjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .lefthook/commitmsg-check.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.lefthook/commitmsg-check.sh b/.lefthook/commitmsg-check.sh index 8ec8713..7542878 100644 --- a/.lefthook/commitmsg-check.sh +++ b/.lefthook/commitmsg-check.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # commit message 规范校验(awesome-rules tools/git 分发,由 lefthook 调用) # 用法: bash .lefthook/commitmsg-check.sh -# 单一规则源: commitlint + 项目内 commitlint.config.js;缺 commitlint 时自动安装(一次性)。 +# 单一规则源: commitlint + 项目内 commitlint.config.cjs;缺 commitlint 时自动安装(一次性)。 # 无 node/npm 时提示后放行 —— commit 钩子不阻塞环境问题,只拦规范违规。 set -u MSG_FILE="${1:-}" @@ -34,8 +34,8 @@ if [ -z "$CL" ]; then fi # 规则配置是分发物之一,缺失说明未跑 install.sh -[ -f "$(git rev-parse --show-toplevel)/commitlint.config.js" ] || { - echo "⚠ [commitmsg] 缺 commitlint.config.js,请跑 awesome-rules tools/git/install.sh;本次放行" +[ -f "$(git rev-parse --show-toplevel)/commitlint.config.cjs" ] || { + echo "⚠ [commitmsg] 缺 commitlint.config.cjs,请跑 awesome-rules tools/git/install.sh;本次放行" exit 0 } From 07087f8e57532d57d456ed6009f91974405b0006 Mon Sep 17 00:00:00 2001 From: im47cn-bot Date: Wed, 18 Nov 2026 17:10:15 +0800 Subject: [PATCH 4/4] =?UTF-8?q?chore:=20=E7=89=88=E6=9C=AC=200.2.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b8d37d1..314a003 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "wop-python-sdk" -version = "0.2.0" +version = "0.2.1" description = "WOP 商户侧官方 Python SDK:协议核心(签名/摘要/数字信封/验签解密)+ 可插拔 HTTP 适配层" readme = "README.md" license = { text = "MIT" }