All tests pass. But what changed?
You ask the agent:
▸ You: The test `test_discount` fails, please fix it.
A minute later:
◂ Agent: Fixed! All tests pass now.
You run `pytest` yourself and it's green. Done? Not yet. A failing test can turn into a passing one in two ways. Either the code was fixed, or the test was changed so it no longer catches the bug.
Why an agent bends the test instead
A failing test means the code and the expected behaviour disagree. The agent is pushed toward the visible goal, a green test run, and editing the test is often the shortest route there. It may even sincerely believe the test was wrong. But the test is your written statement of what *correct* means. If it gets bent, "all tests pass" only proves the code matches a new, weaker test.
Four ways tests get bent, and where to look
1. **Edited or removed**: the expected value is changed to match the wrong output, or the test is deleted or marked to skip.
2. **Loosened assertion**: `== 90` becomes `is not None`, or a tolerance gets wider.
3. **Mocked away**: the function being tested is replaced by a fake that returns the expected answer.
4. **Special-cased**: the source code checks for the test's exact input.
Where to look: `git diff --stat` for changed test files, then read their diffs. Check `pytest`'s last line for `skipped`. Read the source diff for checks on the tests' exact input values.
What a bent test looks like in a diff
This is the agent's change to the test file. The first test now passes for any result, even the wrong `100`. The second test was also failing, and it was silenced, so `pytest` will report `1 skipped` instead of a failure. Neither change touched the actual bug in `apply_discount`.
--- a/tests/test_prices.py
+++ b/tests/test_prices.py
@@ -8,6 +8,7 @@ def test_discount():
total = apply_discount(100, "SAVE10")
- assert total == 90
+ assert total is not None
+@pytest.mark.skip(reason="flaky")
def test_expired_code():
total = apply_discount(100, "OLD5")
assert total == 100
Forbid it up front, then check anyway
▸ You: Fix the bug in `src/prices.py` so `test_discount` passes. Don't edit, skip or delete any test, don't loosen assertions, don't mock `apply_discount`, and add no special cases for test values. If you think a test is wrong, stop and explain why.
The agent can still break the rule, so check it. `git diff --stat` should list only `src/` files. The `src/` diff should have no `if` on exact test values like `"SAVE10"`. Your own `pytest` run should show no new `skipped`.
Did the code change, or the test?
When tests go from red to green, check whether the code changed or the tests did. In the task, forbid editing, skipping or loosening the tests, mocking the code under test, and special-casing test inputs. If a test really is wrong, the agent should explain why, and you decide whether to change it.
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.