fuzz
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFuzz rules
模糊测试规则
Use after focused rule tests pass. Read its for harness architecture and corpus setup.
packages/fuzzREADME.md在聚焦规则测试通过后,使用工具。可阅读其了解测试 harness 架构和语料库设置。
packages/fuzzREADME.mdRun the harness
运行测试 harness
Run the target rule first:
sh
FUZZ_RULE=<rule-id> FUZZ_STRICT=1 FUZZ_ITERATIONS=500 nr fuzzUseful variants:
sh
nr fuzz
FUZZ_RULE=<rule-id> FUZZ_SEED=42 nr fuzz
FUZZ_INVARIANTS=1 nr fuzz
FUZZ_CORPUS_DIR=<repository-directory> nr fuzz
FUZZ_RULE=<rule-id> FUZZ_PRINT_SILENT=1 nr fuzzConfirm that the target rule fires. A silent rule only exercises early exits. If it stays silent, add a triggering shape to and rerun.
packages/fuzz/src/snippet-pools.tsUse instead of to exercise an entire registry cohort.
FUZZ_TAG=<tag>FUZZ_RULERecommended full sweep (e.g. before a rule-batch release), pointing the
corpus at real checkouts. Ready-made corpora work on any machine — see the
package README "Canonical corpora":
materializes a pinned 48-repo sample (symlinking the RDE cache when
present, cloning otherwise), and
extracts react-bench's diagnostic-dense RD-health target files:
bun scripts/sync-fuzz-corpus.tsbun scripts/build-bench-corpus.tssh
cd packages/fuzz
bun scripts/sync-fuzz-corpus.ts
FUZZ_INVARIANTS=1 FUZZ_ITERATIONS=100 FUZZ_CORPUS_DIR=tmp/corpus-repos nr fuzzRun the direct false-positive check when a rule change affects common syntax:
sh
cd packages/fuzz
bun scripts/hunt-false-positives.ts先运行目标规则:
sh
FUZZ_RULE=<rule-id> FUZZ_STRICT=1 FUZZ_ITERATIONS=500 nr fuzz实用变体命令:
sh
nr fuzz
FUZZ_RULE=<rule-id> FUZZ_SEED=42 nr fuzz
FUZZ_INVARIANTS=1 nr fuzz
FUZZ_CORPUS_DIR=<repository-directory> nr fuzz
FUZZ_RULE=<rule-id> FUZZ_PRINT_SILENT=1 nr fuzz确认目标规则已触发。若规则无输出,说明仅执行了提前退出逻辑。此时需向添加触发代码结构,然后重新运行。
packages/fuzz/src/snippet-pools.ts可使用替代,以测试整个规则注册表中的同类规则。
FUZZ_TAG=<tag>FUZZ_RULE推荐在规则批量发布前进行全面扫描,将语料库指向真实代码仓库。现成的语料库可在任意机器上使用——参考包的README中的“标准语料库”:会生成一个固定的48个仓库样本(若存在RDE缓存则创建符号链接,否则克隆仓库),而会从react-bench中提取诊断密集型的RD-health目标文件:
bun scripts/sync-fuzz-corpus.tsbun scripts/build-bench-corpus.tssh
cd packages/fuzz
bun scripts/sync-fuzz-corpus.ts
FUZZ_INVARIANTS=1 FUZZ_ITERATIONS=100 FUZZ_CORPUS_DIR=tmp/corpus-repos nr fuzz当规则变更影响通用语法时,运行直接误报检查:
sh
cd packages/fuzz
bun scripts/hunt-false-positives.tsTriage findings
分类处理测试发现
Reproducers live in .
packages/fuzz/tmp/fuzz-findings/- Crash: minimize the program, add a no-throw regression test, fix the rule, and replay the seed
- Slow case: profile the pathological shape, bound the walk, and keep the existing threshold
- Verdict drop: fix detection that depends on incidental syntax, then add the rule to the robustness gate when appropriate
- Invariant violation: decide whether the rule should react to the rewrite; fix and test unexpected changes
- False positive: add the valid program to the rule tests and fuzz regression corpus
Replay one finding:
sh
FUZZ_RULE=<rule-id> FUZZ_SEED=<seed> FUZZ_ITERATIONS=1 nr fuzz复现代码位于目录下。
packages/fuzz/tmp/fuzz-findings/- 崩溃问题:简化程序代码,添加不抛出异常的回归测试,修复规则,然后重新运行对应种子
- 性能缓慢问题:分析有性能问题的代码结构,限制遍历范围,保留现有阈值
- 诊断结果丢失:修复依赖于偶然语法的检测逻辑,适当时将规则加入鲁棒性验证门
- 不变量违规:判断规则是否应对代码重写做出反应;修复并测试意外变更
- 误报问题:将有效程序添加到规则测试和模糊测试回归语料库中
复现单个测试发现:
sh
FUZZ_RULE=<rule-id> FUZZ_SEED=<seed> FUZZ_ITERATIONS=1 nr fuzzPreserve false positives
留存误报记录
For every confirmed false positive:
- Add a minimal fixture to .
packages/fuzz/corpus/regressions/<rule-id>--<slug>.tsx - Include the rule ID, weakness class, and source in the fixture header.
- Add a focused valid case to the rule test suite.
- Add a generator snippet when the existing pools cannot produce the weakness.
- Run and replay the target rule.
nr -C packages/fuzz test
Use a stable weakness name such as , , , , , , , , , , , or .
library-idiomcontrol-flowwrapper-transparencyname-heuristicalias-guardcross-fileframework-gatingparen-shapedefault-parameterdynamic-computedprivate-membercopy-trackingProject-level dead-code and dependency findings belong in core tests, not the rule fuzzer.
针对每个已确认的误报:
- 将最小化的测试用例添加到。
packages/fuzz/corpus/regressions/<rule-id>--<slug>.tsx - 在测试用例头部包含规则ID、问题类型和来源。
- 在规则测试套件中添加一个聚焦的有效案例。
- 若现有代码池无法生成该问题类型,添加生成器代码片段。
- 运行并重新运行目标规则。
nr -C packages/fuzz test
使用稳定的问题名称,例如(库惯用写法)、(控制流)、(包装器透明性)、(名称启发式)、(别名防护)、(跨文件)、(框架门控)、(括号结构)、(默认参数)、(动态计算)、(私有成员)或(副本跟踪)。
library-idiomcontrol-flowwrapper-transparencyname-heuristicalias-guardcross-fileframework-gatingparen-shapedefault-parameterdynamic-computedprivate-membercopy-tracking项目级的死代码和依赖问题属于核心测试范畴,而非规则模糊测试器的处理范围。
Report results
报告结果
Record the command, target-rule fire count, findings, replay seeds, corpus fixtures, and generator changes. Pass confirmed implementation findings to .
rule-validate记录命令、目标规则触发次数、测试发现、复现种子、语料库测试用例和生成器变更。将已确认的实现问题提交给。
rule-validate