Files
orch/spike/fake_hx.py
T

24 lines
779 B
Python

#!/usr/bin/env python3
"""Fake hx for the O0 spike: `fake_hx.py -p BODY --mode json`. BODY keywords: FAIL (error), CRASH (exit 2), HANG (sleep)."""
import json, sys, time
body = sys.argv[sys.argv.index("-p") + 1]
def emit(o):
print(json.dumps(o), flush=True)
emit({"type": "session_start"})
if "HANG" in body:
time.sleep(60)
if "CRASH" in body:
sys.exit(2)
emit({"type": "turn_start"})
if "FAIL" not in body:
open("out.txt", "w").write(body)
emit({"type": "tool_result", "name": "write", "args": {"path": "out.txt"}, "content": "ok", "is_error": False})
emit({"type": "done", "error": "boom" if "FAIL" in body else None,
"usage": {"input_tokens": 10, "output_tokens": 5}, "session": "/tmp/fake-session.jsonl"})
sys.exit(1 if "FAIL" in body else 0)