Skip to content

feat: 支持 RSA2048 套件与 x-wop-request-id 透传头 - #39

Merged
im47cn merged 13 commits into
mainfrom
feature_20260915_config
Oct 18, 2026
Merged

im47cn merged 13 commits into
mainfrom
feature_20260915_config

Conversation

@zheng-lei-coder

@zheng-lei-coder zheng-lei-coder commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

对齐 wop-specs(crypto-spec E1 扩展位 + sdk-spec 附录 I,wop-java-sdk feature_20260922_fix 基准):

RSA2048 套件(默认支持)

  • 新增 WOP-RSA2048-SHA256:密钥 2048 位、RSA-2048-OAEP 包装、签名定长 256B/342 字符
  • 套件注册表、密钥算法支持列表、配置层白名单同步扩容

x-wop-request-id 透传头(附录 I)

  • I1 恒不入签:签名落盘后写入头,带/不带透传头签名字节同值
  • I2 构造即校验:trim 前原值控制字符扫描(防头注入)、trim 后 UTF-8 字节 ≤128(trim 集 = G2 TrimAll 同集)
  • I3 缺省生成:未传/空白生成 UUID 去连字符(小写 32 hex,生成器可注入替换);出向构造点 INFO 日志打印最终头值(豁免脱敏)

配套

  • interop 头集合哨兵剥离透传头(fixture sha256 钉死不变);确定性重放场景注入固定生成器(CSPRNG 豁免)
  • 新增 requestId 与 RSA2048 全量测试(校验矩阵/不入签锚点/日志义务/execute 透传)

验证

  • 全量测试通过(详见各提交说明);既有环境项失败集与基线逐字一致

Sourcery 摘要

支持 RSA2048 套件和请求 ID 传播,同时提供经过验证的配置驱动客户端执行功能。

新功能:

  • 默认支持 WOP-RSA2048-SHA256 加密套件。
  • 添加 x-wop-request-id 传播功能,包括验证、默认生成、出站日志记录和执行路径转发。
  • 添加配置加载、验证、传输层发现、默认客户端构造以及一步式请求执行 API。

错误修复:

  • 防止传播的请求 ID 影响签名字节或冻结的协议标头集合。

增强功能:

  • 添加网关响应错误报告、表示形式中的安全凭据脱敏、API 路径验证以及 HTTPS 端点规范化。

测试:

  • 扩展套件、请求 ID、配置、执行、重放和互操作性测试覆盖范围。
Original summary in English

Sourcery 摘要

新增 RSA2048 支持、请求 ID 传播以及配置驱动的客户端执行,同时保持协议签名和互操作性行为不变。

新功能:

  • 默认支持 WOP-RSA2048-SHA256 加密套件。
  • 传播、验证、生成、记录日志并转发 x-wop-request-id 值,同时不影响已签名的请求字节。
  • 提供配置加载与验证、传输方式发现、默认客户端构建以及一步式请求执行 API。

错误修复:

  • 防止请求 ID 进入已签名的请求头集合,或改变互操作性固定测试数据的预期结果。
  • 将非 2xx 网关响应归类为结构化系统错误,并在对象表示中隐藏密钥材料。

增强功能:

  • 规范化并验证 HTTPS 网关 URL 和 API 路径,同时支持缓存的配置快照和可配置的 HTTP 客户端设置。

构建:

  • 将默认 JSON 配置资源打包到 SDK 中。

测试:

  • 扩展套件、请求 ID、配置、执行、重放和互操作性测试覆盖范围。
Original summary in English

Sourcery 摘要

在保持签名行为和互操作性行为不变的前提下,添加对 RSA2048 的支持、请求 ID 传递,以及由配置驱动的请求执行。

新功能:

  • 默认支持 WOP-RSA2048-SHA256 加密套件。
  • 传递、验证、生成、记录日志并转发 x-wop-request-id 请求头,但不将其纳入签名请求头。
  • 提供配置加载与验证、传输层发现、默认客户端构建,以及一步式请求执行 API。

错误修复:

  • 确保传递请求 ID 不会改变已签名请求的字节内容或互操作性测试夹具的预期结果。
  • 将网关返回的非 2xx 响应归类为结构化系统错误,并在对象表示中隐藏密钥材料。

