import asyncio import httpx from httpx import AsyncClient, ASGITransport from server.app import app async def run_test(): # To run lifespan, we must use ASGITransport and standard AsyncClient won't auto-trigger it until httpx 0.28. # A reliable way is via httpx ASGITransport's own lifespan context or simple starlette TestClient from fastapi.testclient import TestClient with TestClient(app) as client: # Reset creates the env r = client.post("/reset") print("Reset:", r.status_code, r.json()) # Auto-attack req = {"strategy_type": "roleplay", "target_category": "privacy"} r = client.post("/auto-attack", json=req) print("Auto-attack:", r.status_code, r.json()) if __name__ == "__main__": asyncio.run(run_test())