Property testing

From indexable-inc/index-bak · View interactive version

Property testing is an AI agent skill from the GitHub repository indexable-inc/index-bak. Property-based testing with hegel (Antithesis's Hypothesis-based library): which properties to reach for, generator patterns, shrinking, replay, CI determinism. Use when adding property tests, fuzzing a parser/converter/codec, or a test needs generated rather than example inputs.

How to use this skill

Skill file

Property testing with hegel

Repo-owned Rust crates use hegeltest (workspace dev-dependency; lib name

hegel). It is Antithesis's Hypothesis-based property-testing library:

pure-Rust engine, #[hegel::test] under plain cargo test, automatic

shrinking to a minimal counterexample, and a failure database (.hegel/,

gitignored) that replays the last counterexample first on the next run.

Reference suites: packages/ix2nix/tests/properties.rs,

packages/minecraft/nbt/tests/property.rs.

Which properties earn their keep

In rough order of value per line:

  1. Never panics: feed gs::text() (or arbitrary bytes) to any parser,

decoder, or converter; assert it returns Ok/Err rather than

panicking. Cheapest test, catches the most.

  1. Round trip: serialize then reparse (or encode/decode) and compare.

For a transpiler the analogue is: generated well-formed source converts,

and the output parses cleanly under an independent parser (ix2nix uses

rnix as its oracle).

  1. Determinism / idempotence: same input twice gives identical output;

f(f(x)) == f(x) where claimed.

  1. Model-based: compare against an obviously-correct implementation

(BTreeMap vs your map; a slow interpreter vs your fast path).

Generator patterns

gs::vecs, or the tree can explode.

binder names, deduplicated object keys) and let values carry the

randomness; otherwise the property tests your generator, not the code.

Two real generator traps from ix2nix: ${...} interpolation only exists

inside backtick templates, and => {} is a block, not an object literal.

that iterates a collected set passes when the set is always empty. Breaking

the code under test does not catch that, so invert a new property once,

watch it fail, then restore. ix2nix's $ref-resolution property passed with

assert!(refs(&parsed).is_empty()) in place of its real assertion, proving

no generated schema ever carried a $ref. Two causes, one of them a

production bug: the generator's type vocabulary omitted the alias name, and

export default ((a: int) => a) recorded no parameters because the mapper

matched the arrow without peeling the parenthesis.

from .map over hegel::tuples!(...); #[hegel::composite] exists for

the draw-style equivalent.

Budget, replay, CI

Keep CI at the default; run big budgets ad hoc.

property test means hegel found a real counterexample that was always

legal input. Fix forward; never re-run to green. The failure database

gives local replay, but CI sandboxes start fresh, so copy the printed

let source = ... shrunk case into a regression #[test] alongside the

fix (see bool_and_boolean_both_lower in ix2nix).

default-features = false); no Python, no network at test time, so tests

run unchanged inside nix sandboxes.

Antithesis

Hegel is Antithesis's PBT family (hegel.dev): the same tests can later run

under the Antithesis platform for guided exploration, and the antithesis

feature wires assertions into its SDK. Do not enable that feature for

ordinary CI; it is for workloads launched via the antithesis-* skills.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.