增强功能:

  • 规范化并验证 HTTPS 网关 URL 和 API 路径,缓存配置快照,并支持可配置的 HTTP 客户端设置和超时。

构建:

  • 将默认 JSON 配置资源打包到 SDK 中。

测试:

  • 扩展加密套件、请求 ID、配置、执行、重放、传输层和互操作性测试的覆盖范围。
Original summary in English

Sourcery 摘要

新增对 RSA2048 的支持、请求 ID 传递和由配置驱动的请求执行,同时保持签名行为和互操作性。

新功能:

  • 默认支持 WOP-RSA2048-SHA256 加密套件。
  • 支持传递经过验证、已记录日志且不参与签名的 x-wop-request-id,并在未提供时默认生成。
  • 提供配置加载、传输方式发现、默认客户端构建和单步请求执行 API。

错误修复:

  • 确保请求 ID 和仅用于互操作的标头不会被纳入已签名的请求字节或冻结的协议标头测试固件中。
  • 将非 2xx 网关响应归类为结构化系统错误,并在对象表示中隐藏密钥材料。

增强:

  • 验证并规范化网关 URL 和 API 路径,缓存配置快照,并支持配置 HTTP 客户端超时时间。

构建:

  • 将默认 JSON 配置资源打包到 SDK 中。

测试:

  • 扩展 RSA2048、请求 ID 处理、配置、请求执行、重放、传输和互操作性行为的测试覆盖。
Original summary in English

Sourcery 总结

在保留签名和互操作行为的同时,添加对 RSA2048 的支持、请求 ID 传递,以及由配置驱动的请求执行。

新功能:

  • 默认支持 WOP-RSA2048-SHA256 加密套件。
  • 添加 x-wop-request-id 的传递机制,对其进行校验、生成、记录日志并转发,同时不将其纳入请求签名。
  • 提供配置加载与校验、传输方式发现、默认客户端构建,以及一步式请求执行 API。

错误修复:

  • 传递请求 ID 时,保留已签名请求的字节内容及冻结的互操作测试夹具。
  • 将非 2xx 网关响应归类为结构化系统错误,并在对象表示中隐藏密钥材料。

增强功能:

  • 校验并规范化 HTTPS 网关 URL 和 API 路径,缓存配置快照,并支持配置 HTTP 客户端超时。

构建:

  • 将默认 JSON 配置资源打包到 SDK 中。

测试:

  • 扩展对 RSA2048、请求 ID 处理、配置、请求执行、重放、传输及互操作行为的测试覆盖。
Original summary in English

Sourcery 摘要

新增 RSA2048 支持、请求 ID 传递和由配置驱动的请求执行,同时保持签名与互操作行为不变。

新功能:

  • 默认支持 WOP-RSA2048-SHA256 加密套件。
  • 支持经过验证的 x-wop-request-id 传递,包括默认生成、出站日志记录和执行路径转发。
  • 提供配置加载与验证、传输方式发现、默认客户端构建以及一步式请求执行 API。

错误修复:

  • 确保请求 ID 和仅用于互操作的标头不会包含在签名请求字节或冻结的协议标头测试样例中。
  • 将非 2xx 网关响应归类为结构化系统错误,并在对象表示中隐藏密钥材料。

改进:

  • 规范化并验证 HTTPS 网关 URL 和 API 路径,缓存配置快照,并应用可配置的 HTTP 客户端超时。

构建:

  • 将默认 JSON 配置资源打包到 SDK 中。

测试:

  • 扩展 RSA2048、请求 ID 处理、配置、执行、重放、传输方式发现和互操作行为的测试覆盖。
Original summary in English

Sourcery 摘要

在保留签名和互操作行为的同时,新增对 RSA2048 的支持、请求 ID 传递,以及由配置驱动的请求执行。

新功能:

  • 默认支持 WOP-RSA2048-SHA256 加密套件。
  • 支持经过验证的 x-wop-request-id 传递,包括默认生成、出站日志记录,以及在执行路径中转发;不会将其包含在请求签名中。
  • 提供配置加载与验证、传输方式发现、默认客户端构建以及一步式请求执行 API。

