Skip to content

Commit b880b71

Browse files
committed
fix windows shellcompletion race
1 parent 2879337 commit b880b71

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

tests/shellcompletion/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,17 @@ def _ensure_shell(self) -> None:
316316
self.shell, *([self.interactive_opt] if self.interactive_opt else [])
317317
)
318318

319-
# Wait for first prompt by echoing a sentinel; the shell will
320-
# process it once the prompt is ready.
321-
sentinel = self._next_sentinel()
322-
self._write_shell(f"echo {sentinel}{os.linesep}")
323-
_wait_for(self._read_shell, sentinel=sentinel, timeout=20.0)
319+
# Wait for the shell to PAINT its first prompt ("PS <cwd>>")
320+
# before typing anything. An echoed sentinel is NOT a readiness
321+
# signal here: until PowerShell takes over the console, conhost's
322+
# cooked-mode echo reflects written input straight back,
323+
# satisfying the wait while the shell is still initializing.
324+
# Input typed during PSReadLine's console mode switch can then be
325+
# split mid-line -- a half-submitted quoted env line leaves the
326+
# shell in a ">>" continuation prompt that swallows everything
327+
# typed after it. Nothing we write contains "PS ", so its
328+
# appearance can only come from the shell itself.
329+
_wait_for(self._read_shell, sentinel="PS ", quiet_period=0.5, timeout=30.0)
324330

325331
for line in self.environment:
326332
self._write_shell(f"{line}{os.linesep}")

0 commit comments

Comments
 (0)