CategoryEngineering
PublishedNOVEMBER 18, 2026

Check Against the Real Thing First: Testing What AI Agents Build

Check Against the Real Thing First: Testing What AI Agents Build

Testing what AI agents build: specify behaviour against the real system first, let agents build to it, and keep a check the agent cannot talk its way past.

Most CTOs have seen this demo. The agent builds the feature, the tests pass, everything is green. Then it meets the real payment provider, the real store or the real cloud account, and it breaks in the first five minutes.

The problem is rarely the code the agent wrote. It is what the agent tested against.

This post is a guide to fixing that. The idea is simple: describe how the real system behaves first, let agents build against that description, and keep one check the agent cannot argue with.

Why Agent-Built Code Passes Its Own Tests

The agent grades its own homework. When you ask an agent to build an integration and test it, it usually writes three things: the code, a mock of the external API, and tests. All three come from the same assumptions. If the agent believes the API returns a field that it does not, the code, the mock and the tests will all agree. Everything passes.

Mocks describe what you think, not what is true. A hand-written mock is a guess about someone else's system. Real APIs have quirks that never make it into documentation: an error format that differs by endpoint, a field that is missing instead of empty, a limit that only shows up under load. A mock invented by the agent has none of them.

Agents are persuasive. When a test fails, an agent will often find a reason it is fine, or adjust the test until it passes. That is not malice. It is an agent doing what it was asked: make the tests pass. If the agent can change the check, the check stops meaning anything.

Put together, you get green dashboards and broken products. The fix is to change what the tests are anchored to.

Step 1: Specify the Behaviour Against the Real System

Testing what agents build: record how the real system behaves, write the expected behaviour as tests, verify the tests pass against the real system, let agents build against them, run a check the agent cannot edit, then ship

Start with the real thing, not the code. Before an agent writes a line of the feature, write down how the external system actually behaves. What does a successful call return? What does a failure look like? What happens with a duplicate request, an expired token, an empty result?

Then prove it. Turn that description into tests and run them against the real system. Most payment providers, e-commerce platforms and cloud services offer a sandbox or test mode for exactly this. A test that passes against the real API is a fact. A test that only passes against a mock is an opinion.

Record what you learn. Save the real responses. These recordings become the fixtures your fast tests run against every day, without calling the real API each time. The difference from a hand-written mock is that every fixture came from the real system, not from anyone's memory of it.

Do this for the risky edges first. You do not need a full model of every API. Start with the calls that move money, change data or fail in ways users will notice.

Step 2: Let the Agents Build Against It

Now the agent has a target it did not invent. With verified tests in place, the task becomes clear: make these tests pass. The agent is no longer deciding what "correct" means. It is meeting a definition that came from the real system.

Keep tasks small. One integration, one behaviour, one set of tests. An agent with a narrow target and a real check does good work. An agent asked to "integrate the payment provider" will do something, and you will spend an hour finding out what.

Say how the result will be checked. Every task should name the tests that decide whether it is done. If you cannot say how you will check the result, the agent cannot either.

Step 3: Keep a Check the Agent Cannot Talk Its Way Past

Separate the builder from the judge. The agent that writes the code should not be able to change the tests or fixtures that judge it. Keep them in a place the agent does not edit, or flag any change to them for a person to approve.

Let the pipeline decide, not the agent. An agent saying "done" means nothing on its own. The check that matters runs in CI, on every change, outside the agent's control. If it fails, the work goes back.

Check the real output, not just the code. For anything with a screen, capture screenshots of the actual build with the change visible. For APIs, run the verified tests against a sandbox on a schedule, so you find out when the real system changes before your users do.

Use a second reviewer with fresh eyes. An AI reviewer that has not seen the conversation behind the code does not share the builder's assumptions. Ask it to report only problems it can prove.

A Public Example: AWS Emulator

The clearest public example of this approach is AWS Emulator, which Amazon Web Services released as open source in November 2026. It is a local emulator of AWS APIs, so developers and coding agents can test applications without calling AWS.

What makes it interesting is how it was built. According to AWS, it was written entirely by autonomous agents, working in three groups. One group writes tests from the public AWS API specifications and checks those tests against real AWS. A second group runs the verified tests against the emulator and reports where it differs. A third fixes the differences, and every change has to pass build checks and review by other agents.

That is exactly the pattern above. The behaviour is specified against the real system first. Agents build against it. The check is something no agent can argue with: the emulator either behaves like real AWS, or it does not.

It is honest about its gaps. AWS publishes a fidelity score for each service with every release. Operations that have not been implemented or verified return an error instead of a guess. And the project states plainly that it does not check permissions the way AWS does, so it should not be used for security testing.

That honesty is the second lesson. A stand-in for a real system is only useful if you know exactly where it stops being accurate.

Know What Your Stand-In Does Not Cover

Mock written by the agent versus a spec checked against the real system: guessed responses versus recorded real responses, agent can edit it versus agent cannot edit it, passes by agreeing with itself versus passes by matching reality, gaps unknown versus gaps listed, breaks on first real call versus breaks in CI first

No emulator, mock or recording is the real system. Each one has things it does not model: rate limits, outages, permissions, timing, data that only exists in production.

Write the gaps down. For every external system, keep a short list of what your tests do not cover. That list tells you where to spend your manual testing and your monitoring.

Still test against the real thing before launch. Local tests make development fast. A final run against the real sandbox, and careful monitoring after launch, is what makes it safe.

We see this in our own products. Totebot, our AI shopping agent platform, works with Shopify stores, AI models from OpenAI, Anthropic and Google, and messaging channels like WhatsApp and Telegram. Each of those is a real system with its own behaviour, and none of them cares what a mock assumed. You can read about how it fits together in the Totebot case study.

It is also why so many AI projects stall between the demo and production. As we wrote in why AI projects fail, the hard part is rarely the model. It is connecting it to the real work.

Real First, Then Fast

AI agents make writing code cheap. That makes checking it the part that decides whether you ship a product or a demo.

Anchor your tests to the real system. Let agents build against something they did not invent. Keep one check outside their reach.

Do that, and the demo that worked on your laptop is the same product that works on your users' real accounts.

Share this post:
Launch Your AI Project

We collaborate with future and technology focused brands and companies.