Spaces:
Sleeping
Sleeping
Download verify.py from varun1235/RLhackathon: direct link, hf CLI and curl.
- Browser
- Download file 6.97 kB
-
https://huggingface.co/spaces/varun1235/RLhackathon/resolve/main/verify.py
- Command line
-
hf download hf://spaces/varun1235/RLhackathon/verify.py
-
curl -L -o verify.py https://huggingface.co/spaces/varun1235/RLhackathon/resolve/main/verify.py
6.97 kB
| #!/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() | |