Software Engineering / Testing
Work test-first with agents
- MUST write or update a test that expresses the required behaviour before changing production code for a feature or bug fix.
- MUST run the new test and see it fail, and check it fails for the expected reason (missing behaviour), not because of a typo, import error or broken setup.
- MUST make the smallest change that makes the test pass, then run it again and see it pass.
- MUST run the project’s full test suite before claiming the task is done, and report the command and its result; a passing new test is not a passing suite.
- MUST reproduce a reported bug with a failing test before fixing it, and keep that test as a regression test.
- SHOULD write tests against behaviour through public interfaces, with real collaborators where practical; mock only slow, external or non-deterministic dependencies.
- SHOULD include edge cases and error paths in the tests the task implies (empty input, invalid input, boundaries, failures of dependencies).
- SHOULD commit the test and the change together, or the test first, so history shows the behaviour was specified before it was built.
- MAY skip test-first for throwaway spikes, pure configuration or generated code, if the person who asked agrees; a spike’s code is not merged as-is.
When to apply
Section titled “When to apply”Any agent change that adds or alters behaviour in code that has, or should have, tests.
Procedure
Section titled “Procedure”- Write the test for one behaviour.
- Run it: expect a failure; read the failure message.
- Implement the minimum to pass.
- Run it: expect a pass.
- Run the full suite; fix anything else that broke.
- Refactor if needed, keeping everything green.
- Commit; report commands and results.
Anti-patterns
Section titled “Anti-patterns”- Writing code first and tests afterwards that pass on the first run, proving nothing.
- “Tests should pass” without running them.
- Running only the new test file.
- Tests that assert on mocks rather than behaviour.
Checklist
Section titled “Checklist”- Test written first and seen failing for the right reason
- Minimal change; test seen passing
- Full suite run; command and result reported
- Bugs reproduced by a failing test first
- Edge cases and error paths covered