My suspicion is that this problem you describe is one core reason why "a raymarcher in a single shader" has become such a popular demo platform. Nobody writes unit tests inside shaders, it just.. doesn't make much sense. The environment sort of forces you to stop thinking like an engineer and start thinking like a coder.
This is very true. Having said that, even with shader I've managed to go down the rabbit hole. "Perhaps this shader can be generalized so it'll work for every vertex format...hmm, it should probably dynamically recompile then...once I'm doing that I might as well start linking arbitrary snippets of code then..." etc.