Merge remote-tracking branch 'origin/main' into item-420

# Conflicts:
#	bin/loop_claude/test_loop_claude.py
#	bin/loop_effects/test_effects.py
This commit is contained in:
2026-11-19 07:46:23 +01:00
162 changed files with 8606 additions and 1433 deletions
+34 -1
View File
@@ -7,6 +7,7 @@ import signal
import subprocess
import sys
import tempfile
import threading
import time
import unittest
import unittest.mock
@@ -14,7 +15,7 @@ import unittest.mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from loop_effects import child_shells
from loop_effects.effects import run_python, say, StreamingClaude, system_effects
from loop_effects.effects import run_python, say, start_timer, StreamingClaude, system_effects
NOW = 1790000000
# How a line said at NOW opens, with clocked's local_time.
@@ -283,3 +284,35 @@ class StreamingClaudeLines(unittest.TestCase):
return
time.sleep(0.05)
self.fail("the shell did not start")
class Timer(unittest.TestCase):
def test_runs_the_action_beside_the_caller_once_the_delay_has_passed(self):
ran = threading.Event()
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()
# stop returns once the timer's thread has ended, so the action cannot run later.
start_timer(0.2, ran.set)()
self.assertFalse(ran.is_set())
def test_stopping_a_timer_whose_action_runs_waits_for_the_action_to_end(self):
started, ended = threading.Event(), threading.Event()
def action():
started.set()
time.sleep(0.2)
ended.set()
stop = start_timer(0, action)
self.assertTrue(started.wait(10))
stop()
self.assertTrue(ended.is_set())