diff --git a/pol_env/Tribes/py/register_env.py b/pol_env/Tribes/py/register_env.py index 418118a..c88b3a1 100644 --- a/pol_env/Tribes/py/register_env.py +++ b/pol_env/Tribes/py/register_env.py @@ -469,16 +469,10 @@ def __init__(self, level_file=None, map_type=None): ) except (MapGeometryError, ObservationContractError): raise - except Exception as e: - # Fallback to placeholders if initialization fails - print(f"Warning: Could not initialize environment properly: {e}") - self.action_space = gym.spaces.Discrete(200) # safe fallback - self.observation_space = gym.spaces.Box( - low=-np.inf, - high=np.inf, - shape=(1000,), - dtype=np.float32 - ) + except Exception as exc: + raise RuntimeError( + "TribesGymWrapper failed while establishing the real PolyVision interface." + ) from exc def reset(self, seed=None, options=None): t_reset_start = time.perf_counter() if self._profile_sps_enabled else None diff --git a/pol_env/Tribes/py/tests/test_environment_contract.py b/pol_env/Tribes/py/tests/test_environment_contract.py index 181c8f2..2214f0f 100644 --- a/pol_env/Tribes/py/tests/test_environment_contract.py +++ b/pol_env/Tribes/py/tests/test_environment_contract.py @@ -93,6 +93,29 @@ def test_wrapper_loaded_observation_geometry_uses_same_contract(self): validate_fixed_square_geometry(*dims, wrapper._catalog.width, wrapper._catalog.height) +class BootstrapFailureTests(unittest.TestCase): + def test_unexpected_bootstrap_failure_is_chained_and_fails_closed(self): + bootstrap_failure = RuntimeError("distinctive reset bootstrap failure") + tribes_env = SimpleNamespace(reset=mock.Mock(side_effect=bootstrap_failure)) + + with mock.patch( + "pol_env.Tribes.py.register_env.make_default_env", return_value=tribes_env + ), mock.patch.object( + TribesGymWrapper, "_resolve_level_pool", return_value=["bootstrap.csv"] + ), mock.patch.object( + TribesGymWrapper, "_resolve_map_profile", return_value="BARDUR" + ), mock.patch.object( + TribesGymWrapper, "_validate_level_file_is_square" + ): + with self.assertRaisesRegex( + RuntimeError, "establishing the real PolyVision interface" + ) as raised: + TribesGymWrapper() + + self.assertIs(raised.exception.__cause__, bootstrap_failure) + tribes_env.reset.assert_called_once() + + class CheckpointCompatibilityTests(unittest.TestCase): def test_same_environment_is_accepted(self): meta = compatibility_metadata()