Files
orch/tests/fake_claude.py
T

24 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""Fake `claude -p` for the claude_cli provider (orch tests). It is the process that "executes tools": it reads the
file named in $FAKE_CLAUDE_READ the way the real claude would (directly, no hx involved) and writes what it saw to
./claude-read.txt, then answers. Logs argv to $FAKE_CLAUDE_LOG."""
import json, os, sys
if "--version" in sys.argv:
print("fake")
sys.exit(0)
open(os.environ.get("FAKE_CLAUDE_LOG", "/dev/null"), "a").write(json.dumps(sys.argv[1:]) + "\n")
out = lambda o: print(json.dumps(o), flush=True)
target = os.environ.get("FAKE_CLAUDE_READ")
if target:
try:
open("claude-read.txt", "w").write(open(target).read())
except OSError as e:
open("claude-read.txt", "w").write("ERR " + str(e))
out({"type": "system", "subtype": "init", "session_id": "S1"})
if os.environ.get("FAKE_CLAUDE_READ"):
out({"type": "assistant", "session_id": "S1", "message": {"content": [
{"type": "tool_use", "name": "Read", "input": {"file_path": os.environ["FAKE_CLAUDE_READ"]}}]}})
out({"type": "stream_event", "session_id": "S1", "event": {"type": "content_block_delta", "delta": {"type": "text_delta", "text": "done"}}})
out({"type": "result", "session_id": "S1", "is_error": False, "result": "done", "usage": {"input_tokens": 3, "output_tokens": 4}})