Appearance
date: 2026-06-25 tags: [mutation-testing, eager-loading, inertia, testing] status: active graduated_to:
An eager-load RemoveArrayItem can't be killed by a query-count test — assert the prop shape
Symptom — RemoveArrayItem mutants on a controller's ->with(['categories.items', 'categories.children.items']) / ->load([...]) survived a query-count N+1 test (expect(count(DB::getQueryLog()))->toBeLessThanOrEqual(n)) — dropping a relation didn't push the count over the bound.
Root cause — Model::toArray() (how Inertia serialises page props) does not lazy-load relations; it serialises only what's already loaded. So removing a relation from an eager-load doesn't trigger N+1 queries during serialisation — it just yields incomplete data. The query count is unchanged, so a count-based assertion can't tell the mutant apart.
Fix — assert the rendered nested prop shape instead, so a dropped relation = a missing key (commit d8f4097, tests/Feature/PackingListsControllerTest.php):
php
->has('templates.0.categories.0.items', 1)
->has('templates.0.categories.0.children.0.items', 1) // dropping either with() path fails thisGuard — .claude/rules/database.md: the N+1 note now adds that an eager-load's mutation coverage comes from asserting the serialised nested prop shape, not a query count (a query-count test still belongs where a genuine runtime N+1 is the risk).