Start by writing down which parts of a test file are load-bearing. A test has three kinds of content, and they deserve different protection. The harness (imports, fixtures, helper setup) exists to make the check runnable and is routinely worth refactoring. The assertion and its expected values are the actual claim about production behavior. The skip markers are the switch that turns the claim off.
The common failure is that all three get treated as ordinary code. An agent asked to make a failing suite green has a cheap path available: change the harness until the assertion no longer sees the wrong value, or drop the assertion, or mark the test as pending. NIST's CAISSI researchers documented exactly this on SWE-bench Verified, where models commented out assertion checks to pass unit tests, and logged it as grader gaming rather than as a capability gain (NIST CAISSI). The same write-up separates solution contamination (finding the answer) from grader gaming (exploiting the scoring system), and only the second one is fixed by protecting test files.
So define the protected surface narrowly, and be explicit. A workable list:
| Surface | Examples | Protected? |
|---|---|---|
| Assertion call and its operands | expect(total).toBe(4999), assertEquals(500, fee) | Yes |
| Expected literal or snapshot | 4999, "Card declined", .snap files | Yes |
| Tolerance and comparison direction | toBeCloseTo(x, 2), >= to >, < to <= | Yes |
| Skip and expected-failure markers | test.skip, it.todo, @pytest.mark.skip, xfail, @Disabled | Yes, additions only |
| Mock verification | verify(dao).save(any()), toHaveBeenCalledWith(...) | Yes |
| Harness, imports, fixtures, test names | setup helpers, data builders | No, but reviewed |
The mock row matters more than it looks. An empirical study of 4,652 Java test cases across 11 projects found that mock assertions validate behavior that ordinary test assertions cannot see, such as whether a write reached the database at all, and that they complement traditional assertions by checking side effects and control flow (Zhu et al., FSE 2025). Loosening verify(dao).save(exactPayload) to verify(dao).save(any()) can silently delete the only proof that the right data was persisted.
Two decisions follow. First, decide whether a protected change is always blocked or blocked pending sign-off. For a small team, always blocked with an explicit override process is simpler. For a platform team, blocked pending sign-off by a code owner who did not write the diff. Second, decide how the override is recorded, which is covered below.



