test(fuzz): add deterministic fuzz harness for parser, kitchen, analyzer and formatter #196
No reviewers
Labels
No labels
bug
discussion
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
research
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gram-lang/gram!196
Loading…
Reference in a new issue
No description provided.
Delete branch "test/fuzz-harness"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds
fuzz/, a private workspace (no new dependency) that feeds mutated versions of every.gramsnippet in the repo to the parser, the compiler, the analyzer and the formatter, and checks invariants on each input. First topic of the 1.6 cycle (step 0: a safety net onmainbefore the multi-editor launch exposes the parser to more users). No changeset: private tooling only.What it does
collectCorpus()(audit/src/corpus.ts).bun run auditoutput is byte-identical before and after.fuzz/src/invariants.ts):getASTonly throwsGramParseErrorwith a validoffset/expected;compile,analyze(playground example database) andformatGramnever throw; the formatter is idempotent and keeps the meaning of a recipe that parses; parse + compile + format stay within a time budget.fuzz/src/normalize.ts): compiled JSON compared up to positions and deliberate canonicalizations, one commented rule each, calibrated on the unmutated corpus. Formatter rules that repair a mistake by design (composite<,->&x {},##Title) are exempted.bun run fuzz --seed … --index …) and a minimized input.fuzz/tests/pathological.test.ts): worst-case generators, judged by the growth exponent per stage between 3 125 and 50 000 characters (linear measures 0.90–1.06, threshold 1.15).Ratchet
fuzz/known-failures.jsonlists the violations found so far, each tied to an issue;KNOWN_SLOWdoes the same for super-linear cases (it.failing). The test fails on any new violation, and on a listed one that no longer reproduces: once fixed, drop the entry and add the minimized input tofuzz/regressions/.Budget
bun test fuzzruns in about 10 s locally (fixed seed, 2 000 mutated inputs + the unmutated corpus + growth tests). A 200 000-input local session found no cause beyond those already caught by the CI run.Merge order
Merge this PR first, then the parser fix for the quadratic sum (its PR removes the matching
KNOWN_SLOWentry).