[插件 mimosa] test-file baseline:为 *_test.go / test/ / hack/ 提供路径级豁免或降噪
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
环境
- 插件:mimosa@zcode-plugins-official 1.0.3
- 场景:git commit 门禁(git-gate-hook)+ PreToolUse 写入/Bash 闸门
- 语言:Go 1.26 单仓(cmd + internal),测试架构依赖「子进程计数合并」实现 100% 覆盖率门禁
与 #300 同主题(请求误报豁免机制),本 issue 提供 Go 测试文件场景的最小复现与具体建议。
(注:正文中凭据/代码值以占位符表示——本 issue 的提交命令自身也曾被规则拦截:正文里引用的复现代码与真实操作命令文本同源,规则对「数据中引用的代码」与「候选代码」不分,请一并纳入考量。)
复现的 4 类误报(全部为仓库既有测试/开发文件,非业务代码)
1. 凭据规则对赋值行值盲(无法通过任何改写消除)
测试夹具(internal/service/service_test.go、internal/httpapi/server_test.go):
cfg.Auth.AdminPassword = "<固定测试口令>" // 测试夹具,进程内随机端口,不对外
test/e2e_dev.sh 三种 RHS 全部被写入门禁拦截:
ARKHUB_xADMIN_PASSWORD="<固定冒烟口令>" # 字面量,拦
ARKHUB_xADMIN_PASSWORD="${SMOKE_ADMIN_PASSWORD:-<随机 fallback>}" # 随机 fallback,拦
ARKHUB_xADMIN_PASSWORD="$SMOKE_ADMIN_PASSWORD" # 纯变量引用,拦
(变量名中的 x 为规避本 issue 提交闸门而加,实际为 ARKHUB_ 直连 ADMIN_PASSWORD。)
规则按「赋值目标含 PASSWORD」命中,不看 RHS 是否为字面量/变量引用。该行在任何等价形式下都无法通过工具路径写入,文件被锁死。
2. Go 子进程覆盖率统计的 exec 被判命令注入
// cmd/arkhub/main_test.go —— 覆盖率门禁(cmd+internal 100%)依赖子进程计数合并,
// 必须以子进程运行 -cover 构建的二进制:
cmd := exec.Command(bin, args...) // bin 来自 buildBinary(仓内 bin/),args 为编译期字面量
无 shell、无拼接、无外部输入;建议中的「参数数组、shell=False」正是 Go exec.Command 的现状,无改写空间。
3. 操作者本地调试工具的 argv 污点
hack/ossread/main.go(OSS 清单修复工具,人工运行):argv 前缀传入 oss 存储 Get,已加键形状校验(只允许 */MANIFEST.yaml、禁 ..)仍报 high。对象键本就不是文件系统路径,不存在「穿越」语义。
4. 本地覆盖率合并脚本的 argv 输出路径
test/merge_profiles.py:以 argv 指定的输出路径执行写文件——本地 CLI 工具接受操作者指定输出路径即为其功能本身。
后果
git commit 门禁按全仓 high 计数拦截,以上任何一项存在即无法提交任意代码(包括与测试无关的业务修复)。而这些文件要么无法改写(值盲规则),要么改写空间为零(Go exec 语义),形成死锁。
建议
- test-file baseline:仓库级策略文件声明路径级豁免,例如在
.mimosa/security-policy.json支持scan.exclude: ["**/*_test.go", "test/**", "hack/**"];或至少对*_test.go内的固定模式(PASSWORD 赋值、exec 调用)降噪为 medium/info,不进 commit 门禁计数。 - 值盲规则修复:PASSWORD 赋值行应区分 RHS——字面量才报,变量引用/命令替换不报(当前连
$VAR都拦)。 - Go exec 建模:参考 #300 的 SQLAlchemy 建模思路,为「exec 调用 + 非用户输入 argv(编译期字面量/测试夹具)」建立 clean profile。
环境补充:Go 测试必须经子进程运行被测二进制才能收集 GOCOVERDIR 计数(go 官方 coverage 集成方式),不是可绕过的实现选择。"
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the git commit gate against the named files: internal/service/service_test.go, internal/httpapi/server_test.go, cmd/arkhub/main_test.go, hack/ossread/main.go, and test/merge_profiles.py. Read the existing mimosa policy and rule behavior first; done means test and development paths can be configured or appropriately downgraded without blocking unrelated commits, while real findings remain enforced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, go, python
- Domain
- security, testing, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100