From 0b8b807754d5b52e681e7e78a8cd07a6708193dd Mon Sep 17 00:00:00 2001 From: xiaotao Date: Tue, 27 Oct 2026 20:06:17 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(core):=20=E6=94=AF=E6=8C=81=20ISV=20?= =?UTF-8?q?=E5=AD=90=E5=95=86=E6=88=B7=E8=BA=AB=E4=BB=BD=E5=A4=B4=20x-wop-?= =?UTF-8?q?sub-mch-id=20=E5=85=A5=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ISV D-13:build_request/execute 新增 sub_mch_id,签名前写入 x-wop-sub-mch-id 并自动纳入 signedHeaders;不传/空白 = 应用自身身份,头缺席,头集合与签名与旧版逐字节一致(AC-20)。extra_headers 携带该头等价参数,双来源同传即拒。校验:可打印 ASCII、无内部空白、trim 后 ≤128 字符。补 test_submchid.py。 Co-Authored-By: Claude Code --- README.en.md | 22 +++++++ README.md | 18 ++++++ src/wop_sdk/client.py | 59 ++++++++++++++++++- tests/test_submchid.py | 129 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 tests/test_submchid.py diff --git a/README.en.md b/README.en.md index faf65fe..bb4b180 100644 --- a/README.en.md +++ b/README.en.md @@ -52,6 +52,28 @@ else: # integrity / consistency errors are explicit ``` +## ISV Sub-Merchant Identity (ISV D-13) + +When calling business APIs on behalf of a sub-merchant, pass `sub_mch_id` per request +(value = the sub-merchant's `plf_co_id`): + +```python +draft = client.build_request("POST", "/gateway/order/create", body, level="L0", + sub_mch_id="PLF-SUB-001") +# one-shot: +result = client.execute("POST", "/gateway/order/create", body, level="L0", + sub_mch_id="PLF-SUB-001") +``` + +The SDK writes `x-wop-sub-mch-id` before signing and includes it in the `x-wop-sign` +signedHeaders. Leading/trailing whitespace is trimmed; the value must be printable ASCII +(0x20–0x7E), contain no internal whitespace, and be at most 128 characters — violations +raise `ConfigurationError`. Omitting it (or passing blank) keeps the app's own identity: +the header is absent and the header set/signature are byte-identical to earlier versions +(AC-20). Passing the header via `extra_headers` is equivalent to the parameter; supplying +both is rejected. The header takes effect only when the gateway sub-merchant gray gate is +open for the app and the app is an ISV app (`app_type=20`). + ## Key Preparation Keys are passed as strings (PEM or single-line Base64) and parsed inside the SDK diff --git a/README.md b/README.md index b9581db..05f271e 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,24 @@ else: print(result.reason) # 验签/解密失败对外模糊(I7),格式/完整性/一致性类明确 ``` +## ISV 子商户身份(ISV D-13) + +代子商户调用业务 API 时,按请求传 `sub_mch_id`(值 = 子商户 `plf_co_id`): + +```python +draft = client.build_request("POST", "/gateway/order/create", body, level="L0", + sub_mch_id="PLF-SUB-001") +# 一站式调用: +result = client.execute("POST", "/gateway/order/create", body, level="L0", + sub_mch_id="PLF-SUB-001") +``` + +SDK 在签名前写入 `x-wop-sub-mch-id`,并自动纳入 `x-wop-sign` 的 signedHeaders。 +首尾空白 trim 后发送;仅接受可打印 ASCII(0x20–0x7E)、无内部空白、≤128 字符, +违规抛 `ConfigurationError`。不传或纯空白 = 应用自身身份,头缺席,请求头集合与签名 +与旧版逐字节一致(AC-20)。`extra_headers` 携带该头等价于参数;双来源同传构造即拒。 +该头仅在网关子商户灰度放行且应用为 ISV 应用(`app_type=20`)时生效。 + ## 密钥准备 密钥入参为字符串(PEM 或 Base64 单行),SDK 内部解析(D12 分发契约): diff --git a/src/wop_sdk/client.py b/src/wop_sdk/client.py index d421098..6445538 100644 --- a/src/wop_sdk/client.py +++ b/src/wop_sdk/client.py @@ -51,6 +51,7 @@ _LEVELS = ("L0", "L2") _DEK_PREFIX = "L2;dek=" _HEADER_REQUEST_ID = "x-wop-request-id" +_HEADER_SUB_MCH_ID = "x-wop-sub-mch-id" # 附录 I/I3 日志义务:出向构造点 INFO 打印最终透传头值(非敏感,豁免脱敏) _OUT_LOG = logging.getLogger("wop_sdk.outbound") @@ -84,6 +85,32 @@ def resolve_request_id(raw: Optional[str]) -> Optional[str]: return trimmed +def resolve_sub_mch_id(raw: Optional[str]) -> Optional[str]: + """ISV D-13 子商户身份头 x-wop-sub-mch-id 校验(构造即拒,configuration 类)。 + + 1. trim 前按**原值**逐字符扫描可打印 ASCII(0x20..0x7E)——控制字符(CR/LF/NUL/DEL 等) + 防头注入,非 ASCII 在 HTTP 头编码下不可靠; + 2. trim(G2 TrimAll 同集)后为空 → 视为未设置(返回 None,头缺席 = 应用自身身份,AC-20); + 3. trim 后含内部空格 → 拒(网关 canonical 的 trimall 会折叠内部空白,而身份查询只做 + trim,内部空白破坏签名与身份一一对应); + 4. trim 后长度 > 128 字符 → 拒(ASCII 下字符数 = 字节数)。 + 返回 trim 后上行值;None = 未设置。 + """ + if raw is None: + return None + for ch in raw: + if ord(ch) < 0x20 or ord(ch) > 0x7E: + raise ConfigurationError(f"subMchId 须为可打印 ASCII(防头注入/签名歧义): {ord(ch)}") + trimmed = raw.strip(_TRIM_CHARS) + if not trimmed: + return None + if " " in trimmed: + raise ConfigurationError("subMchId 不能包含内部空白") + if len(trimmed) > 128: + raise ConfigurationError(f"subMchId 长度不能超过 128(实际 {len(trimmed)})") + return trimmed + + def _now_ms() -> int: """毫秒时间戳(F9);独立函数便于测试冻结。""" return int(time.time() * 1000) @@ -233,6 +260,7 @@ def build_request( timestamp_ms: Optional[int] = None, nonce: Optional[str] = None, request_id: Optional[str] = None, + sub_mch_id: Optional[str] = None, ) -> RequestDraft: """构造请求(F9):协议头组装 → L2 可选封装 → canonicalRequest → 签名。 @@ -244,6 +272,10 @@ def build_request( (头恒存在),显式传值 trim 后原值上行,控制字符(trim 前扫描)与超长 (trim 后 UTF-8 字节 > 128)构造即拒。extra_headers 携带该头等价 request_id 参数(同解析链、恒不入签);双来源同传构造即拒(configuration)。 + sub_mch_id 为 ISV 子商户身份(D-13,值 = 子商户 plf_co_id):签名前写入 + x-wop-sub-mch-id 并自动纳入 signedHeaders;未传/空白 = 应用自身身份(头缺席, + 与旧版逐字节一致,AC-20)。须为可打印 ASCII、无内部空白、trim 后 ≤128 字符, + 违规构造即拒。extra_headers 携带该头等价 sub_mch_id 参数,双来源同传即拒。 """ if level not in _LEVELS: raise ConfigurationError("level 必须为 L0 或 L2,实际 %r" % level) @@ -265,6 +297,22 @@ def build_request( resolved_request_id = resolve_request_id( request_id if request_id is not None else header_request_id ) + # ISV D-13:subMchId 同解析链(extra_headers 等价参数;双来源同传 = 歧义即拒) + header_sub_mch_id = next( + ( + str(value) + for name, value in (extra_headers or {}).items() + if name.strip().lower() == _HEADER_SUB_MCH_ID + ), + None, + ) + if header_sub_mch_id is not None and sub_mch_id is not None: + raise ConfigurationError( + "sub_mch_id 参数与 extra_headers['x-wop-sub-mch-id'] 同时显式提供,请仅保留一处" + ) + resolved_sub_mch_id = resolve_sub_mch_id( + sub_mch_id if sub_mch_id is not None else header_sub_mch_id + ) safe_method = method.strip().upper() # spec:interop-v1 随机流消费顺序:nonce 池最前,先于 seal_l2 的 CEK/IV if not nonce: @@ -283,6 +331,9 @@ def build_request( "x-wop-timestamp": str(_now_ms() if timestamp_ms is None else int(timestamp_ms)), "x-wop-nonce": nonce, } + # ISV D-13:签名前写入,signedHeaders 自动包含;缺席时头集合与旧行为完全一致 + if resolved_sub_mch_id is not None: + headers[_HEADER_SUB_MCH_ID] = resolved_sub_mch_id if wire is not None: # D2:有 body 必产 digest;I1:digest 必入 signedHeaders(下方签名集合即全部头) headers["x-wop-content-digest"] = build_digest_header(self._suite, wire) @@ -292,9 +343,9 @@ def build_request( app_headers: Dict[str, str] = {} for name, value in (extra_headers or {}).items(): low = name.strip().lower() - if low == _HEADER_REQUEST_ID: - # 恒不入签(附录 I):值已在解析链消费;若并入 headers 会被签名后 - # 覆盖 → 签名集合含旧值、线上是新值,网关验签必败且 SDK 零报错 + if low in (_HEADER_REQUEST_ID, _HEADER_SUB_MCH_ID): + # request_id 恒不入签(附录 I);sub_mch_id 已在签名前由解析链写入。 + # 若此处再并入会覆盖已验证值 → 签名/身份不一致 continue if low.startswith("x-wop-"): headers[low] = str(value).strip() @@ -364,6 +415,7 @@ def execute( *, level: str = "L0", request_id: Optional[str] = None, + sub_mch_id: Optional[str] = None, ) -> VerifyResult: """一站式:签名 → 发送 → 非 2xx 拦截 → 验签解密(§2 execute 语义)。""" if self._transport is None or self._sdk_config is None: @@ -376,6 +428,7 @@ def execute( level=level, expired_seconds=self._sdk_config.expired_seconds, request_id=request_id, + sub_mch_id=sub_mch_id, ) from .transports import send_draft diff --git a/tests/test_submchid.py b/tests/test_submchid.py new file mode 100644 index 0000000..75b3c31 --- /dev/null +++ b/tests/test_submchid.py @@ -0,0 +1,129 @@ +# -*- coding: utf-8 -*- +"""ISV D-13:子商户身份头 x-wop-sub-mch-id 入签与 AC-20 零回归。""" +import pytest + +import wop_sdk.client as client_mod +from wop_sdk.canonical import build_canonical, canonical_headers +from wop_sdk.client import WopClient, WopConfig +from wop_sdk.encoding import b64url_decode +from wop_sdk.errors import ConfigurationError +from wop_sdk.keys import load_rsa_public_key +from wop_sdk.signature import verify + +RSA_REQ = "WOP-RSA3072-SHA256" +PATH = "/gateway/order.create" + + +@pytest.fixture(scope="module") +def vec_keys(vectors): + return vectors["keys"] + + +@pytest.fixture(scope="module") +def rsa_client(vec_keys): + return WopClient( + WopConfig( + app_key="app_10012481831", + suite=RSA_REQ, + merchant_private_key=vec_keys["rsa3072"]["privatePkcs8B64"], + platform_public_key=vec_keys["rsa3072"]["publicSpkiB64"], + ), + csprng=lambda n: b"\x5a" * n, + ) + + +def _assert_signature_valid(client, draft, pub_b64): + suite_part, rest = draft.headers["x-wop-sign"].split(" ", 1) + version, expired, names, sig = rest.split("/") + assert suite_part == RSA_REQ + signed_map = {n: draft.headers[n] for n in names.split(";")} + canonical = build_canonical( + f"{version}/{expired}", draft.method, draft.path, "", canonical_headers(signed_map) + ) + verify( + client.suite, + load_rsa_public_key(pub_b64), + canonical.encode("utf-8"), + b64url_decode(sig), + ) + + +class TestSubMchIdSigned: + def test_signed_and_signature_valid(self, rsa_client, vec_keys): + cases = [ + (b'{"k":1}', "L0", ["x-wop-appkey", "x-wop-content-digest", "x-wop-nonce", + "x-wop-sub-mch-id", "x-wop-timestamp"]), + (None, "L0", ["x-wop-appkey", "x-wop-nonce", "x-wop-sub-mch-id", + "x-wop-timestamp"]), + (b'{"amount":1}', "L2", ["x-wop-appkey", "x-wop-content-digest", "x-wop-encrypt", + "x-wop-nonce", "x-wop-sub-mch-id", "x-wop-timestamp"]), + ] + for body, level, want in cases: + draft = rsa_client.build_request( + "POST", PATH, body, level=level, timestamp_ms=1774340000000, nonce="n", + request_id="req-001", sub_mch_id="PLF-SUB-001", + ) + assert draft.headers["x-wop-sub-mch-id"] == "PLF-SUB-001" + signed_names = draft.headers["x-wop-sign"].split(" ", 1)[1].split("/")[2].split(";") + assert signed_names == want + assert "x-wop-request-id" not in signed_names + _assert_signature_valid(rsa_client, draft, vec_keys["rsa3072"]["publicSpkiB64"]) + + def test_trimmed_upstream(self, rsa_client): + draft = rsa_client.build_request("GET", PATH, sub_mch_id=" PLF-SUB-001 ") + assert draft.headers["x-wop-sub-mch-id"] == "PLF-SUB-001" + + def test_extra_headers_equivalent_and_signed(self, rsa_client): + draft = rsa_client.build_request( + "GET", PATH, extra_headers={"X-Wop-Sub-Mch-Id": " PLF-SUB-001 "} + ) + assert draft.headers["x-wop-sub-mch-id"] == "PLF-SUB-001" + signed_names = draft.headers["x-wop-sign"].split(" ", 1)[1].split("/")[2].split(";") + assert "x-wop-sub-mch-id" in signed_names + + def test_both_sources_rejected(self, rsa_client): + with pytest.raises(ConfigurationError, match="x-wop-sub-mch-id"): + rsa_client.build_request( + "GET", PATH, sub_mch_id="p1", + extra_headers={"x-wop-sub-mch-id": "p2"}, + ) + + +class TestSubMchIdZeroRegression: # spec:AC-20 + def test_absent_or_blank_behaves_as_before(self, rsa_client, monkeypatch): + monkeypatch.setattr(client_mod, "request_id_generator", lambda: "fixed" + "0" * 27) + common = dict(timestamp_ms=1774340000000, nonce="n1") + baseline = rsa_client.build_request("POST", PATH, b'{"k":1}', **common) + for blank in (None, "", " "): + draft = rsa_client.build_request("POST", PATH, b'{"k":1}', sub_mch_id=blank, **common) + assert "x-wop-sub-mch-id" not in draft.headers + assert draft.headers == baseline.headers + + +class TestSubMchIdValidation: + @pytest.mark.parametrize( + "bad", ["a\nb", "a\rb", "a\x00b", "a\tb", "\tsub", "sub\t", "a\x7fb"] + ) + def test_control_chars_rejected_pre_trim(self, rsa_client, bad): + with pytest.raises(ConfigurationError, match="可打印 ASCII"): + rsa_client.build_request("GET", PATH, sub_mch_id=bad) + + def test_non_ascii_rejected_without_echo(self, rsa_client): + with pytest.raises(ConfigurationError, match="可打印 ASCII") as exc: + rsa_client.build_request("GET", PATH, sub_mch_id="PLF中文") + assert "中文" not in str(exc.value) + + @pytest.mark.parametrize("bad", ["PLF SUB", "PLF SUB"]) + def test_internal_space_rejected(self, rsa_client, bad): + with pytest.raises(ConfigurationError, match="内部空白"): + rsa_client.build_request("GET", PATH, sub_mch_id=bad) + + def test_length_boundary(self, rsa_client): + ok = rsa_client.build_request("GET", PATH, sub_mch_id="x" * 128) + assert ok.headers["x-wop-sub-mch-id"] == "x" * 128 + with pytest.raises(ConfigurationError, match="实际 129"): + rsa_client.build_request("GET", PATH, sub_mch_id="x" * 129) + + def test_printable_ascii_boundary(self, rsa_client): + draft = rsa_client.build_request("GET", PATH, sub_mch_id="!~") + assert draft.headers["x-wop-sub-mch-id"] == "!~" From 06709db57558e33d234de56fee65473ad9733def Mon Sep 17 00:00:00 2001 From: im47cn Date: Wed, 28 Oct 2026 11:18:58 +0000 Subject: [PATCH 2/4] =?UTF-8?q?fix(core):=20=E6=8B=92=E7=BB=9D=E9=9D=9E=20?= =?UTF-8?q?str=20=E5=AD=90=E5=95=86=E6=88=B7=E8=BA=AB=E4=BB=BD=E5=80=BC?= =?UTF-8?q?=EF=BC=8C=E5=B0=81=E9=97=AD=20str(None)=20=E9=9D=99=E9=BB=98?= =?UTF-8?q?=E5=85=A5=E7=AD=BE=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - resolve_sub_mch_id 与 extra_headers 取值链增加 isinstance(str) 校验: extra_headers={'x-wop-sub-mch-id': None} 此前被 str() 归一为 'None' 并静默入签, 数值入参则抛裸 TypeError;现统一构造期抛 configuration - 去掉 extra_headers 侧 str() 强转,原值进同一校验链 - 双来源消歧改为「两侧各自按 J2 解析后再判」:空白参数不再与真实 extra 值误判为同传 - 补测试:execute 入口入签、extra_headers 空白零回归、None/数值/bytes 负例、双来源消歧 --- src/wop_sdk/client.py | 16 ++++++++--- tests/test_submchid.py | 64 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/wop_sdk/client.py b/src/wop_sdk/client.py index 6445538..c3fd0de 100644 --- a/src/wop_sdk/client.py +++ b/src/wop_sdk/client.py @@ -98,6 +98,11 @@ def resolve_sub_mch_id(raw: Optional[str]) -> Optional[str]: """ if raw is None: return None + if not isinstance(raw, str): + # J2 构造即拒:非 str(如数值型 plf_co_id)不得被 str() 归一后静默入签 + raise ConfigurationError( + "subMchId 须为字符串(子商户 plf_co_id),实际 %s" % type(raw).__name__ + ) for ch in raw: if ord(ch) < 0x20 or ord(ch) > 0x7E: raise ConfigurationError(f"subMchId 须为可打印 ASCII(防头注入/签名歧义): {ord(ch)}") @@ -300,18 +305,21 @@ def build_request( # ISV D-13:subMchId 同解析链(extra_headers 等价参数;双来源同传 = 歧义即拒) header_sub_mch_id = next( ( - str(value) + value for name, value in (extra_headers or {}).items() if name.strip().lower() == _HEADER_SUB_MCH_ID ), None, ) - if header_sub_mch_id is not None and sub_mch_id is not None: + # 两侧各按 J2 解析(trim 后空 = 未设置):只有两侧都解析出值才构成双来源歧义 + param_resolved = resolve_sub_mch_id(sub_mch_id) + header_resolved = resolve_sub_mch_id(header_sub_mch_id) + if param_resolved is not None and header_resolved is not None: raise ConfigurationError( "sub_mch_id 参数与 extra_headers['x-wop-sub-mch-id'] 同时显式提供,请仅保留一处" ) - resolved_sub_mch_id = resolve_sub_mch_id( - sub_mch_id if sub_mch_id is not None else header_sub_mch_id + resolved_sub_mch_id = ( + param_resolved if param_resolved is not None else header_resolved ) safe_method = method.strip().upper() # spec:interop-v1 随机流消费顺序:nonce 池最前,先于 seal_l2 的 CEK/IV diff --git a/tests/test_submchid.py b/tests/test_submchid.py index 75b3c31..f7f0582 100644 --- a/tests/test_submchid.py +++ b/tests/test_submchid.py @@ -1,14 +1,18 @@ # -*- coding: utf-8 -*- """ISV D-13:子商户身份头 x-wop-sub-mch-id 入签与 AC-20 零回归。""" +import json + import pytest import wop_sdk.client as client_mod from wop_sdk.canonical import build_canonical, canonical_headers from wop_sdk.client import WopClient, WopConfig from wop_sdk.encoding import b64url_decode +from wop_sdk.config._parser import parse_config_json from wop_sdk.errors import ConfigurationError from wop_sdk.keys import load_rsa_public_key from wop_sdk.signature import verify +from helpers import _valid_config_dict RSA_REQ = "WOP-RSA3072-SHA256" PATH = "/gateway/order.create" @@ -127,3 +131,63 @@ def test_length_boundary(self, rsa_client): def test_printable_ascii_boundary(self, rsa_client): draft = rsa_client.build_request("GET", PATH, sub_mch_id="!~") assert draft.headers["x-wop-sub-mch-id"] == "!~" + + +class TestSubMchIdSources: + """附录 J/J2 + J3:来源消歧与非 str 输入不得被 str() 归一。""" + + def test_blank_param_with_real_header_uses_header(self, rsa_client): + draft = rsa_client.build_request( + "GET", PATH, sub_mch_id=" ", + extra_headers={"x-wop-sub-mch-id": "PLF-1"}, + ) + assert draft.headers["x-wop-sub-mch-id"] == "PLF-1" + + def test_extra_headers_none_means_unset(self, rsa_client): + draft = rsa_client.build_request("GET", PATH, extra_headers={"x-wop-sub-mch-id": None}) + assert "x-wop-sub-mch-id" not in draft.headers + + @pytest.mark.parametrize("bad", [123, 12.5, b"PLF-1"]) + def test_extra_headers_non_string_rejected(self, rsa_client, bad): + with pytest.raises(ConfigurationError, match="须为字符串"): + rsa_client.build_request("GET", PATH, extra_headers={"x-wop-sub-mch-id": bad}) + + @pytest.mark.parametrize("bad", [123, b"PLF-1"]) + def test_param_non_string_rejected(self, rsa_client, bad): + with pytest.raises(ConfigurationError, match="须为字符串"): + rsa_client.build_request("GET", PATH, sub_mch_id=bad) + + def test_extra_headers_blank_behaves_as_before(self, rsa_client, monkeypatch): + monkeypatch.setattr(client_mod, "request_id_generator", lambda: "fixed" + "0" * 27) + common = dict(timestamp_ms=1774340000000, nonce="n1") + baseline = rsa_client.build_request("POST", PATH, b'{"k":1}', **common) + draft = rsa_client.build_request( + "POST", PATH, b'{"k":1}', + extra_headers={"x-wop-sub-mch-id": " "}, **common, + ) + assert "x-wop-sub-mch-id" not in draft.headers + assert draft.headers == baseline.headers + + +class TestSubMchIdExecute: + """附录 J/J3:一站式 execute 与分步 buildRequest 同等生效。""" + + def test_execute_carries_signed_header(self, vec_keys): + cfg = parse_config_json(json.dumps(_valid_config_dict(vec_keys))) + client = WopClient.from_config(cfg, csprng=lambda n: b"\x5a" * n) + seen = {} + + class Stop(Exception): + pass + + class RecordingTransport: + def send(self, method, url, headers, body): + seen["headers"] = dict(headers) + raise Stop + + client._transport = RecordingTransport() + with pytest.raises(Stop): + client.execute("POST", PATH, b'{"k":1}', sub_mch_id="PLF-SUB-001") + assert seen["headers"]["x-wop-sub-mch-id"] == "PLF-SUB-001" + signed_names = seen["headers"]["x-wop-sign"].split(" ", 1)[1].split("/")[2].split(";") + assert "x-wop-sub-mch-id" in signed_names From b12f037d23e37dbb606e6f51623272baa02d0833 Mon Sep 17 00:00:00 2001 From: im47cn-bot Date: Wed, 28 Oct 2026 11:29:58 +0000 Subject: [PATCH 3/4] =?UTF-8?q?test(api):=20=E9=87=8D=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=85=AC=E5=85=B1=20API=20=E5=BF=AB=E7=85=A7=EF=BC=8C=E7=BA=B3?= =?UTF-8?q?=E5=85=A5=20sub=5Fmch=5Fid=20=E5=8F=82=E6=95=B0=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit api-snapshot 门禁在 0b8b807 起即漂移(新增 build_request/execute 的 sub_mch_id 参数与 docstring 未随 PR 更新基线,该 commit 的 CI 为 action_required 未执行到)。 按 scripts/check-api-snapshot.py --update(griffe==1.14.0)重生成,无其他 API 变更。 Co-Authored-By: Claude --- tests/api_snapshot.json | 98 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/tests/api_snapshot.json b/tests/api_snapshot.json index a73b002..b3a3259 100644 --- a/tests/api_snapshot.json +++ b/tests/api_snapshot.json @@ -1750,10 +1750,10 @@ "parsed": [ { "kind": "text", - "value": "\u6784\u9020\u8bf7\u6c42\uff08F9\uff09\uff1a\u534f\u8bae\u5934\u7ec4\u88c5 \u2192 L2 \u53ef\u9009\u5c01\u88c5 \u2192 canonicalRequest \u2192 \u7b7e\u540d\u3002\n\ntimestamp_ms / nonce \u4e3a\u786e\u5b9a\u6027\u94a9\u5b50\uff08\u91cd\u653e/\u8054\u8c03\u7528\uff1b\u955c\u50cf Go WithTimestamp/\nWithNonce\uff09\u3002\u968f\u673a\u6d41\u6d88\u8d39\u987a\u5e8f\u5408\u540c\uff08wop-specs/interop/v1\uff09\uff1a\n[16B nonce \u6c60][CEK][12B IV][k\u2026]\u2014\u2014nonce \u6ce8\u5165\u65f6\u8df3\u8fc7 nonce \u6c60\u6bb5\u3002\nrequest_id \u4e3a\u5546\u6237\u8bf7\u6c42\u6807\u8bc6\uff08\u9644\u5f55 I\uff1ax-wop-request-id \u900f\u4f20\u5934\uff0c\u6052\u4e0d\u5165\u7b7e\uff1b\n\u987b\u4e3a\u4e0d\u542b\u4e2a\u4eba\u6570\u636e\u7684\u4e0d\u900f\u660e\u5173\u8054\u6807\u8bc6\uff09\uff1b\u672a\u4f20/\u7a7a\u767d \u2192 \u7f3a\u7701\u751f\u6210 UUID \u53bb\u8fde\u5b57\u7b26\n\uff08\u5934\u6052\u5b58\u5728\uff09\uff0c\u663e\u5f0f\u4f20\u503c trim \u540e\u539f\u503c\u4e0a\u884c\uff0c\u63a7\u5236\u5b57\u7b26\uff08trim \u524d\u626b\u63cf\uff09\u4e0e\u8d85\u957f\n\uff08trim \u540e UTF-8 \u5b57\u8282 > 128\uff09\u6784\u9020\u5373\u62d2\u3002extra_headers \u643a\u5e26\u8be5\u5934\u7b49\u4ef7\nrequest_id \u53c2\u6570\uff08\u540c\u89e3\u6790\u94fe\u3001\u6052\u4e0d\u5165\u7b7e\uff09\uff1b\u53cc\u6765\u6e90\u540c\u4f20\u6784\u9020\u5373\u62d2\uff08configuration\uff09\u3002" + "value": "\u6784\u9020\u8bf7\u6c42\uff08F9\uff09\uff1a\u534f\u8bae\u5934\u7ec4\u88c5 \u2192 L2 \u53ef\u9009\u5c01\u88c5 \u2192 canonicalRequest \u2192 \u7b7e\u540d\u3002\n\ntimestamp_ms / nonce \u4e3a\u786e\u5b9a\u6027\u94a9\u5b50\uff08\u91cd\u653e/\u8054\u8c03\u7528\uff1b\u955c\u50cf Go WithTimestamp/\nWithNonce\uff09\u3002\u968f\u673a\u6d41\u6d88\u8d39\u987a\u5e8f\u5408\u540c\uff08wop-specs/interop/v1\uff09\uff1a\n[16B nonce \u6c60][CEK][12B IV][k\u2026]\u2014\u2014nonce \u6ce8\u5165\u65f6\u8df3\u8fc7 nonce \u6c60\u6bb5\u3002\nrequest_id \u4e3a\u5546\u6237\u8bf7\u6c42\u6807\u8bc6\uff08\u9644\u5f55 I\uff1ax-wop-request-id \u900f\u4f20\u5934\uff0c\u6052\u4e0d\u5165\u7b7e\uff1b\n\u987b\u4e3a\u4e0d\u542b\u4e2a\u4eba\u6570\u636e\u7684\u4e0d\u900f\u660e\u5173\u8054\u6807\u8bc6\uff09\uff1b\u672a\u4f20/\u7a7a\u767d \u2192 \u7f3a\u7701\u751f\u6210 UUID \u53bb\u8fde\u5b57\u7b26\n\uff08\u5934\u6052\u5b58\u5728\uff09\uff0c\u663e\u5f0f\u4f20\u503c trim \u540e\u539f\u503c\u4e0a\u884c\uff0c\u63a7\u5236\u5b57\u7b26\uff08trim \u524d\u626b\u63cf\uff09\u4e0e\u8d85\u957f\n\uff08trim \u540e UTF-8 \u5b57\u8282 > 128\uff09\u6784\u9020\u5373\u62d2\u3002extra_headers \u643a\u5e26\u8be5\u5934\u7b49\u4ef7\nrequest_id \u53c2\u6570\uff08\u540c\u89e3\u6790\u94fe\u3001\u6052\u4e0d\u5165\u7b7e\uff09\uff1b\u53cc\u6765\u6e90\u540c\u4f20\u6784\u9020\u5373\u62d2\uff08configuration\uff09\u3002\nsub_mch_id \u4e3a ISV \u5b50\u5546\u6237\u8eab\u4efd\uff08D-13\uff0c\u503c = \u5b50\u5546\u6237 plf_co_id\uff09\uff1a\u7b7e\u540d\u524d\u5199\u5165\nx-wop-sub-mch-id \u5e76\u81ea\u52a8\u7eb3\u5165 signedHeaders\uff1b\u672a\u4f20/\u7a7a\u767d = \u5e94\u7528\u81ea\u8eab\u8eab\u4efd\uff08\u5934\u7f3a\u5e2d\uff0c\n\u4e0e\u65e7\u7248\u9010\u5b57\u8282\u4e00\u81f4\uff0cAC-20\uff09\u3002\u987b\u4e3a\u53ef\u6253\u5370 ASCII\u3001\u65e0\u5185\u90e8\u7a7a\u767d\u3001trim \u540e \u2264128 \u5b57\u7b26\uff0c\n\u8fdd\u89c4\u6784\u9020\u5373\u62d2\u3002extra_headers \u643a\u5e26\u8be5\u5934\u7b49\u4ef7 sub_mch_id \u53c2\u6570\uff0c\u53cc\u6765\u6e90\u540c\u4f20\u5373\u62d2\u3002" } ], - "value": "\u6784\u9020\u8bf7\u6c42\uff08F9\uff09\uff1a\u534f\u8bae\u5934\u7ec4\u88c5 \u2192 L2 \u53ef\u9009\u5c01\u88c5 \u2192 canonicalRequest \u2192 \u7b7e\u540d\u3002\n\ntimestamp_ms / nonce \u4e3a\u786e\u5b9a\u6027\u94a9\u5b50\uff08\u91cd\u653e/\u8054\u8c03\u7528\uff1b\u955c\u50cf Go WithTimestamp/\nWithNonce\uff09\u3002\u968f\u673a\u6d41\u6d88\u8d39\u987a\u5e8f\u5408\u540c\uff08wop-specs/interop/v1\uff09\uff1a\n[16B nonce \u6c60][CEK][12B IV][k\u2026]\u2014\u2014nonce \u6ce8\u5165\u65f6\u8df3\u8fc7 nonce \u6c60\u6bb5\u3002\nrequest_id \u4e3a\u5546\u6237\u8bf7\u6c42\u6807\u8bc6\uff08\u9644\u5f55 I\uff1ax-wop-request-id \u900f\u4f20\u5934\uff0c\u6052\u4e0d\u5165\u7b7e\uff1b\n\u987b\u4e3a\u4e0d\u542b\u4e2a\u4eba\u6570\u636e\u7684\u4e0d\u900f\u660e\u5173\u8054\u6807\u8bc6\uff09\uff1b\u672a\u4f20/\u7a7a\u767d \u2192 \u7f3a\u7701\u751f\u6210 UUID \u53bb\u8fde\u5b57\u7b26\n\uff08\u5934\u6052\u5b58\u5728\uff09\uff0c\u663e\u5f0f\u4f20\u503c trim \u540e\u539f\u503c\u4e0a\u884c\uff0c\u63a7\u5236\u5b57\u7b26\uff08trim \u524d\u626b\u63cf\uff09\u4e0e\u8d85\u957f\n\uff08trim \u540e UTF-8 \u5b57\u8282 > 128\uff09\u6784\u9020\u5373\u62d2\u3002extra_headers \u643a\u5e26\u8be5\u5934\u7b49\u4ef7\nrequest_id \u53c2\u6570\uff08\u540c\u89e3\u6790\u94fe\u3001\u6052\u4e0d\u5165\u7b7e\uff09\uff1b\u53cc\u6765\u6e90\u540c\u4f20\u6784\u9020\u5373\u62d2\uff08configuration\uff09\u3002" + "value": "\u6784\u9020\u8bf7\u6c42\uff08F9\uff09\uff1a\u534f\u8bae\u5934\u7ec4\u88c5 \u2192 L2 \u53ef\u9009\u5c01\u88c5 \u2192 canonicalRequest \u2192 \u7b7e\u540d\u3002\n\ntimestamp_ms / nonce \u4e3a\u786e\u5b9a\u6027\u94a9\u5b50\uff08\u91cd\u653e/\u8054\u8c03\u7528\uff1b\u955c\u50cf Go WithTimestamp/\nWithNonce\uff09\u3002\u968f\u673a\u6d41\u6d88\u8d39\u987a\u5e8f\u5408\u540c\uff08wop-specs/interop/v1\uff09\uff1a\n[16B nonce \u6c60][CEK][12B IV][k\u2026]\u2014\u2014nonce \u6ce8\u5165\u65f6\u8df3\u8fc7 nonce \u6c60\u6bb5\u3002\nrequest_id \u4e3a\u5546\u6237\u8bf7\u6c42\u6807\u8bc6\uff08\u9644\u5f55 I\uff1ax-wop-request-id \u900f\u4f20\u5934\uff0c\u6052\u4e0d\u5165\u7b7e\uff1b\n\u987b\u4e3a\u4e0d\u542b\u4e2a\u4eba\u6570\u636e\u7684\u4e0d\u900f\u660e\u5173\u8054\u6807\u8bc6\uff09\uff1b\u672a\u4f20/\u7a7a\u767d \u2192 \u7f3a\u7701\u751f\u6210 UUID \u53bb\u8fde\u5b57\u7b26\n\uff08\u5934\u6052\u5b58\u5728\uff09\uff0c\u663e\u5f0f\u4f20\u503c trim \u540e\u539f\u503c\u4e0a\u884c\uff0c\u63a7\u5236\u5b57\u7b26\uff08trim \u524d\u626b\u63cf\uff09\u4e0e\u8d85\u957f\n\uff08trim \u540e UTF-8 \u5b57\u8282 > 128\uff09\u6784\u9020\u5373\u62d2\u3002extra_headers \u643a\u5e26\u8be5\u5934\u7b49\u4ef7\nrequest_id \u53c2\u6570\uff08\u540c\u89e3\u6790\u94fe\u3001\u6052\u4e0d\u5165\u7b7e\uff09\uff1b\u53cc\u6765\u6e90\u540c\u4f20\u6784\u9020\u5373\u62d2\uff08configuration\uff09\u3002\nsub_mch_id \u4e3a ISV \u5b50\u5546\u6237\u8eab\u4efd\uff08D-13\uff0c\u503c = \u5b50\u5546\u6237 plf_co_id\uff09\uff1a\u7b7e\u540d\u524d\u5199\u5165\nx-wop-sub-mch-id \u5e76\u81ea\u52a8\u7eb3\u5165 signedHeaders\uff1b\u672a\u4f20/\u7a7a\u767d = \u5e94\u7528\u81ea\u8eab\u8eab\u4efd\uff08\u5934\u7f3a\u5e2d\uff0c\n\u4e0e\u65e7\u7248\u9010\u5b57\u8282\u4e00\u81f4\uff0cAC-20\uff09\u3002\u987b\u4e3a\u53ef\u6253\u5370 ASCII\u3001\u65e0\u5185\u90e8\u7a7a\u767d\u3001trim \u540e \u2264128 \u5b57\u7b26\uff0c\n\u8fdd\u89c4\u6784\u9020\u5373\u62d2\u3002extra_headers \u643a\u5e26\u8be5\u5934\u7b49\u4ef7 sub_mch_id \u53c2\u6570\uff0c\u53cc\u6765\u6e90\u540c\u4f20\u5373\u62d2\u3002" }, "is_class_private": false, "is_deprecated": false, @@ -1930,6 +1930,24 @@ "default": "None", "kind": "keyword-only", "name": "request_id" + }, + { + "annotation": { + "cls": "ExprSubscript", + "left": { + "cls": "ExprName", + "member": "build_request", + "name": "Optional" + }, + "slice": { + "cls": "ExprName", + "member": "build_request", + "name": "str" + } + }, + "default": "None", + "kind": "keyword-only", + "name": "sub_mch_id" } ], "path": "wop_sdk.client.WopClient.build_request", @@ -2107,6 +2125,24 @@ "default": "None", "kind": "keyword-only", "name": "request_id" + }, + { + "annotation": { + "cls": "ExprSubscript", + "left": { + "cls": "ExprName", + "member": "execute", + "name": "Optional" + }, + "slice": { + "cls": "ExprName", + "member": "execute", + "name": "str" + } + }, + "default": "None", + "kind": "keyword-only", + "name": "sub_mch_id" } ], "path": "wop_sdk.client.WopClient.execute", @@ -3178,6 +3214,64 @@ }, "runtime": true }, + "resolve_sub_mch_id": { + "analysis": "static", + "decorators": [], + "docstring": { + "parsed": [ + { + "kind": "text", + "value": "ISV D-13 \u5b50\u5546\u6237\u8eab\u4efd\u5934 x-wop-sub-mch-id \u6821\u9a8c\uff08\u6784\u9020\u5373\u62d2\uff0cconfiguration \u7c7b\uff09\u3002\n\n1. trim \u524d\u6309**\u539f\u503c**\u9010\u5b57\u7b26\u626b\u63cf\u53ef\u6253\u5370 ASCII\uff080x20..0x7E\uff09\u2014\u2014\u63a7\u5236\u5b57\u7b26\uff08CR/LF/NUL/DEL \u7b49\uff09\n \u9632\u5934\u6ce8\u5165\uff0c\u975e ASCII \u5728 HTTP \u5934\u7f16\u7801\u4e0b\u4e0d\u53ef\u9760\uff1b\n2. trim\uff08G2 TrimAll \u540c\u96c6\uff09\u540e\u4e3a\u7a7a \u2192 \u89c6\u4e3a\u672a\u8bbe\u7f6e\uff08\u8fd4\u56de None\uff0c\u5934\u7f3a\u5e2d = \u5e94\u7528\u81ea\u8eab\u8eab\u4efd\uff0cAC-20\uff09\uff1b\n3. trim \u540e\u542b\u5185\u90e8\u7a7a\u683c \u2192 \u62d2\uff08\u7f51\u5173 canonical \u7684 trimall \u4f1a\u6298\u53e0\u5185\u90e8\u7a7a\u767d\uff0c\u800c\u8eab\u4efd\u67e5\u8be2\u53ea\u505a\n trim\uff0c\u5185\u90e8\u7a7a\u767d\u7834\u574f\u7b7e\u540d\u4e0e\u8eab\u4efd\u4e00\u4e00\u5bf9\u5e94\uff09\uff1b\n4. trim \u540e\u957f\u5ea6 > 128 \u5b57\u7b26 \u2192 \u62d2\uff08ASCII \u4e0b\u5b57\u7b26\u6570 = \u5b57\u8282\u6570\uff09\u3002\n\u8fd4\u56de trim \u540e\u4e0a\u884c\u503c\uff1bNone = \u672a\u8bbe\u7f6e\u3002" + } + ], + "value": "ISV D-13 \u5b50\u5546\u6237\u8eab\u4efd\u5934 x-wop-sub-mch-id \u6821\u9a8c\uff08\u6784\u9020\u5373\u62d2\uff0cconfiguration \u7c7b\uff09\u3002\n\n1. trim \u524d\u6309**\u539f\u503c**\u9010\u5b57\u7b26\u626b\u63cf\u53ef\u6253\u5370 ASCII\uff080x20..0x7E\uff09\u2014\u2014\u63a7\u5236\u5b57\u7b26\uff08CR/LF/NUL/DEL \u7b49\uff09\n \u9632\u5934\u6ce8\u5165\uff0c\u975e ASCII \u5728 HTTP \u5934\u7f16\u7801\u4e0b\u4e0d\u53ef\u9760\uff1b\n2. trim\uff08G2 TrimAll \u540c\u96c6\uff09\u540e\u4e3a\u7a7a \u2192 \u89c6\u4e3a\u672a\u8bbe\u7f6e\uff08\u8fd4\u56de None\uff0c\u5934\u7f3a\u5e2d = \u5e94\u7528\u81ea\u8eab\u8eab\u4efd\uff0cAC-20\uff09\uff1b\n3. trim \u540e\u542b\u5185\u90e8\u7a7a\u683c \u2192 \u62d2\uff08\u7f51\u5173 canonical \u7684 trimall \u4f1a\u6298\u53e0\u5185\u90e8\u7a7a\u767d\uff0c\u800c\u8eab\u4efd\u67e5\u8be2\u53ea\u505a\n trim\uff0c\u5185\u90e8\u7a7a\u767d\u7834\u574f\u7b7e\u540d\u4e0e\u8eab\u4efd\u4e00\u4e00\u5bf9\u5e94\uff09\uff1b\n4. trim \u540e\u957f\u5ea6 > 128 \u5b57\u7b26 \u2192 \u62d2\uff08ASCII \u4e0b\u5b57\u7b26\u6570 = \u5b57\u8282\u6570\uff09\u3002\n\u8fd4\u56de trim \u540e\u4e0a\u884c\u503c\uff1bNone = \u672a\u8bbe\u7f6e\u3002" + }, + "is_class_private": false, + "is_deprecated": false, + "is_exported": false, + "is_imported": false, + "is_private": false, + "is_public": true, + "is_special": false, + "is_wildcard_exposed": true, + "kind": "function", + "name": "resolve_sub_mch_id", + "parameters": [ + { + "annotation": { + "cls": "ExprSubscript", + "left": { + "cls": "ExprName", + "member": "resolve_sub_mch_id", + "name": "Optional" + }, + "slice": { + "cls": "ExprName", + "member": "resolve_sub_mch_id", + "name": "str" + } + }, + "default": null, + "kind": "positional or keyword", + "name": "raw" + } + ], + "path": "wop_sdk.client.resolve_sub_mch_id", + "returns": { + "cls": "ExprSubscript", + "left": { + "cls": "ExprName", + "member": "resolve_sub_mch_id", + "name": "Optional" + }, + "slice": { + "cls": "ExprName", + "member": "resolve_sub_mch_id", + "name": "str" + } + }, + "runtime": true + }, "seal_l2": { "analysis": "static", "inherited": false, From 28760a027bf9d87a6ebe12e47e48fc4b3b5c82dc Mon Sep 17 00:00:00 2001 From: im47cn-bot Date: Wed, 28 Oct 2026 11:29:58 +0000 Subject: [PATCH 4/4] =?UTF-8?q?ci:=20=E9=94=81=E5=AE=9A=20pytest=208.4.2?= =?UTF-8?q?=20/=20pytest-bdd=208.1.0=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=85=A8?= =?UTF-8?q?=E9=87=8F=20BDD=20=E5=81=87=E7=BA=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pytest 9.2 移除了 FixtureManager._arg2fixturedefs,pytest-bdd(含最新 9.0.0)仍引用旧名, 不锁版即 21 条 test_bdd.py 全部 AttributeError——与业务代码无关,任何分支今天跑都红。 证据:2026-10-26 最近一次全绿 run 40294534964 装的是 pytest-8.4.2 + pytest-bdd-8.1.0; 今天 run 40679072217 装到 pytest-9.2.0 + pytest-bdd-9.0.0,失败仅限 test_bdd.py(21/21)。 本地按锁定组合复跑:453 passed。 Co-Authored-By: Claude --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee71810..e683779 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,8 +35,10 @@ jobs: run: | python -m pip install --upgrade pip # pytest/pytest-bdd 属测试工具链而非运行时依赖,CI 显式安装; + # 上限锁定:pytest 9.2 移除 FixtureManager._arg2fixturedefs,pytest-bdd(≤9.0)尚未跟进, + # 不限版即全量 BDD 用例 AttributeError(与业务代码无关);8.4.2/8.1.0 为最近一次全绿组合 # coverage[toml]:py<3.11 需 tomli 才能读 pyproject.toml 的 coverage 配置 - pip install -e '.[httpx,requests]' pytest pytest-bdd pytest-cov 'coverage[toml]' + pip install -e '.[httpx,requests]' 'pytest==8.4.2' 'pytest-bdd==8.1.0' pytest-cov 'coverage[toml]' - name: Test with coverage gate (line+branch ≥ 98%, vector conformance must pass) run: python -m pytest --cov=wop_sdk --cov-branch --cov-fail-under=98 - name: Coverage detail (line & branch)