fix(tests): keep the single-owner scheme-list sentinel green on Windows - #5356
Conversation
str(path.relative_to(REPOSITORY_ROOT)) renders repo-relative paths with backslash separators on Windows, so the sole legitimate owner never matches the asserted POSIX literal and the loopx-project#5136 drift sentinel can never pass there. Render with as_posix() instead - an identity transform on POSIX, a separator normalisation on Windows. Refs loopx-project#5136 Signed-off-by: AronSwan <10492180@users.noreply.github.com>
huangruiteng
left a comment
There was a problem hiding this comment.
动机
现有唯一 owner 检查应拒绝重复规则,而不是拒绝 Windows 的路径分隔符。旧 helper 把相对路径直接转字符串,与固定 POSIX 期望值不一致;这会让正常贡献得到虚假的测试失败。本次完整解决的是这个测试格式问题,不更改运行时政策。
改动思路
复用标准库 Path.as_posix 在现有扫描 helper 的输出边界规范化标签。读取哪些源文件、匹配哪些 scheme、排序及“只能有一个 owner”的断言全部保留。无需放宽断言、增加 Windows 特判或另建一套扫描;这是足够小且可直接回滚的修复。
具体改动
仅 tests/control_plane/test_remote_location_shape_owner.py 第 65 行,把 str(path.relative_to(REPOSITORY_ROOT)) 换成 path.relative_to(REPOSITORY_ROOT).as_posix(),一行替换,没有生产文件、依赖、schema、权限、启用入口或隐含默认变更。
关键代码讲解
- 第 60 行 _source_text_spelling_the_scheme_list 仍读取实际匹配源文件;新的格式化只把诊断路径中的反斜杠变为统一斜杠,不改变源文本判定。
- 第 69 行 test_the_pattern_is_compiled_once_by_the_owner 仍要求结果严格等于唯一规范 owner。出现第二个相同规则时依旧失败,并未降低到“只要包含合法文件就通过”。
对主干的风险
我直接调用现有 helper 和断言,以标准库 PureWindowsPath 作为相对路径语义:旧版唯一 owner 输出反斜杠路径并触发 AssertionError,head 同一输入规范化后通过;再注入第二个匹配文件,head 的原断言仍失败。该反例同时验证修复误报和保留真正报警。普通源测试在不可变 base 与 head 上各 17 passed;改动文件 Ruff、精确提交 DCO 与 diff hygiene 均通过。
这里没有亲自运行 Windows 主机:上述是实际 helper/断言加标准库 WindowsPath 语义的合成复现,不是作者 Windows 报告的继承。全仓测试及远端 CI 未查询,也没有把未知红 CI 当成 PR 缺陷。生产 remote-location 格式、隐私边界和三个能力调用方均未改,因此不需要新的前端、Lark 或运行时验证面。
我的整体评价
APPROVE,适用于 6b0ede2。长期维护和贡献者体验都改善:合法 Windows 路径不再误报,重复 owner 仍阻断。复用现有测试满足持续回归价值,没有新增一次性 smoke;未来演进检查也已采用标准库格式化,不需要额外抽象或跟踪任务。残余限制是未执行原生 Windows OS,全局部署/整个议题完成不在本结论内;本次不执行合并。
English verdict: APPROVE - The existing owner guard now uses portable path labels, with the old false positive reproduced and duplicate-owner rejection preserved; native Windows execution was not claimed.
fix(tests): keep the single-owner scheme-list sentinel green on Windows
Fixes a Windows-only failure in the scheme-list drift sentinel introduced with the single-owner refactor (Refs #5136, via #5245 / #5270).
Problem
_source_text_spelling_the_scheme_list()intests/control_plane/test_remote_location_shape_owner.pybuilds the offender list with:On Windows,
str(Path.relative_to(...))renders separators as\, so the one legitimate owner shows up asloopx\public_safe_text.pyand the assertion against the POSIX literal["loopx/public_safe_text.py"]can never pass:CI runs on Linux, where
str()and POSIX rendering coincide, so this slipped through review of the refactor.Impact
All substantive coverage in the file passes on Windows — the seven scheme-recognition parameters, the unlisted-scheme rejection, and the three entry-point wiring tests. Only the literal-scan drift sentinel is affected. The practical consequence is that the #5136 anti-drift guard is permanently red for Windows developers: every run reports the sentinel as failed whether or not a real duplicate has crept in, which both kills the guard's signal on that platform and invites alert fatigue.
Fix
PurePath.as_posix()is an identity transform on POSIX (Linux/CI behavior unchanged); on Windows it renders the repo-relative path with/separators, matching the asserted literal.Evidence
Windows 11, Python 3.14, at
ee1ea64b0(currentmain):1 failed, 16 passed(sentinel only)17 passedRefs #5136