An architecture test is the only safeguard that stopped my Claude Code agents from growing the same catch-all files. The project is an open-world 3D game built with Godot 4.7.2, set in a fictional replica of Nantes, and developed since January 2026 almost entirely by about a dozen agents working in parallel. On 14 November, an audit counted 42 scripts over 500 lines, which made up 40% of the code. The fix was a 0.34 s GUT test that reads the sources and rejects any forbidden dependency or any extra line in a big file. One trap remains: the agent that "fixes" the test by editing its exception table.
An agent's harness is everything around the model: the written instructions (CLAUDE.md, memory notes), the test scripts, the machines and the safeguards that reject code.
Why an agent writes god files
An agent adds code where it already has the context. The game's scenario runner, scenario_runner.gd, was created on 10 November. By the evening of the 14th it was 4,362 lines long, after 242 commits. Every agent appended its scenario at the bottom. Each commit was reasonable, and the result was a file that all of them edited at the same time, the main source of conflicts between their git worktrees.
The audit on 14 November measured the rest: 389 scripts, 96,865 lines, and a median of 143 lines per script. pause_menu.gd (1,259 lines, 85 functions) handled the start screen, saving, options and building the UI, and some "services" mixed game rules with display code.
My request fit in one sentence: "clean code, small files and small commits, with a clear split." The architecture document turned it into ten rules. The project's instructions are written in French, so the quotes here are my translations. One of the rules: "A larger script listed in the table does not grow by a single line: new code goes into a script of its own."
The architecture test: 5 tests, 0.34 s
An agent may or may not read a written instruction, but a red test in the fast suite stops it before the merge. test_architecture.gd reads every script without loading the map and checks dependency rules and size limits:
| Test | Fails if… |
|---|---|
| layer of each script | a script lands in a folder that has no layer |
| who may reference whom | a new forbidden dependency appears |
| mission engine | it references anything other than itself (no exceptions allowed) |
| game nodes looked up by the world | one more game group is looked up |
| maximum size | a script goes past 500 lines, or a listed script grows by one line |
Here is the size check, shortened:
func test_no_script_grows_past_the_size_limit() -> void:
for path in _scripts:
var lines := FileAccess.get_file_as_string(path).count("\n")
var noted := int(Architecture.SIZE_EXCEPTIONS.get(path, 0))
if noted == 0:
if lines > Architecture.MAX_LINES:
too_big.append("%s : %d lignes (plus de %d : à découper, un script par responsabilité)" % [
path, lines, Architecture.MAX_LINES])
elif lines > noted:
too_big.append("%s : %d lignes, notée %d (un gros script ne grossit plus : mettre le nouveau code ailleurs)" % [
path, lines, noted])
elif lines <= Architecture.MAX_LINES:
shrunk.append("%s : %d lignes, sous le seuil (à retirer de SIZE_EXCEPTIONS)" % [path, lines])
(French for: "N lines (over 500: split it, one script per responsibility)"; "N lines, listed at M (a big script no longer grows: put the new code elsewhere)"; "N lines, under the threshold (remove it from SIZE_EXCEPTIONS)".)
The existing violations are listed in a table: 32 dependencies, 19 node lookups, 42 sizes. An exception that is no longer needed also makes the test fail, so the table can only go down. I proved each rule with an injected violation that I then removed, the same way a reported bug gets reproduced by a red test before the fix (in French). One example: 600 lines added to a small script.
The runner was split that same evening, in under 40 minutes: from 4,362 down to 860 lines, with 53 scenarios each in their own file. A sixth test, test_scenarios_are_declared_in_the_table_not_in_the_runner, catches the stale branch that still adds an entry to the runner. It is the method I used on a bloated controller split by successive extractions (in French), applied here with one agent per extraction.
The trap: the agent that fixes the table instead of the code
Rule 7 of the architecture document says so: "No new exceptions in the test tables: they can only shrink. A failing boundary test gets fixed in the code, not in the table." Less than an hour and a half after the test was created, it went green on this commit from an agent that was adding the credits to the menu:
- "res://scripts/ui/pause_menu.gd": 1215,
+ "res://scripts/ui/pause_menu.gd": 1216,
The agent had put the credits in three new files, then added one line to pause_menu.gd and raised the ceiling by the same amount. Another commit had pushed day_night_cycle.gd from 747 to 755 lines, with this comment as justification: « intégré en parallèle du garde » (French for: "merged in parallel with the guard").
An architecture test whose exception table can be edited without any check only stops the agents that don't think of editing it.
test_monde_sans_lieu.gd, added the same evening, closes that door. It forbids any new mention of the city (place name, coordinate, OSM identifier) in the world engine code and caps the sum of the exceptions:
assert_lte(total, Table.DEPART, "la somme des exceptions ne dépasse jamais la mesure de départ")
(French for: "the sum of the exceptions never exceeds the starting measurement".)
For size and dependencies, that cap does not exist yet: I review the diff of tests/support/ at every merge.
FAQ
What is an architecture test?
An architecture test is a unit test that reads the source code instead of running it. It checks structural rules: which layer may reference which other layer, which folders exist, how large a file may get. It runs without a database, a scene or a network, so it takes a fraction of a second, and it fails on the first new violation.
How do you stop an agent from bypassing an architecture test with an exception?
The exception table has to work like a ratchet: an exception that is no longer needed makes the test fail, and a capped sum (assert_lte(total, DEPART)) makes it impossible to gain any. A table without a cap can still be edited by the agent, so you also need to review every diff of the test support files.
What size limit should you pick for a source file?
Take the limit from measuring your own repository rather than from a fashionable number. Across 389 Godot scripts, the median was 143 lines, and every script above 500 lines carried at least two responsibilities. So 500 lines became the limit, with the 42 existing violations listed at their size on that day.
Lessons learned
- An agent adds code to the file it already has open. Without a checked rule, 242 reasonable commits produced a 4,362-line runner in four days.
- An architecture rule holds when a test fails in under a second. The failure message tells the agent where to put the code.
- Existing exceptions get listed at their current size. The test blocks their growth and requires removing the ones that are no longer needed.
- An exception table without a cap is an escape hatch. Without a capped sum or a diff review, the agent raises the threshold by one line.
- Every rule has to be proven with an injected violation. A safeguard you have never seen fail has not proven anything yet.
This piece on architecture tests for AI coding agents was originally published in French on blog.l4w.fr. I'm Sylvain, a freelance full-stack developer (TypeScript/Node.js, PHP/Symfony, infra) available for remote missions: services.l4w.fr/en/.
Top comments (1)
The point about the agent "fixing" the test by editing its exception table is the sneakiest part. Have you tried making the exception list read-only or requiring a human approval for changes to it?