The prompt
Score 10 of 10, Excellent
Use it when A module has thin or no test coverage, and you want an agent to pin down its behavior without changing it.
- {{module_path}}
- {{test_command}}
- {{pattern_test_file}}
- {{module_purpose}}
- {{known_cases}}
Full prompt and why it works
Prompt
Goal: Write tests for {{module_path}} that pin down its current behavior, so that it can be refactored later without silently changing what it does. Context: - Test framework and command: {{test_command}} - Existing test file to use as the pattern for style, fixtures and naming: {{pattern_test_file}} - What this code is for and who calls it: {{module_purpose}} - Cases I know matter: {{known_cases}} Constraints: - Do not change the code under test. If you find a bug, write a test that documents the current behavior, mark it clearly (for example with the framework's skip or expected-failure marker and a one-line comment), and report it. Do not fix it in this task. - Test behavior through the public interface, not private helpers. - No network calls, real clocks, or random values without a fixed seed. Use the fakes and fixtures the project already has, and do not add new test dependencies. - Put new tests where the project keeps them, named like the pattern file (for example module_name.test.ts or tests/test_module_name.py). Cover, in this order: the main success paths; boundary values (empty, zero, the maximum, one past the maximum); invalid input and error handling; then any branch in the code that no test reaches yet. Write at least 8 focused tests. Each test checks one behavior, and its name says what that behavior is, such as rejects_quantity_above_stock_limit. Done when: - All new tests pass with {{test_command}}, and the existing tests still pass. - Each new test would fail if its behavior broke. Check this for at least two of them by temporarily breaking the code, then restore it. Verify: run the full test command and include the last 20 lines of its output in your final message, followed by a table with the columns Test and Behavior checked. If the module cannot be tested without changing it, stop and describe the smallest change that would help before making it.
Variables
- {{module_path}}
- The file or folder to test, for example src/billing/invoice.ts.
- {{test_command}}
- The command that runs the tests, for example npm test or pytest.
- {{pattern_test_file}}
- An existing test file whose style the new tests should copy.
- {{module_purpose}}
- One or two sentences on what the code does and what depends on it.
- {{known_cases}}
- Inputs and results you know matter, for example "an order with zero items is rejected". "None" is fine.
Why it works
- Who it's for. Saying the tests exist to protect a later refactor tells the agent to pin down current behavior, bugs included, rather than fixing things as it goes.
- Length. An ordered coverage list and a minimum of 8 tests set the depth, so you do not get three happy-path tests.
- What good looks like. Breaking the code on purpose to watch a test fail proves the tests can actually catch a regression.