Applying catalogs is a tricky business. I'm not certain, but maybe using https://github.com/puppetlabs/puppet/blob/master/spec/lib/puppet_spec/compiler.rb#L21 instead of `compile_to_catalog` would work?  Other than that I'd need to trace through it to understand what is going wrong.