Dev.to AI πŸ€– Ai πŸ‘ 2 πŸ“– 4 min read

What passing tests miss in AI written code

A change can pass every unit test and still fail in production, because the role it runs as lacks one IAM permission. When an AI coding agent reports that all tests pass, it tells you the code does what the tests ask. It

What passing tests miss in AI written code

A change can pass every unit test and still fail in production, because the role it runs as lacks one IAM permission. When an AI coding agent reports that all tests pass, it tells you the code does what the tests ask. It does not tell you the code can run where you deploy it.

Take a change that adds a write to a DynamoDB table. The unit tests mock the client, check the call and go green. The deployed service runs as an IAM role that was never allowed that write. Nobody tried the new path outside the tests, so the first real request fails in production, and the evening goes to the fix.

Tests the agent wrote to mirror its own code, and mocks that drift from the real service, fail the same way. This article is about the cause the diff hides.

Unit tests do not see the IAM role

A unit test can prove that your code calls DynamoDB the right way. It cannot prove that the role in production may make that call. AWS is plain about the default. "By default, all requests are implicitly denied with the exception of the AWS account root user, which has full access."

So the change the code needs may not be in the diff at all. A new table operation can need a new statement in an IAM policy. A new dependency can need a network rule. The test suite covers neither, and a reviewer who reads only the diff sees neither.

Why the agent cannot see it either

An agent works in the repository it is given. The IAM policy often lives somewhere else, in a Terraform repository, a CloudFormation stack, or a change someone once made in the console. What the agent cannot read, it cannot reason about, and its tests cannot exercise.

Its report lists what it ran. The unit tests, the linter, the build. Nothing in it lists what it could not reach, because from inside the repository nothing looks missing. That is why a report that all tests passed is honest, and still not an answer.

The implementation can be reasonable in isolation and still fail at runtime. Reviewing an agent's change means reviewing what it assumes about the world outside the diff.

What to verify before you merge an agent's pull request

Ask what the change assumes about its environment, then check each assumption where it has to hold.

  • Permissions. Run the new operation in a representative environment, as the role the service will use. AWS's policy simulator, aws iam simulate-principal-policy, answers whether that role may call the action before you deploy.
  • Infrastructure. Find the policy, the table or the queue the code expects, and confirm it exists outside your machine.
  • Configuration. A new environment variable or secret has to be set in every environment the service runs in, not only in the test setup.
  • Network. Check that a new dependency can reach what it calls from where it is deployed.
  • Data. Code that reads a new attribute meets items written before the change, which do not have it.

Ask the agent before it writes the code, too. A list of what the change needs from its environment, the permissions, the tables, the variables, is something you can check. A summary that says all tests pass is not.

This takes more effort than a test run. It takes far less than finding a missing permission in production.

Name the infrastructure in the plan

Tillerly runs AI coding agents on your machine, sandboxed, from ticket to pull request. With a plan, the planner designs the change with you before any code is written. It reads your repositories, never changes them, and asks what the code and the documentation cannot answer.

A plan spans as many repositories as it needs, and each of its tickets is in one repository. So the IAM statement can be its own ticket, in the repository that holds your infrastructure, beside the ticket that adds the write. How a plan is designed and published.

A green build is not QA

Tillerly's resolver, the agent that implements the ticket, runs your repository's checks and pushes the branch. It never opens the pull request. Your team does, and Tillerly follows its build on Buildkite, GitHub Actions or GitLab's pipelines.

A green build does not move the ticket on. QA waits for a person, who tests the change and chooses QA Done. The checks above belong in that Step. Your team then merges on the code host.

A ticket in the Tillerly Builder, its resolver's log ending in 48 tests passed and Pushed the branch, CI done, and QA waiting for a person with a QA done button

The Builder and its seven Steps says what each Step does. Our article on managing several agents lists the other moments that need a person.

What Tillerly does not check

  • QA Done is a decision, not a test. Tillerly does not know your IAM policies, your network rules or your production accounts.
  • A plan names what you tell it. The planner reads the repositories you give it. A policy kept only in the console is not one of them.
  • A small change may not need any of this. A checklist in your pull request template does the same job.

Its flow puts a person between the green build and the merge, and that person still does the checks above. Hand the implementation to an agent. Keep the judgment that a change is ready for production with your team.

Originally published on the Tillerly blog. Tillerly is in beta, request access at tillerly.dev.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.