Skip to content
mentoor

Topic 4 of 4 · 4 min read

Verifying migrated code at scale

Goal: Choose verification steps that catch missed call sites and silent behaviour changes after a migration.

Verify a migration with several cheap checks that each catch a different failure: the compiler for broken code, tests for changed behaviour, a search for leftovers, and a sampled read of the diff. No single check is enough, and a green build alone proves little.

Check yourself · 1 of 3

After a migration, what is the most direct check for missed call sites?

Choose one answer

Why it matters

An agent can produce code that compiles and still miss a call site, change a default or "fix" a failing test by editing it. At scale, nobody reads every line, so the checks have to do the work. Google's migration papers describe automatic validation as part of the pipeline, with humans reviewing the results.

How to do it

  1. Search for leftovers. Rerun the inventory search. The number of old-API matches should be zero, or each remaining one should be on a written exception list.
  2. Type check and build the whole repository, not only the touched modules. Shared types break callers far from the edit.
  3. Run the full test suite, and compare the list of changed test files with the plan. A migration that edits many tests deserves a close look: the agent may have changed the expectation, not the code.
  4. Sample the diff. Read a random 10 percent plus every file the agent flagged, every file over a size limit, and every file with an unusual pattern. Use a script to list "files whose diff does not match the recipe shape".
  5. Compare behaviour before and after. Snapshots of API responses, rendered output, query plans or a benchmark on both versions. This catches changed defaults that tests do not cover.
  6. Roll out carefully. Staging first, then a small share of traffic, with a fast way back.
# leftovers: expect no output
rg "from 'request'" src
# files where tests were edited by the migration
git diff --stat main -- '**/*.test.ts'

Before and after

Weak: "Build passes, merge." Better: leftovers search is empty, the full suite is green with no unexplained test edits, 30 sampled files match the recipe, and a before-and-after comparison of 50 recorded API responses shows no differences.

What goes wrong

  • Trusting the type check. Runtime behaviour, such as a changed default, is invisible to it.
  • Counting green tests as proof. The tests may not cover the changed path, or may have been edited.
  • Sampling only easy files. Pick samples by risk and by randomness.
  • Leftover sites in strings or config. Dynamic imports, YAML and docs can hold the old name; search them too.

Examples

A leftovers check

rg -n "from 'request'|require\\('request'\\)" src scripts config docs
test "$(rg -c "from 'request'" src | wc -l)" -eq 0 && echo clean

Searching scripts, config and docs as well as src finds the old name in places the type checker never looks.

Catching a silent default

After the upgrade, the new client retries three times by default and the old one never retried. Types and tests pass. A comparison of recorded requests before and after shows a payment call now sent twice on timeout. The fix is to set retries to zero for that call and add a test for it.

Key points

  • Rerun the original inventory search after the migration; the leftover count should be zero or explained.
  • Type checks catch broken code but not changed behaviour, so add tests and before-and-after comparisons.
  • Treat edited test files in a migration as a warning sign and read those diffs.
  • Sample the diff by risk and at random, and use a script to flag files that do not match the recipe shape.
  • Roll out gradually with a fast way back, because some behaviour changes only show in real use.

Common mistakes

  • Treating a passing build as proof that the migration is complete.
  • Not searching strings, config files and docs for the old API name.
  • Accepting many edited tests without checking whether the expectations were weakened.
  • Sampling only the files that are easy to read.

Check yourself · 2 of 3

Types and tests pass, but a library default changed silently. What catches it?

Choose one answer

Check yourself · 3 of 3

A migration edited 80 test files. What is the right reaction?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic