logoalt Hacker News

BeetleBtoday at 7:25 PM9 repliesview on HN

I wish there was a way to "freeze" the tests. I want to write the tests first (or have Claude do it with my review), and then I want to get Claude to change the code to get them to pass - but with confidence that it doesn't edit any of the test files!


Replies

simlevesquetoday at 7:31 PM

I use devcontainers in all the projects I use claude code on. [1] With it you can have claude running inside a container with just the project's code in write access and also mount a test folder with just read permissions, or do the opposite. You can even have both devcontainers and run them at the same time.

[1] https://code.claude.com/docs/en/devcontainer

If you want to try it just ask Claude to set it up for your project and review it after.

comradesmithtoday at 7:36 PM

1. Make tests 2. Commit them 3. Proceed with implementation and tell agent to use the tests but not modify them

It will probably comply, and at least if it does change the tests you can always revert those files to where you committed them

show 2 replies
paxystoday at 7:32 PM

Why can't you do just that? You can configure file path permissions in Claude or via an external tool.

pfortunytoday at 7:38 PM

Why not use a client-server infrastructure for tests? The server sends the test code, the client runs the code, sends the output to the server and this replies pass/not pass.

One could even make zero-knowledge test development this way.

aray07today at 7:27 PM

yeah i agree - this is somewhat the approach I have been using more of. Write the tests first based on specs and then write code to make the tests pass. This works well for cases where unit tests are sufficient.

SatvikBeritoday at 7:36 PM

You can remove edit permissions on the test directory

show 1 reply
kubbtoday at 7:35 PM

"Add a config option preventing you from modifying files matching src/*_test.py."

dborehamtoday at 7:35 PM

Just tell it that the tests can't be changed. Honestly I'd be surprised if it tried to anyway. I've never had it do that through many projects where tests were provided to drive development.