name: "zig-fuzz"
description: "Build and run replayable fuzzing, property-testing, and deterministic simulation campaigns for Zig projects with hegel-zig; calibrate harnesses and turn confirmed failures into regressions."
createdAt: "2026-11-07T06:16:50.492323+00:00"
repoUrl: "https://skillz.supply/skills/did:plc:xbtmt2zjwlrfegqvch7fboei/skills.zig-fuzz/SKILL.md"
# Zig fuzzing Exercise the real implementation with generated inputs or operation histories. Use [hegel-zig](https://tangled.org/zzstoatzz.io/hegel-zig) for generation, shrinking, replay, and mutation calibration. Inspect the selected revision's README, build module, and examples: older integrations linked Rust; the native Zig engine is now the default. Do not copy an old dependency pin or API blindly. ## Select the oracle and boundary Map the surface before promising whole-project coverage, in the campaign's README: every operation a client can send, every input that selects a different branch, background work, behavior-changing configuration, and the real clients with the request shapes they send. Mark each item with the rule that exercises it, its oracle and its failure paths, or out of scope with a reason. Parser fuzzing is not DST. - Pure codecs: roundtrips plus independent vectors, framing, canonicalization, malformed inputs, and resource limits. Encoder/decoder agreement alone can preserve a shared bug. Read the API contract before asserting roundtrips: canonical varints may have a narrower range; an empty input may request defaults. - Stateful structures: a small independent map or ledger checked after operations, including refused operations. Rebuilding a tree is useful for cache consistency, but is not an independent oracle for its wire format. - Ports: compare with the real reference service in an isolated disposable instance. Normalize only documented differences; keep known divergences narrow and counted. A reference implementation can itself have bugs. - I/O-driven code: drive the real code with controlled time, entropy, scheduling, transport/storage outcomes, cancellation, and restart boundaries. Prefer existing injection seams. Do not substitute a second implementation for the SUT. For network clients, simulate the world beneath the real client and its libraries through the `std.Io` vtable; see [simulated-io.md](references/simulated-io.md). For stateful systems, give every write a unique value so each read traces to one write, record when each request was sent and acknowledged, keep a timed-out or disconnected outcome as unknown (it may still land), and prune history so long histories stay cheap. After injected faults, a recovery step stops faults, waits for the system to serve again, and asserts what must hold afterwards. Write the model from the specification, not from the implementation: a lexicon, an RFC, a registry. Check the source before asserting it. When an oracle fails, first ask whether the oracle overreached: case-insensitive protocol tokens, results an error path cannot carry, or a lower layer's documented behavior. Model every layer that retries or replays. Read [prior-art.md](references/prior-art.md) for concrete repositories and useful patterns. Inspect the actual code; historical branch names and APIs are clues. ## Build the campaign Pin both Zig and Hegel revisions. Keep Hegel optional to ordinary builds unless the project intentionally adopts it. Use a discovery branch or isolated worktree; inspect existing dirty harnesses before reusing them. Include harness files in format/import checks and package paths when the build references them. Use `case.machine`, small key pools, drawn initial state, reads between writes, and reload/copy/retry rules to reach interactions early. Use pools for handles whose identity must survive shrinking. Reject inapplicable rules rather than silently spending steps. Generate valid structured inputs as well as mutations; uniform bytes mostly exercise parser rejection near the entrance. Hegel favors small integers and early pool entries. A uniform wide draw rarely reaches the top of its range, and the last entry of a pool is rarely chosen. Draw the bits that matter explicitly, rotate picks across steps, and judge one variable in isolation against an otherwise healthy world, so earlier failures cannot mask it. Every random choice influencing a case comes from Hegel or a PRNG whose seed Hegel draws. Reset state between cases. Virtualize the clocks the code actually reads; preserve monotonic-clock semantics when testing wall-clock jumps. Seeded test entropy must not escape into real credentials or production traffic. A `std.Io.failing` vtable with deliberate overrides is useful for pure I/O seams. Delegating unspecified calls to `Io.Threaded` can be necessary for integration work, but document that scheduling/files/network are then real and constrain external effects. Avoid a process-global active simulator when cases can overlap. Inject faults at real operation boundaries. A before-write error and an error after the write lands have different contracts. Hegel's `FaultPlan` chooses and replays the interruption; the adapter implements the actual effect. Pause fault injection around oracle reads only, without masking recovery failures. Count selected, fired, and never-reached faults separately. ## Prove and run it Print case counts, per-rule counts including zeroes, completed histories, state sizes, and `case.event` frequencies for interactions the bugs require. Distinguish exploration statistics from calls made during shrinking/replay. Give failures stable property names and notes containing enough arguments to understand a crash. Never convert unexpected errors, OOM, or early termination into success. Before treating a clean campaign as evidence, plant representative behavior bugs and measure detection across seeds. Run mutation tooling in a disposable worktree: it edits source files. Check the clean baseline first; distinguish compilation failure from a behavioral kill. Improve an unexercised rule or weak oracle before increasing the case budget. Keep inverse patches for confirmed fixes as mutants. When a mutant is caught on only some seeds, add a temporary `case.event` probe for the condition it needs, find which precondition is rare, and fix the generator there. To show a new rule earns its place, run its mutant against the harness from before the rule: 0 of 10 seeds then and 10 of 10 now is evidence; 10 of 10 alone may come from an older rule. Run campaigns through hegel-zig's `hegel-campaign` runner (its `docs/campaigns.md`): a committed `campaigns.zon` with a small CI smoke target and a separate calibration target at the recorded budget, wrapped by a `scripts/campaign` that builds the pinned runner. It runs committed source in a disposable worktree, classifies property failures, crashes, timeouts and build failures separately, and saves revisions, logs and `replay-N.json` bundles. Set `timeout_seconds` well above Hegel's 300-second shrink budget per failing property; a shorter timeout turns a real failure into a timeout with no replay. Start bounded, then expand seeds, history sizes and fault modes; many cases are not exhaustive coverage. Declare `.reach` for the `case.event` labels a planted bug needs, so a seed that never sets one up is `unreached` rather than a pass; fault plans emit `fault <point> before|after` when a fault fires. Confirm the event marks the real precondition: run its mutant and check that the property declaring it is the one that catches it. In pmdeflate, "references exactly one window back" fired in the encoder properties, but zlib never emits a match past 32768 − 262 bytes, so only the corrupted-payload property reached the distance the mutant needed. ## Replay and triage Select one property with a stable `Settings.key`. Replay using the printed `HEGEL_ZIG_REPLAY` blob and the same generator/dependency revision. `HEGEL_SEED` repeats exploration; it does not replace a minimized blob. Use `HEGEL_DATABASE` for a persistent corpus when appropriate. `HEGEL_ZIG_ECHO=1` records the history before process-killing panics, which the engine cannot shrink in-process. Classify every failure as a system bug, a harness bug or expected before changing code or rerunning; never rerun an unchanged campaign to see whether it repeats. Record each finding before fixes: violated contract, minimal history/blob, reachability, affected revision, and evidence against alternative explanations. Check for oracle mistakes and deduplicate common causes. Preserve failures before changing the generator; draw-order changes can invalidate old blobs. Implement authorized fixes as separate atomic changes with deterministic regressions that fail before and pass after; include a mirror case when a fix could reject previously valid behavior. Confirm the "before" failure is the behavioral one: deleting a fix line can leave an unused parameter and fail compilation instead, so neutralize the check rather than delete it. A regression that hangs on failure (a test server blocked in `accept`) is not a clean failure; collect results before asserting. For a bug in a dependency, see the last section of [simulated-io.md](references/simulated-io.md). Run repository checks at each commit and rerun the campaign on the fixes. Report tested scope, findings, mutant results, and remaining gaps. Keep the harness optional or isolated according to the project's needs; a reviewer should be able to verify each fix from its regression. ## Keep campaigns current When the system under test changes, repair its campaign before trusting a pass: diff its operations, configuration and guarantees since the campaign's last change, update the surface map, rules and oracles, and rerun calibration. Branch-only campaigns drift fastest; reconcile them with maintained code first. hegel-zig's `docs/scope.md` records what is built in-house and what is a known gap; there is no paid simulation service to fall back on. Ideas borrowed from other tools are written in our own words; record anything copied with its license, as hegel-zig's licensing guide describes.