L6 · AI as your instrument
L6Go deeper4 min read

Large-scale migration with agents

Moving nine hundred tests from one framework to another used to be a quarter of work nobody would fund. It is now days — if you can define the transformation precisely and verify the result at scale, which is the actual skill.

Test migration is moving an existing suite to a different framework, language or pattern without changing what it checks.

It is mechanical, repetitive, and enormous. Three hundred files of the same transformation is the kind of work that gets postponed for two years, because nobody can justify three weeks of typing that adds no coverage.

This is the strongest case for a coding agent in testing. The transformation is well defined, the correct outcome is known, and there is an obvious oracle: the migrated suite must pass and must assert the same things.

The risk is equally clear. At three hundred files nobody reviews every line, so the method has to be a sampling strategy rather than blind trust.

The terms you will hear

  • Batch. A group of files migrated and reviewed together.
  • Error rate. The share of files needing correction, measured on your first fully reviewed batch.
  • Sampling. Reviewing a defined subset of later batches rather than everything.
  • Assertion parity. The migrated test checks exactly what the original did.
  • Parallel run. Old and new suites both running, results compared, until trust is earned.

How to run one

  1. Write down what must not change. Assertions, test names, the number of tests. Anything else is fair game.
  2. Migrate one file by hand first. You need the target pattern before an agent can copy it. This also tells you the awkward parts.
  3. Do one batch of ten, and review all ten. This gives you an error rate and a list of its habits, which is worth more than any estimate.
  4. Fix the prompt, not the output. If it added fixed waits in three of ten, say so explicitly for the next batch.
  5. Then scale in batches of twenty to fifty. Review a sample, plus every file in a high-consequence area.
  6. Diff assertion counts mechanically. A script comparing the number of assertions per file before and after catches silent weakening at scale, which no sampling will.
  7. Run both suites in parallel for a few releases. Compare failures. Retire the old one when the new one has caught the same things, which is the record-keeping habit applied to a migration.

Why the sampling matters

Because full review does not scale and blind trust is unsafe, so you need a defensible middle.

For example, on three hundred files, reviewing everything costs about a week of reading, which defeats the exercise. Reviewing nothing means shipping an unknown number of weakened tests. Reviewing a measured sample, plus everything on the money paths, plus a mechanical assertion diff, costs about a day and gives you a number you can quote.

That number is what makes the migration defensible when somebody asks whether the new suite is as good as the old one.

A worked migration

For example, here is a real one, 312 files from Selenium to Playwright.

migration-312.txt
SCOPE      312 spec files, tests/legacy/ -> tests/e2e/
RULES      assertions must not change. test names must not change.
           test count per file must not change.
ORACLE     the migrated suite passes, and the assertion diff is zero.

BATCH 1  10 files, reviewed fully (2 hours)
  clean                                       7
  added page.waitForTimeout                   2   habit noted
  weakened one assertion to toContain         1   habit noted
  error rate 30 percent
  -> updated the instruction: "never add fixed waits, never change an
     assertion, prefer web-first assertions"

BATCH 2  10 files, reviewed fully (1 hour)
  clean                                       9
  one wrapped a click in a try/catch          1
  error rate 10 percent, and the two named habits did not recur

BATCHES 3 to 12  292 files, sampled review
  sample: 5 files per batch, chosen at random         50 files read
  plus:   every file touching payment, refund or auth 31 files read
  plus:   mechanical assertion-count diff on all 292  automated

  found by sampling            4 files with an extra wait
  found by the assertion diff  2 files where a count dropped by one
                               (both were a deleted assertion, restored)
  found by the money-path pass 1 file asserting a total with toContain

  estimated residual error rate about 3 percent, on files nobody read

PARALLEL RUN  both suites, 4 releases
  new suite caught everything the old one did, plus 2 defects the old
  one missed on timing. old suite retired after release 4.

TOTALS
  agent time    about 6 hours across 12 batches
  my time       about 9 hours of review and scripting
  hand estimate 3 weeks

The batch-one error rate of thirty per cent is the most important number there. It told the team the habits to correct before touching the other three hundred files, and it dropped to ten per cent immediately after one instruction change.

How to show you know it

  • A measured error rate. From a fully reviewed first batch, with the habits it revealed.
  • A mechanical assertion diff. A short script that compares assertion counts before and after. It catches at scale what sampling cannot.
  • A sampling strategy, written down. Random sample plus all high-consequence files plus a mechanical check. That is a defensible method.
  • A parallel run with an outcome. "Both suites for four releases, the new one caught two extra defects." That is how you retire the old suite without an argument.

Questions

Should I migrate the whole suite, or only what earns a place?

Cull first, then migrate. Moving cases nobody should keep is paid twice, so run the pack selection before the migration rather than after.

How large should a batch be?

Ten for the first, then twenty to fifty once the error rate is known and the habits are corrected. Batches large enough to be efficient, small enough that a bad instruction does not damage three hundred files.

What if the migrated suite passes but the old one had failures?

Investigate before celebrating. A suite that goes green during a migration usually means an assertion moved rather than a bug being fixed. That is the review doing its job.

Is this worth it for fifty files?

Probably not. The setup, instruction tuning and review scaffolding costs a day, so it pays off in the hundreds rather than the dozens.