Fix with-profile alias changes

This reverts 3a2cf943243a6bba44294fca741a9e55429127e, refactors to
enable testing, adds tests, then reverts
0334cc8efa5b790b810317e08c568ae8e424041e.  I *think* that the test now
include coverage for what 0334cc8efa5b790b810317e08c568ae8e424041e was
intended to fix, but I can only infer the intent of that commit.