Files
railseek6/test_workspace_endpoint.py

87 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""
Test workspace endpoint after fixing circular import.
"""
import subprocess
import time
import requests
import sys
import os
def start_server():
"""Start LightRAG server using the fixed start script."""
print("Starting LightRAG server...")
# Use start_server_fixed.py which should have proper encoding
cmd = [sys.executable, "start_server_fixed.py"]
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding='utf-8',
bufsize=1,
universal_newlines=True
)
# Wait a bit for server to start
time.sleep(5)
return process
def check_workspace_endpoint():
"""Check if /workspaces endpoint returns 200."""
url = "http://localhost:8000/workspaces"
try:
response = requests.get(url, timeout=10)
print(f"Response status: {response.status_code}")
if response.status_code == 200:
print(f"Response JSON: {response.json()}")
return True
else:
print(f"Response text: {response.text}")
return False
except Exception as e:
print(f"Error checking endpoint: {e}")
return False
def main():
# Kill any existing server on port 8000
try:
subprocess.run(["taskkill", "/F", "/IM", "python.exe"], capture_output=True)
except:
pass
# Start server
process = start_server()
if not process:
print("Failed to start server")
return False
# Give server time to start
time.sleep(10)
# Check health endpoint first
try:
health = requests.get("http://localhost:8000/health", timeout=10)
print(f"Health status: {health.status_code}")
except Exception as e:
print(f"Health check failed: {e}")
process.terminate()
return False
# Check workspace endpoint
success = check_workspace_endpoint()
# Kill server
process.terminate()
process.wait()
if success:
print("SUCCESS: Workspace endpoint is working!")
return True
else:
print("FAILURE: Workspace endpoint not working")
return False
if __name__ == "__main__":
result = main()
sys.exit(0 if result else 1)