Archive each review-replay and judge-replay run's transcript beside its result
CI / tests (pull_request) Failing after 2m52s

This commit is contained in:
2026-11-17 01:49:49 +01:00
parent f2a4347d78
commit 5aabbc87bf
11 changed files with 221 additions and 17 deletions
+6 -6
View File
@@ -1,4 +1,4 @@
"""One `claude -p --output-format json` run, as loop-claude's judge and the replays start it."""
"""One `claude -p --output-format stream-json` run, as loop-claude's judge and the replays start it."""
import dataclasses
import subprocess
import typing
@@ -17,18 +17,18 @@ class Limited:
said: str
# The json reply claude_reply parses; no persistence, so its runs stay out of the session picker; no permission prompt, as no one answers it.
HEADLESS = ["--no-session-persistence", "--output-format", "json", "--permission-mode", "bypassPermissions"]
# stream-json, whose last line claude_reply parses and whose every line a caller may keep as the run's transcript, which --no-session-persistence has Claude Code not write; -p needs --verbose with it. No permission prompt, as no one answers it.
HEADLESS = ["--no-session-persistence", "--output-format", "stream-json", "--verbose", "--permission-mode", "bypassPermissions"]
def claude_reply(claude: Claude, args: list[str], cwd: str, prompt: str, who: str) -> dict | Failure | Limited:
"""claude's json reply to `claude -p <args>` and HEADLESS, or why there is none; who, such as "the judge", names the run in the message for a non-zero exit or a reply that is no json."""
"""claude's reply to `claude -p <args>` and HEADLESS, the result event that ends its stream, or why there is none; who, such as "the judge", names the run in the message for a non-zero exit or a stream that ends in no json object."""
try:
proc = claude(["-p", *args, *HEADLESS], cwd, prompt)
except OSError as failure:
return Failure(f"could not start claude: {failure.strerror}")
reply = json_object(proc.stdout)
# The json output names the reset only in prose, such as "resets 7:40pm (Europe/Stockholm)", so its limit carries no reset time.
reply = json_object(proc.stdout.strip().rpartition("\n")[2])
# The result event names the reset only in prose, such as "resets 7:40pm (Europe/Stockholm)", so its limit carries no reset time.
if reply is not None and hit_limit(reply):
return Limited(None, limit_said(reply))
if proc.returncode != 0:
+5 -1
View File
@@ -199,7 +199,11 @@ class ClaudeReply(unittest.TestCase):
return subprocess.CompletedProcess(args, 0, "{}", "")
reply.claude_reply(run, ["--tools", ""], "/r", "p", "the judge")
self.assertEqual(asked, [(["-p", "--tools", "", "--no-session-persistence", "--output-format", "json", "--permission-mode", "bypassPermissions"], "/r", "p")])
self.assertEqual(asked, [(["-p", "--tools", "", "--no-session-persistence", "--output-format", "stream-json", "--verbose", "--permission-mode", "bypassPermissions"], "/r", "p")])
def test_reads_the_reply_from_the_streams_last_line(self):
stream = "\n".join(json.dumps(event) for event in ({"type": "system", "subtype": "init"}, {"type": "assistant"}, {"type": "result", "result": "ok"}))
self.assertEqual(reply.claude_reply(self.claude((0, stream + "\n", "")), [], "/r", "p", "the judge"), {"type": "result", "result": "ok"})
def test_returns_the_json_reply_a_usage_limit_whatever_the_exit_code_or_why_there_is_none(self):
self.assertEqual(reply.claude_reply(self.claude((0, '{"result": "ok"}', "")), [], "/r", "p", "the judge"), {"result": "ok"})