From 15c0313c3329e72b95b153b8e33fc2c8744f337d Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 2 Jun 2024 13:57:35 -0700 Subject: [PATCH] Fix pexpect_helper.py prompt regex The prompt regex for pexpect was: ``` return re.compile( r"""(?:\r\n?|^) # beginning of line (?:\x1b[\d[KB(m]*)* # optional colors (?:\x1b[\?2004h) # Bracketed paste (?:\x1b[>4;1m) # XTerm's modifyOtherKeys (?:\x1b[>5u) # CSI u with kitty progressive enhancement (?:\x1b=) # set application keypad mode, so the keypad keys send unique codes (?:\[.\]\ )? # optional vi mode prompt """ + (r"prompt\ %d>" % counter) # prompt with counter + r""" (?:\x1b[\d\[KB(m]*)* # optional colors """, re.VERBOSE, ) ``` This has a terrible bug: an accidentally unescaped bracket here: (?:\x1b[>4;1m) # XTerm's modifyOtherKeys ^ This bracket then extends throughout the entire regex, and is accidentally terminated here: (?:\x1b[\d\[KB(m]*)* # optional colors ^ Thus the whole regex is busted; in particular the prompt counters are not being tested correctly. A second issue is that these escape sequences are not emitted before the first prompt, so correcting the regex will cause every test to fail. Fix this by ignoring all of the escape sequences and merely look for the "prompt %d>" portion. THIS DELIBERATELY CAUSES TEST FAILURES. The tests were already broken and falsely reported as passing. These will be fixed in followup commits. Good news is that the tests should become way more reliable after this is fixed - hopefully no more introducing random sleep() calls. --- build_tools/pexpect_helper.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/build_tools/pexpect_helper.py b/build_tools/pexpect_helper.py index 81131043e..347c699f5 100644 --- a/build_tools/pexpect_helper.py +++ b/build_tools/pexpect_helper.py @@ -48,21 +48,7 @@ SANITIZE_FOR_PRINTING_RE = re.compile( def get_prompt_re(counter): """Return a regular expression for matching a with a given prompt counter.""" - return re.compile( - r"""(?:\r\n?|^) # beginning of line - (?:\x1b[\d[KB(m]*)* # optional colors - (?:\x1b[\?2004h) # Bracketed paste - (?:\x1b[>4;1m) # XTerm's modifyOtherKeys - (?:\x1b[>5u) # CSI u with kitty progressive enhancement - (?:\x1b=) # set application keypad mode, so the keypad keys send unique codes - (?:\[.\]\ )? # optional vi mode prompt - """ - + (r"prompt\ %d>" % counter) # prompt with counter - + r""" - (?:\x1b[\d\[KB(m]*)* # optional colors - """, - re.VERBOSE, - ) + return re.compile("prompt %d>" % counter) def get_callsite():