invariant
A condition must remain true across permitted operations.
Use this when Several paths must preserve the same business rule.
without the term
“Account balances should never go below zero, but somehow some did. Can you make sure that rule can't be broken by any code path, not just the form?”
with the term · How do you ask a model for invariant?
Enforce this invariant at the authoritative boundary. Test invalid input and concurrent writers, including paths that bypass the UI.
What is invariant?
An invariant is a rule that every write must keep true, such as a balance never going negative. Enforce it where all writers pass through, ideally the database or one domain function.
Why does invariant matter when vibe coding?
Repeated local checks may leave an unguarded write path.
How do you do invariant?
State the rule precisely, identify all writers, and test attempts to violate it.
What goes wrong with invariant?
Writing the rule only in a comment or form validation.