agent: fix reg of dynamically allocated ports

Also make job service registration test that this works.