Repository navigation
fix: 清零 sourcery gate 16 项 issue - #43
Conversation
- conftest collect 阶段按 WOP_SPECS_REF+sha256 从 wop-specs 真源拉取 crypto-vectors.json 与 interop-cases.json,mismatch 即失败(fail-closed) - 副本出库改 gitignore 生成物,消除副本漂移面 - 升级流程:先合 wop-specs PR,再同步 conftest 钉版三件套
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
审查者指南本 PR 将测试向量从仓库内的静态副本迁移为在测试收集阶段从固定的 wop-specs 提交下载,并通过 SHA-256 校验确保源内容未被替换;同时删除本地副本并忽略生成文件。审查重点是网络依赖、失败行为、下载路径,以及向量映射是否与现有测试兼容。 文件级变更
提示与命令与 Sourcery 交互
自定义体验访问你的控制面板,即可:
获取帮助Original review guide in EnglishReviewer's Guide本 PR 将测试向量从仓库内静态副本迁移为测试收集阶段从固定的 wop-specs 提交下载,并用 SHA-256 校验确保真源内容未被替换;同时删除本地副本并忽略生成文件。审查重点是网络依赖、失败行为、下载路径及向量映射是否与现有测试兼容。 File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
你好——我发现了 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
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
| 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: |
There was a problem hiding this comment.
🟡 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`.| 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: |
There was a problem hiding this comment.
🟡 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.
Sourcery 生成的摘要
将测试规范固定到已验证的 wop-specs 版本;如果引用的向量不匹配,则立即失败。
Bug 修复:
改进:
测试:
杂项:
Original summary in English
Sourcery 摘要
将测试向量固定到经过验证的 wop-specs 修订版本,防止测试使用过期或被篡改的固件。
Bug Fixes:
Enhancements:
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:
Enhancements:
Tests:
Chores: