1) You need to foster a culture where those improvements are allowed in
2) Codify norms of how a shared goal is worked on
2a) refactor tests as part of separate PR
2b) realign code with refactoring in mind (this is the begin transaction portion)
3) commit work
4) merge everything into main
It might take 3x longer, but it is more controlled.
The larger the team, or the more consumers, the more important it is to get the interfaces right. And if you can refactor the interface ahead of the code itself, the refactor isn't even noticed.
2) Codify norms of how a shared goal is worked on
2a) refactor tests as part of separate PR
2b) realign code with refactoring in mind (this is the begin transaction portion)
3) commit work
4) merge everything into main
It might take 3x longer, but it is more controlled.
The larger the team, or the more consumers, the more important it is to get the interfaces right. And if you can refactor the interface ahead of the code itself, the refactor isn't even noticed.