"Invalid device state" when running xctest on Bamboo agent

I have a workspace includes an app and a framework, and both projects have xctest cases. The test target of the framework project fails on bamboo agent with the following error:

"xctest encountered an error (Failed to install or launch the test runner. (Underlying Error: Invalid device state))".

The same script runs without issue from the terminal.

The workaround is to add the xctest to a host app, however, it seems not possible to add host app to frameworks managed using swift package manager.

Does anyone experience the same issue? BTW, the issue is on xcode 12+ only.