Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Pin behavior before a refactor
card 6 of 6
Record first, then refactor
builds on: Refactors that quietly change behavior, What makes a test able to fail
Before a refactor, write characterization tests: record what the old code actually does (edge inputs, error types, order) and confirm the tests are green on the old code. Forbid the agent to edit them, and treat any edit to a pinned test in the diff as a tell. Tests written after the refactor can only agree with it.
Terms on this card
- refactor
- Restructuring code to make it cleaner or simpler while keeping its observable behaviour exactly the same for every caller.
- the diff
- The change under review in unified diff format: '-' lines removed, '+' lines added, unprefixed lines are unchanged context.
- edge inputs
- Inputs at the limits of what code handles, including unusual or invalid ones: empty values, null, duplicates, malformed data, maximum sizes.
- tell
- An observable sign in a diff, transcript or summary that suggests a shortcut or an error.
- the agent
- The AI coding system doing the work: a chat assistant, IDE agent or terminal agent.
Lesson goal: Write characterization tests that capture what existing code currently does before letting an agent refactor it. Use them to catch unintended behaviour changes that the agent's own new tests would miss. ·
the whole lesson