Pin that a non-UTF-8 byte in the worker's stream is skipped
This commit is contained in:
@@ -67,6 +67,8 @@ if role == "worker":
|
|||||||
if "replace" in step:
|
if "replace" in step:
|
||||||
script = pathlib.Path(os.environ["FAKE_CLAUDE_EDIT"])
|
script = pathlib.Path(os.environ["FAKE_CLAUDE_EDIT"])
|
||||||
script.write_text(script.read_text().replace(*step["replace"]))
|
script.write_text(script.read_text().replace(*step["replace"]))
|
||||||
|
sys.stdout.flush()
|
||||||
|
sys.stdout.buffer.write(step.get("stream", "").encode("latin-1"))
|
||||||
print(json.dumps(said))
|
print(json.dumps(said))
|
||||||
if step.get("result", True):
|
if step.get("result", True):
|
||||||
print(json.dumps({{"type": "result"}}))
|
print(json.dumps({{"type": "result"}}))
|
||||||
@@ -319,11 +321,12 @@ class Cycles(unittest.TestCase):
|
|||||||
self.assertEqual(run.roles(), ["worker", "judge", "judge", "worker"])
|
self.assertEqual(run.roles(), ["worker", "judge", "judge", "worker"])
|
||||||
self.assertIn("the judge quoted 'never said', nothing in the transcript, for the question: A or B?", run.stderr)
|
self.assertIn("the judge quoted 'never said', nothing in the transcript, for the question: A or B?", run.stderr)
|
||||||
|
|
||||||
def test_skips_a_malformed_transcript_line(self):
|
def test_skips_a_malformed_transcript_or_stream_line(self):
|
||||||
checkout = Checkout(self)
|
checkout = Checkout(self)
|
||||||
raw = "\xff not UTF-8\nnot JSON\n[1]\n" + json.dumps({"type": "assistant", "message": "not an object"}) + "\n" + json.dumps({"type": "user", "message": None}) + "\n"
|
raw = "\xff not UTF-8\nnot JSON\n[1]\n" + json.dumps({"type": "assistant", "message": "not an object"}) + "\n" + json.dumps({"type": "user", "message": None}) + "\n"
|
||||||
run = checkout.run([worker(raw=raw, say="past the noise"), judge()])
|
run = checkout.run([worker(raw=raw, say="past the noise", stream="\xff not UTF-8\n"), judge()])
|
||||||
self.assertEqual((run.code, run.roles()), (130, ["worker", "judge", "worker"]))
|
self.assertEqual((run.code, run.roles()), (130, ["worker", "judge", "worker"]))
|
||||||
|
self.assertIn("past the noise", run.stdout)
|
||||||
self.assertIn("past the noise", run.calls[1]["stdin"])
|
self.assertIn("past the noise", run.calls[1]["stdin"])
|
||||||
|
|
||||||
@unittest.skipIf(os.geteuid() == 0, "root reads an unreadable file")
|
@unittest.skipIf(os.geteuid() == 0, "root reads an unreadable file")
|
||||||
|
|||||||
Reference in New Issue
Block a user