Spaces:
No application file
No application file
File size: 4,336 Bytes
92ef79b |
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 |
#!/usr/bin/env python3
"""
Test script for safety confirmation workflow
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from gradio_llm_interface import GradioLlmInterface
import json
def test_safety_workflow():
"""Test the safety confirmation workflow"""
print("Testing Safety Confirmation Workflow...")
print("=" * 50)
# Create mock task data
mock_task_data = {
"tasks": [
{
"task": "excavate_soil_from_pile",
"instruction_function": {
"name": "excavate_soil_from_pile",
"robot_ids": ["robot_excavator_01"],
"dependencies": [],
"object_keywords": ["soil_pile"]
}
},
{
"task": "transport_soil_to_pit",
"instruction_function": {
"name": "transport_soil_to_pit",
"robot_ids": ["robot_dump_truck_01"],
"dependencies": ["excavate_soil_from_pile"],
"object_keywords": ["pit"]
}
}
]
}
# Initialize interface
interface = GradioLlmInterface()
# Create mock state with pending task plan
mock_state = {
'pending_task_plan': mock_task_data,
'history': []
}
print("β Mock state created with pending task plan")
print(f" Tasks: {len(mock_task_data['tasks'])}")
# Test validation and deployment
try:
result = interface.validate_and_deploy_task_plan(mock_state)
if result:
confirmation_msg, approved_image_path, button_update, updated_state = result
print("\nπ Validation Results:")
print(f" Confirmation Message: {confirmation_msg[:100]}...")
print(f" Image Generated: {'β' if approved_image_path else 'β'}")
print(f" Button Hidden: {'β' if not button_update.get('visible', True) else 'β'}")
print(f" State Updated: {'β' if updated_state.get('pending_task_plan') is None else 'β'}")
return True
else:
print("β No result returned from validation function")
return False
except Exception as e:
print(f"β Error during validation: {e}")
return False
def test_empty_state():
"""Test with empty state (no pending task plan)"""
print("\nTesting Empty State Handling...")
print("=" * 30)
interface = GradioLlmInterface()
empty_state = {'history': []}
try:
result = interface.validate_and_deploy_task_plan(empty_state)
if result:
warning_msg, image_path, button_update, state = result
if "No Task Plan to Deploy" in warning_msg:
print("β Empty state handled correctly")
return True
else:
print("β Unexpected warning message")
return False
else:
print("β No result returned for empty state")
return False
except Exception as e:
print(f"β Error handling empty state: {e}")
return False
def main():
"""Run safety workflow tests"""
print("π Safety Confirmation Workflow Tests")
print("=" * 50)
tests = [
test_safety_workflow,
test_empty_state
]
passed = 0
total = len(tests)
for test in tests:
try:
if test():
passed += 1
except Exception as e:
print(f"β Test failed with exception: {e}")
print("\n" + "=" * 50)
print(f"Safety Tests passed: {passed}/{total}")
if passed == total:
print("π All safety workflow tests passed!")
print("\nπ Safety Features:")
print(" β Task plan approval workflow")
print(" β Visual confirmation before deployment")
print(" β Error handling and validation")
print(" β State management for pending plans")
return True
else:
print("β Some safety tests failed!")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1) |