Test the compaction's boundaries, an unreadable transcript, a usage limit and the timer's daemon thread
CI / tests (pull_request) Successful in 3m21s
CI / tests (pull_request) Successful in 3m21s
This commit is contained in:
@@ -110,6 +110,7 @@ class FakeEffects:
|
||||
self.free_memory = list(free_memory)
|
||||
self.terminal = on_terminal
|
||||
self.worker_environments = []
|
||||
self.worker_folders = []
|
||||
self.terminal_environments = []
|
||||
self.terminal_folders = []
|
||||
# Each timer started, as its delay and action, which a test runs where the timer fires.
|
||||
@@ -161,6 +162,7 @@ class FakeEffects:
|
||||
|
||||
def stream(self, args, cwd, env):
|
||||
self.worker_environments.append(env)
|
||||
self.worker_folders.append(cwd)
|
||||
return self.answer("stream_claude", args)
|
||||
|
||||
def answer(self, seam, what):
|
||||
@@ -830,6 +832,7 @@ class Interrupts(unittest.TestCase):
|
||||
self.assertEqual([delay for delay, _ in fake.timers], [40 * 60])
|
||||
self.assertEqual([what for seam, what in fake.calls if seam == "stream_claude"], [["--model", "m", "--effort", "high", "--permission-mode", "bypassPermissions", "-p", "/compact", "--resume", str(self.session.id), "--output-format", "stream-json", "--verbose"]])
|
||||
self.assertEqual(fake.worker_environments, [self.session.env])
|
||||
self.assertEqual(fake.worker_folders, [self.session.root])
|
||||
self.assertIn(f"{STAMP} compacted the worker's claude session before its prompt cache expires; still waiting for an answer\n", said)
|
||||
|
||||
def test_an_answer_before_the_timer_fires_stops_it_and_compacts_nothing(self):
|
||||
@@ -845,7 +848,7 @@ class Interrupts(unittest.TestCase):
|
||||
self.assertEqual([call[0] for call in fake.calls if call[0] in ("stop_timer", "claude_on_terminal")], ["stop_timer", "claude_on_terminal"])
|
||||
|
||||
def test_starts_no_timer_under_60k_tokens_of_context_past_the_margin_on_a_five_minute_cache_or_where_claude_opens_at_once(self):
|
||||
for name, minutes_ago, written_1h, written_5m, read, answer_here in (("small", 10, 5000, 0, 50000, True), ("late", 51, 5000, 0, 70000, True), ("five minutes", 1, 0, 5000, 70000, True), ("opens at once", 10, 5000, 0, 70000, False)):
|
||||
for name, minutes_ago, written_1h, written_5m, read, answer_here in (("small", 10, 5000, 0, 54997, True), ("margin begun", 50, 5000, 0, 70000, True), ("five minutes", 1, 0, 5000, 70000, True), ("nothing written", 1, 0, 0, 70000, True), ("opens at once", 10, 5000, 0, 70000, False)):
|
||||
with self.subTest(name):
|
||||
self.transcript.write_text(json.dumps(human("a")) + "\n")
|
||||
self.worked(minutes_ago, written_1h, read, written_5m)
|
||||
@@ -853,6 +856,26 @@ class Interrupts(unittest.TestCase):
|
||||
self.put(fake, answer_here=answer_here)
|
||||
self.assertEqual(fake.timers, [])
|
||||
|
||||
def test_starts_the_timer_at_60k_tokens_of_context(self):
|
||||
self.worked(minutes_ago=10, read=54998)
|
||||
fake = FakeEffects(inputs=["Use B."])
|
||||
self.put(fake)
|
||||
self.assertEqual([delay for delay, _ in fake.timers], [40 * 60])
|
||||
|
||||
def test_starts_no_timer_where_the_transcript_cannot_be_read_and_still_asks(self):
|
||||
self.transcript.unlink()
|
||||
fake = FakeEffects(inputs=["Use B."])
|
||||
self.assertEqual(self.put(fake)[0], "Use B.")
|
||||
self.assertEqual(fake.timers, [])
|
||||
|
||||
def test_a_compaction_that_hits_a_usage_limit_says_the_limits_message_and_keeps_waiting(self):
|
||||
self.worked(minutes_ago=10)
|
||||
fake = FakeEffects(streams=[Streamed(0, {"type": "result", "api_error_status": 429, "result": "You've hit your session limit"})])
|
||||
fake.scripts["input"] = [self.fired(fake, "Use B.")]
|
||||
answer, said = self.put(fake)
|
||||
self.assertEqual(answer, "Use B.")
|
||||
self.assertIn(f"{STAMP} could not compact the worker's claude session: You've hit your session limit; still waiting for an answer\n", said)
|
||||
|
||||
def test_a_compaction_that_fails_says_why_and_keeps_waiting(self):
|
||||
self.worked(minutes_ago=10)
|
||||
fake = FakeEffects(streams=[Streamed(1)])
|
||||
|
||||
@@ -143,6 +143,13 @@ class Timer(unittest.TestCase):
|
||||
start_timer(0.05, ran.set)
|
||||
self.assertTrue(ran.wait(10))
|
||||
|
||||
def test_the_systems_timer_runs_on_a_daemon_thread_so_a_loop_that_exits_while_it_waits_does_not_wait_for_it(self):
|
||||
self.assertIs(system_effects().timer, start_timer)
|
||||
before = set(threading.enumerate())
|
||||
stop = start_timer(60, lambda: None)
|
||||
self.addCleanup(stop)
|
||||
self.assertEqual([thread.daemon for thread in set(threading.enumerate()) - before], [True])
|
||||
|
||||
def test_a_timer_stopped_before_its_delay_has_passed_never_runs_the_action(self):
|
||||
ran = threading.Event()
|
||||
start_timer(0.2, ran.set)()
|
||||
|
||||
Reference in New Issue
Block a user