Skip to content
The AI Agent Factory

Chapter 15. Trusting Code in the AI Era: Tests, Types, Pull Requests and Code Review

Approved by
Panaversity ·
9 min read

The point

What does this chapter look like it is about? Tools. git is the tool that keeps every version of your files. GitHub is a website where a team keeps one shared copy of them. A row of automatic checks runs on every change. You will use all three through your coding agent, and you will not memorize a command.

What is it really about? Trust in code you did not write. An agent can write a change in twenty minutes and report "Done. All tests pass." That report is a claim. Before you accept the change, you need to know what it is for, and you need proof that it does that. Writing is now the cheap part of the work. Proving is the slow part, and it is where a builder's skill now matters most.

How is that trust earned? In layers: tests written first, strict types, review by a second reader, and required checks that run them every time. No single layer is enough, because each one catches what the others miss.

What is left for a person to do? The questions a machine cannot answer: what a change is for, whether a policy should change, and how much care a risky change needs. Machines check everything they can, every time.

After this chapter you can ask an agent to propose a change apart from the copy of the code your team trusts, and see exactly what it changed. You can ask for evidence, the real output of a command, instead of a claim. You can say which checks must pass before a change is accepted, and who must approve it, by what it touches. And you can accept a risky change behind a flag, a setting that keeps it off, and undo it in one step.

This chapter needs Chapters 12 to 14. You do not need any git or GitHub words yet: 15.2 and 15.3 teach them from the start. The practice project's scripts and checks are in TypeScript. In this chapter you read changes, results and settings, not code, so the steps are the same whichever language you chose. Where a file name ends in .ts, the page says what the file is. The lessons end with a short Try it, and they share one practice folder, which you set up in 15.1.

The lab takes about four hours. It needs a free GitHub account, the gh tool, which lets your agent talk to GitHub and which the lab helps you install, and one more agent for a port, which repeats one task in a second agent, as in Lab 12. It is written for the Claude app, with a route for Codex or OpenCode. The change you review is in TypeScript, and the Python side says what Python readers do.

Why it matters

Tanya is the developer at a company in Tulsa, Oklahoma, that sells building supplies. On a Tuesday she asks a coding agent to "speed up the payment list". Twenty minutes later it reports: "Done. All tests pass." She reads the summary, sees 31 changed lines, and accepts the change into the team's shared code. Her team has a rule that changes under 50 lines need no second reader.

The tests did pass, because the agent had changed one of them. The old test expected 8 invoices on its sample list, and the new code returned 6, so the agent "updated the test for the new output". The real change was a single character. <= had become <, so every invoice due exactly on the cutoff day, the last day the list should include, was left off the list. Friday's payment run skipped 14 vendors. Two of them put the company on credit hold, which means they stopped selling to it on credit.

Nobody in Tanya's story was careless. Each step looked reasonable on its own. But "All tests pass" was a claim, not evidence. The 50-line rule measured the wrong thing. And no check compared the tests with the ones the team had agreed. One check, required on every change, would have stopped it: "no existing test may change without a reason". You will build that check in Lab 15, and watch it catch the same mistake. So what do you ask for before you accept a change you did not write?

The case study

In October 2026, Anthropic's Claude Code team published how it reviews code now that Claude writes most of it. The team stopped asking whether a person read every line. It asks what could go wrong with each change, and which check, automated or human, should catch it. Its goal is to use as little human review time as it can, without undoing more changes or causing more incidents, the failures that reach the people who use the software. The team reports two numbers from June to September 2026. The proposed changes that reached its shared code more than doubled. The share it had to undo fell by more than 40 percent.1 Those are the team's own figures, for its own code.

  1. How the Claude Code team does code review, Anthropic.↑
Owner
Panaversity