DEV Community

Amit Spitzer
Amit Spitzer

Posted on AI-assisted

Your AI agent says "done" and the tests are green. Check it in 5 seconds before you believe it

You ask an AI agent for a change. It edits the code, runs the tests, they pass, and it says "done". You merge. A week later someone finds the case it never handled.

The tests were green because they only prove the code does what the tests ask. Nobody checked the change against what you asked.

That check is what Apex verify does. It is a small open-source tool (Apache-2.0) and you can see it work right now, with no key and nothing installed:

npx --yes https://github.com/apex-engine-dev/apex-verify/releases/latest/download/apex-verify.tgz verify --demo
Enter fullscreen mode Exit fullscreen mode

This is the real output:

A pretend AI agent was asked:
  slugify() should return a clean URL slug ... slugify("Hello, World!") should give "hello-world".
It fixed the comma, said "done", and the project's own tests pass. Is it really done?

Project tests: 2 passed. Now Apex verify:

apex verify: NOT READY

  - 1 check written from the task fails on the new code
      check: drops punctuation, not just commas
        expected: hello-world
        actual:   hello-world!
Enter fullscreen mode Exit fullscreen mode

Green tests, wrong change, caught, with the expected and the actual value.

Terminal: the tests pass, then apex verify says NOT READY with expected and actual

What it does, in four steps

  1. Scans for cheating. Tests deleted, skipped or focused with .only, an assertion weakened from toBe(2) to toBeDefined(), a test script that can no longer fail.
  2. Runs your tests before and after. A test that passed and now fails is a regression.
  3. A different model writes checks from your task text. Never from the agent's own tests, and not the model that wrote the change.
  4. Proves each check can fail. Every check runs on the old code first. One that passes there proves nothing and is thrown away. This is the step most "let the AI write tests" setups skip.

The answer is ready, not ready or unknown. It never passes silently, and it works on a copy, so your project is not touched.

Why you might want it

If your project has thin tests (most internal tools, most new code), this is where it pays most. On 17 small projects with one or two tests each, the tests plus a cheating scan stopped about 8 in 100 wrong AI changes. Apex verify stopped about 65 in 100, and wrongly stopped about 3 in 100 good ones.

If your project has good tests, the gain is smaller and I will not pretend otherwise. On 200 AI-written changes to 23 real open-source libraries, the projects' own tests already stopped 75 in 100 wrong changes. Apex verify raised that to 91. Of the 27 wrong changes that got past the tests, it caught 17.

The cost is false alarms. On those real libraries, 13 in 100 good changes that pass the tests were stopped by a generated check. I went through each one: in about 7 of 10 the change really did not do what the task said, which leaves about 4 or 5 in 100 as the checker's own mistakes. That lower number rests on my reading of the tasks, so I give you both. If it is too many for you, run it in warn mode: it reports and never blocks.

Put it where the change happens

  • Claude Code and Gemini CLI: a stop hook. The agent says "done", the hook checks, and a wrong change goes back to the agent with the failing check. It blocks at most 3 times, so a bad check cannot trap the agent.
  • Pull requests: a GitHub Action ("Apex verify: AI change checker" on the Marketplace) that comments the verdict and can be a required check. It works for any agent, or a person.
  • Anything else: a CLI and an MCP tool.
- uses: apex-engine-dev/apex-verify@v1
  with:
    api-key: ${{ secrets.GEMINI_API_KEY }}
Enter fullscreen mode Exit fullscreen mode

Checks are written for node:test, Jest, Vitest, pytest, cargo test and go test. Tests and checks run in a sandbox on macOS, Linux and Windows.

What it will not do

It is not a proof of correctness. On the real libraries it called 1 wrong change "ready" and left 9 as "unknown". One maintainer. Gemini wrote every change in the benchmark and Gemini is the checker, one run each, and two runs of the same code disagreed on 25 of 200 verdicts. I have only run the Gemini checker live; OpenAI and Anthropic are wired but untested by me.

I also got a headline wrong last week and corrected it in public. Every number above is from the corrected runs, and every run is in the repo with its scripts, including the experiments that failed.

Try it on your last AI change

export GEMINI_API_KEY=...
cd your-project
npx --yes https://github.com/apex-engine-dev/apex-verify/releases/latest/download/apex-verify.tgz verify "what you asked the AI to do"
Enter fullscreen mode Exit fullscreen mode

No key? Add --no-model for the tests and the cheating scan only.

The most useful thing you can send me is a ready on a change that was wrong, or a not ready on one that was right. I add it to the benchmark and credit you.

Repo: https://github.com/apex-engine-dev/apex-verify

Top comments (2)

Collapse
 
sudokat_ profile image
Gordon Chase •

Proving each generated check fails on the old code kills vacuous tests, but 25/200 verdicts flipping on identical code turns a required PR check into a slot machine devs just re-run. With the 3-try stop hook, have you seen agents "fix" working code to satisfy a flaky check, or does a second model cut that wobble?

Collapse
 
amit_spitzer profile image
Amit Spitzer •

Fair hit, and "slot machine" is the right name for it. Three straight answers.

Agents "fixing" working code: yes, I have seen it. In a 120-session hook experiment there were 6 false blocks. With the hook as shipped, 2 of 4 agents then broke a change that had been correct. One caveat on the cause: 5 of the 6 false blocks came from the project's own tests (one asserted the old behaviour), and 1 from a generated check. So the damage is real, but the sample is tiny and mostly not the flaky-check case you describe.

A second model: it did not help where I measured it. Requiring two checkers to both object lowered wrong changes caught from 25 of 40 to 17 of 40. I have not measured whether it reduces run-to-run flips, so I cannot claim it does.

The required-check problem: on a laptop the drafted checks are cached per task and code, so a re-run gives the same verdict. On GitHub Actions each job starts fresh, so a re-run redrafts and can flip. That is a real gap and I opened an issue for it with you credited: github.com/apex-engine-dev/apex-ve.... Until it is fixed I would run it with fail-on: never (comment only) rather than as a required check. And a stable verdict is still not a right one.