Skip to content

fix: 清零 sourcery gate 16 项 issue - #43

Merged
im47cn merged 2 commits into
mainfrom
feat/pinned-specs-fetch
Oct 18, 2026
Merged

im47cn merged 2 commits into
mainfrom
feat/pinned-specs-fetch

Conversation

@im47cn-bot

@im47cn-bot im47cn-bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Sourcery 生成的摘要

将测试规范固定到已验证的 wop-specs 版本;如果引用的向量不匹配,则立即失败。

Bug 修复:

  • 通过获取固定版本的来源并在校验和不匹配时立即失败,防止测试静默使用过时或被篡改的加密及互操作性向量。

改进:

  • 让测试向量管理与固定版本的 wop-specs 来源保持一致,并移除已提交的 fixture 副本。

测试:

  • 更新共享测试设置,使其在测试收集期间获取并验证所需的规范向量。

杂项:

  • 将生成或下载的规范 fixture 添加到忽略规则中。
Original summary in English

Sourcery 摘要

将测试向量固定到经过验证的 wop-specs 修订版本,防止测试使用过期或被篡改的固件。

Bug Fixes:

  • 确保在固定的加密和互操作性向量不可用或其校验和与预期不符时,测试会以失败方式关闭。

Enhancements:

  • 将测试向量管理方式改为使用固定的 wop-specs 来源,而不是维护已提交的固件副本。

Tests:

  • 更新共享测试设置,在收集测试期间获取并验证所需的规范向量。

Chores:

  • 忽略生成的或下载的规范固件。
Original summary in English

Summary by Sourcery

Pin test vectors to a verified wop-specs revision and prevent tests from using stale or tampered fixtures.

Bug Fixes:

  • Ensure tests fail closed when pinned cryptographic and interoperability vectors are unavailable or do not match their expected checksums.

Enhancements:

  • Align test vector management with a pinned wop-specs source instead of maintaining committed fixture copies.

Tests:

  • Update shared test setup to fetch and validate the required specification vectors during test collection.

Chores:

  • Ignore generated or downloaded specification fixtures.

- conftest collect 阶段按 WOP_SPECS_REF+sha256 从 wop-specs 真源拉取
  crypto-vectors.json 与 interop-cases.json,mismatch 即失败(fail-closed)
- 副本出库改 gitignore 生成物,消除副本漂移面
- 升级流程:先合 wop-specs PR,再同步 conftest 钉版三件套
@im47cn-bot
im47cn-bot requested a review from im47cn as a code owner October 18, 2026 11:53
@changeset-bot

changeset-bot Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6818b99

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 Oct 18, 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: fd788b4c-d990-484d-bf82-631de32b822d
  • 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 Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

审查者指南

本 PR 将测试向量从仓库内的静态副本迁移为在测试收集阶段从固定的 wop-specs 提交下载,并通过 SHA-256 校验确保源内容未被替换;同时删除本地副本并忽略生成文件。审查重点是网络依赖、失败行为、下载路径,以及向量映射是否与现有测试兼容。

文件级变更

变更 详情 文件
将测试向量改为从 wop-specs 源按提交哈希拉取,并通过 SHA-256 校验确保内容固定。
  • 新增固定的 wop-specs commit ref 与两个向量文件的 SHA-256 白名单
  • 在 pytest collection 阶段通过 HTTPS 下载向量、校验摘要,并在摘要不匹配时 fail-closed
  • 将下载结果写入测试 fixtures 目录,然后继续加载 crypto vectors
tests/conftest.py
移除仓库内提交的测试向量副本,并调整忽略规则,避免下载产物进入版本控制。
  • 删除 crypto 与 interop 向量文件的本地副本
  • 为相关路径新增 gitignore 配置
.gitignore
tests/fixtures/crypto-vectors.json
tests/fixtures/interop-cases.json

提示与命令

与 Sourcery 交互

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

自定义体验

访问你的控制面板,即可:

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

获取帮助

Original review guide in English

Reviewer's Guide

本 PR 将测试向量从仓库内静态副本迁移为测试收集阶段从固定的 wop-specs 提交下载,并用 SHA-256 校验确保真源内容未被替换;同时删除本地副本并忽略生成文件。审查重点是网络依赖、失败行为、下载路径及向量映射是否与现有测试兼容。

File-Level Changes

Change Details Files
将测试向量改为从 wop-specs 真源按提交哈希拉取,并通过 SHA-256 校验保证内容固定。
  • 新增固定的 wop-specs commit ref 与两个向量文件的 SHA-256 白名单
  • 在 pytest collection 阶段通过 HTTPS 下载向量、校验摘要并在不匹配时 fail-closed
  • 将下载结果写入测试 fixtures 目录后继续加载 crypto vectors
tests/conftest.py
移除仓库内提交的测试向量副本,并调整忽略规则以避免拉取产物进入版本控制。
  • 删除 crypto 与 interop 向量文件的本地副本
  • 新增相关路径的 gitignore 配置
.gitignore
tests/fixtures/crypto-vectors.json
tests/fixtures/interop-cases.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.

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

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

## 各条评论

