Introduce Assertion

Removes smells
Symptom

Code that depends on unwritten invariants the agent must reconstruct from context; bugs that violate the invariant surface far from the source.

Goal

Invariants live in code as runtime checks; the agent reads the assertion as a typed constraint that downstream code can take as a precondition without re-deriving it from caller context.

Before the refactoring

// rate must be positive
const tax = base * rate;

After the refactoring

if (rate <= 0) throw new Error('rate must be positive');
const tax = base * rate;
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure

The agent must reconstruct invariants from surrounding code; bugs surface far from the source and tracing them costs reasoning hops.

Tradeoff

Assertions used as control flow couple production behavior to debug-mode invariants; the agent that conflates the two ships a flow-dependent change disguised as documentation.

Relief

Invariants fail loudly at the source; the agent's debugging traces are short; assumptions become enforceable contracts.

Trap

Coupling production behavior to assertion presence/absence — the agent reads them as documentation but the runtime depends on them firing or not.