{"slug": "architecture-tests-that-stop-ai-coding-agents-from-growing-god-files", "title": "Architecture tests that stop AI coding agents from growing god files", "summary": "A developer building an open-world 3D game in Godot 4.7.2 with roughly a dozen parallel Claude Code agents added a 0.34-second GUT architecture test that reads source files and rejects forbidden dependencies or any growth in oversized scripts. After a 14 November audit found 42 scripts over 500 lines (40% of the code), including a scenario_runner.gd that reached 4,362 lines across 242 commits, the test enforces ten architecture rules and a shrinking exception table so large files can only get smaller. The developer notes one remaining trap: an agent that \"fixes\" a failing test by editing its exception table.", "body_md": "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.\n\nAn 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.\n\nAn 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.\n\nThe 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.\n\nMy 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.\"\n\nAn 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:\n\n| Test | Fails if… | \n|---|---|\n| layer of each script | a script lands in a folder that has no layer | \n| who may reference whom | a new forbidden dependency appears | \n| mission engine | it references anything other than itself (no exceptions allowed) | \n| game nodes looked up by the world | one more game group is looked up | \n| maximum size | a script goes past 500 lines, or a listed script grows by one line | \n\nHere is the size check, shortened:\n\n``` php\nfunc test_no_script_grows_past_the_size_limit() -> void:\n    for path in _scripts:\n        var lines := FileAccess.get_file_as_string(path).count(\"\\n\")\n        var noted := int(Architecture.SIZE_EXCEPTIONS.get(path, 0))\n        if noted == 0:\n            if lines > Architecture.MAX_LINES:\n                too_big.append(\"%s : %d lignes (plus de %d : à découper, un script par responsabilité)\" % [\n                    path, lines, Architecture.MAX_LINES])\n        elif lines > noted:\n            too_big.append(\"%s : %d lignes, notée %d (un gros script ne grossit plus : mettre le nouveau code ailleurs)\" % [\n                path, lines, noted])\n        elif lines <= Architecture.MAX_LINES:\n            shrunk.append(\"%s : %d lignes, sous le seuil (à retirer de SIZE_EXCEPTIONS)\" % [path, lines])\n```\n\n(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)\".)\n\nThe 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](https://blog.l4w.fr/posts/agent-code-ia-bug-signale-test-rouge-avant-correctif/) (in French). One example: 600 lines added to a small script.\n\nThe 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](https://blog.l4w.fr/posts/poc-sans-tests-direction-pas-point-de-depart-ddd/) (in French), applied here with one agent per extraction.\n\nRule 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:\n\n```\n-   \"res://scripts/ui/pause_menu.gd\": 1215,\n+   \"res://scripts/ui/pause_menu.gd\": 1216,\n```\n\nThe 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\").\n\nAn architecture test whose exception table can be edited without any check only stops the agents that don't think of editing it.\n\n`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:\n\n```\nassert_lte(total, Table.DEPART, \"la somme des exceptions ne dépasse jamais la mesure de départ\")\n```\n\n(French for: \"the sum of the exceptions never exceeds the starting measurement\".)\n\nFor size and dependencies, that cap does not exist yet: I review the diff of `tests/support/` at every merge.\n\nAn 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.\n\nThe 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.\n\nTake 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.\n\n*This piece on architecture tests for AI coding agents was originally published in French on [blog.l4w.fr](https://blog.l4w.fr/posts/test-architecture-frontiere-fourre-tout-agents-ia/). I'm Sylvain, a freelance full-stack developer (TypeScript/Node.js, PHP/Symfony, infra) available for remote missions: [services.l4w.fr/en/](https://services.l4w.fr/en/?utm_source=devto&utm_medium=article&utm_campaign=test-architecture-frontiere-fourre-tout-agents-ia).*", "url": "https://wpnews.pro/news/architecture-tests-that-stop-ai-coding-agents-from-growing-god-files", "canonical_source": "https://dev.to/sjoffraud/architecture-tests-that-stop-ai-coding-agents-from-growing-god-files-1c49", "published_at": "2026-12-03 17:38:35+00:00", "updated_at": "2026-12-03 17:46:54.564762+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-safety"], "entities": ["Claude Code", "Godot", "GUT", "Nantes"], "also_reported_by": [], "takeaway": "A 0.34-second GUT test that reads scripts without loading the map and fails on forbidden dependencies or any line added to a listed oversized file stops parallel coding agents from growing god files, provided the exception table can only shrink.", "recommendation": {"advice": "Add a fast architecture test to your coding agents' suite that fails on forbidden dependencies and on any growth of listed oversized files, and make stale exceptions fail so the table only shrinks.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/architecture-tests-that-stop-ai-coding-agents-from-growing-god-files", "markdown": "https://wpnews.pro/news/architecture-tests-that-stop-ai-coding-agents-from-growing-god-files.md", "text": "https://wpnews.pro/news/architecture-tests-that-stop-ai-coding-agents-from-growing-god-files.txt", "jsonld": "https://wpnews.pro/news/architecture-tests-that-stop-ai-coding-agents-from-growing-god-files.jsonld"}}