已关闭
[issue] duplication top 模式同尺寸组取舍顺序未文档化 #15
cezarbbb创建于 9月9日关闭于 9月17日
WangZijun
9月15日 评论:
9月15日 评论:
https://gitcode.com/xuanwu/bot-metric/merge_requests/8
结论:
- 问题可复现:已通过修复前最小复现/回归测试确认。
- 问题可修复:当前分支集成测试已验证修复行为。
具体修复:
- 在输出预算检查前完成机器 JSON 序列化,避免 stdout 产生截断 JSON。
- 区分输出预算超限与格式错误的 BM403 原因。
- 明确 duplication top 模式的重复行数及 stable_subject 字典序取舍规则并增加测试。


问题概述
夹具 dup-many 含 22 组等大(11 行)重复块,
duplication_findings = "top"+ 默认duplication_max_findings = 20取 20 组时丢弃 pair_4(组哈希 fc99b7be…)与 pair_14(组哈希 fc56a6cd…),取舍优先级未在任何文档定义;结果确定(跨平台、跨版本一致)但规则不透明。首次出现版本:v1.1.0(duplication findings 为 v1.1.0 新功能)。受影响对象:启用重复发现的 Cargo 软件包/目录输入。实际影响:用户无法预判哪组被丢弃,审计场景可能遗漏关注组。本问题涉及发现条目取舍口径。影响范围
duplication_max_findings覆盖全部组;② 改用duplication_findings = "all";③ 等待文档定义取舍优先级复现步骤
最小源码样例:夹具
fixtures\dup-many(48 个 .rs 文件、831 行,22 组 11 行重复块 + 1 组完全重复文件对)。自包含最小样例如下(3 组等大 11 行重复块 + max_findings=2,即可复现"同尺寸组截断取舍未文档化"现象;完整夹具 22 组下的 pair_4/pair_14 具体编号依赖该夹具,取舍规则本身同样未文档化。下述命令中的<dup-ties>即指向该样例目录):Cargo.toml:[package] name = "dup-ties" version = "0.1.0" edition = "2021"src/lib.rs:pub mod g0; pub mod g1; pub mod g2;src/g0.rs(g1.rs / g2.rs 与其逐字节相同,构成 3 组等大 11 行重复块):// g0.rs - identical 11-line block shared with g1.rs / g2.rs pub fn tie_block(acc: u32) -> u32 { let mut acc = acc; acc += 10000; acc += 10001; acc += 10002; acc += 10003; acc += 10004; acc += 10005; acc += 10006; acc += 10007; acc += 10008; acc }src/g1.rs与src/g2.rs:内容与src/g0.rs完全相同(仅文件名不同)。配置
bot-metric-dup-top-20.toml(关键项):[thresholds] duplication_max_findings = 20 [rules] duplication_findings = "top"BM110 analyze <dup-many> --config bot-metric-dup-top-20.toml --format json→ 20×BM006BM110 analyze <dup-many> --config bot-metric-dup-all.toml --format json(findings="all")→ 22×BM006预期结果
文档定义同尺寸组的取舍优先级(如按哈希序/位置序),或输出中说明取舍规则,使用户可预判截断结果。
实际结果
top-20 丢弃 pair_4(fc99b7be…)与 pair_14(fc56a6cd…),取舍规则未文档化;结果确定,x86 与 ARM64 一致。证据:
x86_linux\records\batch-05\;arm_linux\records-arm64\batch-09\verify-groupB_5-2_5-3_5-4.txt。证据原文(x86_linux\records\batch-05\out\t55-many-top-20.json,共 2671 行,节选 findings 的 stable_subject 清单——20 组入选重复 + 2 条质量目标):
"stable_subject": "quality-target:max_code_duplication_ratio", "stable_subject": "quality-target:max_file_duplication_ratio", "stable_subject": "duplicate:020495a78067cd83:14", "stable_subject": "duplicate:0fc7285907b6d4cb:14", "stable_subject": "duplicate:1c7f0d179e60b763:14", "stable_subject": "duplicate:2191ff92d38bb9d3:14", "stable_subject": "duplicate:239894a2fca9a27b:14", "stable_subject": "duplicate:6098f025d22d102b:14", "stable_subject": "duplicate:646f04eef676eb7b:14", "stable_subject": "duplicate:68140443a7b6d7db:14", "stable_subject": "duplicate:7129c49f7b2e5deb:14", "stable_subject": "duplicate:71693c57fe1fccd3:14", "stable_subject": "duplicate:75897d5fa349a5db:14", "stable_subject": "duplicate:990a7ab4f2277f23:14", "stable_subject": "duplicate:bd8f5a612bfa137b:14", "stable_subject": "duplicate:c5ad085feb7bdf13:14", "stable_subject": "duplicate:c773fea40b4b04ab:14", "stable_subject": "duplicate:c9ea0edf86947383:14", "stable_subject": "duplicate:db5c5d89377cea13:14", "stable_subject": "duplicate:e6b8082ac8c303ab:14", "stable_subject": "duplicate:eeb633027814197b:14", "stable_subject": "duplicate:f005875e1ae1866b:14",……(节选,完整文件见
x86_linux\records\batch-05\out\t55-many-top-20.json;入选 20 组不含 fc99b7be(pair_4)与 fc56a6cd(pair_14))证据原文(arm_linux\records-arm64\batch-09\verify-groupB_5-2_5-3_5-4.txt,5-4 部分):
分析环境与范围
--config bot-metric-dup-top-20.toml与bot-metric-dup-all.toml对照指标、发现与报告证据
x86_linux\records\batch-05\性能与资源证据
附件与提交确认