Pruthvi1762/cloud-devops-openenv
0
1import httpx2import sys3import time4import subprocess5import os6 7def check_env():8 url = "http://localhost:7860"9 print(f"Checking environment at {url}...")10 11 # Start the server in the background12 process = subprocess.Popen([sys.executable, "app.py"], env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE)13 time.sleep(3) # Wait for server to start14 15 try:16 with httpx.Client(timeout=5.0) as client:17 # 1. Check root/health (though uvicorn handles this)18 resp = client.get(url)19 print(f"Server ping: {resp.status_code}")20 21 # 2. Check reset22 resp = client.post(f"{url}/reset", json={"task_id": "task_easy_port_mismatch"})23 if resp.status_code == 200:24 print("✓ Reset endpoint working")25 else:26 print(f"✗ Reset endpoint failed: {resp.status_code}")27 return False28 29 # 3. Check state30 resp = client.get(f"{url}/state")31 if resp.status_code == 200:32 print("✓ State endpoint working")33 else:34 print(f"✗ State endpoint failed: {resp.status_code}")35 return False36 37 print("\nSUCCESS: Environment validation passed!")38 return True39 except Exception as e:40 print(f"✗ Validation failed: {e}")41 return False42 finally:43 process.terminate()44 45if __name__ == "__main__":46 if not check_env():47 sys.exit(1)48 