33import subprocess
44import threading
55import time
6- from pathlib import Path
6+ from dataclasses import replace
77from unittest .mock import patch
88
9- from ralphify ._events import Event , EventType , NullEmitter , QueueEmitter
10- from ralphify .engine import RunConfig , RunState , RunStatus
9+ from ralphify ._events import Event , EventType , QueueEmitter
10+ from ralphify .engine import RunConfig , RunStatus
1111from ralphify .manager import ManagedRun , RunManager , _FanoutEmitter
1212
1313_MOCK_SUBPROCESS = "ralphify.engine.subprocess.run"
@@ -18,15 +18,14 @@ def _make_config(tmp_path, **overrides):
1818 prompt_path = tmp_path / "PROMPT.md"
1919 if not prompt_path .exists ():
2020 prompt_path .write_text ("test prompt" )
21- defaults = dict (
21+ config = RunConfig (
2222 command = "echo" ,
2323 args = [],
2424 prompt_file = str (prompt_path ),
2525 max_iterations = 1 ,
2626 project_root = tmp_path ,
2727 )
28- defaults .update (overrides )
29- return RunConfig (** defaults )
28+ return replace (config , ** overrides ) if overrides else config
3029
3130
3231def _ok (* args , ** kwargs ):
@@ -104,6 +103,7 @@ def test_start_run_emits_events_to_queue(self, mock_run, tmp_path):
104103 run_id = managed .state .run_id
105104
106105 manager .start_run (run_id )
106+ assert managed .thread is not None
107107 managed .thread .join (timeout = 5 )
108108
109109 events = []
@@ -128,6 +128,7 @@ def test_stop_run_stops_running_run(self, mock_run, tmp_path):
128128 time .sleep (0.05 )
129129
130130 manager .stop_run (run_id )
131+ assert managed .thread is not None
131132 managed .thread .join (timeout = 5 )
132133
133134 assert managed .state .status == RunStatus .STOPPED
@@ -169,6 +170,7 @@ def counting_ok(*args, **kwargs):
169170 time .sleep (0.05 )
170171 manager .resume_run (run_id )
171172
173+ assert managed .thread is not None
172174 managed .thread .join (timeout = 5 )
173175 assert managed .state .completed == 3
174176
@@ -232,6 +234,7 @@ def test_extra_listeners_receive_events(self, mock_run, tmp_path):
232234 managed .add_listener (extra )
233235
234236 manager .start_run (run_id )
237+ assert managed .thread is not None
235238 managed .thread .join (timeout = 5 )
236239
237240 # Both the primary emitter and the extra listener should have events
0 commit comments