A lot of real projects still run on callback code. So I took a 27-line callback file, had an AI agent refactor it to async/await, and then ran both versions side by side to check the answers match. Not a style review. A behavior test.

The two versions

The old version reads several JSON files one at a time, builds a report, and calls back with the result. It has a nested function, a manual counter, and an error check at every level.

The new version is 12 lines. It reads all the files at the same time with Promise.all, flattens the rows, and returns the same report. Errors now come out as normal exceptions, so the repeated error checks are gone.

The test that matters

I ran both versions on the same four inputs: two good files, one file with broken JSON, and one file that does not exist.

  • Good files. Both versions return five rows, top scored average 78.8. Same numbers.
  • Broken JSON. Both fail with the same message.
  • Missing file. Both fail with the same error code.

All four results are identical. The refactor kept the behavior, including the failure behavior, which is the part rewrites usually get wrong.

The one real difference

The old code reads files one after another. The new code reads them in parallel. That is faster, but it cuts both ways: if you point it at thousands of files, you would want to limit the concurrency instead of opening them all at once.

The verdict

Shorter, safer, and provably the same output. "Provably" is doing the work here: I did not trust the diff, I ran both versions and compared what came out.

The full refactor and every run are in the video:

https://youtu.be/IwyDzuBQQlw

We are building Ship Stack: real experiments on real backends, with the actual numbers, no hand-waving. More of these are on the channel.