test: 移除测试里指向仓库外的绝对 sys.path 硬编码(+ 清掉被跟踪的 .pyc) #1

Closed
xiaozhai wants to merge 0 commits from fix/abs-path into main
Collaborator

改了什么

  1. tests/test_protocol.py:把 sys.path.insert(0, "/home/program/NextAgent/src") 改成相对本仓库布局的 Path(__file__).resolve().parent.parent / "src",消除对宿主机另一份(已改动的)检出的耦合。
  2. 顺手清理:.pyc 不再被版本控制跟踪。

为什么

原写法让测试 import 到仓库外的脏副本,31 个用例里 1 FAIL + 1 ERROR;改用相对路径后 31/31 全绿。

## 改了什么 1. `tests/test_protocol.py`:把 `sys.path.insert(0, "/home/program/NextAgent/src")` 改成相对本仓库布局的 `Path(__file__).resolve().parent.parent / "src"`,消除对宿主机另一份(已改动的)检出的耦合。 2. 顺手清理:`.pyc` 不再被版本控制跟踪。 ## 为什么 原写法让测试 import 到仓库外的脏副本,31 个用例里 1 FAIL + 1 ERROR;改用相对路径后 31/31 全绿。
xiaozhai added 1 commit 2026-10-16 09:33:13 +08:00
tests/test_protocol.py 原本把 "/home/program/NextAgent/src" 硬编码进
sys.path,指向宿主机上另一份(工作区为脏的)NextAgent 检出。结果测试
import 的是那份副本而非本仓库的 src,导致两个用例失败:

  - test_decode_raises_on_wrong_fmt_id → DecodingError not raised
  - test_register_and_send → ValueError: inhomogeneous shape

改为基于 __file__ 推导仓库内的 src/ 路径,测试不再依赖仓库外的任何
绝对路径,任何检出位置都能跑通。实现代码未做改动——这是测试耦合问题,
不是实现 bug。

同时取消跟踪 7 个误提交的 .pyc(.gitignore 规则此前加晚了)。
仅 git rm --cached,工作区文件保留;.gitignore 的 __pycache__/ 与 *.pyc
规则继续生效。

python3 -m unittest discover -s tests → Ran 31 tests, OK
git ls-files '*.pyc' | wc -l → 0
jianf approved these changes 2026-10-16 09:34:51 +08:00
jianf left a comment
Owner

复审通过:改动与判据一致,两条正向判据全绿、两条变异均被咬住。

复审通过:改动与判据一致,两条正向判据全绿、两条变异均被咬住。
jianf closed this pull request 2026-10-17 22:23:16 +08:00

Pull request closed

Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jianf/NextAgent#1
No description provided.