Skip to content

The corpus

A bug a run found once is worth checking every run after, even once it’s fixed: bugs come back. A pin does that for the inputs you choose. The corpus does it for the rest, on its own: a store of inputs that found something before, run first each time.

Each property has a folder under .proptastic/corpus/, and each input in it is a file:

proptastic.corpus/v1
choices=50/1000000 0/1000000 49/999999
domain=dbb236166b054eee
input=aliceHas = 50, bobHas = 0, amount = 50
  • choices replay the input, as a saved counterexample’s do.
  • domain is a fingerprint of the property’s domains when the entry was found.
  • input is the input as the failure printed it, for a person reading the folder.

An entry’s file is named by the hash of its choices, so the same input found twice, or on two machines, is one file. A property.txt in the folder names the property it’s for.

A run tries a property’s corpus entries after its pinned examples and saved counterexample, and before its random tries, in the same order on every machine: fewer choices first, then smaller ones. The pr profile runs every entry and only 10 random tries, so a pull request always checks what was found before.

A counterexample is added when PROPTASTIC_CORPUS_RECORD is on, as it is in the nightly profile. PROPTASTIC_CORPUS moves the corpus, or with off runs none.

A property’s folder is named for its test’s class and method, made safe and its own as a counterexample’s file is, so renaming or moving the test starts its corpus afresh. Give the property an id of its own and the corpus follows it:

forAll(fields()).id("fields-round-trip").check(…);

An id is letters, digits, ., _ and -, as a folder’s name is.

An entry is choices, and choices mean what the domains make of them. Change a domain, a bound, a new field in a record, and an old entry’s choices make a different input. That entry is stale: its domain fingerprint isn’t the property’s any more. It still runs, as a different input is still an input, and one that finds something is stamped again with the new fingerprint.

The corpus holds inputs worth trying first, and nothing in it is needed: delete it and every property still runs its own tries, and a longer search finds what was there again. That’s why it’s safe to cache in CI and to prune. The proptastic command’s corpus shows each property’s entries and the stale ones, merges another machine’s in, and prunes it.

Privacy