### 评论 1
<location path="tests/conftest.py" line_range="34" />
<code_context>
+                f"wop-specs {src} sha256 mismatch:期望 {expected},实得 {digest};"
+                "向量升级须先合 wop-specs PR 再同步钉版"
+            )
+        with open(os.path.join(HERE, "fixtures", os.path.basename(src)), "wb") as f:
+            f.write(data)
+
</code_context>
<issue_to_address>
**全新检出无法收集测试**

如果干净检出的代码中没有 `tests/fixtures` 目录,且 GitHub 获取操作成功,那么 `_fetch_pinned_specs()` 中的 `open(...)` 会因为父目录不存在而引发 `FileNotFoundError`,导致 pytest 中止测试收集。`f.write(data)` 无法执行完成。

打开下载的 fixture 文件之前,请先创建 `tests/fixtures`。

另请参阅 `tests/conftest.py:35`。
</issue_to_address>

### 评论 2
<location path="tests/conftest.py" line_range="26" />
<code_context>
+def _fetch_pinned_specs():
+    for src, expected in WOP_SPECS_SHA256.items():
+        url = f"https://raw.githubusercontent.com/wop-platform/wop-specs/{WOP_SPECS_REF}/{src}"
+        with urllib.request.urlopen(url, timeout=30) as resp:
+            data = resp.read()
+        digest = hashlib.sha256(data).hexdigest()
</code_context>
<issue_to_address>
**离线环境无法收集测试**

如果无法访问 GitHub,或测试环境没有网络,`urllib.request.urlopen()` 会引发异常,而模块级的 `_fetch_pinned_specs()` 调用会在导入 conftest 时传播该异常。即使本地已经存在有效的 fixture 文件,pytest 也无法收集测试。

如果现有 fixture 可用,请使用经过哈希验证的本地 fixture,并避免在获取失败时中止测试收集。

另请参阅 `tests/conftest.py:38`。
</issue_to_address>

### 评论 3
<location path="tests/conftest.py" line_range="34" />
<code_context>
+                f"wop-specs {src} sha256 mismatch:期望 {expected},实得 {digest};"
+                "向量升级须先合 wop-specs PR 再同步钉版"
+            )
+        with open(os.path.join(HERE, "fixtures", os.path.basename(src)), "wb") as f:
+            f.write(data)
+
</code_context>
<issue_to_address>
**并发运行时会读取到不完整的 fixture**

当多个 pytest 进程同时使用同一份检出代码时,以 `wb` 模式打开 fixture 会将其截断,而另一个进程可能正在读取该文件,因此 JSON 解析或 fixture 完整性测试会间歇性失败。

请先将每个 fixture 写入临时文件,写入完成后再以原子操作替换目标文件。
</issue_to_address>

Sourcery 评估

等待批准。 需先处理 3 项发现。

阻断性发现:tests/conftest.py:34、tests/conftest.py:26、tests/conftest.py:34


Sourcery 对开源项目免费——如果你喜欢我们的审查,请考虑分享 ✨
Original comment in English

Hey - I've found 3 issues

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

## Individual Comments

### Comment 1
<location path="tests/conftest.py" line_range="34" />
<code_context>
+                f"wop-specs {src} sha256 mismatch:期望 {expected},实得 {digest};"
+                "向量升级须先合 wop-specs PR 再同步钉版"
+            )
+        with open(os.path.join(HERE, "fixtures", os.path.basename(src)), "wb") as f:
+            f.write(data)
+
</code_context>
<issue_to_address>
**Fresh checkouts cannot collect tests**

When a clean checkout has no `tests/fixtures` directory and the GitHub fetch succeeds, `open(...)` in `_fetch_pinned_specs()` raises `FileNotFoundError` because the parent directory does not exist, so pytest aborts collection. `f.write(data)` cannot complete.

Create `tests/fixtures` before opening the downloaded fixture files.

Also at `tests/conftest.py:35`.
</issue_to_address>

### Comment 2
<location path="tests/conftest.py" line_range="26" />
<code_context>
+def _fetch_pinned_specs():
+    for src, expected in WOP_SPECS_SHA256.items():
+        url = f"https://raw.githubusercontent.com/wop-platform/wop-specs/{WOP_SPECS_REF}/{src}"
+        with urllib.request.urlopen(url, timeout=30) as resp:
+            data = resp.read()
+        digest = hashlib.sha256(data).hexdigest()
</code_context>
<issue_to_address>
**Offline tests cannot be collected**

When gitHub is unreachable or the test environment has no network access, `urllib.request.urlopen()` raises, and the module-level `_fetch_pinned_specs()` call propagates the exception during conftest import. Pytest cannot collect tests, even when valid fixture files are already present locally.

Use existing hash-verified fixtures when available, and avoid aborting collection on fetch failure when those fixtures are usable.

Also at `tests/conftest.py:38`.
</issue_to_address>

### Comment 3
<location path="tests/conftest.py" line_range="34" />
<code_context>
+                f"wop-specs {src} sha256 mismatch:期望 {expected},实得 {digest};"
+                "向量升级须先合 wop-specs PR 再同步钉版"
+            )
+        with open(os.path.join(HERE, "fixtures", os.path.basename(src)), "wb") as f:
+            f.write(data)
+
</code_context>
<issue_to_address>
**Concurrent runs read incomplete fixtures**

