Backport 2.0 repl test improvements to 1.4

Backporting some repl test bits back to 1.4, and also fixing some problems found while testing repl backport.