错误修复:

  • 传递请求 ID 时,保留已签名的请求字节和固定的互操作测试样例。
  • 将非 2xx 网关响应归类为结构化系统错误,并在对象表示中隐藏密钥材料。

增强功能:

  • 验证并规范化 HTTPS 网关端点和 API 路径,缓存配置快照,并应用可配置的 HTTP 客户端超时时间。

构建:

  • 将默认 JSON 配置资源打包到 SDK 中。

测试:

  • 扩大测试覆盖范围,涵盖 RSA2048、请求 ID 处理、配置、执行、重放、传输方式发现和互操作行为。
Original summary in English

Summary by Sourcery

Add RSA2048 support, request ID propagation, and configuration-driven request execution while preserving signing and interoperability behavior.

New Features:

  • Add default support for the WOP-RSA2048-SHA256 encryption suite.
  • Support validated x-wop-request-id propagation with default generation, outbound logging, and execution-path forwarding without including it in request signatures.
  • Provide configuration loading and validation, transport discovery, default client construction, and one-step request execution APIs.

Bug Fixes:

  • Preserve signed request bytes and frozen interoperability fixtures when propagating request IDs.
  • Classify non-2xx gateway responses as structured system errors and redact key material from object representations.

Enhancements:

  • Validate and normalize HTTPS gateway endpoints and API paths, cache configuration snapshots, and apply configurable HTTP client timeouts.

Build:

  • Package the default JSON configuration resource with the SDK.

Tests:

  • Expand coverage for RSA2048, request ID handling, configuration, execution, replay, transport discovery, and interoperability behavior.

zheng-lei-coder and others added 4 commits September 16, 2026 15:07
协议核心(wop-specs crypto-spec E1 扩展位 + sdk-spec 附录 I,对齐
wop-java-sdk feature_20260922_fix 基准):

- suites.py:新增 WOP-RSA2048-SHA256 套件(RSA 2048 位、
  RSA-2048-OAEP 包装),密钥算法表与包装算法表同步扩容
- client.py:build_request/execute 新增 request_id 请求级参数
  (附录 I)——恒不入签(签名落盘后写入头)、构造即校验(trim 前
  原值控制字符扫描防头注入、trim 后 UTF-8 字节 ≤128,trim 集 =
  G2 TrimAll 同集,不用 str.strip 的 Unicode 超集)、未传/空白
  缺省生成 uuid4().hex(request_id_generator 模块级可替换)、
  wop_sdk.outbound INFO 日志打印最终头值(日志义务)
- interop 头集合哨兵剥离透传头(fixture sha256 钉死不变)
- 确定性重放/BDD 两次构建场景注入固定生成器(附录 I3 CSPRNG 豁免)
- API 快照随公共签名/docstring 变化刷新

测试:346 全绿(新增 requestId 8 项 + RSA2048 套件 2 项);
equivalent-anchors 与 api-snapshot 门禁通过。
说明:覆盖率门禁(98%)在本仓分支为既有缺口(基线 89.37%,
本次改动后 89.59%,集中在 P0 config loader 发现序列用例,
与本次改动无关)
@changeset-bot

changeset-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 620d3c4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 73a6576d-e17c-42d9-a31c-77d563e4a2f1
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

审查者指南

本 PR 对齐最新 wop-specs:增加 RSA2048 套件支持,并在签名完成后实现经过严格构造期校验、缺省 UUID 生成和 INFO 日志记录的 x-wop-request-id 透传;同时引入配置加载/校验、默认客户端、传输发现及 execute 一站式调用,并相应调整互操作基线和测试。

使用 x-wop-request-id 进行请求签名的时序图

sequenceDiagram
    participant Caller
    participant WopClient
    participant Signer
    participant OutboundLog

    Caller->>WopClient: build_request(method, path, body, request_id)
    WopClient->>WopClient: resolve_request_id(request_id)
    WopClient->>Signer: build_canonical(headers, body)
    Signer-->>WopClient: signature
    WopClient->>WopClient: write x-wop-request-id after x-wop-sign
    WopClient->>OutboundLog: info(x-wop-request-id, method, path)
    WopClient-->>Caller: RequestDraft
