fix(bcos): add regression test for .git suffix stripping in _detect_repo_name (#7955)#7998
Conversation
Add test_detect_repo_name_strips_dotgit_suffix_not_chars to verify that
repos like audit, test, gigi are not truncated by the old rstrip('.git')
bug which stripped individual characters instead of the exact suffix.
Refs Scottcjn#7955
elianguitarra
left a comment
There was a problem hiding this comment.
I reviewed the focused regression test against the original #7955 bug and the current _detect_repo_name() implementation.
Substantive observations:
-
The new cases are well scoped for the exact
.gitsuffix regression:audit.git,test.git, andgigi.gitall end in characters from the oldrstrip(.git)character set, so this test would catch the accidental truncation class that motivated #7955. Keeping this intests/test_bcos_engine_core.pyis also a good fit because it exercises_detect_repo_name()without pulling in the full BCOS scan path. -
One coverage gap remains from the original issue: #7955 also showed remotes without a
.gitsuffix being corrupted by the old code, for examplehttps://github.com/acme/my-botbecomingacme/my-boortoolkitbecomingtoolki. This PR only tests.git-suffixed URLs. I would add at least one no-suffix case ending int,i, org, such ashttps://github.com/owner/my-bot\n->owner/my-bot, to make sure future refactors preserve therstrip(/)then exact-suffix behavior. -
The existing parser handles both HTTPS and SSH prefixes, but the new suffix-sensitive regression only runs through the HTTPS branch. Since the old bug sat after prefix stripping, an SSH case like
git@github.com:owner/audit.git->owner/auditwould cheaply confirm both URL branches stay protected.
Validation I ran locally:
python -m pytest tests/test_bcos_engine_core.py -q-> 7 passedgit diff --check main...HEAD-> passed
GitHub currently shows the broad test check failing on the PR, while the focused local BCOS engine test passes. I did not inspect the failing workflow logs deeply enough to attribute that failure to this patch.
|
Thanks @elianguitarra — great catch. I've pushed an update adding the missing coverage:
All 7 tests pass locally. Could you take another look when you have a moment? |
|
Thanks @elianguitarra — great catch. I've pushed an update adding the missing coverage:
All 7 tests pass locally. Could you take another look when you have a moment? |
elianguitarra
left a comment
There was a problem hiding this comment.
Thanks for the quick update. The added regression cases address both coverage gaps from my previous review:
- The no-
.gitcases (https://github.com/acme/my-botandhttps://github.com/acme/toolkit) now pin the original #7955 behavior whererstrip(.git)could also mangle remotes that never had a.gitsuffix. - The SSH cases (
git@github.com:owner/audit.gitandgit@github.com:owner/my-bot) now exercise the second supported URL prefix, so both parser branches are covered.
I also re-ran the focused validation locally:
python -m pytest tests/test_bcos_engine_core.py -q-> 7 passedgit diff --check main...HEAD-> passed- GitHub checks are now green on this head.
However, this PR currently also deletes specs/RIP_POA_SPEC_v1.0.md in full (1007 deleted lines). That file is unrelated to the BCOS repo-name regression test and was not part of the review/fix scope. Please restore that spec file or remove the deletion from this branch, leaving only the tests/test_bcos_engine_core.py regression coverage change. Once that accidental deletion is gone, the test update itself looks good to me.
…ession Address @elianguitarra review feedback: - Add no-suffix URL cases ending in t/i/g (my-bot, toolkit) to ensure rstrip('/') + exact-suffix matching is preserved. - Add SSH remote cases (git@github.com:owner/repo.git) to confirm both URL branches are protected by the fix. Refs Scottcjn#7955
82b9e72 to
aa32e79
Compare
|
@elianguitarra The accidental spec file deletion has been removed. The PR now contains only:
No deletion remains. Ready for another look when you have a moment. 🙏 |
|
The accidental spec file deletion has been removed. The PR now contains only:
No |
elianguitarra
left a comment
There was a problem hiding this comment.
Thanks for cleaning that up. I re-reviewed the current head aa32e791ed8505f4080f55f1cf20b5ede23284b1.
The accidental specs/RIP_POA_SPEC_v1.0.md deletion is gone, and the remaining BCOS regression coverage looks good:
- The no-
.gitHTTPS cases now cover the originalrstrip(.git)failure mode for names ending int/i/gwithout requiring a suffix. - The SSH cases now exercise the second remote-parsing branch, including both
.gitand no-suffix inputs. - The only non-test change is the local Speckit/specs ignore rule; it does not remove the tracked spec file anymore.
Validation re-run locally:
git diff --name-status origin/main...HEAD-> only.gitignoreandtests/test_bcos_engine_core.pygit diff --check origin/main...HEAD-> passedpython -m pytest tests/test_bcos_engine_core.py -q-> 7 passed
Looks good to me now.
RTC RewardThis merged PR earned 5 RTC — sent to |
FlintLeng
left a comment
There was a problem hiding this comment.
🔍 PR #7998 审查报告
标题: fix(bcos): add regression test for .git suffix stripping in _detect_repo_name (#7955)
作者: IcanBENCHurCAT
钱包地址: RTC019e78d600fb3131c29d7ba80aba8fe644be426e
📊 改动摘要
| 文件 | 新增 | 删除 |
|---|---|---|
.gitignore |
+8 | 0 |
tests/test_bcos_engine_core.py |
+35 | 0 |
| 总计 | +43 | 0 |
🔬 技术评估
1. 问题背景
此 PR 针对 commit 2e3318f6 中已修复的 .git 后缀剥离 bug 添加回归测试。原始 bug 是 Python 字符串方法 rstrip(".git") 的典型误用——它会剥离任意在字符集 ".git" 中的字符,而非精确移除 ".git" 字符串。
例如:
audit.git会被错误地处理为audi(t 被剥离)test.git会变成s(t, e 被剥离)gigi.git会变成空字符串
2. 测试设计评估
新增的测试用例位于 tests/test_bcos_engine_core.py,覆盖以下场景:
- 标准仓库(如
repo.git→repo) - 边界情况(如
audit.git、test.git、gigi.git) - 确保不会发生字符级剥离
测试设计合理,使用参数化测试模式验证多个 repo 名称的正确处理。
3. 代码质量
- ✅ 测试独立于业务逻辑,无副作用
- ✅ 明确引用关联 issue #7955
- ✅ 回归测试覆盖已知 bug 场景
- ✅
.gitignore更新(可能是 IDE/环境配置)
4. 潜在改进建议
- 可考虑添加反向测试:非
.git结尾的仓库名应保持不变 - 测试文档可更明确说明"为什么这些 repo 名称是边界情况"
✅ 审查结论
APPROVE ✅
这是一个高质量的回归测试 PR。针对已修复的 Python 字符串处理 bug,测试用例覆盖了关键的边界情况,确保该 bug 不会再次引入。代码简洁、目的明确,符合测试最佳实践。
认领 RTC 奖励: 2 RTC → RTC019e78d600fb3131c29d7ba80aba8fe644be426e
Add regression test for the .git suffix stripping fix already in main (commit 2e3318f).
This test ensures repos like audit, test, gigi are not incorrectly truncated by the old rstrip(".git") bug which stripped individual characters instead of the exact ".git" suffix.
Refs #7955