langstage-cli 0.6.59__tar.gz → 0.6.61__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langstage_cli-0.6.59/langstage_cli.egg-info → langstage_cli-0.6.61}/PKG-INFO +1 -1
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/langstage_cli/cli.py +46 -8
- {langstage_cli-0.6.59 → langstage_cli-0.6.61/langstage_cli.egg-info}/PKG-INFO +1 -1
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/langstage_cli.egg-info/SOURCES.txt +2 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/pyproject.toml +1 -1
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_dumb_term.py +3 -1
- langstage_cli-0.6.61/tests/test_mintty_approval_219.py +145 -0
- langstage_cli-0.6.61/tests/test_nul_approval_217.py +123 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/LICENSE +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/README.md +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/deepagent_code/__init__.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/langstage_cli/__init__.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/langstage_cli/agui_stream.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/langstage_cli/config.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/langstage_cli/exit_codes.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/langstage_cli/sessions.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/langstage_cli.egg-info/dependency_links.txt +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/langstage_cli.egg-info/entry_points.txt +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/langstage_cli.egg-info/requires.txt +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/langstage_cli.egg-info/top_level.txt +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/setup.cfg +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_advertised_wave4.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_agui_stream.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_approval_menu_abort.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_approval_menu_keys_211.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_async_mode.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_checkpointer.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_cli.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_cli_help.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_codeconfig.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_config.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_config_command.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_configurable.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_ctrl_c_sync_tool.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_custom_decision_195.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_decision_shapes_209.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_deferred_pass.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_exit_codes.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_generic_interrupt.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_help_render.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_hidden_option_suggestions.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_history_persist.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_hitl_approval_preview.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_hitl_resume_warning.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_init.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_interrupt_answer_text_206.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_interrupt_non_tty.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_legacy_config_home.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_load_error.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_menu_allowed_197.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_message_boundaries.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_no_color.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_no_interactive_approve.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_no_persist_resume.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_paused_session_message.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_persist_env.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_quiet_output.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_quiet_tool_result_204.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_reasoning_render.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_rename_shim.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_render_markdown.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_routine_1024.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_session_agent_215.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_session_lifecycle.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_sessions.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_show_config.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_show_config_bare_spec_213.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_show_config_malformed.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_spec_loading_core.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_spec_resolution.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_spinner_reply_survives.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_stdin_interactive.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_stdin_single_shot.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_stream_mode.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_streaming_marker.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_terminal_width.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_toml_relative_paths.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_tool_card_args.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_tool_output_escape.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_turn_error_verbose.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_turn_exit_and_render.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_unicode_console.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_usage_hint_186.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_verbose_command.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_verify_flag.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_workspace.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.61}/tests/test_wrong_type_graph.py +0 -0
|
@@ -164,6 +164,26 @@ def _stdin_is_interactive(stream=None) -> bool:
|
|
|
164
164
|
return name is not None and _is_msys_pty_name(name)
|
|
165
165
|
|
|
166
166
|
|
|
167
|
+
def _stdin_drives_menu(stream=None) -> bool:
|
|
168
|
+
"""Whether the arrow-key approval menu can read keys from stdin (gh #217).
|
|
169
|
+
|
|
170
|
+
On POSIX the menu reads the stdin fd through termios, so it needs ``isatty()``.
|
|
171
|
+
On Windows ``get_key()`` reads keys with ``msvcrt.getch()``, which reads the
|
|
172
|
+
console, not stdin. So stdin itself has to be that console. ``NUL`` passes
|
|
173
|
+
``isatty()`` but isn't one: it used to reach the menu, and ``getch()`` then
|
|
174
|
+
waited forever for keys nobody would type. A mintty / Git Bash pty is a pipe that
|
|
175
|
+
``getch()`` can't read either, so it stays "not a terminal" for the menu, though
|
|
176
|
+
it does count as interactive for the REPL's own line input. If the console check
|
|
177
|
+
can't run, the ``isatty()`` answer stands.
|
|
178
|
+
"""
|
|
179
|
+
stream = sys.stdin if stream is None else stream
|
|
180
|
+
tty = _is_a_tty(stream)
|
|
181
|
+
if not IS_WINDOWS or not tty:
|
|
182
|
+
return tty
|
|
183
|
+
console = _win_is_console(stream)
|
|
184
|
+
return tty if console is None else console
|
|
185
|
+
|
|
186
|
+
|
|
167
187
|
def _disable_ansi() -> None:
|
|
168
188
|
"""Blank every ANSI constant so nothing colorized reaches a pipe, a file or a
|
|
169
189
|
``NO_COLOR`` terminal (gh #172).
|
|
@@ -1870,12 +1890,18 @@ def select_option(options: List[str], prompt: str = "Select an option:") -> int:
|
|
|
1870
1890
|
|
|
1871
1891
|
|
|
1872
1892
|
def _select_option_typed(options: List[str], prompt: str) -> int:
|
|
1873
|
-
"""The approval menu
|
|
1893
|
+
"""The approval menu as a numbered list and a typed choice.
|
|
1874
1894
|
|
|
1875
1895
|
The arrow-key menu redraws itself with cursor-up and line-clear escapes, which a
|
|
1876
1896
|
dumb terminal prints as literal text, and editor shells (Emacs ``M-x shell``) send
|
|
1877
|
-
whole lines, not keypresses.
|
|
1878
|
-
|
|
1897
|
+
whole lines, not keypresses (gh #182). A mintty / Git Bash pty on Windows feeds
|
|
1898
|
+
lines to stdin but not the keypresses ``msvcrt.getch()`` reads, so it gets this
|
|
1899
|
+
menu too (gh #219).
|
|
1900
|
+
|
|
1901
|
+
A choice is the option's number, or a word that starts exactly one option's label
|
|
1902
|
+
(``a`` or ``approve`` for "Approve all actions", ``r``, ``e`` ...). Enter alone
|
|
1903
|
+
picks the first option. ``q``, Ctrl-C or end of input abandon the prompt the same
|
|
1904
|
+
way the arrow-key menu's Esc does: exit 2, paused.
|
|
1879
1905
|
"""
|
|
1880
1906
|
print(f"\n{prompt}")
|
|
1881
1907
|
for i, opt in enumerate(options, 1):
|
|
@@ -1890,7 +1916,14 @@ def _select_option_typed(options: List[str], prompt: str) -> int:
|
|
|
1890
1916
|
return 0
|
|
1891
1917
|
if raw.isdigit() and 1 <= int(raw) <= len(options):
|
|
1892
1918
|
return int(raw) - 1
|
|
1893
|
-
|
|
1919
|
+
word = raw.lower()
|
|
1920
|
+
if word in ("q", "quit"):
|
|
1921
|
+
print()
|
|
1922
|
+
sys.exit(EXIT_PAUSED)
|
|
1923
|
+
matches = [i for i, opt in enumerate(options) if opt.lower().startswith(word)]
|
|
1924
|
+
if len(matches) == 1:
|
|
1925
|
+
return matches[0]
|
|
1926
|
+
print(f"Enter a number from 1 to {len(options)}, or the start of an option's name.")
|
|
1894
1927
|
|
|
1895
1928
|
|
|
1896
1929
|
def _prompt_line(prompt: str) -> str:
|
|
@@ -1943,8 +1976,12 @@ def handle_interrupt_input(
|
|
|
1943
1976
|
# printed, and fail loudly rather than auto-approving: an interrupt() is a request
|
|
1944
1977
|
# for human review, so silently approving an action nobody saw is worse than
|
|
1945
1978
|
# stopping. `--no-interactive` remains the documented way to opt into
|
|
1946
|
-
# auto-approval, and the message points at it. (gh #86)
|
|
1947
|
-
|
|
1979
|
+
# auto-approval, and the message points at it. (gh #86) On Windows `<NUL` passes
|
|
1980
|
+
# isatty() but can't feed the menu's msvcrt.getch(), so it's checked too (gh #217).
|
|
1981
|
+
# A mintty / Git Bash pty is a person at a terminal whose keypresses getch() can't
|
|
1982
|
+
# read either, but it does feed lines, so it gets the typed menu (gh #219).
|
|
1983
|
+
typed = not _stdin_drives_menu() and _stdin_is_interactive()
|
|
1984
|
+
if not typed and not _stdin_drives_menu():
|
|
1948
1985
|
print(
|
|
1949
1986
|
"Error: approval required but stdin is not a terminal.\n"
|
|
1950
1987
|
"Re-run with --no-interactive to auto-approve pending actions.",
|
|
@@ -1952,6 +1989,7 @@ def handle_interrupt_input(
|
|
|
1952
1989
|
)
|
|
1953
1990
|
# The run is fine but paused on human input: the family "paused" code (ADR 0007).
|
|
1954
1991
|
sys.exit(EXIT_PAUSED)
|
|
1992
|
+
pick = _select_option_typed if typed else select_option
|
|
1955
1993
|
|
|
1956
1994
|
if is_generic:
|
|
1957
1995
|
# A generic interrupt() asks for an arbitrary value, not tool approval, so
|
|
@@ -1961,7 +1999,7 @@ def handle_interrupt_input(
|
|
|
1961
1999
|
# case, where the user types `Alice` and the agent must receive `"Alice"`,
|
|
1962
2000
|
# not an envelope. What was typed is the answer, as text (gh #206).
|
|
1963
2001
|
options = ["Provide a response", "Exit"]
|
|
1964
|
-
choice =
|
|
2002
|
+
choice = pick(options, "How would you like to respond?")
|
|
1965
2003
|
if choice != 0:
|
|
1966
2004
|
sys.exit(EXIT_PAUSED) # left while paused on the interrupt (ADR 0007)
|
|
1967
2005
|
print(
|
|
@@ -1982,7 +2020,7 @@ def handle_interrupt_input(
|
|
|
1982
2020
|
options = [label for label, _ in entries]
|
|
1983
2021
|
|
|
1984
2022
|
while True:
|
|
1985
|
-
action = entries[
|
|
2023
|
+
action = entries[pick(options, "How would you like to proceed?")][1]
|
|
1986
2024
|
|
|
1987
2025
|
if action in ("approve", "reject"):
|
|
1988
2026
|
return {"decisions": [{"type": action} for _ in range(num_actions)]}
|
|
@@ -45,9 +45,11 @@ tests/test_legacy_config_home.py
|
|
|
45
45
|
tests/test_load_error.py
|
|
46
46
|
tests/test_menu_allowed_197.py
|
|
47
47
|
tests/test_message_boundaries.py
|
|
48
|
+
tests/test_mintty_approval_219.py
|
|
48
49
|
tests/test_no_color.py
|
|
49
50
|
tests/test_no_interactive_approve.py
|
|
50
51
|
tests/test_no_persist_resume.py
|
|
52
|
+
tests/test_nul_approval_217.py
|
|
51
53
|
tests/test_paused_session_message.py
|
|
52
54
|
tests/test_persist_env.py
|
|
53
55
|
tests/test_quiet_output.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "langstage-cli"
|
|
7
|
-
version = "0.6.
|
|
7
|
+
version = "0.6.61"
|
|
8
8
|
description = "The terminal stage for your LangGraph agent — Claude Code-style CLI for any CompiledGraph"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -96,7 +96,9 @@ def test_menu_asks_again_on_a_bad_choice(dumb, monkeypatch):
|
|
|
96
96
|
with redirect_stdout(buf):
|
|
97
97
|
assert cli.select_option(["Approve", "Reject"]) == 1
|
|
98
98
|
assert len(prompts) == 3
|
|
99
|
-
assert
|
|
99
|
+
assert (
|
|
100
|
+
buf.getvalue().count("Enter a number from 1 to 2, or the start of an option's name.") == 2
|
|
101
|
+
)
|
|
100
102
|
|
|
101
103
|
|
|
102
104
|
@pytest.mark.parametrize("abort", [KeyboardInterrupt(), EOFError()], ids=["ctrl-c", "eof"])
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Approvals can be answered in a mintty / Git Bash terminal (gh #219).
|
|
2
|
+
|
|
3
|
+
On Windows a mintty pty is a pipe with an MSYS pty name. It counts as interactive, so
|
|
4
|
+
the REPL runs, but the arrow-key approval menu reads keys with ``msvcrt.getch()``,
|
|
5
|
+
which can't read it. Since gh #217 the first approval therefore exited 2. The menu now
|
|
6
|
+
falls back to the typed, line-based menu there: a number, or a word that starts one
|
|
7
|
+
option's name. ``NUL`` and real pipes still exit 2.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import builtins
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from langstage_cli import cli
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _mintty(monkeypatch):
|
|
18
|
+
monkeypatch.setattr(cli, "_stdin_drives_menu", lambda stream=None: False)
|
|
19
|
+
monkeypatch.setattr(cli, "_stdin_is_interactive", lambda stream=None: True)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _feed(monkeypatch, *lines):
|
|
23
|
+
it = iter(lines)
|
|
24
|
+
|
|
25
|
+
def fake_input(prompt=""):
|
|
26
|
+
try:
|
|
27
|
+
return next(it)
|
|
28
|
+
except StopIteration:
|
|
29
|
+
raise EOFError from None
|
|
30
|
+
|
|
31
|
+
monkeypatch.setattr(builtins, "input", fake_input)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _no_keys(monkeypatch):
|
|
35
|
+
def boom():
|
|
36
|
+
raise AssertionError("the arrow-key menu must not read keys here")
|
|
37
|
+
|
|
38
|
+
monkeypatch.setattr(cli, "get_key", boom)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@pytest.mark.parametrize(
|
|
42
|
+
"answer, verb",
|
|
43
|
+
[
|
|
44
|
+
("1", "approve"),
|
|
45
|
+
("2", "reject"),
|
|
46
|
+
("a", "approve"),
|
|
47
|
+
("approve", "approve"),
|
|
48
|
+
("R", "reject"),
|
|
49
|
+
("Reject", "reject"),
|
|
50
|
+
("", "approve"),
|
|
51
|
+
],
|
|
52
|
+
)
|
|
53
|
+
def test_mintty_answers_the_approval_with_a_typed_line(monkeypatch, capsys, answer, verb):
|
|
54
|
+
_mintty(monkeypatch)
|
|
55
|
+
_no_keys(monkeypatch)
|
|
56
|
+
_feed(monkeypatch, answer)
|
|
57
|
+
result = cli.handle_interrupt_input(num_actions=2)
|
|
58
|
+
assert result == {"decisions": [{"type": verb}, {"type": verb}]}
|
|
59
|
+
out = capsys.readouterr().out
|
|
60
|
+
assert "1. Approve all actions" in out
|
|
61
|
+
assert "\033[?25l" not in out # no cursor escapes from the arrow-key menu
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@pytest.mark.parametrize("answer", ["4", "e", "exit", "q", "quit"])
|
|
65
|
+
def test_mintty_leaving_the_menu_exits_paused(monkeypatch, answer):
|
|
66
|
+
_mintty(monkeypatch)
|
|
67
|
+
_no_keys(monkeypatch)
|
|
68
|
+
_feed(monkeypatch, answer)
|
|
69
|
+
with pytest.raises(SystemExit) as exc:
|
|
70
|
+
cli.handle_interrupt_input(num_actions=1)
|
|
71
|
+
assert exc.value.code == cli.EXIT_PAUSED
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_mintty_end_of_input_exits_paused(monkeypatch):
|
|
75
|
+
_mintty(monkeypatch)
|
|
76
|
+
_no_keys(monkeypatch)
|
|
77
|
+
_feed(monkeypatch) # EOF at once
|
|
78
|
+
with pytest.raises(SystemExit) as exc:
|
|
79
|
+
cli.handle_interrupt_input(num_actions=1)
|
|
80
|
+
assert exc.value.code == cli.EXIT_PAUSED
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_mintty_unknown_answer_asks_again(monkeypatch, capsys):
|
|
84
|
+
_mintty(monkeypatch)
|
|
85
|
+
_no_keys(monkeypatch)
|
|
86
|
+
_feed(monkeypatch, "maybe", "9", "a")
|
|
87
|
+
assert cli.handle_interrupt_input(num_actions=1) == {"decisions": [{"type": "approve"}]}
|
|
88
|
+
out = capsys.readouterr().out
|
|
89
|
+
assert out.count("or the start of an option's name") == 2
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_mintty_generic_interrupt_takes_a_typed_answer(monkeypatch):
|
|
93
|
+
_mintty(monkeypatch)
|
|
94
|
+
_no_keys(monkeypatch)
|
|
95
|
+
_feed(monkeypatch, "p", "Alice")
|
|
96
|
+
assert cli.handle_interrupt_input(is_generic=True) == "Alice"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_mintty_custom_decision_flow(monkeypatch):
|
|
100
|
+
_mintty(monkeypatch)
|
|
101
|
+
_no_keys(monkeypatch)
|
|
102
|
+
_feed(monkeypatch, "3", '[{"type": "reject", "message": "not now"}]')
|
|
103
|
+
assert cli.handle_interrupt_input(num_actions=1) == {
|
|
104
|
+
"decisions": [{"type": "reject", "message": "not now"}]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_mintty_honours_allowed_decisions(monkeypatch, capsys):
|
|
109
|
+
# An approve-only action offers no "Reject all", so "r" matches nothing.
|
|
110
|
+
_mintty(monkeypatch)
|
|
111
|
+
_no_keys(monkeypatch)
|
|
112
|
+
_feed(monkeypatch, "r", "a")
|
|
113
|
+
interrupt = {
|
|
114
|
+
"action_requests": [{"name": "send_email", "args": {}}],
|
|
115
|
+
"review_configs": [{"action_name": "send_email", "allowed_decisions": ["approve"]}],
|
|
116
|
+
}
|
|
117
|
+
assert cli.handle_interrupt_input(num_actions=1, interrupt=interrupt) == {
|
|
118
|
+
"decisions": [{"type": "approve"}]
|
|
119
|
+
}
|
|
120
|
+
assert "Reject all actions" not in capsys.readouterr().out
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_ambiguous_prefix_asks_again(monkeypatch):
|
|
124
|
+
_feed(monkeypatch, "rej", "2")
|
|
125
|
+
assert cli._select_option_typed(["Reject all", "Reject one"], "Pick") == 1
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_not_interactive_still_exits_paused(monkeypatch, capsys):
|
|
129
|
+
# NUL or a real pipe: neither drives the menu nor counts as a person (gh #217).
|
|
130
|
+
monkeypatch.setattr(cli, "_stdin_drives_menu", lambda stream=None: False)
|
|
131
|
+
monkeypatch.setattr(cli, "_stdin_is_interactive", lambda stream=None: False)
|
|
132
|
+
_no_keys(monkeypatch)
|
|
133
|
+
with pytest.raises(SystemExit) as exc:
|
|
134
|
+
cli.handle_interrupt_input(num_actions=1)
|
|
135
|
+
assert exc.value.code == cli.EXIT_PAUSED
|
|
136
|
+
assert "approval required but stdin is not a terminal" in capsys.readouterr().err
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_real_console_keeps_the_arrow_menu(monkeypatch, capsys):
|
|
140
|
+
monkeypatch.setattr(cli, "_stdin_drives_menu", lambda stream=None: True)
|
|
141
|
+
monkeypatch.setattr(cli, "_stdin_is_interactive", lambda stream=None: True)
|
|
142
|
+
monkeypatch.setattr(cli, "_DUMB_TERM", False)
|
|
143
|
+
monkeypatch.setattr(cli, "get_key", lambda: "enter")
|
|
144
|
+
assert cli.handle_interrupt_input(num_actions=1) == {"decisions": [{"type": "approve"}]}
|
|
145
|
+
assert "Choose 1-" not in capsys.readouterr().out
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""An approval with stdin from ``NUL`` exits 2 instead of hanging (gh #217).
|
|
2
|
+
|
|
3
|
+
On Windows ``NUL`` is a character device, so ``isatty()`` is True for ``<NUL``. The
|
|
4
|
+
approval guard used a plain ``isatty()``, let the run into the arrow-key menu, and
|
|
5
|
+
``msvcrt.getch()`` (which reads the console, not stdin) then waited forever. Task
|
|
6
|
+
Scheduler, services, CI runners and ``subprocess.run(..., stdin=DEVNULL)`` all hand a
|
|
7
|
+
process ``NUL``, so an unattended approval-gated run never ended. The guard now asks
|
|
8
|
+
whether stdin can actually drive the menu.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
import textwrap
|
|
14
|
+
|
|
15
|
+
import pytest
|
|
16
|
+
from click.testing import CliRunner
|
|
17
|
+
|
|
18
|
+
from langstage_cli import cli
|
|
19
|
+
from langstage_cli.cli import main
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class _Stream:
|
|
23
|
+
def __init__(self, tty: bool):
|
|
24
|
+
self._tty = tty
|
|
25
|
+
|
|
26
|
+
def isatty(self) -> bool:
|
|
27
|
+
return self._tty
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _on_windows(monkeypatch, *, console=None, name=None):
|
|
31
|
+
monkeypatch.setattr(cli, "IS_WINDOWS", True)
|
|
32
|
+
monkeypatch.setattr(cli, "_win_is_console", lambda stream: console)
|
|
33
|
+
monkeypatch.setattr(cli, "_win_handle_name", lambda stream: name)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_windows_console_drives_the_menu(monkeypatch):
|
|
37
|
+
_on_windows(monkeypatch, console=True)
|
|
38
|
+
assert cli._stdin_drives_menu(_Stream(tty=True)) is True
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_windows_nul_does_not_drive_the_menu(monkeypatch):
|
|
42
|
+
# isatty() is True for NUL, but GetConsoleMode fails on it.
|
|
43
|
+
_on_windows(monkeypatch, console=False)
|
|
44
|
+
assert cli._stdin_drives_menu(_Stream(tty=True)) is False
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_windows_console_check_unavailable_keeps_isatty(monkeypatch):
|
|
48
|
+
_on_windows(monkeypatch, console=None)
|
|
49
|
+
assert cli._stdin_drives_menu(_Stream(tty=True)) is True
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_windows_mintty_pty_does_not_drive_the_menu(monkeypatch):
|
|
53
|
+
# A mintty pty is interactive for line input, but msvcrt.getch() can't read it,
|
|
54
|
+
# so the menu keeps refusing it cleanly (exit 2) rather than hanging.
|
|
55
|
+
_on_windows(monkeypatch, name="\\msys-dd50a72ab4668b33-pty0-from-master")
|
|
56
|
+
assert cli._stdin_is_interactive(_Stream(tty=False)) is True
|
|
57
|
+
assert cli._stdin_drives_menu(_Stream(tty=False)) is False
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@pytest.mark.parametrize("tty", [True, False])
|
|
61
|
+
def test_posix_is_plain_isatty(monkeypatch, tty):
|
|
62
|
+
monkeypatch.setattr(cli, "IS_WINDOWS", False)
|
|
63
|
+
assert cli._stdin_drives_menu(_Stream(tty=tty)) is tty
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
_HITL_AGENT = textwrap.dedent(
|
|
67
|
+
"""
|
|
68
|
+
from langgraph.graph import StateGraph, START, END
|
|
69
|
+
from langgraph.graph.message import MessagesState
|
|
70
|
+
from langgraph.checkpoint.memory import MemorySaver
|
|
71
|
+
from langgraph.types import interrupt
|
|
72
|
+
from langchain_core.messages import AIMessage
|
|
73
|
+
|
|
74
|
+
def ask(state):
|
|
75
|
+
decision = interrupt({"action": "delete_file", "path": "/tmp/x"})
|
|
76
|
+
return {"messages": [AIMessage(content=f"Decision was: {decision}")]}
|
|
77
|
+
|
|
78
|
+
g = StateGraph(MessagesState)
|
|
79
|
+
g.add_node("ask", ask)
|
|
80
|
+
g.add_edge(START, "ask")
|
|
81
|
+
g.add_edge("ask", END)
|
|
82
|
+
graph = g.compile(checkpointer=MemorySaver())
|
|
83
|
+
"""
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_nul_stdin_approval_exits_paused_without_reading_keys(tmp_path, monkeypatch):
|
|
88
|
+
# Simulate Windows `<NUL`: isatty() True, not a console.
|
|
89
|
+
(tmp_path / "hitl_agent.py").write_text(_HITL_AGENT)
|
|
90
|
+
monkeypatch.chdir(tmp_path)
|
|
91
|
+
monkeypatch.setattr(cli, "IS_WINDOWS", True)
|
|
92
|
+
monkeypatch.setattr(cli, "_win_is_console", lambda stream: False)
|
|
93
|
+
monkeypatch.setattr(cli, "_is_a_tty", lambda stream: True)
|
|
94
|
+
|
|
95
|
+
def _no_keys():
|
|
96
|
+
raise AssertionError("the menu must not read keys from NUL")
|
|
97
|
+
|
|
98
|
+
monkeypatch.setattr(cli, "get_key", _no_keys)
|
|
99
|
+
r = CliRunner().invoke(main, ["-a", "hitl_agent.py:graph", "please act"])
|
|
100
|
+
|
|
101
|
+
assert r.exit_code == 2, (r.exit_code, r.output, r.exception)
|
|
102
|
+
assert "approval required but stdin is not a terminal" in r.stderr, r.stderr
|
|
103
|
+
assert "--no-interactive" in r.stderr, r.stderr
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@pytest.mark.skipif(sys.platform != "win32", reason="NUL passes isatty() only on Windows")
|
|
107
|
+
def test_real_devnull_run_exits_2_instead_of_hanging():
|
|
108
|
+
proc = subprocess.run(
|
|
109
|
+
[
|
|
110
|
+
sys.executable,
|
|
111
|
+
"-c",
|
|
112
|
+
"from langstage_cli.cli import main; main()",
|
|
113
|
+
"-a",
|
|
114
|
+
"langstage_core.demo.tools:graph",
|
|
115
|
+
"ask me",
|
|
116
|
+
],
|
|
117
|
+
stdin=subprocess.DEVNULL,
|
|
118
|
+
capture_output=True,
|
|
119
|
+
text=True,
|
|
120
|
+
timeout=120,
|
|
121
|
+
)
|
|
122
|
+
assert proc.returncode == 2, (proc.returncode, proc.stdout, proc.stderr)
|
|
123
|
+
assert "approval required but stdin is not a terminal" in proc.stderr, proc.stderr
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|