# Testing and verification for agent-written code

URL: https://developertoolkit.ai/en/workflows/test/
Description: Verify agent-written code without reading every line: measure oracle strength, lock tests from edits, and layer fitness, slop, and dependency gates.

Verifying agent-written code means building deterministic, tamper-resistant checks strong enough that a green CI run proves correctness without a human reading every diff line. Developers wire these checks into local loops and pipelines, while tech leads govern Station 5 (Verification) across the Software Factory.

An agent opens a 600-line pull request carrying 40 green tests. Reading everything burns an afternoon; merging blindly trusts assertions authored by the same agent trying to pass them. The six guides below prove checks catch bugs, lock them against silent edits, and catch erosion, slop, and bad packages automatically.

## Order your verification gates

Work top to bottom: a strong suite the authoring agent can edit proves nothing.

| Engineering question | Guide | Role in Station 5 |
| --- | --- | --- |
| Do tests actually fail when code breaks? | [Oracle strength](/en/workflows/test/oracle-strength/) | Mutation score, negative controls, provenance, flake discipline |
| Can the agent edit tests or CI to pass? | [Protecting the oracle](/en/workflows/test/protect-the-oracle/) | Session locks, `CODEOWNERS`, out-of-diff CI, private holdouts |
| How do we grade copy, docs, or visuals? | [Model-graded checks](/en/workflows/test/model-graded-checks/) | Calibrated cross-vendor rubric judges with spot-checks |
| How do we stop architectural erosion? | [Architecture fitness functions](/en/workflows/test/fitness-functions/) | Layering, cycles, complexity, clones, and API ratchets |
| How do we catch plausible-but-wrong code? | [Slop detection](/en/workflows/test/slop-detection/) | Lint/AST detectors + fresh reviewers for swallowed errors and dead layers |
| How do we stop hallucinated packages? | [Dependency verification](/en/workflows/test/dependency-verification/) | Lockfile-diff CI gates, cooldowns, proxies, and approval hooks |

Pair these gates with [test-driven development](/en/method/principles/test-driven-development/), [acceptance criteria](/en/workflows/plan/acceptance-criteria/), and the [lifecycle test stage](/en/method/lifecycle/test/).

## Connecting tools to the verification bar

Keep decisive gates inside repo scripts and CI so every tool clears one standard:

- **Claude Code:** Enforce test-vs-code separation via `permissions.deny`, `PreToolUse`, and `Stop` hooks ([Claude Code testing](/en/claude-code/test/testing/), [Claude Code docs](https://code.claude.com/docs)).
- **OpenAI Codex:** Run test and mutation commands under `sandbox_mode = "workspace-write"` with strict `approval_policy` and CI diff gates ([Codex testing](/en/codex/test/testing/), [Codex docs](https://developers.openai.com/codex)).
- **Cursor:** Pair Plan Mode audits, local hooks, and scheduled Cloud Agent flake sweeps with required CI and `CODEOWNERS` ([Cursor testing](/en/cursor-ide/test/testing-tdd/), [Cursor docs](https://cursor.com/docs)).

## Four signals replacing line-by-line test review

| Signal | Ready to trust when | Owner |
| --- | --- | --- |
| **Changed-code mutation score** | Clears break threshold; every survivor triaged | Developer |
| **Criterion-to-test map** | Every criterion links to a fail-then-pass check | Developer / reviewer |
| **Oracle protection** | Test and CI edits require code-owner review | Tech lead |
| **Zero-retry flake rate** | Flaky tests quarantined instead of retried | Tech lead |

These signals feed the [evidence bundle](/en/workflows/ship/evidence-bundle/) (see [evidence, not diffs](/en/ladder/evidence-not-diffs/)). Audit Station 5 automatically via `npx @wondelai/harness-audit` ([Harness Audit](/en/harness-audit/)).

## What breaks when agents write tests?

- **Green suites leak bugs:** Tests assert on mocks. *Recovery:* Run diff mutation testing and assert observable behavior.
- **Assertions weaken during fixes:** Exact checks relax into loose matchers. *Recovery:* Revert and lock oracle paths via `CODEOWNERS` and CI.
- **Line coverage replaces verification:** Assertionless tests execute branches silently. *Recovery:* Gate on criterion mapping and mutation scores.
- **Generated suites grow slow and flaky:** Red builds get retried blindly. *Recovery:* Prune redundant tests and quarantine flippers on zero-retry sweeps.

## Official docs and next steps

- Official references: [Claude Code](https://code.claude.com/docs), [OpenAI Codex](https://developers.openai.com/codex), and [Cursor](https://cursor.com/docs).
- [Oracle strength](/en/workflows/test/oracle-strength/) — Measure whether tests actually fail when code is wrong.
- [Protecting the oracle](/en/workflows/test/protect-the-oracle/) — Lock tests, snapshots, configs, and CI outside agent reach.
- [The evidence bundle](/en/workflows/ship/evidence-bundle/) — Package verification proof into every pull request.
- [Agent PR review](/en/workflows/ship/agent-pr-review/) — Triage agent pull requests on verified evidence.
