this is all pretty much copied from Benji's work around the origin functional test run. We might be able to refactor this to remove duplication, but saving as a follow up step.