Loading

已配置客户端执行流程的时序图

sequenceDiagram
    participant Caller
    participant WopClient
    participant Transport
    participant Gateway

    Caller->>WopClient: execute(method, path, body, request_id)
    WopClient->>WopClient: validate_api_path(path)
    WopClient->>WopClient: build_request(..., request_id)
    WopClient->>Transport: send_draft(transport, server_root, draft)
    Transport->>Gateway: HTTP request with x-wop-request-id
    Gateway-->>Transport: HTTP response
    alt response status is 2xx
        Transport-->>WopClient: response
        WopClient-->>Caller: verify_response(...)
    else response status is non-2xx
        Transport-->>WopClient: response
        WopClient-->>Caller: WopGatewayResponseError
    end
Loading

文件级变更

变更 详情 文件
扩展套件注册与配置支持,使 RSA2048 成为可解析、可校验和可用于加解密签名流程的默认支持套件。
  • 新增 RSA2048 密钥算法映射、OAEP 包装算法和 2048 位密钥长度约束。
  • 同步更新套件、密钥加载及配置校验路径,并补充 RSA2048 解析与兼容性测试。
src/wop_sdk/suites.py
src/wop_sdk/config/_validator.py
tests/test_suites.py
tests/test_config.py
config/wopSdkConfigDefault.json
实现 x-wop-request-id 透传头的构造、校验、生成、日志和不入签语义。
  • 在请求构造阶段对原始值扫描控制字符,按指定 TrimAll 集合裁剪,并以 UTF-8 字节数限制为 128。
  • 对未传或空白值生成可注入的无连字符 UUID,并在签名生成后追加头部,确保其不影响签名字节。
  • 在出向构造点以 INFO 级别记录最终 request ID,并覆盖显式值、缺省生成、边界校验、日志及确定性生成器测试。
src/wop_sdk/client.py
tests/test_client.py
tests/test_bdd.py
tests/test_interop.py
新增配置加载与一站式客户端执行能力,将配置发现、校验、传输选择和网关调用串联起来。
  • 增加不可变配置模型、Builder、JSON 解析、重复键与非有限数拒绝、缓存及多来源配置发现。
  • 增加 HTTPS 网关 URL/API path 校验、传输适配器发现、默认客户端单例与重置机制。
  • 新增 execute 入口,负责路径校验、请求构造、发送、非 2xx 响应转换及响应验签解密。
  • 公开配置 API、网关响应错误类型和相关客户端接口,并为 repr 中的密钥增加脱敏。
src/wop_sdk/config/__init__.py
src/wop_sdk/config/_loader.py
src/wop_sdk/config/_models.py
src/wop_sdk/config/_parser.py
src/wop_sdk/config/_validator.py
src/wop_sdk/transport_discovery.py
src/wop_sdk/client.py
src/wop_sdk/errors.py
src/wop_sdk/__init__.py
tests/test_config.py
tests/test_coverage_gaps.py
调整互操作测试和确定性重放基线以适配新增透传头,同时维持原有协议 fixture 不变。
  • 更新 interop fixture 哈希哨兵,并在协议头集合比较前剥离透传头。
  • 通过注入固定 request ID 生成器保持重放场景的完整头部和报文可确定。
  • 扩大测试快照及配置、request ID、RSA2048 的覆盖范围。
tests/test_interop.py
tests/test_bdd.py
tests/test_client.py
tests/api_snapshot.json

提示和命令

与 Sourcery 交互

  • 触发新的审查: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 根据审查评论生成 GitHub issue: 回复审查评论,请 Sourcery 根据该评论创建 issue。你也可以回复审查评论并使用 @sourcery-ai issue,根据该评论创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,随时重新生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任意位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,随时重新生成摘要。
  • 生成审查者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时重新生成审查者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,此功能会很有用。
  • 忽略所有 Sourcery 审查: 在拉取请求中评论 @sourcery-ai dismiss,忽略所有现有的 Sourcery 审查。如果你想从新的审查开始,这尤其有用——别忘了评论 @sourcery-ai review 以触发新的审查!

自定义使用体验

访问你的控制面板以:

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

