/appmap-analyze finds the error paths your unit tests never run

/appmap-analyze finds the error paths your unit tests never run

Your coding agent just opened a pull request. The tests pass and the check is green. So far, so good. Now look at what those tests actually did. Not one of them sent your code a busy reply. Each one swapped the network for a stand-in that answers on the first try. Before you approve it, run AppMap’s /appmap-analyze skill on the branch and read the first finding in the report.

AppMap records your code while your tests run. Each recording holds the calls in your code and the SQL queries and HTTP requests behind them. AppMap is built for teams that ship AI-written code. In this video, AppMap CTO Kevin Gilpin walks through the skill.

Where serious failures come from

A team at the University of Toronto took 198 failures that users reported in Cassandra, HBase, HDFS, Hadoop MapReduce and Redis. They traced each one back to its cause. The results are worth reading closely.

  • In 92% of the catastrophic failures, the code mishandled a non-fatal error.
  • 35% of the catastrophic failures came from trivial mistakes in error-handling code.
  • 77% of all the failures needed more than one input event before they showed up.

(Yuan et al., OSDI 2014)

The title of the paper is “Simple Testing Can Prevent Most Critical Failures.” The testing the authors mean is aimed at error-handling code, with the right events in the right order. Those projects shipped without it.

Green tests and high coverage won’t find them

A study of crashes in Eclipse compared methods that had unit tests with methods that didn’t. 67 of 589 unit-tested methods crashed. 1,099 of 8,934 untested methods crashed. That’s about 11% against 12%, and the authors found no statistical evidence that the unit-tested code crashed less. (Chioteli, Batas and Spinellis, MSR 2020)

Raising coverage doesn’t fix this. Another study built 31,000 test suites for five Java systems, the largest with 724,000 lines of code, and counted how many seeded bugs each suite caught. The authors concluded that coverage “is not a good indicator of test suite effectiveness.” (Inozemtseva and Holmes, ICSE 2014)

Reading the code won’t find them either

Static analysis reads your code without running it. So does an AI reviewer that reads the diff. Both are useful, and both share a blind spot. Neither one can see what the other service sends back, which branch runs, or how many times a loop goes around.

One study ran three widely used static bug detectors on 594 real bugs from 15 Java projects. The detectors “miss the large majority of the studied bugs.” (Habib and Pradel, ASE 2018) Another ran six C and C++ analyzers on 27 projects with 192 known vulnerabilities. The tools missed between 47% and 80% of them. (Lipp, Banescu and Pretschner, ISSTA 2022)

The polling loop in Kevin’s video is a good example. It looks fine when you read it. Run it against a busy device and it reads 4,309 times in 5 seconds, with no wait between reads. It gets nothing back until the timeout.

How a recording tells you where to aim

Start with what actually ran. A recording of your test suite lists every function your tests called, in order. Reading the diff and the test files, you can only guess which tests reach which code. Some calls come in through a framework or a callback that no test file mentions. The recording shows those too, because it watched the code run.

Find the changed code that nothing ran. Compare the recording with the functions your branch changed. Any changed function that never shows up in the recording is about to ship with no test behind it. On an AI-written branch, that’s often the error handling. The agent writes the retry and the timeout handler right next to the main path, and its tests cover the main path. That gap in the recording is where your next test goes.

Test the hand-off. This next test is not another unit test. A unit test checks one function and fakes everything around it. That’s exactly why it misses these bugs. Your retry code only runs when the other service is busy, and your timeout handler only runs when that service is slow. In a unit test the service is a stub, and the stub answers right away. The retry never fires.

So write a focused integration test instead. The request comes in through your real handler, reads your real database and goes out through your real client code. The only fake is the service at the far end, and the test tells it to be busy or slow. Now the error actually reaches your code. Most of the failures in the Toronto study needed a sequence of events like this one, and a test of one function never sets it up.

Keep it to one flow. One flow gives you a short recording that you can read in a few minutes, and a finding that points at one place in the code.

Read the whole recording. A test only checks what someone thought to assert. The recording shows everything the code did. In the video, one recording counts those 4,309 reads. No assertion asked how many times the loop read. In another recording, a request timed out. It got a 504 on main and a 200 on the branch, so the branch told its caller the request had worked. The diff never mentions that change. The recording shows it as two numbers side by side.

What /appmap-analyze does

Type /appmap-analyze in Claude Code and name a branch, a component or a whole project. You don’t need to set anything up first. The skill gets your test suite running without AppMap and fixes the environment if it has to. Then it installs the AppMap recorder and writes its configuration. It uses the appmap-setup, appmap-config and appmap-record skills for this, so install the whole set.

  1. It records your existing tests and lists the changed code they never call.
  2. It writes focused integration tests for that code. These are not more unit tests. Each one runs a whole flow through your real code.
  3. It runs and records every test, old and new.
  4. It queries the recordings for bugs. It looks for loops that repeat with no I/O, wrong values such as a dropped timeout, hidden I/O, swallowed exceptions and work on the wrong thread.
  5. It reruns every finding without the recorder to confirm it. It checks timings the same way.
  6. On a branch, it compares recordings of the same tests on the base and on the head.
  7. It writes a report with the most important findings first. Each finding names its evidence and the command that reproduces it. The skill commits the report and the new tests on a branch.

Your next pull request

Your agent opens its next pull request. Before you approve it, you run /appmap-analyze on the branch. The report and the new tests land on a branch of their own. The first finding says the polling loop read a busy device 4,309 times in 5 seconds, with no wait between reads. The recording is linked right under it. You paste that part into your review comment and send the pull request back.

Get the skill

The appmap-analyze skill is in beta. Get the AppMap skills from github.com/getappmap/skills. The repository documents how to use them with Claude Code. Run /appmap-analyze on your next branch before you approve it.


AppMap logo Get AppMap