Make AI-written code safe to merge
Set up the checks that catch a coding agent's mistakes before a person has to: lint, types, tests with a coverage floor, and a commit hook.
You build: A repo where a bad commit is refused on your machine, by tools rather than by review.
- Python 3.11 or newer and uv
- Any small Python project (the harness from lab 30 works)
-
01Add a linter and a type checker and fix what they find
uv run ruff check . && uv run pyrightYou pass when: Both exit 0.
-
02Write tests until coverage reaches 80 percent, and make less than that a failure
uv run pytest --cov --cov-fail-under=80You pass when: Tests pass and the coverage line shows 80 percent or more.
-
03Run all three before every commit
lefthook install && lefthook run pre-commitYou pass when: The hook runs lint, types and tests and passes.
-
04Try to commit a file with an unused import
Checks a machine runs are the only review that scales with the amount of code an agent writes.
git commit -am "should fail"; echo "exit $?"You pass when: The commit is refused and the exit code is not 0. Add the three commands to AGENTS.md so the agent runs them itself.
The check runs on the computer, not on your word: a step passes when its command exits with 0 there.
Computers are not set up on this site yet. Run each command on your own machine and compare with "You pass when".
Commands run in labs/33-hardening and may take up to 60 seconds each. Every command starts a new shell: put keys and settings in a .env file there, it is loaded each time.