本 PR 对齐最新 wop-specs:增加 RSA2048 套件支持,并在签名完成后实现经过严格构造期校验、缺省 UUID 生成和 INFO 日志记录的 x-wop-request-id 透传;同时引入配置加载/校验、默认客户端、传输发现及 execute 一站式调用,并相应调整互操作基线和测试。

Sequence diagram for request signing with x-wop-request-id

sequenceDiagram
    participant Caller
    participant WopClient
    participant Signer
    participant OutboundLog

    Caller->>WopClient: build_request(method, path, body, request_id)
    WopClient->>WopClient: resolve_request_id(request_id)
    WopClient->>Signer: build_canonical(headers, body)
    Signer-->>WopClient: signature
    WopClient->>WopClient: write x-wop-request-id after x-wop-sign
    WopClient->>OutboundLog: info(x-wop-request-id, method, path)
    WopClient-->>Caller: RequestDraft
Loading

Sequence diagram for configured client execute flow

sequenceDiagram
    participant Caller
    participant WopClient
    participant Transport
    participant Gateway

    Caller->>WopClient: execute(method, path, body, request_id)
    WopClient->>WopClient: validate_api_path(path)
    WopClient->>WopClient: build_request(..., request_id)
    WopClient->>Transport: send_draft(transport, server_root, draft)
    Transport->>Gateway: HTTP request with x-wop-request-id
    Gateway-->>Transport: HTTP response
    alt response status is 2xx
        Transport-->>WopClient: response
        WopClient-->>Caller: verify_response(...)
    else response status is non-2xx
        Transport-->>WopClient: response
        WopClient-->>Caller: WopGatewayResponseError
    end
Loading

File-Level Changes

Change Details Files
扩展套件注册与配置支持,使 RSA2048 成为可解析、可校验和可用于加解密签名流程的默认支持套件。
  • 新增 RSA2048 密钥算法映射、OAEP 包装算法和 2048 位密钥长度约束。
  • 同步更新套件、密钥加载及配置校验路径,并补充 RSA2048 解析与兼容性测试。
src/wop_sdk/suites.py
src/wop_sdk/config/_validator.py
tests/test_suites.py
tests/test_config.py
config/wopSdkConfigDefault.json
实现 x-wop-request-id 透传头的构造、校验、生成、日志和不入签语义。
  • 在请求构造阶段对原始值扫描控制字符,按指定 TrimAll 集合裁剪,并以 UTF-8 字节数限制为 128。
  • 对未传或空白值生成可注入的无连字符 UUID,并在签名生成后追加头部,确保其不影响签名字节。
  • 在出向构造点以 INFO 级别记录最终 request ID,并覆盖显式值、缺省生成、边界校验、日志及确定性生成器测试。
src/wop_sdk/client.py
tests/test_client.py
tests/test_bdd.py
tests/test_interop.py
新增配置加载与一站式客户端执行能力,将配置发现、校验、传输选择和网关调用串联起来。
  • 增加不可变配置模型、Builder、JSON 解析、重复键与非有限数拒绝、缓存及多来源配置发现。
  • 增加 HTTPS 网关 URL/API path 校验、传输适配器发现、默认客户端单例与重置机制。
  • 新增 execute 入口,负责路径校验、请求构造、发送、非 2xx 响应转换及响应验签解密。
  • 公开配置 API、网关响应错误类型和相关客户端接口,并为 repr 中的密钥增加脱敏。
src/wop_sdk/config/__init__.py
src/wop_sdk/config/_loader.py
src/wop_sdk/config/_models.py
src/wop_sdk/config/_parser.py
src/wop_sdk/config/_validator.py
src/wop_sdk/transport_discovery.py
src/wop_sdk/client.py
src/wop_sdk/errors.py
src/wop_sdk/__init__.py
tests/test_config.py
tests/test_coverage_gaps.py
调整互操作测试和确定性重放基线以适配新增透传头,同时维持原有协议 fixture 不变。
  • 更新 interop fixture 哈希哨兵,并在协议头集合比较前剥离透传头。
  • 通过注入固定 request ID 生成器保持重放场景的完整头部和报文可确定。
  • 扩大测试快照及配置、request ID、RSA2048 的覆盖范围。
