Hide test files in GitHub PR diffs with .gitattributes
The new economics of tests#
If you're like me, you've probably adopted some form of TDD with your AI agents. Although they aren't perfect, and can be gamed by the agent itself, having some sanity checks helps improve your confidence that for most cases the expected output is verifiable, and forces you into a loose coupling architecture.
Writing tests in many places was a luxury that required large amounts of effort to write, and maintain, and reviewing tests if they existed was never anyone's priority. Now, given the right architecture, it is extremely cheap to generate tests that hit most of your code paths. And you should do that, but one of the problems with having lots of tests is that it can get very noisy during the review phase.
After vibing your latest feature you get a PR like this:
38 files changed, with 2,809 lines of code, in this particular PR. Around 30% of the PR is test coverage. When I open that PR, I want to see the three files where the actual logic changed. Instead I'm scrolling past assert_eq! after assert_eq! to find them. The signal-to-noise on a diff this size is brutal when hundreds of lines are scaffolding I already trust the agent to have written.
Read less, ship faster#
In today's slop factories...I mean engineering organizations, there's a massive drive to read less code in favor of shipping faster, which sounds an awful lot like skipping tests for speed. Not here to discuss the merits of that, but it's a trend that's happening, and I am never one to fight the tide. With that in mind it's best to be surgical about the code that you do read, and test harnesses are for me not worthy of that attention.
The hack#
I needed a simple way to try and get rid of the noise from my GitHub PRs. Unfortunately there's no way to do this by default, but:
- GitHub uses github-linguist to classify files.
- Files marked
linguist-generated=trueare collapsed by default in diffs and excluded from language stats.
I do wish that it could hide them entirely from PR reviews, but alas that would be a GitHub feature request — or perhaps an interesting feature for a new git platform.
# Lockfiles — already conventional
Cargo.lock linguist-generated=true
package-lock.json linguist-generated=true
pnpm-lock.yaml linguist-generated=true
yarn.lock linguist-generated=true
# Sibling unit-test files (e.g. foo.rs has foo_tests.rs next to it)
*_tests.rs linguist-generated=true
# Integration test directories
server/tests/** linguist-generated=true
It's a semantic lie. Or maybe not — linguist-generated is meant for generated files, but if the tests were written by an agent, maybe that qualifies as "generated."
Ultimately your review process is meant to get you the most important things up to the front as quickly as possible. This is a small thing that might help with that.
Linus's Law said "given enough eyeballs, all bugs are shallow." Sadly most of us only have two eyeballs. I'll try to maximize where I can use them.