Skip to main content
The sandbox answers from the spec, from armed faults, and from recorded traffic. None of those can say “when a charge with this reference already exists, answer 422 with this body”, which is what an undocumented provider rule is. A rule can. Rules live beside the imported spec in <data_dir>/apis/<sandbox>.rules.json, one versioned file per sandbox, written atomically. The sandbox loads them with the spec, and a rule that cannot be true of this spec is refused at load, by name.
With that file in place and pikopod up serving examplepay, the first create with reference: order-77 is answered from the spec and the second by the rule:
Every response a rule produced carries x-pikopod-rule with the rule’s id.

When a rule is consulted

For every request, in this order: auth, faults, route, rules, operation. A rule is only consulted once the request is authenticated, no armed fault answered, and the route matched a declared operation. The first matching rule in file order wins, and the operation behind it never runs. A rule cannot fire on a route the spec does not declare.

when

Body matchers: State conditions read the state a resource carries in the store, which a rule’s set_state sets:

respond

provenance is manual for a rule you wrote, promoted:<fingerprint> for one promoted from an observed divergence, and imported:<fingerprint> for one that arrived in an incident bundle. version is stamped when the rule is first saved, and the file’s version advances on every save.

Seeing which rule fired

requests --explain replays a request against a fork and names the rule:
That run had a second rule, reference-required, with "body": { "reference": "absent" }. The fork starts from an empty store, so a rule that depends on stored state, such as exists_in_store, only fires against the served sandbox.

Refused at load

A rule naming a route, an event or an example the spec does not declare is refused when the sandbox loads, and the error names the rule:
Rules replay byte for byte under the same seed, like everything else the sandbox answers, and the parity suite holds a transcript that proves it.