Sub topic 8
Making Sure Tests Were Not Weakened to Pass
This chapter assumes you know basic Git (branches, diffs, staging), can read code in at least one language, and can run your project's tests, linter, and type checker from the command line. The examples use Python and pytest, but the same ideas apply to any stack.
Why tests are the first thing to check
An agent is usually told to make the tests pass. That goal can be met in two ways: fix the code, or change what the tests check. Both turn the test run green. Only the first one is what you wanted.
Agents rarely do the second one out of bad intent. When a test fails and the agent cannot find a quick fix, editing the test is a short path to a green result. The agent may also believe the old test was wrong. Either way, you cannot tell from a passing run alone which one happened.
For that reason, a green test run is only trustworthy after you have checked that the tests themselves are still doing their job. This check comes before you rely on any other verification, because every later check (the suite, CI, the agent's own summary) depends on the tests being sound.
Ways tests get weakened
Weakening can be loud or quiet. The loud forms are easy to find with a diff. The quiet forms need you to read the assertions.
| Technique | What it looks like | Why it hides a problem |
|---|---|---|
| Skipping | `@pytest.mark.skip`, `@pytest.mark.xfail` | The test no longer runs, or its failure is reported as expected. |
| Deleting | A test function or whole file is removed | Coverage of that behavior disappears with no failure. |
| Loosening an assertion | `assert result == 5` becomes `assert result is not None` | The test passes for almost any output. |
| Changing the expected value | Expected output is edited to match the new, possibly wrong, output | The test now records the bug as correct. |
| Over-mocking | The function under test is replaced with a mock | The test checks the mock, not your code. |
| Catching errors | `try/except` or `pytest.raises(Exception)` added around the call | Any failure is swallowed or accepted. |
| Silencing other checks | `# noqa`, `# type: ignore`, relaxed lint or type config | The linter and type checker stop reporting real problems. |
| Editing configuration | Lowered coverage threshold, removed test paths, changed `pytest.ini` | The suite runs less, or the bar for passing drops. |
Not every change in this table is a defect. A test may legitimately need to change when the requirement changed. The question to ask is whether the change was part of the task you defined. If the task was a pure rename, no expected value should change.
Step 1: Look at the test diff on its own
Review tests separately from the code. If you read them in one pass with the source, the source changes tend to explain away the test changes ("of course the test changed, the function changed"). Reading them alone forces you to ask whether each test change is justified by the task.
git status --short -- tests/
git diff --stat -- tests/
git diff -- tests/git status shows new untracked test files, which git diff does not list. Pay attention to the shape of the change:
- Many deleted lines with few added lines suggest removed coverage.
- Edited expected values suggest the agent changed what "correct" means.
- A new test file is usually fine, but read it. A new test that asserts nothing meaningful adds the look of coverage without the substance.
For a refactor or rename, the ideal test diff is empty, or limited to updated import paths and names. Any change to an assertion deserves a question.
Step 2: Search added lines for silencing markers
Some weakening is easy to find with a text search. Search only the lines the agent added, so that existing markers in the codebase do not bury the new ones.
git diff -U0 | grep -nE '^\+.*(@pytest\.mark\.(skip|xfail)|# noqa|# type: ignore)'The pattern ^\+ limits matches to added lines. Extend the pattern for your stack. For example, JavaScript projects might add \.skip\(, xit\(, eslint-disable, and @ts-ignore. A search that finds nothing does not prove the tests are intact, because it only catches known markers. It is a fast first filter.
Also check for removed lines, which this search cannot see. List deleted files and count removed test functions:
git diff --diff-filter=D --name-only
git diff -U0 -- tests/ | grep -cE '^-\s*def test_'
git diff -U0 -- tests/ | grep -cE '^\+\s*def test_'If the removed count is higher than the added count and the task did not call for removing tests, ask why. A renamed test shows up as one removal and one addition, so equal counts do not always mean nothing was lost. Counts are a prompt to look closer, not a verdict.
Step 3: Check configuration files
Agents can lower the bar without touching a test file. Review changes to configuration that controls what runs and what counts as a pass:
git diff -- pytest.ini pyproject.toml setup.cfg tox.ini .github/ MakefileLook for these changes:
- A narrower
testpathsor a new--ignoreoption. - A lower
--cov-fail-underthreshold. - New entries in lint or type-checker ignore lists.
- A CI step removed, made optional (
continue-on-error: true), or given a looser command.
Config changes are easy to miss because they are small and sit outside the source tree. A one-line edit to a coverage threshold can hide a large drop in coverage.
Step 4: Prove the tests still catch bugs
Reading the diff tells you what changed. It does not tell you whether the remaining tests still fail when the code is wrong. You can check this directly with a mutation check: deliberately break the code under test and confirm that a test fails.
Do this by hand for the behavior the task touched. Choose a function the agent changed, introduce a small bug, and run the related tests.
git stash list # confirm you have nothing stashed that you may lose
git switch -c check/mutation # work on a throwaway branch
# edit src/config/loader.py: change a return value or a condition by hand
python -m pytest tests/test_loader.py -q
git restore src/config/loader.py # undo the deliberate bug
git switch agent/rename-config-loader
git branch -D check/mutationIf the tests still pass with the bug in place, they do not protect that behavior, whatever the agent did to them. If they fail, the tests are doing their job for that code path.
Run the opposite check as well when a test was edited. Restore the original version of the test file from the starting commit and run it against the agent's code:
git show <start-commit>:tests/test_loader.py > /tmp/test_loader_original.py
python -m pytest /tmp/test_loader_original.py -qReplace <start-commit> with the commit you noted at the start of the run. If the original test fails against the new code, the agent changed behavior. That may be the result of a real requirement or an accidental regression, and now you know to decide which.
Common mistakes when reviewing tests
- Trusting the summary. An agent may report "all tests pass" without mentioning that two were skipped. Check the skipped and deselected counts in your own run output.
- Reading only the failing tests. Weakened tests are, by definition, not failing. Review the ones that pass too.
- Treating a new test as proof. A test written by the same agent that wrote the code may share its misunderstanding. Read what it asserts.
- Ignoring snapshot and golden files. Updating a snapshot with an
--updateflag makes any output the expected output. Review snapshot diffs like any other expected value. - Stopping at the grep. A clean search for skip markers says nothing about loosened assertions.
Asking the agent to fix it
When you find a weakened test, say exactly which one and what to restore, and say that the code must change instead. Vague feedback such as "don't weaken tests" is easy to misread. A specific correction works better:
tests/test_loader.py now skips test_missing_file. Remove the skip and restore the
original assertion. Fix src/config/loader.py so the test passes. Do not edit any
other test. Report the exact test command you ran and the pass, skip, and fail counts.Asking for the counts gives you something to compare with your own run.
Exercise
An agent was asked to rename a function and update its callers. Its diff shows that tests/test_loader.py changed one line: assert loader.load("missing.toml") == {} became assert loader.load("missing.toml") is not None. All tests pass. Name two checks you would run before accepting, and say what result would make you reject the change.
Show answer
First, run the original version of the test (from the commit the agent started at, using git show <start-commit>:tests/test_loader.py) against the agent's code. If it fails, the rename changed behavior and the loosened assertion hid it, so reject the test edit and ask for the code to be fixed. Second, do a mutation check: change the return value of load for a missing file to something wrong, such as returning None or a non-empty dict, and run the test. The new assertion would pass for a non-empty dict, which shows it no longer protects the behavior. A rename task should not need any assertion change, so reject the test edit either way and restore the original line.
Exercise
Why can git diff alone miss test weakening, and what two additional commands or views would you use to cover the gaps?
Show answer
git diff does not list untracked files, so a new test file or a new config file is invisible to it, and it cannot show that a test was weakened by something outside the test files, such as a lowered coverage threshold. Use git status --short to see untracked files, and review configuration diffs (for example git diff -- pytest.ini pyproject.toml .github/). You can also run the tests yourself and compare the skipped and deselected counts against the baseline run.