diff --git a/bin/loop_claude/test_black_box.py b/bin/loop_claude/test_black_box.py index de16ade3..d08131fe 100644 --- a/bin/loop_claude/test_black_box.py +++ b/bin/loop_claude/test_black_box.py @@ -157,7 +157,7 @@ class Run: code: int sleeps: list starts: list - # Without the local time that opens each message loop-claude prints. + # stderr and stdout are without the local time that opens each message loop-claude prints; raw_stderr and raw_stdout keep it. stderr: str stdout: str raw_stderr: str @@ -704,6 +704,7 @@ class Interrupt(unittest.TestCase): self.assertEqual(verdict, f"Task: {TASK}\n\n Verdict: interrupt\n\nA or B?\n\nEvidence:\n> Shall I use A or B?\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n\n Stopped: the human is needed to answer the question above, but stdin or stdout is not a terminal; rerun loop-claude on a terminal\n\nWorker: {OFF_LADDER}\n") self.assertEqual(stat.S_IMODE((checkout.temp / "deep").stat().st_mode), 0o700) self.assertIn(f"transcript: {checkout.archive() / 'proj'}/", run.stderr) + self.assertRegex(run.raw_stderr, rf"(?m)^{STAMP} transcript: ") session = argument(run.calls[0], "--session-id") run = checkout.run(steps, terminal_input="", stdout_on_terminal=False) self.assertEqual((run.code, run.roles()), (2, ["worker", "judge"])) diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index 5564eec6..8952bcf1 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -576,6 +576,22 @@ class Said(unittest.TestCase): say("\n=== cycle 2 ===", FakeEffects().effects(), stdout=True) self.assertEqual((stderr.getvalue(), stdout.getvalue()), ("", f"\n{STAMP} === cycle 2 ===\n")) + def test_keeps_the_indent_of_the_first_line_after_the_time(self): + with contextlib.redirect_stderr(io.StringIO()) as stderr: + say("\n indented", FakeEffects().effects()) + self.assertEqual(stderr.getvalue(), f"\n{STAMP} indented\n") + + def test_flushes_so_piped_lines_arrive_when_said(self): + flushes = [] + + class Counting(io.StringIO): + def flush(self): + flushes.append(self.getvalue()) + + with contextlib.redirect_stderr(Counting()): + say("hello", FakeEffects().effects()) + self.assertEqual(flushes, [f"{STAMP} hello\n"]) + class Limits(unittest.TestCase): def test_the_worker_reports_the_latest_reset_its_stream_names(self): @@ -1111,7 +1127,7 @@ class ChunkFacts(unittest.TestCase): class LocalTime(unittest.TestCase): def test_renders_seconds_in_the_machines_zone(self): - # A POSIX zone two hours ahead of UTC, so a time in UTC would read 14:13:20. Cleanups run last in, first out: the zone is restored before the clock rereads it. + # A POSIX zone two hours ahead of UTC, so a time in UTC would read 14:13:20. Cleanups run last in, first out: the zone is restored before time.tzset makes the clock read it again. self.addCleanup(time.tzset) zone = unittest.mock.patch.dict(os.environ, {"TZ": "XXX-2"}) zone.start()