153 lines
4.7 KiB
Python
153 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
TSNet Phase 2 - Test Simple Verificación
|
|
Test simple para verificar que las correcciones TSNet funcionan
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
import time
|
|
|
|
|
|
def test_simple_tsnet():
|
|
"""Test simple de funcionalidad TSNet"""
|
|
try:
|
|
# Test básico de conectividad
|
|
response = requests.post(
|
|
"http://localhost:5006",
|
|
json={
|
|
"jsonrpc": "2.0",
|
|
"method": "execute_python",
|
|
"params": {
|
|
"code": """
|
|
# Test simple de TSNet Phase 2
|
|
print("=== TSNet Phase 2 Simple Test ===")
|
|
|
|
try:
|
|
# Test 1: Verificar que el manager existe
|
|
if hasattr(app, 'tsnetSimulationManager'):
|
|
print("✅ TSNetSimulationManager exists")
|
|
else:
|
|
print("❌ TSNetSimulationManager not found")
|
|
|
|
# Test 2: Test método básico
|
|
app.tsnetSimulationManager.ResetAllCalculatedValues()
|
|
print("✅ ResetAllCalculatedValues works")
|
|
|
|
# Test 3: Crear objetos hidráulicos y verificar que no hay NullReference
|
|
from CtrEditor.ObjetosSim import osHydTank
|
|
|
|
tank = osHydTank()
|
|
tank.CheckData() # Esto debe inicializar el ID
|
|
print(f"✅ Tank created with ID: {tank.Id.Value}")
|
|
|
|
# Test 4: Registrar objeto sin crash
|
|
app.tsnetSimulationManager.RegisterHydraulicObject(tank)
|
|
print("✅ Object registered without NullReference")
|
|
|
|
# Test 5: Validar configuraciones
|
|
errors = app.tsnetSimulationManager.ValidateAllConfigurations()
|
|
print(f"✅ Configuration validation completed: {len(errors)} errors")
|
|
|
|
# Test 6: Test método principal sin crash
|
|
app.TestTSNetIntegrationSync()
|
|
print("✅ TestTSNetIntegrationSync completed")
|
|
|
|
print("\\n🎉 ALL TESTS PASSED - TSNet Phase 2 corrections working!")
|
|
result = "SUCCESS"
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error: {str(e)}")
|
|
import traceback
|
|
print(f"Stack trace: {traceback.format_exc()}")
|
|
result = f"FAILED: {str(e)}"
|
|
|
|
print(f"\\nFinal result: {result}")
|
|
"""
|
|
},
|
|
"id": 1,
|
|
},
|
|
timeout=30,
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
if "result" in result:
|
|
print("📋 Test Output:")
|
|
print("-" * 50)
|
|
print(result["result"])
|
|
print("-" * 50)
|
|
|
|
# Verificar si el test fue exitoso
|
|
if "SUCCESS" in str(result["result"]):
|
|
print("\n🎉 TSNet Phase 2 is working correctly!")
|
|
print("✅ NullReference issues resolved")
|
|
print("✅ Object registration working")
|
|
print("✅ Configuration validation working")
|
|
return True
|
|
else:
|
|
print("\n❌ Test completed but with errors")
|
|
return False
|
|
else:
|
|
print(f"❌ MCP Error: {result.get('error', 'Unknown error')}")
|
|
return False
|
|
else:
|
|
print(f"❌ HTTP Error: {response.status_code}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Connection Error: {e}")
|
|
return False
|
|
|
|
|
|
def main():
|
|
print("🧪 TSNet Phase 2 - Simple Verification Test")
|
|
print("=" * 50)
|
|
print(f"Testing at: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
|
print()
|
|
|
|
# Verificar que CtrEditor esté ejecutándose
|
|
print("🔍 Checking CtrEditor status...")
|
|
try:
|
|
status_response = requests.post(
|
|
"http://localhost:5006",
|
|
json={"jsonrpc": "2.0", "method": "get_ctreditor_status", "id": 0},
|
|
timeout=5,
|
|
)
|
|
|
|
if status_response.status_code == 200:
|
|
status = status_response.json()
|
|
if (
|
|
"result" in status
|
|
and status["result"].get("connection_status") == "available"
|
|
):
|
|
print("✅ CtrEditor is running and MCP server is responding")
|
|
else:
|
|
print("⚠️ CtrEditor is running but MCP may have issues")
|
|
else:
|
|
print("❌ Cannot reach CtrEditor MCP server")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Cannot connect to CtrEditor: {e}")
|
|
return False
|
|
|
|
print("\n🚀 Running TSNet verification test...")
|
|
success = test_simple_tsnet()
|
|
|
|
print("\n" + "=" * 50)
|
|
if success:
|
|
print("🎉 VERIFICATION SUCCESSFUL!")
|
|
print(" TSNet Phase 2 corrections are working properly")
|
|
print(" The system is ready for production use")
|
|
else:
|
|
print("❌ VERIFICATION FAILED!")
|
|
print(" Please check the output above for details")
|
|
|
|
return success
|
|
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
exit(0 if success else 1)
|