Having the state files always created for locking breaks a lot of tests. Most can be fixed by simple checking for state within a file, but a few still might be writing state when they shouldn't.
This is a complex function that handles all the potential cases that can happen with legacy remote state, new configurations, etc.