tests/test_interop.py
tests/test_bdd.py
tests/test_client.py
tests/api_snapshot.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好——我发现了 2 个问题

面向 AI Agent 的提示
请处理此次代码审查中的评论:

## 单条评论

### 评论 1
<location path="src/wop_sdk/config/_loader.py" line_range="18-116" />
<code_context>
+PACKAGED_CONFIG = "config/wopSdkConfig.json"
</code_context>
<issue_to_address>
**issue (bug_risk):** 默认配置发现使用 `resources.files("wop_sdk.config").joinpath("wopSdkConfig.json")` 查找打包资源,但本次新增文件位于仓库根目录 `config/wopSdkConfigDefault.json`,名称和包内路径均不匹配;没有用户配置文件时 `load_default()` 必然抛出“未找到可读配置文件”。

**触发条件:** 当调用 `WopClient.default_client()` 且环境变量、当前目录和用户目录均没有配置文件。

**建议修复:** 将默认配置以 `wop_sdk/config/wopSdkConfig.json` 打包,或让 `PACKAGED_CONFIG` 与新增文件的实际资源路径和文件名一致。
</issue_to_address>

### 评论 2
<location path="src/wop_sdk/config/_validator.py" line_range="79" />
<code_context>
+    if not parsed.netloc:
+        raise ConfigurationError(f"{field_name} 不是合法 URL: {trimmed}")
+    host = parsed.hostname or ""
+    port = parsed.port
+    path = parsed.path or ""
+    normalized = "https://" + host.lower()
</code_context>
<issue_to_address>
**issue (bug_risk):** `parsed.port` 在 URL 端口不是合法整数或超出范围时直接抛出 `ValueError`,该异常未被转换为 `ConfigurationError`;配置加载因此泄漏底层异常,违反配置校验接口的统一错误契约。

**触发条件:** 当 `serverRoot` 或 `backupServerRoots` 包含非法端口,例如 `https://gw.example.com:abc`。

**建议修复:** 在读取 `parsed.port` 时捕获 `ValueError`,并重新抛出带字段名的 `ConfigurationError`。

```suggestion
    try:
        port = parsed.port
    except ValueError as exc:
        raise ConfigurationError(f"{field_name} 不是合法 URL: {trimmed}") from exc
```
</issue_to_address>

Sourcery 评估

需要人工审查。 请先处理 2 个待解决的问题。此外,本次变更新增了 RSA-2048 签名/加密路径,以及由配置驱动的执行流程,该流程可以向配置的网关主机发送已签名或已加密的请求;加密实现或主机验证中的错误可能导致凭据或请求数据泄露,而回滚并不能撤回已经发送的流量或已经暴露的数据。

阻塞性问题:src/wop_sdk/config/_loader.py:116、src/wop_sdk/config/_validator.py:79


Sourcery 对开源项目免费提供服务——如果您喜欢我们的审查结果,欢迎分享 ✨
Original comment in English

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/wop_sdk/config/_loader.py" line_range="18-116" />
<code_context>
+PACKAGED_CONFIG = "config/wopSdkConfig.json"
</code_context>
<issue_to_address>
**issue (bug_risk):** 默认配置发现使用 `resources.files("wop_sdk.config").joinpath("wopSdkConfig.json")` 查找打包资源,但本次新增文件位于仓库根目录 `config/wopSdkConfigDefault.json`,名称和包内路径均不匹配;没有用户配置文件时 `load_default()` 必然抛出“未找到可读配置文件”。

**Triggers:** 当调用 `WopClient.default_client()` 且环境变量、当前目录和用户目录均没有配置文件。

**Suggested fix:** 将默认配置以 `wop_sdk/config/wopSdkConfig.json` 打包,或让 `PACKAGED_CONFIG` 与新增文件的实际资源路径和文件名一致。
</issue_to_address>

