diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-04-02 15:55:06 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-02 15:55:06 -0600 |
commit | 3b9fd1af804e4fe534798ec2d7da440d97ba610c (patch) | |
tree | 0719c35c46a4d1210dcb48f8b69304744ca2fcc0 /tests/util/server/src/pty.rs | |
parent | cc4ede41a7d39e318d18d3bccf797d232a5b286a (diff) |
fix(cli): Enforce a human delay in prompt to fix paste problem (#23184)
The permission prompt doesn't wait for quiescent input, so someone
pasting a large text file into the console may end up losing the prompt.
We enforce a minimum human delay and wait for a 100ms quiescent period
before we write and accept prompt input to avoid this problem.
This does require adding a human delay in all prompt tests, but that's
pretty straightforward. I rewrote the locked stdout/stderr test while I
was in here.
Diffstat (limited to 'tests/util/server/src/pty.rs')
-rw-r--r-- | tests/util/server/src/pty.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/util/server/src/pty.rs b/tests/util/server/src/pty.rs index 3e3331b84..9b2a5eb5d 100644 --- a/tests/util/server/src/pty.rs +++ b/tests/util/server/src/pty.rs @@ -77,6 +77,12 @@ impl Pty { self.pty.flush().unwrap(); } + /// Pause for a human-like delay to read or react to something (human responses are ~100ms). + #[track_caller] + pub fn human_delay(&mut self) { + std::thread::sleep(Duration::from_millis(250)); + } + #[track_caller] pub fn write_line(&mut self, line: impl AsRef<str>) { self.write_line_raw(&line); @@ -161,6 +167,23 @@ impl Pty { }); } + /// Expects the raw text to be found next. + #[track_caller] + pub fn expect_raw_next(&mut self, text: impl AsRef<str>) { + let expected = text.as_ref(); + let last_index = self.read_bytes.len(); + self.read_until_condition(|pty| { + if pty.read_bytes.len() >= last_index + expected.len() { + let data = String::from_utf8_lossy( + &pty.read_bytes[last_index..last_index + expected.len()], + ); + data == expected + } else { + false + } + }); + } + pub fn all_output(&self) -> Cow<str> { String::from_utf8_lossy(&self.read_bytes) } |