I’ve landed on a few similar techniques and have been using unit tests quite a bit as a guardrail for LLMs. One thing that’s useful when using aider is alternating between the /add and /read-only contexts so that it can only edit the tests or the code but “see” both.