/amplihack:property-based-testingfrom amplihack
Guides developers in adopting property-based and metamorphic testing: choosing a library, finding invariants/round-trips/idempotence/oracle properties, and integrating generative tests into existing runners.
Ships in amplihack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Expert guidance for property-based and metamorphic testing: instead of asserting one hand-picked example, you state a rule that must hold for every input, and the library generates hundreds of inputs to try to break it.
amplihack ships two other formal-methods skills. Property-based testing is the practical middle ground between them:
| Approach | Skill | What it checks | Cost |
|---|---|---|---|
| Example tests | (unit tests) | Behavior on inputs you thought of | Low |
| Property-based / metamorphic | property-based-testing | Invariants over generated inputs, at runtime, against real code | Medium |
| BDD acceptance | gherkin-expert | Human-readable behavior scenarios | Low–medium |
| Model checking / proof | tla-plus-expert | Exhaustive state-space or temporal properties of a model | High |
Reach for property-based testing when:
Prefer TLA+ instead when the property is about concurrency, ordering, or temporal/liveness behavior of a design you can model. Prefer Gherkin when the value is a shared, human-readable acceptance spec. These are complements, not substitutes — a mature component often has all three.
| Stack | Library | Runner it plugs into |
|---|---|---|
| Rust | proptest (preferred) or quickcheck | cargo test |
| Python | Hypothesis | pytest / unittest |
| .NET | FsCheck (F#-friendly) or CsCheck (C#-friendly) | xunit / nunit |
| JS/TS | fast-check | jest / vitest / mocha |
| Java | jqwik | JUnit 5 platform |
Do not build a separate harness. Every library above runs inside your existing test runner as ordinary test cases. A property test is just a test that loops over generated inputs.
A "property" is a rule that holds for all valid inputs. The reliable families:
decode(encode(x)) == x. Great for serializers, parsers,
compressors, config load/save.f(f(x)) == f(x).
Redaction, normalization, dedup, formatting.merge(a, b) == merge(b, a).When you can't state an exact expected value, a metamorphic relation is usually still available. That is the whole point of metamorphic testing.
"a"). Never disable shrinking — the minimal case is the bug report.The snippets below use amplihack's own invariants as worked examples.
use proptest::prelude::*;
proptest! {
// redact(redact(x)) == redact(x)
#[test]
fn redact_is_idempotent(s in ".*") {
let once = redact(&s);
let twice = redact(&once);
prop_assert_eq!(once, twice);
}
// output never contains the secret
#[test]
fn redacted_output_has_no_secret(secret in "[A-Za-z0-9]{8,32}", prefix in ".*", suffix in ".*") {
let input = format!("{prefix}{secret}{suffix}");
let out = redact_secret(&input, &secret);
prop_assert!(!out.contains(&secret));
}
}
from hypothesis import given, strategies as st
# shard_jobs_max <= effective <= jobs_max
@given(
jobs_max=st.integers(min_value=1, max_value=256),
shard_jobs_max=st.integers(min_value=1, max_value=256),
requested=st.integers(min_value=0, max_value=512),
)
def test_effective_jobs_respects_bounds(jobs_max, shard_jobs_max, requested):
shard_jobs_max = min(shard_jobs_max, jobs_max)
effective = compute_effective_jobs(requested, shard_jobs_max, jobs_max)
assert shard_jobs_max <= effective <= jobs_max
using FsCheck;
using FsCheck.Xunit;
public class CoverageProperties
{
// bundle >= in_scope AND scanned + excluded == in_scope
[Property]
public Property CoverageTallyHolds(PositiveInt inScope, PositiveInt extra, NonNegativeInt excluded)
{
int in_scope = inScope.Get;
int bundle = in_scope + extra.Get; // bundle is a superset
int exc = Math.Min(excluded.Get, in_scope);
int scanned = in_scope - exc;
bool bundleSuperset = bundle >= in_scope;
bool tallyBalances = scanned + exc == in_scope;
return (bundleSuperset && tallyBalances).ToProperty();
}
}
import fc from "fast-check";
import { recordTelemetry } from "../src/telemetry";
// totality: recordTelemetry never throws and always returns a well-formed event
test("telemetry is total and safe", () => {
fc.assert(
fc.property(fc.anything(), fc.string(), (payload, name) => {
const event = recordTelemetry(name, payload); // must not throw
expect(event.name).toBe(name);
expect(typeof event.timestamp).toBe("number");
expect(typeof event.dropped).toBe("boolean"); // always a boolean, never undefined
}),
);
});
import net.jqwik.api.*;
class ConfigRoundTripProperties {
// decode(encode(x)) == x (round-trip)
@Property
boolean encodeDecodeRoundTrips(@ForAll("configs") Config c) {
return Config.decode(Config.encode(c)).equals(c);
}
// oracle/differential: fast parser agrees with reference parser
@Property
boolean parsersAgree(@ForAll("configText") String text) {
return FastParser.parse(text).equals(ReferenceParser.parse(text));
}
@Provide Arbitrary<Config> configs() { return Arbitraries.of(Config.defaults()); }
@Provide Arbitrary<String> configText() { return Arbitraries.strings().ofMaxLength(64); }
}
For amplihack's multi-runtime components, run the same generated inputs through each language implementation and assert identical outputs. Generate the corpus once (with a fixed seed), feed it to every implementation, and diff the results. Any divergence is a conformance bug — shrink it to the minimal input.
Check your understanding (answers below).
normalize_path is claimed to be safe to call more than once.
Which property family proves that, and how do you write it?normalize_path(normalize_path(p)) == normalize_path(p)
over generated paths.decode(encode(x)) == x.redact(redact(x)) == redact(x)) and a no-secret-leak
invariant (the output never matches the secret). The first is an
idempotence property; the second is a safety invariant.tla-plus-expert — exhaustive model checking of designs (the high-cost leg).gherkin-expert — human-readable BDD acceptance scenarios.test-gap-analyzer — find which code lacks coverage; then add properties here.smart-test — run the resulting property tests through the existing runner.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Python, JavaScript, Rust, Java, .NET
npx claudepluginhub rysweet/amplihack-rs --plugin amplihack30 skills in this plugin
/agentic-workflow-firstStart new work as a deterministic workflow of agentic steps, prompts, and tools instead of code. Use when designing a feature, deciding how to build something, choosing code vs recipe, or asking "how should I structure this"./amplihack-expertComprehensive knowledge of amplihack framework architecture, patterns, and usage/code-atlasBuilds comprehensive, living code-atlases as multi-layer architecture documents derived from
code-first truth. Defaults to both Graphviz DOT and Mermaid. User can override to single format.
Language-agnostic (Go, TypeScript, Python, .NET, Rust, Java). Files issues with
'code-atlas-bughunt' label. Treats atlas-building as a multi-agent bug-hunting journey:
graph-form reasoning exposes structural bugs, route/DTO mismatches, orphaned env vars,
dead code paths, and stale documentation that linear review misses. Three-pass bug hunt
with per-journey PASS/FAIL/NEEDS_ATTENTION verdicts.
Use when: creating architecture documentation, investigating unfamiliar codebases,
hunting structural bugs, setting up CI/CD diagram refresh, or publishing to GitHub Pages/mkdocs.
/code-philosophyMulti-pass code philosophy audit skill. Performs three distinct passes
over target code to verify adherence to the project's PHILOSOPHY.md
principles. Produces a structured report with findings and delegates
fixes to dev-orchestrator. This is an advisory audit-only skill — it
does not modify code directly.
/crusty-old-engineerCurmudgeonly engineering advisor that provides grounded skepticism, evidence-linked judgment,
and constructive progress on architectural decisions, legacy refactors, tooling choices, and
broad "how should I start?" questions. Sounds like a senior systems engineer who has reviewed
too many designs to be impressed, but still cares about correctness.
Use when: architectural decisions, legacy replacements, new tooling evaluation, broad planning questions.
/default-workflowDevelopment workflow for features, bugs, refactoring. Normally executed as a
sub-recipe by dev-orchestrator/smart-orchestrator. Supports direct invocation
via recipe runner for standalone use.
Other plugins' skills for the same job