state: pass environment uuid via config rather than generate it during initialize

In order to have the uuid of the environment available _before_ state is initialised the uuid is now a part of the environment configuration.

This PR also contains some drive-by cleanups to state tests to make them more robust if they fail.