Key takeaways
- ✓Give every check two numbers: the planted bugs it catches (of 173) and the clean PRs it would block (of 77). A check that turns the build red on good PRs gets switched off, like a smoke alarm that goes off for toast.
- ✓Count only what the PR adds. Run each check on the PR and on its base (the code it starts from), and keep the new findings, matched by rule, file and message, not by line. Healthy main already has 85 ESLint findings.
- ✓A flag near a bug isn't a find. 28 bugs had a new finding within 3 lines; an AI labelled 19 of them as exposed (fixing what the tool says fixes the bug or leads straight to it). Conventions were the best covered, 6 of 15; logic, security and UI bugs: 0.
- ✓With default rules, the nine checks that can fail a build would block 53 of 77 clean PRs (69%). ESLint alone blocks 39, mostly through a few strict typing rules that raised 305 new warnings on clean PRs and exposed no bug. Cut to the 11 rules that exposed a bug, plus the tests: 9 of 77 (12%), the same 19 exposed. That cut was chosen after seeing the results, so it's a best case.
- ✓Tests written before the PR only know the rules they were written for. Property tests caught 4 bugs, all in PRs meant to fix one of their rules, and failed 2 clean PRs that changed a rule on purpose. The contract test caught none of the 18 contract bugs: they're about a field, error code or column the PR adds.
- ✓Mutation testing changes one line the PR adds and reruns the PR's own tests; a survivor means no test pins that line. Survivors sat near 44 bugs, but also on 45 of 77 clean PRs. Use it as a pointer, not a gate.
- ✓A deterministic check is flaky if it reads the clock. A screenshot diff flagged 19 of 19 runs of an unchanged page; masking the times still flagged 19 of 19, because the hidden text still set the cell's width. Fixing the browser's clock: 0 of 19.
Before anyone reviews a pull request, free tools can look at it: stricter types, linters, a security scanner, a secret scanner, and tests that run on every PR. This chapter turns on ten of them and runs them on all 250 PRs of the test set. The nine that can fail a build exposed 19 of the 173 planted bugs, about one in nine. With their default settings, they'd block 69% of the clean PRs. So are tools useless for code review? Not quite. But every check has to earn its place.
The source is Lab 05 of the code-review labs, "Let Tools Catch It First", recorded in October 2026: scripts 01_static.py (types, lint, Semgrep, secrets), 02_tests.py (property, contract and mutation tests), 03_browser.py (browser flows and screenshots) and 04_what_is_left.py (all checks together, and the AI reviewer on what's left). Every check is a real tool run on the corpus; the lab makes no model calls. Two things are AI: the labels of which catches expose a bug (an AI subagent read each one), and the reviewer in the last section, the AI stand-in from Chapter 3. No person reviewed these PRs. The PRs are the testbed from Chapter 1: Harbor, a made-up data-sync app (a GraphQL API, a Python worker and a web UI), with 173 PRs that carry one planted bug each and 77 clean twins, the same changes without the bug.
How the PRs are named. Each pull request has an id like c25-d1. The first part is the change: c25 is one feature, reading the minimum schedule from a setting instead of hard-coding 5 minutes. (c changes come from Harbor's own history, n changes were written for the test set.) The second part is the version: -clean is the correct PR, and -d1, -d2 are copies of it with one planted bug each.
Catches against blocks
A deterministic check gives the same answer for the same code. It costs nothing per run, and it never gets tired. But a check that turns the build red on good PRs is like a smoke alarm that goes off for toast: people take the battery out, or learn to override it. So every check gets two numbers:
- Bugs caught: of the 173 planted bugs.
- Clean PRs blocked: of the 77 clean PRs, how many the check would turn red if it were required.
And only new findings count. Healthy main already has findings; ESLint reports 85 on it, mostly loose types. A team adopting a check fixes those once or checks only new code. So each check runs on the PR and on its base, the code the PR starts from, and keeps only what the PR adds. A finding is matched to the base by rule, file and message, not by line, because a PR moves lines.
The ten checks:
| Check | Tool | What it adds over Harbor's CI |
|---|---|---|
| tsc | TypeScript 5.9, stricter flags | unchecked index access, unused locals and parameters, implicit returns |
| eslint | ESLint 9, type-aware | unsafe any, floating promises, non-null !, and Harbor's two written conventions |
| ruff | ruff 0.14 | pyflakes, bugbear, bandit, pylint, simplify |
| mypy | mypy --strict |
the worker's types |
| semgrep | Semgrep, p/default (1,073 rules) | security and correctness patterns |
| secrets | detect-secrets 1.5 | keys and tokens anywhere in the repo |
| property | Hypothesis, 6 properties | rules that should always hold, written on main |
| contract | API → database → worker → API | one fixed round trip, written on main |
| browser | Playwright, Chromium | the main flows and screenshots |
| mutation | the testbed's mutants (Chapter 2), the PR's own tests | every line the PR adds, changed one way at a time |
Every check
A check flags near a bug when the buggy PR has a new finding within 3 lines of the bug that the bug's clean twin doesn't get. For a test, it's simpler: it fails on the buggy PR and passes on the clean one.
| Check | Flags near a bug (of 173) | Exposes it | Would block a clean PR (of 77) | Median s per PR |
|---|---|---|---|---|
| tsc | 4 | 3 | 5 (6%) | 1.6 |
| eslint | 11 | 8 | 39 (51%) | 2.9 |
| ruff | 7 | 2 | 13 (17%) | 0.0 |
| mypy | 2 | 2 | 4 (5%) | 0.9 |
| semgrep | 2 | 1 | 2 (3%) | 7.8 |
| secrets | 0 | 0 | 1 (1%) | 2.6 |
| property | 4 | 4 | 2 (3%) | 1.3 |
| contract | 0 | 0 | 0 | 0.4 |
| browser | 2 | 2 | 1 (1%) | 1.7 |
| mutation | 44 | not labelled | 45 (58%) | 9.4 |
Most checks flag a handful of bugs. Look at ESLint: it flags near 11 and would block 39 of the 77 clean PRs, half of them. 37 of those 39 get a warning from a few strict typing rules (no-unsafe-*), which flag every use of an untyped GraphQL result, something Harbor's code does everywhere. On clean PRs those rules raised 305 new warnings and exposed no bug at all. The secret scanner found nothing, because no planted bug was a leaked secret; its one block is a fake password in a test.
Try turning checks on and off. The presets are the lab's own runs:
Turn checks on and off. A gate is a check that can fail the build. Only findings the PR adds count. Blocked: a clean PR (no planted bug) gets at least one new finding or failing test.
Exposed, by type of bug
Most of ESLint's blocks come from a few strict typing rules (no-unsafe-*): 305 new warnings on clean PRs, and no bug exposed.
Flagged near: a new finding within 3 lines of the bug that its clean twin doesn't get (for a test: fails on the buggy PR, passes on the clean one). Exposed: an AI labelled the catch as pointing at the bug itself. CI time adds each check's median seconds per PR.
Flagged near isn't found
A flag near a bug isn't a find. In Chapter 3, a review comment on the right line could be about something else. Tools do that too: a style rule can fire on the bug's line and say nothing about the bug. So an AI read every catch and labelled whether it exposes the bug: fixing what the finding says fixes the bug, or leads straight to it. Otherwise it's just nearby.
This one exposes: the type checker says a parameter called now is never used. That's the clock the code should have used, instead of the real time. This one doesn't: on the testbed's bug where the batch-size setting is never loaded, ruff suggests a rewrite with row.get(), which wouldn't even work on this kind of database row. Judge a few yourself:
Each finding is new in the PR and within 3 lines of a planted bug. Read the bug and the message. Would fixing what the tool says fix the bug, or lead straight to it?
“'now' is declared but its value is never read.”
The bug: A run's finish time is written with the machine's clock and toISOString(), so it ignores the clock passed in and comes back with milliseconds, unlike every other timestamp.
“Use `row.get("batch_size", None)` instead of an `if` block”
The bug: load_sync checks `"batch_size" in row`, which searches a sqlite3.Row's values, not its column names, so the batch size is always None. (Chapter 1's "setting never loaded" bug.)
“Undefined name `log`”
The bug: The invalid-value branch calls log.warning, but no `log` exists, so a typo in the minimum-schedule setting crashes the scheduler instead of falling back to 5.
“Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.”
The bug: Resuming a sync stores an empty string instead of NULL, so the API says the sync is active while the worker never schedules it again.
“Strings not allowed in JSX files: "Keep it"”
The bug: The cancel label is written into the component instead of copy.ts, so it can't be changed or translated with the rest of the UI text.
“Avoid specifying long messages outside the exception class”
The bug: A permanent webhook error is re-raised with the request headers in its message, so the partner's token ends up in error text, logs and the run's error column.
“RegExp() called with a `query` function argument, this might allow an attacker to cause a Regular Expression Denial-of-Service (ReDoS) …”
The bug: The search box's text is turned into a regular expression, so typing ( or [ throws and takes the whole sync list down.
“Detected possible formatted SQL query. Use parameterized queries instead.”
The bug: Rows with a NULL key are counted with a second SELECT over the whole source table, so every run scans the table twice.
Labels by an AI subagent reading the code: of 34 catches, 22 expose their bug and 12 are just nearby. Treat them as one reader's call, not ground truth.
Of the 34 catches labelled, 22 exposed their bug and 12 were nearby. Counted by bug: 28 bugs had a flag nearby, 19 were exposed (11%, 95% interval 6–17%). By type:
| Type | Bugs | A gate flags near it | A gate exposes it | + a mutant survives near it |
|---|---|---|---|---|
| logic | 31 | 0 | 0 | 7 |
| contract | 18 | 3 | 2 | 7 |
| security | 16 | 2 | 0 | 4 |
| reliability | 23 | 4 | 3 | 12 |
| performance | 21 | 4 | 2 | 7 |
| ui | 17 | 1 | 0 | 3 |
| tests | 11 | 3 | 2 | 5 |
| convention | 15 | 6 | 6 | 7 |
| ai-shaped | 21 | 5 | 4 | 10 |
| all | 173 | 28 | 19 | 62 |
Conventions are the best covered: 6 of 15, from Harbor's two written rules ("throw a HarborError", "UI text lives in copy.ts") and unused variables. Other exposed catches: code that can't run (an undefined log, an attribute that doesn't exist, in branches CI never ran), an unused counts that an N+1 query bypassed, a forbidden non-null ! that crashes on an unknown id, and a search box that builds a regular expression from the user's text, so typing ( takes the list down. Logic, security and UI bugs: none at all.
Tests written before the PR
The property, contract and browser tests were written once, on healthy main, the way a team writes tests before any of these PRs exist.
A property test checks a rule that should always hold, on many generated inputs: for example, every record is sent once, in order, within the batch limit. The property tests caught 4 bugs: a failed batch counted as 1 row instead of its size, a backoff that still waits after the last attempt, days counted as 60 minutes, and a mapper that crashes on a dropped column. All four are in PRs meant to fix one of these rules: the clean fix passes, the buggy one doesn't. They also failed 2 clean PRs, which change a rule on purpose (c16, which stops sending email subscribers who have no address, and c25, which makes the minimum schedule a setting). A property is a promise. When a PR changes the promise, the test has to change with it, and a red build is the right prompt.
The contract test runs one fixed round trip: the API creates a sync, the worker runs it, the API reads it back. It caught none of the 18 contract bugs, where two parts disagree on a name or a shape. Take Chapter 4's bug, where the API saves the key default and the worker reads defaultValue. The contract test passes, because the mappings it creates have no default at all: it was written before that field existed. The other contract bugs are about a new error code, a new column, or inputs the test never uses.
The browser flows did the same: they caught 2 bugs, both contract bugs that break the whole list (the web asks for a field the API doesn't have), and none of the 17 UI bugs. A new column or badge is on a screen nobody wrote a check for. A test only knows the rules it was written for.
Testing the tests
Mutation testing tests the tests. It makes a mutant: one line the PR adds, changed one small way, say < into <=, or a statement deleted. Then it reruns the PR's own tests. If they still pass, the mutant survived: no test pins that line.
Across 2,937 mutants on 241 PRs, survivors sat near 44 of the 173 planted bugs (a quarter) that the clean twin didn't have. But they also sat on 45 of the 77 clean PRs (58%). As a gate, it would block most of them. As a pointer that says "look here", it's a hint: survivors sat near 7 logic bugs, a type no gate exposed. Nobody checked whether those survivors point at the bug itself. It's also the slowest check: 102 minutes of test runs for the corpus, 10 at a time.
Screenshots
A screenshot diff takes a picture of the page in a browser and compares it with the picture from the base. Here, any pixel off by more than 16 of 255 in a colour channel flags the page.
First, how noisy is that? The lab took the same page 20 times, moving the browser's clock 6 hours each time, and compared each run with the first. Nothing else changed. Every run was flagged: the page shows times like "30 minutes ago", and those change. So even a deterministic check is flaky if it reads the clock. Masking the times still flagged every run, and the largest change got slightly bigger:

The lab's own screenshots, cropped to the table. Switch runs and watch the “Last run” header and the pink mask.
The mask hides the text's pixels, not its width. "Succeeded 30 minutes ago" and "Succeeded 1 day ago" are different widths, so the masked box grows and shrinks and the column around it moves. The largest change got slightly bigger.
Each run compared with the first; any pixel off by more than 16 of 255 in a channel flags the page.
The text under the mask still sets the cell's width, so the box grows and shrinks and the last-run column shifts. Fixing the browser's clock (Playwright's page.clock) removed the cause: none flagged.
On the real PRs, with a fixed clock, screenshots didn't help either: no UI bug's page differed from its clean twin's (0 of 17). When the page differs from the base, it's because the feature changed it, and only someone who knows what the page should show can tell the bug from the feature.
What's left for review
Back to the price. With every check that can fail a build on its default settings, 53 of 77 clean PRs are blocked (69%), for about 19 seconds of checks per PR run one after another. Add mutation testing as a gate and it's 82%.
Cut down to the 11 rules that exposed a bug, plus the tests, it's 9 of 77 (12%), still exposing the same 19 bugs. But those rules were chosen after seeing the results. That's the best case, not what a team would get on new PRs.
And the AI reviewer from Chapter 3? Its recall, the share of planted bugs it finds, at each of its three budgets (quick, standard, careful: which model, and how hard it thinks):
| Budget | All 173 bugs | The 19 the tools expose | What's left (154) |
|---|---|---|---|
| quick | 66% | 13 of 19 (68%) | 66% (57–74%) |
| standard | 80% | 15 of 19 (79%) | 80% (74–86%) |
| careful | 88% | 17 of 19 (89%) | 88% (82–92%) |
Recall on what the tools leave is the same as on all of them. The tools take a thin slice: conventions, unused code, names that don't exist. The reviewer finds those just as often as the rest, so the tools don't take its easy finds and don't make it less useful. They catch a few for free, before any review, and those never cost a review comment. With 19 bugs, "the same" means no sign of a difference, not a proven equality.
Also in the lab
From the lab's README and checklist answers (its own run, October 2026), beyond the video:
- Screenshots on PRs. The list page differed from the base on 6 of 20 clean PRs that touch the web app, 0 of 57 that don't, 5 of 17 with a UI bug and 12 of 156 with another bug.
- Weak tests and missed bugs. Splitting changes at the median mutation score of their clean PR (85%), the stand-in's recall was 67% vs 67% (quick), 76% vs 84% (standard), 88% vs 87% (careful): no consistent relation, with intervals about ±9 points.
- Tests bugs. For the 11 bugs that weaken a test so the bug passes, the buggy PR's mutation score dropped below its clean twin's on 4. On the daily-schedule fix with days counted as 60 minutes and the test's daily cases deleted (
c08-d1), it went from 100% to 0%. - What went wrong while building it. The first contract test compared whole objects and blocked 2 clean PRs that added a mapping field; it now compares the fields main has, because additive changes aren't broken contracts. The secret scanner first flagged a hash in mypy's cache inside the checkout; caches now live outside. The first browser flow failed on healthy main, and a test that fails on main is a broken test.
- Cost. No API calls. Tools take about 800 MB to install; mutation testing is most of the run time.
What to do
- Measure every check on two numbers, bugs caught and clean PRs blocked, before making it required.
- Count only new findings: compare with the base, or use the tool's baseline file.
- Read the catches. A finding near a bug isn't a find until fixing what it says fixes the bug.
- Keep the few rules that earn their place, and run the rest on new code only, or as warnings.
- Write tests with the PR. Tests written earlier can't see a new field, error code or screen.
- Use mutation testing as a pointer to thin tests, not as a gate.
- When a check is flaky, fix the cause. Fix the clock instead of masking the pixels.
Caveats
- The bugs were written to pass the build and to be found by reading. On a codebase with no types and no tests, tools would probably catch more.
- The "exposes" labels are from an AI. Relabel before quoting; the video's reviewer called the two browser catches borderline.
- The cut-down gate is a best case. Its 11 rules were picked after seeing which ones exposed a bug here.
- No gate was enforced. "Would block" means a clean PR got a new finding or a failing test.
- The reviewer is a stand-in. The recall numbers are Chapter 3's AI model, not people, from one run.
- One machine. A fixed clock made screenshots stable on one machine; a CI fleet with different fonts may not be.
The checklist
- Run each candidate check on your recent PRs and their bases, and keep new findings only.
- Count, per rule, bugs it caught and clean PRs it would have blocked.
- Label the catches: does fixing the finding fix the bug, or is it just nearby?
- Require only the rules that catch more than they block; demote the rest to new-code-only warnings.
- Ask for tests with each PR that changes a rule, a field, an error or a screen; update properties when the promise changes.
- Report surviving mutants to the reviewer as "no test pins this line", not as a failure.
- Pin the clock (and other inputs) in screenshot and browser tests before trusting their diffs.
Practice: the scoring in code
Write the four pieces the lab's numbers rest on: keep the findings a PR adds, decide when a finding flags near a bug, price a set of required checks on the recorded per-PR results, and the screenshot diff. The tests expect the lab's numbers: 19 exposed and 53 of 77 blocked with every gate, 39 for ESLint alone, 9 after the cut, 82% with mutation testing, and a shrinking mask that still flags.
Quiz
1.Why run every check on the PR's base as well as on the PR?
2.ESLint flagged 11 planted bugs and would block 39 of 77 clean PRs. What does the lab suggest?
3.Ruff flags a line next to the bug where 'batch_size in row' searches a database row's values, not its column names. It suggests row.get(...). Has it caught the bug?
4.A property test written on healthy main fails on a clean PR. Is it a false alarm?
5.Surviving mutants sat near 44 of 173 planted bugs and on 45 of 77 clean PRs. How should you use mutation testing?
6.Your screenshot diff flags an unchanged page. You mask the relative times and it still flags every run. Why, and what fixes it?
Check your understanding
Try each question before opening its answer.
Why does every check need two numbers, and what are they?
Bugs it catches (here, of 173 planted) and clean PRs it would block (of 77). A check that blocks good PRs gets switched off or overridden, so catching bugs isn't enough: ESLint flagged 11 bugs and would block 39 clean PRs.
Why compare each PR with its base, and why not match findings by line?
A stricter check also finds problems already on main (ESLint: 85), which aren't the PR's fault. Only what the PR adds counts. Findings are matched by rule, file and message, because a PR moves lines around.
A tool finding lands on the bug's line. Has the tool caught the bug?
Not necessarily. It exposes the bug only if fixing what it says fixes the bug or leads straight to it. 28 bugs were flagged nearby, 19 exposed: a "use ??" on a resume bug that ?? doesn't fix, SQL-injection warnings on a query whose bug is a second full-table scan.
Why did tests written on healthy main catch so little?
A test only knows the rules it was written for. Property tests caught 4 bugs, all in PRs meant to fix one of their rules. The contract test caught none of 18 contract bugs, which are about a field, error code or column the PR adds; the browser flows caught no UI bug, which sit on screens nobody wrote a check for.
Is mutation testing worth running?
As a pointer, yes: survivors sat near 44 bugs, including 7 logic bugs no gate exposed. As a gate, no: survivors were on 45 of 77 clean PRs. Use it to tell a reviewer where no test pins the code.
Your screenshot diff keeps flagging an unchanged page. What do you do?
Find the cause. Here it was the clock: relative times changed. Masking them still flagged 19 of 19 runs, because the hidden text still set the cell's width. Fixing the browser's clock: 0 of 19.
Tools exposed 11% of the bugs. Are they worth it, and do they change the AI reviewer's value?
Yes, for what they're good at: cut to the rules that exposed something, they'd block 12% of clean PRs (a best case) and cost seconds. The AI reviewer's recall on what they leave is the same as on all bugs (66, 80, 88%), so tools don't take its easy finds; they catch a few for free.
Next up: Chapter 7 pulls the other lever: making the pull request itself easier to review, by splitting it, reordering it and adding a walkthrough.