Spaces:
Sleeping
Sleeping
File size: 6,965 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 | #!/usr/bin/env python3
"""
Verification tests for ISS Safety Operations environment.
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from env.environment import ISSEnvironment
from env.objects import Action
def run_tests():
env = ISSEnvironment()
all_passed = True
# ββββββββββββββββββββββββββββββββββββββββββββββββ
# Test 1: Audit episode loads and runs
# ββββββββββββββββββββββββββββββββββββββββββββββββ
print("\n=== Test 1: Audit episode loads ===")
obs = env.reset("audit_001")
assert obs.episode_type == "audit", f"Expected 'audit', got '{obs.episode_type}'"
assert obs.turns_remaining == 6, f"Expected 6 turns, got {obs.turns_remaining}"
assert len(obs.objects) > 0, "Expected objects in observation"
print(f" β episode_type={obs.episode_type}, turns_remaining={obs.turns_remaining}, objects={len(obs.objects)}")
# ββββββββββββββββββββββββββββββββββββββββββββββββ
# Test 2: Correct audit sequence scores > 0.8
# ββββββββββββββββββββββββββββββββββββββββββββββββ
print("\n=== Test 2: Correct audit sequence scores > 0.8 ===")
env.reset("audit_001")
action1 = Action(
action_type="inspect_object",
target_object_id="FE_airlock_01",
reasoning="Checking extinguisher expiry and status before EVA clearance",
)
obs, reward, done, info = env.step(action1)
assert not done, "Should not be done after inspect"
assert reward.score == 0.0, f"Expected 0.0 (non-terminal), got {reward.score}"
print(f" β inspect_object: done={done}, reward.score={reward.score}")
# Reset for a clean scoring test
env.reset("audit_001")
env.step(Action(action_type="inspect_object", target_object_id="FE_airlock_01",
reasoning="Checking extinguisher status"))
env.step(Action(action_type="flag_non_compliant", target_object_id="FE_airlock_01",
reasoning="FireExtinguisher FE_airlock_01 is expired (expiry_days_remaining=-3) and tag invalid"))
obs, reward, done, info = env.step(Action(
action_type="submit_report",
target_module="block_eva",
reasoning="EVA-42 must be blocked due to expired FireExtinguisher in Airlock. Safety compliance requires all equipment be valid before EVA clearance.",
))
assert done, "Should be done after submit_report"
print(f" β submit_report: done={done}, reward.score={reward.score:.3f}")
print(f" breakdown={reward.breakdown}")
assert reward.score > 0.8, f"Expected score > 0.8, got {reward.score:.3f}"
print(f" β Score {reward.score:.3f} > 0.8")
# ββββββββββββββββββββββββββββββββββββββββββββββββ
# Test 3: Dangerous action is penalized
# ββββββββββββββββββββββββββββββββββββββββββββββββ
print("\n=== Test 3: Dangerous action oxygen_near_fire ===")
env.reset("emergency_001")
dangerous_action = Action(
action_type="deploy_resource",
target_object_id="OT_lab_01",
reasoning="Using oxygen tank to enhance combustion β THIS IS WRONG",
)
obs, reward, done, info = env.step(dangerous_action)
print(f" actions_taken={obs.actions_taken}")
assert "DANGEROUS:oxygen_near_fire" in obs.actions_taken, \
"Expected 'DANGEROUS:oxygen_near_fire' in actions_taken"
print(" β Dangerous oxygen_near_fire logged correctly")
# ββββββββββββββββββββββββββββββββββββββββββββββββ
# Test 4: Investigation hidden log revealed
# ββββββββββββββββββββββββββββββββββββββββββββββββ
print("\n=== Test 4: Hidden log revealed via pull_sensor_log ===")
env.reset("investigation_001")
# Initial evidence_log has 4 visible entries
obs_init = env.reset("investigation_001")
initial_len = len(obs_init.evidence_log)
print(f" Initial evidence_log length: {initial_len}")
pull_action = Action(
action_type="pull_sensor_log",
target_object_id="FE_service_01",
reasoning="Checking extinguisher discharge history to look for anomalies in timing",
)
obs, reward, done, info = env.step(pull_action)
print(f" After pull_sensor_log, evidence_log length: {len(obs.evidence_log)}")
assert len(obs.evidence_log) > initial_len, "Hidden log should have been added to evidence_log"
hidden_entry = next((e for e in obs.evidence_log if e.object_id == "FE_service_01"), None)
assert hidden_entry is not None, "FE_service_01 log entry should now be visible"
assert hidden_entry.visible_to_agent, "Entry should be visible after pull"
print(f" β Hidden entry revealed: {hidden_entry.timestamp} β {hidden_entry.event[:60]}...")
# ββββββββββββββββββββββββββββββββββββββββββββββββ
# Test 5: Grade functions return 0.0 to 1.0
# ββββββββββββββββββββββββββββββββββββββββββββββββ
print("\n=== Test 5: grades are in [0.0, 1.0] ===")
assert 0.0 <= reward.score <= 1.0, f"score {reward.score} out of range"
# Full investigation scoring
env2 = ISSEnvironment()
env2.reset("investigation_001")
env2.step(Action(action_type="pull_sensor_log", target_object_id="FE_service_01",
reasoning="Check extinguisher log for timing anomalies"))
env2.step(Action(action_type="cross_reference", target_object_id="FE_service_01+NT_service_01",
reasoning="Cross-referencing extinguisher discharge with nitrogen pressure drop"))
obs3, reward3, done3, _ = env2.step(Action(action_type="identify_root_cause",
target_object_id="FE_service_01",
reasoning="Extinguisher discharged before alarm β propellant interfered with nitrogen sensor"))
assert 0.0 <= reward3.score <= 1.0, f"Investigation score {reward3.score} out of range"
print(f" β Investigation score={reward3.score:.3f} (in range)")
print(f" breakdown={reward3.breakdown}")
print("\nβ
ALL TESTS PASSED\n")
if __name__ == "__main__":
run_tests()
|