sample: draw n values from a generator without running a property #1
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Missing
A way to draw
nvalues from a generator deterministically without running a property:sample { seed; tests; maxSize ? 100; } gen -> [ value ], using the same seed splitting and size cyclecheckuses.Where it was needed
jsonschema2nix (
tests/generators.nix,samples) checks one direction of its first invariant in a derivation: generated (schema, value) pairs are handed to a Python validator at build time, which aforAllpredicate cannot do. To get the cases it reaches intonixcheck.rng.fromSeed/rng.splitand reimplements the size cycle by hand:That couples the test to
rnginternals and to howcheckhappens to pace sizes today; if the runner changes, the sampled distribution silently diverges from what the properties see.Suggested shape
sample opts geninproperty.nixsharing the loop withcheck.sampleTreereturning the trees, for callers that want to shrink a failing external check by hand.Plan
Extract the case-producing part of the
checkloop (lib/property.nix) intocases { seed; tests; maxSize; } gen -> [ { tree; size; index; } ].checkfolds over it,samplemaps.value,sampleTreereturns the trees. Same seed => the exact caseschecksees, by construction.Shape follows fast-check
fc.sample(arb, { seed, numRuns })(explicit seed) rather than HedgehogGen.sample(IO, fixed size 30), since Nix is pure.The same
caseslist is what #7 (replay info) and #8 (labels) need, so land those on top of this refactor.Order in the overall roadmap: after #6, #5, #2.
Implemented in
ff3990b, pushed to main.