Spaces:
Sleeping
Sleeping
File size: 6,692 Bytes
9c920f3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | """
test_env.py
Sanity check for ISSEnvironment across all three episode types.
Run with: python test_env.py
"""
from env.environment import ISSEnvironment
from env.objects import Action
# ---------------------------------------------------------------------------
# Test 1 β Audit episode
# ---------------------------------------------------------------------------
def test_audit():
env = ISSEnvironment()
obs = env.reset("audit_001")
print("Episode type:", obs.episode_type)
print("Objects count:", len(obs.objects))
print("Turns remaining:", obs.turns_remaining)
assert obs.episode_type == "audit"
assert obs.turns_remaining == 6
assert any(o.object_id == "FE_airlock_01" for o in obs.objects)
# Turn 1 β inspect the non-compliant extinguisher
action = Action(
action_type="inspect_object",
target_object_id="FE_airlock_01",
target_module=None,
reasoning="Checking extinguisher expiry and pressure status",
)
obs, reward, done, info = env.step(action)
assert done is False
# Turn 2 β flag it as non-compliant
action = Action(
action_type="flag_non_compliant",
target_object_id="FE_airlock_01",
target_module=None,
reasoning="Extinguisher is expired and pressure critically low at 0.12",
)
obs, reward, done, info = env.step(action)
# Turn 3 β submit report with decision as target_object_id so grader sees
# "submit_report:block_eva" in actions_taken
action = Action(
action_type="submit_report",
target_object_id="block_eva",
target_module=None,
reasoning="Blocking EVA due to non-compliant extinguisher",
)
obs, reward, done, info = env.step(action)
assert done is True
assert reward.score > 0.0
print("Audit reward score:", reward.score)
print("Audit test PASSED")
# ---------------------------------------------------------------------------
# Test 2 β Emergency episode
# ---------------------------------------------------------------------------
def test_emergency():
env = ISSEnvironment()
obs = env.reset("emergency_001")
assert obs.episode_type == "emergency"
assert len(obs.active_alerts) > 0
print("Active alerts:", [a.module for a in obs.active_alerts])
# Turn 1 β evacuate crew before any resource deployment
action = Action(
action_type="evacuate_module",
target_object_id=None,
target_module="Lab",
reasoning="Crew member inside Lab, must evacuate before any resource deployment",
)
obs, reward, done, info = env.step(action)
assert done is False
print("Crew locations after evacuation:", obs.crew_locations)
assert obs.crew_locations.get("crew_1") == "Node1"
# Turn 2 β deploy the correct extinguisher
action = Action(
action_type="deploy_resource",
target_object_id="FE_lab_01",
target_module=None,
reasoning="Deploying correct extinguisher to suppress Lab fire",
)
obs, reward, done, info = env.step(action)
# Turn 3 β trigger the safety switch panel
action = Action(
action_type="trigger_switch",
target_object_id="SSP_lab_01",
target_module=None,
reasoning="Isolating Lab power to prevent re-ignition",
)
obs, reward, done, info = env.step(action)
# Turn 4 β contact ground control
action = Action(
action_type="contact_ground",
target_object_id="EP_node1_01",
target_module=None,
reasoning="Notifying ground control of fire incident",
)
obs, reward, done, info = env.step(action)
# Turn 5 β submit report (terminal)
action = Action(
action_type="submit_report",
target_object_id=None,
target_module=None,
reasoning="Fire suppressed, crew safe, power isolated, ground notified",
)
obs, reward, done, info = env.step(action)
assert done is True
assert reward.score > 0.5
print("Emergency reward score:", reward.score)
print("Emergency test PASSED")
# ---------------------------------------------------------------------------
# Test 3 β Investigation episode
# ---------------------------------------------------------------------------
def test_investigation():
env = ISSEnvironment()
obs = env.reset("investigation_001")
assert obs.episode_type == "investigation"
print("Visible evidence log entries:", len(obs.evidence_log))
assert len(obs.evidence_log) == 4
# Turn 1 β pull log for the obvious suspect (red herring)
action = Action(
action_type="pull_sensor_log",
target_object_id="NT_service_01",
target_module=None,
reasoning="Starting with the obvious nitrogen pressure drop",
)
obs, reward, done, info = env.step(action)
# Turn 2 β pull log for the depleted extinguisher (reveals hidden entry)
action = Action(
action_type="pull_sensor_log",
target_object_id="FE_service_01",
target_module=None,
reasoning="Extinguisher is depleted with 0.0 pressure β investigating discharge",
)
obs, reward, done, info = env.step(action)
print("Evidence log after pulling FE log:", len(obs.evidence_log))
assert len(obs.evidence_log) == 5
# Turn 3 β cross-reference discharge with pressure drop
action = Action(
action_type="cross_reference",
target_object_id="FE_service_01",
target_module=None,
reasoning="Cross referencing extinguisher discharge at 14:33 with nitrogen drop at 14:32",
)
obs, reward, done, info = env.step(action)
# Turn 4 β identify root cause (terminal)
action = Action(
action_type="identify_root_cause",
target_object_id="FE_service_01",
target_module=None,
reasoning="Extinguisher propellant caused false nitrogen reading β not a real leak",
)
obs, reward, done, info = env.step(action)
assert done is True
assert reward.score > 0.7
print("Investigation reward score:", reward.score)
print("Investigation test PASSED")
# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------
if __name__ == "__main__":
try:
test_audit()
test_emergency()
test_investigation()
print("\nALL TESTS PASSED β safe to hand off to Person 3")
except AssertionError as e:
print(f"\nASSERTION FAILED: {e}")
except Exception as e:
import traceback
print(f"\nERROR: {e}")
traceback.print_exc()
|