From fffa3442ba8a43bc699cfbbd3afc7dc73e27ec9e Mon Sep 17 00:00:00 2001 From: Mohammed Alkindi Date: Sat, 15 Aug 2026 02:47:35 +0400 Subject: [PATCH] test: isolate the prompt_toolkit app session so UI tests run on Windows Building a prompt_toolkit Application binds the ambient AppSession's output, and constructing that output probes the terminal. Under pytest's captured stdout on Windows the probe raises NoConsoleScreenBufferError, so every test that builds UI fails there. Linux CI never sees it because the POSIX Vt100 output has no equivalent probe. Bind a DummyOutput and a pipe input for the duration of each test, which is the documented prompt_toolkit pattern for this and also stops the tests reaching for the real terminal when run locally. On Windows this takes tests/unit from 231 failures to 200, and removes all 62 NoConsoleScreenBufferError occurrences. Totals reconcile at 7408 either way, so no previously-passing test changes state. --- tests/conftest.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 9e367b5d4..24029ea8e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +1,32 @@ from __future__ import annotations import pytest +from prompt_toolkit.application import create_app_session +from prompt_toolkit.input import create_pipe_input +from prompt_toolkit.output import DummyOutput from fast_agent.integrations import herdr_lifecycle +@pytest.fixture(autouse=True) +def isolate_prompt_toolkit_app_session(): + """Give every test its own prompt_toolkit app session, detached from the terminal. + + Building a prompt_toolkit Application binds the ambient AppSession's output, + and constructing that output probes the terminal. Under pytest's captured + stdout on Windows the probe raises NoConsoleScreenBufferError, so every test + that builds UI fails there — while Linux CI never sees it, because the POSIX + Vt100 output has no equivalent probe. + + Binding a DummyOutput and a pipe input makes the session explicit rather than + ambient, which is also what keeps these tests from touching the real terminal + when they are run locally. + """ + with create_pipe_input() as pipe_input: + with create_app_session(input=pipe_input, output=DummyOutput()): + yield + + @pytest.fixture(autouse=True) def isolate_herdr_lifecycle(monkeypatch: pytest.MonkeyPatch): """Prevent tests run inside Herdr from reporting against the developer's pane."""