Sub topic 3
Closing the Loop on Agent-Assisted Changes
Closing the loop with tests, type checks, and linters
Assume you can read code, use Git, run tests, and use an AI coding agent. Verification means checking the changed behavior from several angles:
set -e
pytest
mypy src/
ruff check .Tests check runtime behavior. A type checker finds inconsistent interfaces before execution. A linter catches style problems and some likely defects. Run the narrowest relevant checks first, then the full project checks before merging.
Reviewing the diff like a pull request
Read the diff as if another developer submitted it. Check that:
- Every changed file belongs to the task.
- The implementation matches the requested design.
- Public APIs and error behavior remain compatible.
- Tests cover the changed paths.
- Generated files, debug output, and unrelated formatting changes are absent.
Use git diff and inspect the surrounding code when a change seems surprising. Ask the agent to explain a suspicious line, but verify its explanation against the repository.
Failure modes and guardrails
Agents may invent APIs that are plausible but absent from the installed version. They may also alter behavior while preserving obvious tests, or edit every matching file when only one module was in scope. Prevent these failures by naming allowed files, requiring evidence from existing code, and using characterization tests.
| Failure | Guardrail |
|---|---|
| Invented API | Search documentation and existing usages |
| Behavior drift | Add tests for current behavior |
| Over-broad edits | Set file boundaries and review `git diff --stat` |
Deterministic tools for repetitive changes
Use an agent for judgment and a codemod for mechanical edits. Structural search matches syntax rather than text, reducing accidental changes inside comments or unrelated identifiers. Preview a rewrite before applying it, then run tests and review the resulting diff.
Planning a large migration
Split a migration into tracked slices: inventory affected code, define compatibility constraints, update one subsystem, verify it, and record remaining work. Keep a checklist of callers, configuration, tests, documentation, and removal steps. Each slice should have a clear owner and completion check.
Rolling out and cleaning up
Prefer a gradual rollout when the migration affects users or data. Support the old and new paths temporarily, enable the new path for a small group, compare errors and performance, then expand. Set a removal date for compatibility code. Delete the old path only after usage has reached zero and the final checks pass.
Exercise
What should you inspect after all automated checks pass?
Show answer
Review the diff for unintended files, behavior changes, invented APIs, missing tests, and temporary code that should not be merged.