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.
Hardcoding the answer the test expects
card 3 of 6
Three tells of a hardcoded answer
builds on: Agents optimise the signal they can see
1. **Fixture literals in production code:** a string, number or date from the test file appears in an `if`, `switch` or lookup table.
2. **Canned return:** a branch returns exactly the expected value instead of computing it.
3. **Test detection:** the code checks whether it is under test, e.g. `"pytest" in sys.modules`, `NODE_ENV === "test"`, a `CI` env var, or Go's `testing.Testing()`.
To settle it, run one input the tests never use, with an answer you know.
Terms on this card
- fixture
- A fixed input (and often its expected output) written into a test so the test is repeatable.
- production code
- The code that ships and runs for real users, as opposed to test code.
- CI
- Continuous integration: a server that automatically builds and tests every push or pull request.
- env var
- Environment variable: a named value the operating system passes to a running program, e.g. `CI=true`.
- NODE_ENV
- A Node.js environment variable conventionally set to `production`, `development` or `test`. Jest sets it to `test` if it is unset.
Lesson goal: Recognise code that branches on the exact fixture input, returns a canned expected value or detects that it is running under test. Explain why it passes the suite yet fails on the first real input. ·
the whole lesson