case studies

How to Upgrade a Dependency With CodeInstances Replaying Real Runs

You need to bump something underneath your program. A new major version of the HTTP client library, a vendor’s SDK, or the Go toolchain itself. The changelog is long. Your unit tests pass, but they use mocks written two years ago against the old behaviour, so passing doesn’t tell you much. What you’d like to know is simple: does the program still do the same thing on real work?

Real runs answer that. Before the upgrade, record a handful of runs of the current build doing real work, against the real services, into one folder:

codeinstances record -o runs/report-daily.instance -- ./app report --daily
codeinstances record -o runs/report-monthly.instance -- ./app report --monthly
codeinstances record -o runs/sync-full.instance -- ./app sync --full

Pick runs that cover the paths you care about. Each one keeps every request the program made, every answer, what it printed and how it exited.

Record before the upgrade, replay after it. Real runs of the old build are kept as runs/*.instance. Each one is replayed against the new build, with the client library, SDK or Go bumped. Runs 1 and 2 matched. Run 3 diverged with stdout line 4 recorded as “total 12.50” and replayed as “total 12.5”. Run 4 diverged because a POST request isn’t in the recording.

Run the Folder as Tests

Make the upgrade and build the new version at the same path, ./app, where the recordings expect it. Then replay the whole folder against it, as regression tests:

codeinstances test runs/

Each run goes through the new build with its own recorded arguments. (A command after -- replaces the recorded one for every run in the folder, so it only fits when the runs share their arguments.)

A run that passed when it was recorded has to replay exactly: the same requests, the same output, the same exit code. test exits 0 when every run did, so it drops straight into CI as the check for the upgrade branch. -json gives the results to a script, and -v lists every note.

A run that didn’t match says how, in plain words. “stdout line 4: recorded …, replayed …” means the program printed something different, which after a library bump is often number formatting or field order. “request POST … isn’t in the recording” means the new build sent a request the old one didn’t, maybe a new endpoint version or a changed query parameter. “recorded call 2 … was never made” means it skipped one. “exit code: recorded 0, replayed 1” means it now fails. Each points at a specific behaviour change, which is a lot easier to judge than a changelog.

When the Requests Change on Purpose

Sometimes the upgrade is supposed to change what goes over the wire, an SDK that moves from /v1 to /v2, say. Then every replay diverges on its first request and tells you little. Record the new build doing the same work instead, and compare the two runs:

codeinstances record -o new/sync-full.instance -- ./app sync --full
codeinstances diff runs/sync-full.instance new/sync-full.instance

diff pairs the calls of the two runs, shows which answers changed down to the JSON field, which calls only one run made, what each printed and how it ended. It also lines up the timing of every call both runs made, so if the new SDK is slower against the same service, you see that too.

When It Doesn’t Fit

Request order doesn’t matter by default, since threads race, so a new client that reorders concurrent calls still matches. Pass -strict if you want order checked too. If stderr carries timings or warnings that change, -ignore-stderr leaves it out. Headers aren’t compared, since replay matches on method, URL and body, so a new header the SDK adds won’t show up. And for Go upgrades, the clock and random numbers only replay exactly if the program uses the hook package.