-
Notifications
You must be signed in to change notification settings - Fork 9.8k
fix: disable Rich Live transient mode on Windows to prevent PS 5.1 hang #2938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mnriem
wants to merge
1
commit into
main
Choose a base branch
from
mnriem/fix-2927-init-hang-windows
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+89
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """Tests for Rich Live transient=False on Windows (GitHub issue #2927). | ||
|
|
||
| PowerShell 5.1's legacy console host does not support VT escape sequences | ||
| reliably. Rich's ``Live(transient=True)`` attempts cursor restoration on | ||
| exit, which hangs indefinitely on that console. The fix disables transient | ||
| mode when ``sys.platform == "win32"``. | ||
|
|
||
| These tests patch ``sys.platform`` and intercept the ``Live`` constructor | ||
| to verify the correct ``transient`` value reaches Rich. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # _console.py — Live in the select_with_arrows helper | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def _invoke_select_with_arrows(platform: str) -> bool: | ||
| """Patch sys.platform and Live, invoke select_with_arrows, return transient kwarg.""" | ||
| captured = {} | ||
|
|
||
| mock_live_instance = MagicMock() | ||
| mock_live_instance.__enter__ = MagicMock(return_value=mock_live_instance) | ||
| mock_live_instance.__exit__ = MagicMock(return_value=False) | ||
|
|
||
| def fake_live(*args, **kwargs): | ||
| captured.update(kwargs) | ||
| return mock_live_instance | ||
|
|
||
| # Patch readchar so the loop immediately returns "enter" | ||
| import readchar | ||
|
|
||
| with ( | ||
| patch("sys.platform", platform), | ||
| patch("specify_cli._console.Live", side_effect=fake_live), | ||
| patch("specify_cli._console.readchar.readkey", return_value=readchar.key.ENTER), | ||
| ): | ||
| from specify_cli._console import select_with_arrows | ||
|
|
||
| select_with_arrows({"a": "Option A", "b": "Option B"}, "Pick one", "a") | ||
|
|
||
| return captured.get("transient") | ||
|
|
||
|
|
||
|
|
||
| class TestSelectWithArrowsLiveTransient: | ||
| """Verify that select_with_arrows passes transient=False on Windows.""" | ||
|
|
||
| def test_transient_false_on_windows(self): | ||
| assert _invoke_select_with_arrows("win32") is False | ||
|
|
||
| def test_transient_true_on_linux(self): | ||
| assert _invoke_select_with_arrows("linux") is True | ||
|
|
||
| def test_transient_true_on_macos(self): | ||
| assert _invoke_select_with_arrows("darwin") is True | ||
|
Comment on lines
+50
to
+60
|
||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # init.py — verify source contains the platform guard (regression check) | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class TestSourceContainsPlatformGuard: | ||
| """Ensure the platform guard is present in source (prevents regression).""" | ||
|
|
||
| def test_init_has_win32_guard(self): | ||
| """init.py must contain the win32 platform check for transient.""" | ||
| init_src = Path(__file__).resolve().parent.parent / "src" / "specify_cli" / "commands" / "init.py" | ||
| content = init_src.read_text(encoding="utf-8") | ||
| assert '_transient = sys.platform != "win32"' in content | ||
|
Comment on lines
+73
to
+75
|
||
|
|
||
| def test_console_has_win32_guard(self): | ||
| """_console.py must contain the win32 platform check for transient.""" | ||
| console_src = Path(__file__).resolve().parent.parent / "src" / "specify_cli" / "_console.py" | ||
| content = console_src.read_text(encoding="utf-8") | ||
| assert '_transient = sys.platform != "win32"' in content | ||
|
Comment on lines
+79
to
+81
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.