157 lines
4.5 KiB
Python
157 lines
4.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Script de test para validar las correcciones TSNet Phase 2
|
|
Prueba que los objetos hidráulicos se pueden crear sin errores de NullReference
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
import time
|
|
import sys
|
|
|
|
|
|
def test_mcp_connection():
|
|
"""Probar conectividad básica con MCP"""
|
|
try:
|
|
response = requests.post(
|
|
"http://localhost:5006",
|
|
json={"jsonrpc": "2.0", "method": "get_status", "id": 1},
|
|
timeout=10,
|
|
)
|
|
print(f"✅ MCP Connection: Status {response.status_code}")
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ MCP Connection failed: {e}")
|
|
return False
|
|
|
|
|
|
def test_create_hydraulic_objects():
|
|
"""Probar creación de objetos hidráulicos"""
|
|
objects_to_test = [
|
|
{"type": "osHydTank", "name": "Tank Test"},
|
|
{"type": "osHydPump", "name": "Pump Test"},
|
|
{"type": "osHydPipe", "name": "Pipe Test"},
|
|
]
|
|
|
|
success_count = 0
|
|
|
|
for obj in objects_to_test:
|
|
try:
|
|
response = requests.post(
|
|
"http://localhost:5006",
|
|
json={
|
|
"jsonrpc": "2.0",
|
|
"method": "create_object",
|
|
"params": {"type": obj["type"], "x": 1.0 + success_count, "y": 1.0},
|
|
"id": success_count + 1,
|
|
},
|
|
timeout=10,
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
if "error" not in result:
|
|
print(f"✅ {obj['name']} created successfully")
|
|
success_count += 1
|
|
else:
|
|
print(
|
|
f"❌ {obj['name']} creation failed: {result.get('error', 'Unknown error')}"
|
|
)
|
|
else:
|
|
print(f"❌ {obj['name']} HTTP error: {response.status_code}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ {obj['name']} exception: {e}")
|
|
|
|
return success_count
|
|
|
|
|
|
def test_tsnet_simulation():
|
|
"""Probar la simulación TSNet"""
|
|
try:
|
|
response = requests.post(
|
|
"http://localhost:5006",
|
|
json={
|
|
"jsonrpc": "2.0",
|
|
"method": "execute_python",
|
|
"params": {
|
|
"code": """
|
|
try:
|
|
# Test basic TSNet integration
|
|
app.TestTSNetIntegrationSync()
|
|
print("✅ TSNet Test Integration successful")
|
|
|
|
# Test full TSNet simulation
|
|
app.RunTSNetSimulationSync()
|
|
print("✅ TSNet Full Simulation successful")
|
|
|
|
result = "SUCCESS"
|
|
except Exception as e:
|
|
print(f"❌ TSNet Error: {str(e)}")
|
|
result = f"ERROR: {str(e)}"
|
|
"""
|
|
},
|
|
"id": 10,
|
|
},
|
|
timeout=30,
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
if "error" not in result:
|
|
print("✅ TSNet simulation test completed")
|
|
return True
|
|
else:
|
|
print(
|
|
f"❌ TSNet simulation failed: {result.get('error', 'Unknown error')}"
|
|
)
|
|
else:
|
|
print(f"❌ TSNet simulation HTTP error: {response.status_code}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ TSNet simulation exception: {e}")
|
|
|
|
return False
|
|
|
|
|
|
def main():
|
|
print("🔧 TSNet Phase 2 Fix Validation Test")
|
|
print("=" * 50)
|
|
|
|
# Test 1: MCP Connection
|
|
print("\n1. Testing MCP Connection...")
|
|
if not test_mcp_connection():
|
|
print("❌ Cannot proceed without MCP connection")
|
|
return False
|
|
|
|
# Wait for stability
|
|
time.sleep(2)
|
|
|
|
# Test 2: Object Creation
|
|
print("\n2. Testing Hydraulic Object Creation...")
|
|
created_objects = test_create_hydraulic_objects()
|
|
print(f"Created {created_objects}/3 objects successfully")
|
|
|
|
# Test 3: TSNet Simulation
|
|
print("\n3. Testing TSNet Simulation...")
|
|
simulation_success = test_tsnet_simulation()
|
|
|
|
# Summary
|
|
print("\n" + "=" * 50)
|
|
print("🎯 TEST SUMMARY:")
|
|
print(f" • MCP Connection: ✅")
|
|
print(f" • Objects Created: {created_objects}/3")
|
|
print(f" • TSNet Simulation: {'✅' if simulation_success else '❌'}")
|
|
|
|
if created_objects == 3 and simulation_success:
|
|
print("\n🎉 ALL TESTS PASSED - TSNet Phase 2 fixes are working!")
|
|
return True
|
|
else:
|
|
print("\n⚠️ Some tests failed - please check the output above")
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
sys.exit(0 if success else 1)
|