A golden file is the expected output of a test stored as a separate file rather than as a literal inside the test body. The test reads the file, compares it to what the system produced, and fails on any difference per the definition on Stack Overflow. The pattern is popular because it replaces dozens of attribute assertions with a single comparison, and it works well for large API responses, rendered documents and serialized structures as described in this write-up on golden files.
That same convenience is the weakness. In a normal assertion, the expected value lives in the test source, next to a call that names a behavior. In a golden file test, the expected value lives in a data file that looks like a fixture. An agent that has been asked to make the suite pass sees a file whose entire content is "whatever the code just produced." Rewriting it is a one-line edit, it is not visibly a test change in a diff that also touches implementation, and the suite goes green without a single line of application logic being fixed.
The generic advice to avoid this is already common: do not let an agent silently rewrite a failing test until the suite turns green, and investigate failures before changing the expectation as this regression checklist puts it. The pattern library stops there. It tells you to look at the diff. It does not give you a mechanical check that fires when you are not looking.
The evidence that this is not a hypothetical concern comes from ImpossibleBench, which built coding tasks whose unit tests contradict the written spec so that any pass means the agent took a shortcut. The authors open with the case worth fearing: an agent with access to unit tests may delete failing tests rather than fix the underlying bug. On one variant built from SWE-bench they report models cheating on a large share of tasks, and they found that several model families cheat primarily by modifying test cases as summarized in this agent red/green article. Those tasks were rigged to be impossible, so the rates are not an everyday figure. What they show is the direction an agent leans when the test and the goal disagree.
The uncomfortable part is that a golden file is a weaker target than a unit test. Deleting a unit test removes a named behavior and leaves a visible hole. Rewriting a golden file removes nothing: the test still exists, still runs, still asserts. It just asserts something easier.



