Test for test ratchet

This is just a followup to #7623 which adds some tests to the code in that PR (and picks out a bug). Only the final changeset in this series is new past that PR.