Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions pol_env/Tribes/py/register_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions pol_env/Tribes/py/tests/test_environment_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading