What each check guarantees
Bree checks rules at several points: while you edit, when your application builds, when it loads the rules, and on every call. This page lists which mistakes each point catches, and what Bree cannot catch for you.
Mistakes and where they stop
| Mistake | Stopped by | Where |
|---|---|---|
A misspelled field, a string used as a number, a missing end |
the Luau type checker, strict mode | editor, bree check, cargo build, go generate, load |
A rule that returns the wrong shape, or forgets a case and returns nil |
the check that a rule returns (Input) -> Output |
same |
| A test that passes impossible input or expects an impossible output | type checking of test files | same |
Logic that is wrong but well typed (> for >=) |
the rule's tests | bree check, cargo build, go generate, load and reload |
| Rust or Go code using a field the rule does not have | the Rust or Go compiler, against generated types | cargo build, go build |
| An application running against rules whose types changed since it was built | the fingerprint check | load and reload |
Input that does not match Input, or a value the rule rejects with invalid |
input validation | every call: invalid_input |
Output that escapes its type, for example through a cast to any |
output validation | every call: invalid_output |
| A loop that never ends, or a rule that uses too much memory | step, memory and time limits | every call |
Build time
In Rust, bree::rules! does all of the first four rows while the crate compiles; any failure is a compile error with the file and line. In Go, bree-gen (run by go generate) does the same before it writes bree_rules.go, and writes nothing when anything fails, so the previous generated file stays in place and CI can catch a stale one with bree-gen -check.
examples/typed-but-wrong is a crate whose rule type checks but fails one test. CI builds it and requires the build to fail with this message:
error: rules/shipment_eligibility.test.luau:29: test "a parcel exactly at the weight limit ships" failed
expected { eligible = true, reason = "eligible" }
got { eligible = false, reason = "overweight" }Load time
Every engine type checks the rules and runs their tests when it loads them, whatever loaded them: an application at startup, a reload, bree serve, bree run. An application built with generated types also checks each rule's fingerprint: a hash of its Input and Output types. If the rules it loads have different types from the ones it was compiled against, it refuses them:
rules/shipment_eligibility.luau: changed its Input or Output types since this application was built (fingerprint 23dedf5065136b58 became fb3be3b30efe8eea); rebuild the application to use themA rule the application was built with that has gone missing is refused the same way.
At startup that stops the application from starting. On a reload it keeps the rules that were already serving. Either way, generated types and the rules they describe never disagree at run time. Callers that evaluate by name can send the fingerprint they were built with (the Bree-Fingerprint header in the HTTP API) and get types_mismatch instead of a decision.
Call time
Every call checks the input against Input before the rule runs and the output against Output after it returns, listing every problem:
{"error":{"code":"invalid_input","message":"the input does not match the Input type of free_shipping","violations":[{"field":"order_total_cents","message":"must be a whole number"},{"field":"country","message":"must be one of \"CA\", \"US\""},{"field":"x","message":"is not a field of this type"}]}}Fields the type does not declare are rejected rather than ignored, so a misspelled optional field in a request does not silently fall back to its default.
The output check is a backstop. The type checker already proves a rule returns an Output, unless the rule opts out with a cast:
return ({ ok = "yes" } :: any){"error":{"code":"invalid_output","message":"liar returned something its Output type does not allow","violations":[{"field":"ok","message":"must be a boolean, got a string"}]}}What Bree cannot check
- Cases nobody tested. Tests prove the cases they cover. Test each boundary: at the limit and one past it.
- What the numbers mean.
weight_grams: intandweight_kg: intare the same type. Put the unit in the name. - Whether the input is true. Bree checks that the input has the right shape and passes
invalidchecks, not that the carrier's limits you passed in are current.