Skip to content
mentoor

Topic 4 of 4 · 4 min read

Verifying migrations across many files

Goal: Verify a large migration with tests, a search for leftover patterns and a sampled diff review rather than reading every file.

You cannot read every changed file in a large migration, so replace reading with checks: run the tests, search for leftover old patterns, and review a sample of the diff. The goal is evidence that the batch is done, not a feeling that it looks right.

Check yourself · 1 of 3

After a migration, a search for the old pattern returns zero results. What does that prove?

Choose one answer

Why it matters

A migration PR can touch 400 files. Reviewers stop reading after the first screens, and an agent's summary will say it all worked. If you rely on either, errors pass through. Verification at scale works because most of the diff is repetitive, so a few well-chosen checks cover most of it, and a human reads the rest where the risk is.

The four checks

  1. Tests and type checks. Run the full suite for the touched area and the compiler. A type check is very good at catching missed call sites after an API change. Tests only help where tests exist, so note the untested files.
  2. Leftover search. Search for the old pattern and expect zero results. Search for related shapes too: aliases, re-exports, strings in config files, docs and tests. Count the results and compare with the inventory.
  3. Shape search for the new code. Search for the new pattern and compare the count to the old inventory. If 412 files used the old call and only 380 use the new one, 32 files went somewhere else.
  4. Sampled diff review. Group changed files by shape, then read a few from each group, plus every file that did not match any group. Always read the files the agent flagged as unsure, and files with unusually large or unusually small diffs.

Before and after

Weak: "I skimmed the PR and it looks consistent."

Better, as a verification script and a sampling note:

set -e
npx tsc --noEmit
npm test
echo "old imports left:"; grep -rn "from 'moment'" src test | wc -l
echo "new imports:";      grep -rln "from 'date-fns'" src test | wc -l   # expect close to 412
git diff --stat main... | sort -k3 -n -r | head -20   # largest diffs: read these

Sample note: "Read 5 of 31 files in each of the 3 shape groups, plus the 4 largest diffs and the 2 files the agent marked unsure."

What goes wrong

  • Searching only for the exact old text. An aliased import or a string in a config file is missed.
  • Passing tests that changed. The agent edited tests to fit new behaviour. Look at test diffs separately.
  • Sampling only easy files. Pick samples across groups and add the outliers.
  • Trusting the agent's count. Run the search yourself; do not accept a number in a summary.

Examples

The missing 32

The inventory said 412 files used the old date library. After the migration, the search for the old import returned 0 and 380 files used the new one. The 32 missing files turned out to be test helpers that had been deleted by the agent instead of migrated. The count caught what the leftover search could not.

The edited test

- expect(formatDate(d)).toBe('01/02/2025')
+ expect(formatDate(d)).toBe('2025-02-01')

The test changed with the migration. Either the format was meant to change, or the agent edited the test to pass. Test diffs are read separately, and each needs a reason.

Key points

  • Replace reading every file with checks that can fail: tests, type check, leftover search and a count of the new pattern.
  • A type check is strong at finding missed call sites after an API change.
  • Search for the old pattern in all its forms, including aliases, config, docs and tests, and expect zero.
  • Compare the count of new patterns with the inventory to find files that went missing.
  • Review a sample from each group of changes, plus the outliers and the files the agent flagged.

Common mistakes

  • Searching only for the exact old import and missing aliases, re-exports and config strings.
  • Accepting green tests without checking whether the agent changed the tests.
  • Sampling files at random without grouping, so rare shapes are never read.
  • Using the agent's reported counts instead of running the searches yourself.

Check yourself · 2 of 3

What is a good way to review a 400-file mechanical diff?

Choose one answer

Check yourself · 3 of 3

The inventory had 412 files with the old call, and afterwards 380 files use the new call and none use the old. What is the best next step?

Choose one answer

Practice items, not counted towards your mastery.

Start here