Try to actually design the test that would have caught this. There is no way in this universe that one can blindly rely on tests when refactoring.
// Image inlined because error may be due to dropped connection
You don’t have to have tests to prevent bad refactoring. 100% test coverage isn’t realistic for most code bases (or isn’t even a net positive in many cases).
self-documenting code, or tests, or comments would have saved the situation. You don’t need to design a test in this case. A one line comment that takes five seconds to write is enough.