My AI's tests were green for weeks. They were reading the comments.
Thirteen tests my AI agents wrote were green for weeks. Not one of them was testing the code. Each had found the line it was looking for, in a comment.
Under one of my posts, @sri_ramya_1205 asked this:
How do you make sure these checks stay useful over time, instead of slowly becoming just another green tick in the pipeline?
This is my longest answer to that. It has the numbers from one repo, including the part where my own fix went slack.
The test that reads code as text
There's a kind of test that's cheap to write and easy to trust. It opens a source file as a string and checks that a line is in it:
const src = readFileSync("app/welcome/page.tsx", "utf8")
expect(src).toContain('if (path === "/welcome") return null')It pins a decision: this route never shows the onboarding tour. In my repos, AI coding agents write most of the code and most of the tests, and they love this kind of check. It's the fastest way to show a reviewer the change is in the file. It reads like proof, it runs in milliseconds, and it goes green on the first try.
A string search has no idea what a comment is. That's the whole story, but it took me a while to see it.
How a passing test goes blind
Two cases from the same week (names translated from German).
The welcome guard. The line above was the real code once. Later it became if (tourPaused(path)) return null, which covers more routes. The comment above it still explained the old rule, with the old line in it. The test kept finding that line. Green.
The quarter label. A test asserted that labels match /^Q[1-4]$/. The code had moved to /^Q([1-4])(\s+\d{4})?$/ to allow "Q3 2026". The old expression survived in the comment. Green.
Both reported "fine" for weeks while the code did something else. Nothing about them looked different from a test that works.

The count
On 19 August 2026 I counted the whole repo:
| test files | 193 |
| …that read source code as text | 109 |
| …with no comment filter at all | 102 |
| …green only because the line was in a comment | 13 |

My first count said 14. One of them was my counting script's fault: it treated .not.toContain(…) like .toContain(…). The tool I'd built to catch blind checks had a blind spot on its first run.
There's an opposite direction too. Seven checks went red the same week because they found the pattern they were looking for in an explanation. That one is annoying, and it fixes itself, because red gets attention.
Green never gets read. A false alarm costs you ten minutes. A false all-clear costs you nothing, until the day it costs you the bug.
The fix, in three parts
One reading function for every check. codeOnly(path) strips comments before anything gets searched. Getting it right took three cuts in a fixed order: JSX comments {/* … */} first, then block comments, then line comments. My first version filtered lines that start with * and missed every JSX comment, because its first line starts with { and the rest start with letters. Later a check on a CI workflow needed # comments. The answer was to extend the shared function, not to write a second one. A second hand-written filter is a second truth.
A hard line at zero. One test reads all the other tests. For every positive toContain("…") it looks the needle up twice: in the raw file and in the comment-free file. Found in raw, missing in code: that check is green because of a comment, and the build fails. The allowed number is 0.
A ratchet for the old debt. Rewriting 90 checks in one go wasn't going to happen. So the number of checks that still read raw text went into the file as a constant, 90, with one rule: it may go down, never up.
What 82 days did to it
This is the part Sri actually asked about. Same repo, same counting rule:
| 19 Aug (after the fix) | 9 Nov | |
|---|---|---|
| test files | 193 | 387 |
| …that read source as text | 109 | 140 |
| …without the comment filter | 90 | 89 |
The number of source-reading checks grew by 31. The unfiltered ones went down by one. Net, everything new came in through the shared function. On new code, the rule held.
The old debt moved by one in 82 days. And the constant in the file still says 90.

That's the weak spot I only saw while counting for this post. My ratchet fails when the number grows. Nothing fails when it shrinks, so nobody writes the new number down. When I counted, there was room for one new unfiltered check that would pass without a word.
A ratchet nobody tightens is a green tick too.
The repair is small: fail in both directions. If the real count is lower than the constant, the build says "lower me to 89". Then the only way to stay green is to write the progress down.
Four rules I'd keep
- Show the check failing, every time what it watches changes. Not once when it's written. Delete the line it asserts, keep the comment, run it.
- Count false all-clears, not just false alarms. Red corrects itself. Green waits.
- One reading function. Every hand-rolled variant is a place where the rule quietly differs.
- Ratchets need two edges. One that stops the number growing, and one that makes you record when it shrank.
Count it yourself (two minutes)
# test files that read source code as text
grep -rlE "readFileSync|readFile\(" --include="*.test.*" . | grep -v node_modules | wc -l
# ...of those, how many never strip comments
# (replace stripComments with the name of your own helper)
grep -rlE "readFileSync|readFile\(" --include="*.test.*" . | grep -v node_modules \
| xargs grep -L "stripComments" | wc -lThen pick one file from the second list. Open the file it checks, delete the asserted line from the code, leave any comment that mentions it, and run the test. If it stays green, it's reading the comment.
I'd like to see your two numbers. Mine started at 109 and 102.
Where this stops
- One TypeScript repo, mine. Your share will differ.
- The detector checks literal needles of six characters or more, in files the test names by path. Regex needles and computed paths slip past it.
- The comment filter cuts lines that start with a comment. A needle in a trailing comment (
run(); // old line) still counts as code. - Tests that read source as text are a cheap tool. Some of mine should be behaviour tests. The filter makes them honest; it doesn't make them good.
Using Jira or Confluence with Claude Code, Cursor or JetBrains in the EU? I'll set up your team memory in 15 minutes, with your real Git and Jira history. Free for the first 5 teams. Write to [email protected] or reply here: cachly.dev
cachly.dev
For solo developers, teams and whole companies
Explain it once. Every AI knows it.
Shared team memory between your code, your tickets and your AI. Hosted in the EU, in every tool. cachly keeps the fixes, the decisions and the traps, so the next session starts with them. Claude Code, Cursor, Copilot, Windsurf, Codex, Gemini CLI and JetBrains all read it. Free for one project, no card needed.
Servers in the EU · one command, restart your editor, done · 1 project free
Four ways to install
- Claude Code
/plugin marketplace add cachly-dev/cachly-mcp /plugin install cachly-brain@cachlyThen turn on auto-update once:
/plugin→ Marketplaces → cachly → Enable auto-update- Any MCP editor
npx @cachly-dev/mcp-server@latest autopilot- JetBrains
- JetBrains Marketplace: cachly-brain