When multiple pytest processes use the same checkout concurrently, opening the fixture with `wb` truncates it while another process may be reading it, so JSON parsing or fixture-integrity tests fail intermittently.

Write each fixture to a temporary file and atomically replace the destination after the write completes.
</issue_to_address>

Sourcery assessment

Approval pending. 3 findings to address first.

Blocking findings: tests/conftest.py:34, tests/conftest.py:26, tests/conftest.py:34


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

Comment thread tests/conftest.py
Comment thread tests/conftest.py
def _fetch_pinned_specs():
for src, expected in WOP_SPECS_SHA256.items():
url = f"https://raw.githubusercontent.com/wop-platform/wop-specs/{WOP_SPECS_REF}/{src}"
with urllib.request.urlopen(url, timeout=30) as resp:

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.

🟡 Medium · 离线环境无法收集测试

如果无法访问 GitHub,或测试环境没有网络,urllib.request.urlopen() 会引发异常,而模块级的 _fetch_pinned_specs() 调用会在导入 conftest 时传播该异常。即使本地已经存在有效的 fixture 文件,pytest 也无法收集测试。

如果现有 fixture 可用,请使用经过哈希验证的本地 fixture,并避免在获取失败时中止测试收集。

另请参阅 tests/conftest.py:38。

AI Agent 提示
在 `tests/conftest.py` 第 26 行:

**离线环境无法收集测试**

如果无法访问 GitHub,或测试环境没有网络,`urllib.request.urlopen()` 会引发异常,而模块级的 `_fetch_pinned_specs()` 调用会在导入 conftest 时传播该异常。即使本地已经存在有效的 fixture 文件,pytest 也无法收集测试。

如果现有 fixture 可用,请使用经过哈希验证的本地 fixture,并避免在获取失败时中止测试收集。

另请参阅 `tests/conftest.py:38`。
Original comment in English

🟡 Medium · Offline tests cannot be collected

When gitHub is unreachable or the test environment has no network access, urllib.request.urlopen() raises, and the module-level _fetch_pinned_specs() call propagates the exception during conftest import. Pytest cannot collect tests, even when valid fixture files are already present locally.

Use existing hash-verified fixtures when available, and avoid aborting collection on fetch failure when those fixtures are usable.

Also at tests/conftest.py:38.

Prompt for AI agents
In `tests/conftest.py` at line 26:

**Offline tests cannot be collected**

When gitHub is unreachable or the test environment has no network access, `urllib.request.urlopen()` raises, and the module-level `_fetch_pinned_specs()` call propagates the exception during conftest import. Pytest cannot collect tests, even when valid fixture files are already present locally.

Use existing hash-verified fixtures when available, and avoid aborting collection on fetch failure when those fixtures are usable.

Also at `tests/conftest.py:38`.

Comment thread tests/conftest.py
f"wop-specs {src} sha256 mismatch:期望 {expected},实得 {digest};"
"向量升级须先合 wop-specs PR 再同步钉版"
)
with open(os.path.join(HERE, "fixtures", os.path.basename(src)), "wb") as f:

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.

🟡 Medium · 并发运行时会读取到不完整的 fixture

当多个 pytest 进程同时使用同一份检出代码时,以 wb 模式打开 fixture 会将其截断,而另一个进程可能正在读取该文件,因此 JSON 解析或 fixture 完整性测试会间歇性失败。

请先将每个 fixture 写入临时文件,写入完成后再以原子操作替换目标文件。

AI Agent 提示
在 `tests/conftest.py` 第 34 行:

**并发运行时会读取到不完整的 fixture**

当多个 pytest 进程同时使用同一份检出代码时,以 `wb` 模式打开 fixture 会将其截断,而另一个进程可能正在读取该文件,因此 JSON 解析或 fixture 完整性测试会间歇性失败。

请先将每个 fixture 写入临时文件,写入完成后再以原子操作替换目标文件。
Original comment in English

🟡 Medium · Concurrent runs read incomplete fixtures

When multiple pytest processes use the same checkout concurrently, opening the fixture with wb truncates it while another process may be reading it, so JSON parsing or fixture-integrity tests fail intermittently.

Write each fixture to a temporary file and atomically replace the destination after the write completes.

Prompt for AI agents
In `tests/conftest.py` at line 34:

**Concurrent runs read incomplete fixtures**

When multiple pytest processes use the same checkout concurrently, opening the fixture with `wb` truncates it while another process may be reading it, so JSON parsing or fixture-integrity tests fail intermittently.

Write each fixture to a temporary file and atomically replace the destination after the write completes.

@im47cn
im47cn merged commit 7f439b2 into main Oct 18, 2026
25 checks passed
@im47cn
im47cn deleted the feat/pinned-specs-fetch branch October 18, 2026 12:35
@im47cn-bot
im47cn-bot restored the feat/pinned-specs-fetch branch October 19, 2026 23:59
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.

2 participants