Engineering · Testing

The string the pay button tried to call

A payment sheet returned a word where its caller expected an object. No test failed. It was found by reading every caller, which is slow and was the only way.


Two of the till’s card screens share a caller. When the operator presses pay, the till opens whichever card sheet fits the venue, waits for it to finish, and calls a function on the result to learn whether the sale went through. One of those sheets, the one that drives a separate card machine over the network, had two extra ways to finish: it could hand back the word manual, meaning the operator chose to record the sale by hand, or the word retry, meaning try the machine again.

The caller did not know that. It expected a result object and called a method on it, and a word has no such method. In a browser that is a type error, thrown inside the pay button’s handler, which means the button stops responding and the basket sits there with no explanation. It had been that way for over three hundred releases.

No test caught it, and it is worth saying why. The driven sheet has tests that check it returns manual and retry when it should. The caller has tests that check it records a sale on a good result. Each side was correct on its own terms and the seam between them was never exercised, because exercising it means a venue with a card machine configured, an operator choosing the manual route, and a browser running the real pay handler end to end. Nothing in the suite did all three.

It was found by reading. Adding a third card sheet this week meant adding a third way for the caller to be answered, and the only responsible way to do that was to read every existing answer the caller might receive and every place it was received. The two words were there in the sheet’s source, returned from named buttons, and the caller’s source had no branch for either. The fix is small: the caller now handles both words itself, opening the manual sheet for one and looping for the other, and the test that pins the caller’s shape was moved from the old text to the new.

The lesson is not that the tests were bad. It is that a function’s return values are part of its contract, and when a contract has more cases than its callers handle, the extra cases are bugs that no amount of testing each side separately will show. Reading every caller is slow. It was also the only thing that would have found this, and it did.


Try it on tonight’s service.

Nothing to install, no card. Not better by the weekend? Close the tab.