Add test for per-user command history

Helping you out with the unit test for your pull request :)

In the end it wasn't so bad, but I discovered a bug and had to change our TestBackend slightly so we can pretend to be someone else. ;)

This includes all the commits from gbin/err#123 because there's no way to make it work without those.