Yanis Fourel

Ephemeral tests

As AI writes more and more of the code, the new bottleneck in development is trust. As an engineer, how can I delegate the details to AI and focus on higher-level work while staying confident in what it does and in control of what I delegate?

One way to gain confidence that AI hasn’t introduced bugs is to run automated tests. This is nothing new: people have been writing automated tests since the punch card era.

Tests are amazing. A test checks that a system behaves as expected under specific conditions. Once you’ve written it, you can run it again whenever you like. In theory, you can keep checking that behavior forever. In my experience, though, code rarely ages well, and test suites take that to another level. If you’ve worked on a codebase with a strong test suite for a few years, you’ve probably made a perfectly legitimate change only to see a bunch of seemingly unrelated tests fail. Often, the problem is in the tests themselves.

In my experience, maintaining an automated test suite is probably the most difficult and valuable part of a project. We try to capture the project’s invariants in tests: the things we care about that should keep working even as the code changes. In practice, we can’t always check those invariants directly, so our assertions end up depending on details of the current implementation. When those details change, often for good reason, the tests break even though the behavior we care about hasn’t changed. That’s why test suites can age so poorly, so fast.

AI lets a codebase evolve faster, which makes this problem worse. AI agents also benefit from writing tests to check their own work. They tend to write a lot of them, so the test suite grows even faster.

On the one hand, I want a complete automated test suite with robust and relevant tests. I want tests that check high-level behavior as close as possible to the project’s invariants, so they don’t break every time the implementation changes. I also want to prioritize parts of the system where bugs are likely or would do the most damage. So I definitely want AI’s help writing tests. On the other hand, I don’t want an agent to add a ton of unit tests tied to the details of the change it just made. Those tests bloat the suite now and are likely to break when those details change.

The solution I found was to separate ephemeral tests from permanent tests.

Permanent tests make up the automated test suite as we know it. I’m very selective about which tests belong there. Only relevant, easy-to-understand tests get into this VIP club. They shouldn’t break very often, and when they do, it should be easy to understand why.

Ephemeral tests are there to check that the details of the current change are correct. What sets them apart is that they’re deleted before the feature branch is merged. Their only job is to give the worker and the reviewer confidence in that change. There’s no limit to how many of these tests we can write. Since we don’t have to worry about how they’ll age, we can rely on as many implementation details as we want. That makes them much easier to write. They’re exactly the tests an AI agent benefits from writing but that I don’t want to keep around.

It’s okay to delete tests that check a feature’s internals before merging the feature. The next time someone changes those internals, an AI agent can write the tests it needs against the implementation that exists then. That way, we can test the details thoroughly whenever they change without having to maintain tests for an implementation we’ve since replaced.

It’s still important to add tests to the VIP club: the ones that actually stand the test of time. But it’s much easier to curate that suite when we label it as permanent and keep it separate from the ephemeral tests.

Implementation

Here’s how I use this in practice. I add the following to AGENTS.md:

When you need a test to check that a change works but the test doesn't belong
in the permanent suite, write it as a one-off test program in `ephemeral/`
and run it with `sh ephemeral/run.sh`. This is the common case for new utility
functions or pure functions. Give the reviewer either permanent tests or
one-off tests in `ephemeral/` that show your change works.

Only add robust, relevant tests to the permanent suite. Test invariants that
are unlikely to change, and avoid relying on implementation details. Focus on
areas where bugs would have serious consequences or are likely to occur.

When in doubt, prefer a one-off test in `ephemeral/` over a permanent test.

The `ephemeral/` folder gives reviewers everything they need to see how a
change was tested and to rerun the tests themselves. Reviewers don't need to
judge these tests by the code quality standards of the permanent suite, since
the tests won't be kept. It should still be clear to the reviewer how the
tests demonstrate that the change works.

The `ephemeral/` folder is deleted automatically before the merge. You don't
need to delete it yourself.

I’ve found that this approach gives me much more confidence in each incremental change and keeps the main test suite relevant and under control.