Add a notion of contract checking. Current contracts are just trivial size checks on intmap and union
turns out a lot of that low test coverage was because we were forcing too much and thus were hardly ever actually using the query optimiser. Once the optimiser is in play, testmachine revealed a bug where were rewriting wrong
yet more test coverage