All posts
AI-native method

Static guards instead of endless tests

7 Sept 20263 min read7 views
Static guards instead of endless tests

What I found instead was static guards. As a project grows, so does the urge to test everything. SimaCMS went through that phase too, and CI got slower with every PR. Worse than the slowness, many of those tests guarded nothing important: "the button renders", "the form has three fields". Every small change broke ten tests, and the agent spent half its time fixing tests that never caught a real bug.

The rule now is: only sensitive paths get tests. That means payments and money, sign-up and sign-in, keeping sites apart (tenancy) and permissions, and the main flows. One or two happy paths for money, one refusal per permission boundary. That's it. The rest is held by a guard, or doesn't need holding.

What a static guard is

A small script that doesn't run the code, it only reads it. Each guard is one file, scripts/check-<name>.mjs, checking one rule. There are about forty. A few examples:

  • Module boundaries: a Go package that belongs to one capability may not import another capability's package. If the store calls bookings directly, the PR is refused.
  • The platform never names a module: the core must not know that "store" or "restaurant" exist. Modules register themselves.
  • Stale documents: every path a spec or document names must exist.
  • Prose language: comments and specs are English; user-facing strings and translations are exempt.
  • Bundle budget: public pages' JavaScript stays under a ceiling, because the customer's site speed matters.
  • Security headers and a few infrastructure rules.

All of them together take a few seconds. An end-to-end test of the same rule, if one could even be written, takes minutes.

Why it matters for agents

An agent never gets tired or distracted, but it doesn't know a rule you never wrote down. Say "don't call that module directly here" in a code review, and the next session does it again. Make the rule a guard, and the agent sees the error before it even opens a PR, and fixes it itself.

A guard is the rule, written in a language CI understands. Human code review is expensive and should go to what a machine can't see, whether the solution is right, not whether a forbidden import slipped in.

Guard or test?

My question: "is this rule about the shape of the code or its behaviour?" Shape (who imports whom, where a file lives, whether a translation key exists): a guard. Behaviour (money is deducted correctly, a user of site A never sees site B's data): a test.

One more rule: nobody, person or agent, deletes a money or permission test on their own reading. Those tests are few, but each one holds something genuinely expensive.

What static guards gave us

CI got fast, agents get stuck on meaningless tests far less, and the architecture rules no longer live only in my head. Whenever I see a repeated mistake I ask: "can a guard catch this?" Usually it can, in under fifty lines.

Static guards hold the lines defined in modular architecture with one question. The other side, where a test is a must, is in multi-tenancy without leaks. The idea behind them is plain static analysis.

Comments

Sign in to leave a comment.

Sign in

Loading…

Related posts

What goes in CLAUDE.md? A real before-and-afterAI-native method

What goes in CLAUDE.md? A real before-and-after

I gave Claude Code the same sentence twice. The first time it made seven business decisions on its own; the second time, with a twenty-line CLAUDE.md, it asked eight questions instead of guessing. This note covers what the file is, where it lives and what is worth writing in it.

24 Nov 20265 min