test(cli): deterministically join bg worker thread instead of polling deadline

test_background_task_registers_thread_local_approval_callbacks polled a
2s wall-clock deadline waiting for the background daemon thread to pop
its entry from _background_tasks. Under loaded CI the thread's
finally-block cleanup could lag the deadline, flaking the final
'assert not cli._background_tasks'. Join the actual worker thread
(timeout=10) so the wait ends exactly when the thread finishes.
This commit is contained in:
teknium1 2026-06-30 03:53:23 -07:00 committed by Teknium
parent 6148a9a3fe
commit 1cae1bd0de

View file

@ -354,9 +354,11 @@ class TestCliApprovalUi:
chat_console.return_value.print = MagicMock()
cli._handle_background_command("/btw check weather")
deadline = time.time() + 2
while cli._background_tasks and time.time() < deadline:
time.sleep(0.01)
# Join the worker thread deterministically rather than polling a
# wall-clock deadline — under load the thread's finally-block pop
# of _background_tasks can lag a fixed timeout, which flaked CI.
for _thread in list(cli._background_tasks.values()):
_thread.join(timeout=10)
assert seen["approval"].__self__ is cli
assert seen["approval"].__func__ is HermesCLI._approval_callback