### Comment 2
<location path="src/wop_sdk/config/_validator.py" line_range="79" />
<code_context>
+    if not parsed.netloc:
+        raise ConfigurationError(f"{field_name} 不是合法 URL: {trimmed}")
+    host = parsed.hostname or ""
+    port = parsed.port
+    path = parsed.path or ""
+    normalized = "https://" + host.lower()
</code_context>
<issue_to_address>
**issue (bug_risk):** `parsed.port` 在 URL 端口不是合法整数或超出范围时直接抛出 `ValueError`,该异常未被转换为 `ConfigurationError`;配置加载因此泄漏底层异常,违反配置校验接口的统一错误契约。

**Triggers:** 当 `serverRoot` 或 `backupServerRoots` 包含非法端口,例如 `https://gw.example.com:abc`。

**Suggested fix:** 在读取 `parsed.port` 时捕获 `ValueError`,并重新抛出带字段名的 `ConfigurationError`。

```suggestion
    try:
        port = parsed.port
    except ValueError as exc:
        raise ConfigurationError(f"{field_name} 不是合法 URL: {trimmed}") from exc
```
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and this adds a new RSA-2048 signing/encryption path and a configuration-driven execute flow that can send signed or encrypted requests to configured gateway hosts; a cryptographic or host-validation mistake could expose credentials or request data, and reverting would not undo traffic already sent or data already exposed.

Blocking findings: src/wop_sdk/config/_loader.py:116, src/wop_sdk/config/_validator.py:79


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/wop_sdk/config/_loader.py Resolved
Comment thread src/wop_sdk/config/_validator.py Resolved
zheng-lei-coder and others added 4 commits September 29, 2026 11:00
Sourcery 评审两条(PR #39):

- 配置发现兜底(K6 优先级 6):默认模板此前仅在仓根 config/
  wopSdkConfigDefault.json,包内无 wopSdkConfig.json,无用户配置时
  load_default() 必然「未找到可读配置文件」。现将模板打入
  wop_sdk/config/wopSdkConfig.json(pyproject 增加 package-data),
  兜底可被发现并读取(占位符密钥在密钥校验阶段给出明确文案)
- validate_gateway_url:parsed.port 对非法端口(:abc/越界)抛原生
  ValueError,归一为带字段名的 ConfigurationError,符合配置校验
  统一错误契约

测试:新增打包兜底与非法端口 2 项回归,348 全绿;anchors 与
api-snapshot 门禁通过
- extra_headers 携带 x-wop-request-id 不再入签名集合,并入 request_id
  解析链同口径校验;双来源同传构造期拒
- EXPECTED_SHA256 回滚为真源实测值 c920ca1a(9a51486d 无来源,合入即红)
- urllib 传输接线 readTimeout 超时,消除无限挂起面
- 冻结向量接入:rsa2048 签名字节级/OAEP 解包/位宽校验/L2 往返 +
  extra_headers 组合的恒不入签金丝雀(先红后绿 7 例)
重审(2026-10-18)发现:双变体同传时按插入序取首值、其余静默丢弃,
与双来源构造即拒同属消歧语义,补测试显式钉定防漂移。
字节级同步合并后 crypto-vectors.json:_meta v0.4-draft、rsa2048 节内联就位
@coderabbitai

coderabbitai Bot commented Oct 18, 2026

Copy link
Copy Markdown

Add Carrot credits or activate Agent usage billing to use Autofix

- parser/loader/validator/builder/transport 发现负例与边界闭合(91→99%)
- 修 expiredSeconds 整 float 被拒:与 _parse_int_field 同语义
@im47cn-bot

Copy link
Copy Markdown
Contributor

本仓未启用 changesets 体系(无 .changeset/ 目录,pyproject.toml 无相关依赖)。发版由 .github/workflows/release.yml tag 驱动,且校验 vX.Y.Z tag 与 pyproject [project].version 严格一致,版本由发版流程管理,PR 无需 changeset 文件,此提示可忽略。

_read_positive_int 语义(须为正,与 dotnet 口径一致)下
readTimeout=0 应拒绝;ok 判定同时修掉 bool 陷阱
(False == 0 误判为 maxRetryCount=0 合法组)。
@im47cn
im47cn enabled auto-merge October 18, 2026 08:24
@im47cn
im47cn merged commit f219c44 into main Oct 18, 2026
23 of 24 checks passed
@im47cn
im47cn deleted the feature_20260915_config branch October 18, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants