defender-env / scripts /smoke_client.py
its-wasp's picture
Upload folder using huggingface_hub
bf5fd17 verified
Raw
History Blame Contribute Delete
1.67 kB
"""Hour-0 smoke test: drive the stub env through a full episode via the WebSocket client."""
import sys
from pathlib import Path
# Add the grandparent dir (chaotic_hackathon) so we can `import defender_env` as a package
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
from defender_env import DefenderAction, DefenderEnv
def main(base_url: str = "http://127.0.0.1:8765"):
print(f"Connecting to {base_url}...")
with DefenderEnv(base_url=base_url).sync() as client:
print("\n=== RESET ===")
result = client.reset()
print(f" attacker_message : {result.observation.attacker_message}")
print(f" turn_index : {result.observation.turn_index}")
print(f" history_len : {len(result.observation.conversation_history)}")
print(f" done : {result.done}")
for i in range(1, 7):
print(f"\n=== STEP {i} ===")
result = client.step(DefenderAction(response=f"Defender reply {i}"))
print(f" attacker_message : {result.observation.attacker_message[:80]}")
print(f" turn_index : {result.observation.turn_index}")
print(f" history_len : {len(result.observation.conversation_history)}")
print(f" reward : {result.reward}")
print(f" done : {result.done}")
if result.done:
print(f" metadata : {result.observation.metadata}")
print("\n[OK] Episode terminated cleanly.")
return
print("\n[ERR] Episode did NOT terminate within 6 steps.")
if __name__ == "__main__":
main()