Spaces:
Sleeping
Sleeping
| """ | |
| Test to verify global environment singleton fallback works. | |
| Tests that repeated /reset and /step calls without session_id | |
| reuse the same environment instance and progress through tasks. | |
| """ | |
| import requests | |
| BASE_URL = "https://nandukondreddy-config-debug-env.hf.space" | |
| print("=" * 70) | |
| print("GLOBAL ENV SINGLETON TEST (no session_id)") | |
| print("=" * 70) | |
| print() | |
| print("[TEST] Calling /reset without session_id...") | |
| r = requests.post(f"{BASE_URL}/reset", json={}) | |
| print(f"Status: {r.status_code}") | |
| if r.status_code != 200: | |
| print(f"Error: {r.text}") | |
| exit(1) | |
| data = r.json() | |
| print(f"Initial task: {data.get('observation', {}).get('task_id')}") | |
| print() | |
| print("[TEST] Stepping through 15 requests with /step (no session_id)...") | |
| print() | |
| for step_num in range(1, 16): | |
| r = requests.post( | |
| f"{BASE_URL}/step", | |
| json={"fixed_config": "{}"} | |
| ) | |
| if r.status_code != 200: | |
| print(f"[FAIL] Step {step_num} returned {r.status_code}") | |
| print(f"Error: {r.text}") | |
| exit(1) | |
| data = r.json() | |
| obs = data.get("observation", {}) | |
| task_id = obs.get("task_id") | |
| reward = data.get("reward") | |
| done = data.get("done") | |
| print(f"Step {step_num:2d}: task_id={task_id:20s} reward={reward:.2f} done={done}") | |
| print() | |
| print("=" * 70) | |
| print("FINAL TEST") | |
| print("=" * 70) | |
| # One more call to verify progression | |
| r = requests.post( | |
| f"{BASE_URL}/step", | |
| json={"fixed_config": "{}"} | |
| ) | |
| data = r.json() | |
| obs = data.get("observation", {}) | |
| final_task = obs.get("task_id") | |
| print(f"After 16 steps: task_id={final_task}") | |
| if final_task != "task1_json": | |
| print() | |
| print("[OK] SUCCESS: Task progressed beyond task1!") | |
| print(f"Currently on: {final_task}") | |
| else: | |
| print() | |
| print("[ERROR] STILL STUCK ON TASK1 - Fallback not working") | |
| exit(1) | |