From 33e64fd83cfc1c4c061a276d3314b8a3a4b62b7b Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 19 Aug 2026 22:55:44 -0700 Subject: [PATCH] test: capture worktree messages through the _cprint route --- tests/hermes_cli/test_worktree_command.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/hermes_cli/test_worktree_command.py b/tests/hermes_cli/test_worktree_command.py index af6563794f..bf9443e771 100644 --- a/tests/hermes_cli/test_worktree_command.py +++ b/tests/hermes_cli/test_worktree_command.py @@ -28,8 +28,24 @@ class _Stub(CLICommandsMixin): def _run(stub, command): + """Capture handler output. + + Worktree messages route through ``cli._cprint`` (the ANSI-aware + prompt_toolkit renderer) since the garbled-escape fix; its output binds + to the prompt_toolkit session output object, not ``sys.stdout``, so + ``redirect_stdout`` alone cannot capture it. Mirror ``_cprint`` into the + same buffer to keep asserting the user-visible text. + """ + import re + from unittest.mock import patch as _patch + buf = io.StringIO() - with contextlib.redirect_stdout(buf): + ansi = re.compile(r"\x1b\[[0-9;]*m") + + def _fake_cprint(text): + buf.write(ansi.sub("", str(text)) + "\n") + + with contextlib.redirect_stdout(buf), _patch.object(cli_mod, "_cprint", _fake_cprint): stub._handle_worktree_command(command) return buf.getvalue()