From 063f9a17c5fe292b641f25c0c30c50f55beda820 Mon Sep 17 00:00:00 2001 From: Simon Klee Date: Wed, 18 Nov 2026 12:57:25 +0100 Subject: [PATCH] test(cli-rs): wait for each P-PTY Escape and exit before the next key A step that only settled could not tell a slow program from one that was done. On a loaded box that let two kinds of key go out too early. A second Ctrl+C reached a TUI that was already exiting, as a SIGINT once the terminal was restored (P.0b/title-off-exit exited 130). A lone ESC the program had not yet timed out joined the next key as Alt+key. The harness can now wait until a string is gone (until.gone) or the program exited (until.exit). The TUI scenarios exit with one Ctrl+C and wait for the exit. Each Escape waits for what it closes; where nothing visible changes, it goes as the Kitty keyboard sends it (CSI 27 u), which both clients turned on. Mini's two-press exit and E.20's selection-ending Ctrl+C keep their two presses. --- packages/cli-rs/parity/pty/run.ts | 18 +++++++++++++++--- .../parity/scenarios/D131/designs.pty.ts | 9 +++++---- .../parity/scenarios/D131/early-typing.pty.ts | 6 +++--- .../parity/scenarios/D131/palette.pty.ts | 9 +++++---- .../cli-rs/parity/scenarios/D131/plugins.ts | 6 +++--- .../parity/scenarios/E.1/epilogue.pty.ts | 5 ++--- .../parity/scenarios/E.15a/ctrl-c.pty.ts | 2 +- .../cli-rs/parity/scenarios/E.15a/route.pty.ts | 4 ++-- .../parity/scenarios/E.18a/channel.pty.ts | 4 ++-- .../parity/scenarios/E.19a/attention.pty.ts | 4 ++-- .../cli-rs/parity/scenarios/E.20/copy.pty.ts | 10 ++++++---- .../cli-rs/parity/scenarios/E.5/editor.pty.ts | 4 ++-- .../scenarios/E.5/leader-timeout-config.pty.ts | 3 ++- .../parity/scenarios/E.5/leader-timeout.pty.ts | 3 ++- .../cli-rs/parity/scenarios/H.3/title.pty.ts | 4 ++-- .../parity/scenarios/M.2/interrupt.pty.ts | 6 ++++-- .../cli-rs/parity/scenarios/M.2/queue.pty.ts | 4 +++- .../scenarios/M.2/shell-interrupt.pty.ts | 6 ++++-- .../cli-rs/parity/scenarios/M.2/shell.pty.ts | 3 ++- .../cli-rs/parity/scenarios/M.2/slash.pty.ts | 3 ++- .../parity/scenarios/M.3/permission.pty.ts | 5 +++-- .../parity/scenarios/M.4/cold-catalog.pty.ts | 5 +++-- .../cli-rs/parity/scenarios/M.4/models.pty.ts | 3 ++- .../parity/scenarios/M.4/mono-keyboard.pty.ts | 4 +++- .../parity/scenarios/M.5/subagents.pty.ts | 3 ++- .../parity/scenarios/OT/text-sizing-tui.pty.ts | 4 ++-- .../cli-rs/parity/scenarios/P.0b/fixture.ts | 13 ++++++------- .../scenarios/P.0b/foreground-signals.pty.ts | 2 +- .../parity/scenarios/P.0b/title-long.pty.ts | 2 +- .../scenarios/P.0b/title-off-exit.pty.ts | 3 ++- .../parity/scenarios/P.luau/hello.luau-pty.ts | 4 ++-- .../cli-rs/parity/scenarios/P4c/give-up.pty.ts | 5 +++-- .../parity/scenarios/P4c/second-crash.pty.ts | 3 ++- 33 files changed, 101 insertions(+), 68 deletions(-) diff --git a/packages/cli-rs/parity/pty/run.ts b/packages/cli-rs/parity/pty/run.ts index bed27d12d23..1e163d7855f 100644 --- a/packages/cli-rs/parity/pty/run.ts +++ b/packages/cli-rs/parity/pty/run.ts @@ -38,8 +38,17 @@ export type PtyStep = { // Pushed to the `fallback: "tui"` event stream after the keys. emit?: Parameters[0][] // Waits until an OSC sequence or the screen matches (a string matches as a substring). - // `oscCount` waits until that many OSC sequences contain the string. - until?: { osc?: string | RegExp; screen?: string | RegExp; oscCount?: [string, number] } + // `oscCount` waits until that many OSC sequences contain the string. `gone` waits until the screen no longer + // contains the string, and `exit` until the program exited: a key whose effect is a closed view or an exit, such + // as Escape or Ctrl+C, waits for it before the next keys go out, since a still screen cannot tell a slow program + // from one that is done (a lone ESC the program has not yet timed out joins the next key as Alt+key). + until?: { + osc?: string | RegExp + screen?: string | RegExp + oscCount?: [string, number] + gone?: string + exit?: boolean + } // Once `until` holds and the screen settled: the screen must not contain this. absent?: string // Waits until the screen has not changed for this long. @@ -445,7 +454,10 @@ async function waitFor(step: PtyStep, probe: Probe) { const countOk = counted === undefined || probe.osc().filter((entry) => entry.data.includes(counted[0])).length >= counted[1] const screenOk = - countOk && (want === undefined || (typeof want === "string" ? text.includes(want) : want.test(text))) + countOk && + (want === undefined || (typeof want === "string" ? text.includes(want) : want.test(text))) && + (step.until?.gone === undefined || !text.includes(step.until.gone)) && + (!step.until?.exit || exited) const settled = step.settle === undefined || Date.now() - state.since >= step.settle if (oscOk && screenOk && settled) { if (step.absent !== undefined && text.includes(step.absent)) diff --git a/packages/cli-rs/parity/scenarios/D131/designs.pty.ts b/packages/cli-rs/parity/scenarios/D131/designs.pty.ts index 95398306cab..49ebd4d2142 100644 --- a/packages/cli-rs/parity/scenarios/D131/designs.pty.ts +++ b/packages/cli-rs/parity/scenarios/D131/designs.pty.ts @@ -18,7 +18,8 @@ export default definePty({ checkpoint: "palette", deviation: { file: "X02-new-designs-graduated", lines: 12 }, }, - { keys: "\x1b", settle: 300 }, + // Each Escape waits for its dialog to close: a lone ESC not yet read would join the next key. + { keys: "\x1b", until: { gone: "Suggested" }, settle: 300 }, { keys: "/debug", until: { screen: "/debug" }, settle: 300 }, { keys: "\r", @@ -27,9 +28,9 @@ export default definePty({ checkpoint: "debug", deviation: { file: "X02-new-designs-graduated", lines: 12 }, }, - { keys: "\x1b", settle: 300 }, - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + { keys: "\x1b", until: { gone: "Share this when reporting an issue" }, settle: 300 }, + // Ctrl+C on the empty prompt exits; a second press could land once the terminal is restored, as a SIGINT. + { keys: "\x03", until: { exit: true } }, ], masks: [ { pattern: /Date\s+\S+/, reason: "the time the dialog opened" }, diff --git a/packages/cli-rs/parity/scenarios/D131/early-typing.pty.ts b/packages/cli-rs/parity/scenarios/D131/early-typing.pty.ts index b49fa3d87ea..29d300b0e46 100644 --- a/packages/cli-rs/parity/scenarios/D131/early-typing.pty.ts +++ b/packages/cli-rs/parity/scenarios/D131/early-typing.pty.ts @@ -19,9 +19,9 @@ export default definePty({ // Well inside the model list's delay, with no settle: the keys show while it loads. { keys: "typed early", until: { screen: "typed early" }, timeout: 1500, absent: "Demo Model" }, { until: { screen: "Demo Model" }, settle: 300, checkpoint: "loaded", timeout: 10_000 }, - { keys: "\x15", settle: 300 }, - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + { keys: "\x15", until: { gone: "typed early" }, settle: 300 }, + // Ctrl+C on the empty prompt exits; a second press could land once the terminal is restored, as a SIGINT. + { keys: "\x03", until: { exit: true } }, ], exits: true, }) diff --git a/packages/cli-rs/parity/scenarios/D131/palette.pty.ts b/packages/cli-rs/parity/scenarios/D131/palette.pty.ts index 70cba085b69..15a024cf757 100644 --- a/packages/cli-rs/parity/scenarios/D131/palette.pty.ts +++ b/packages/cli-rs/parity/scenarios/D131/palette.pty.ts @@ -20,13 +20,14 @@ export default definePty({ checkpoint: "update", deviation: { file: "D131-update-command", lines: 2 }, }, - { keys: "\x1b", settle: 300 }, + // Each Escape waits for its dialog to close: a lone ESC not yet read would join the next key. + { keys: "\x1b", until: { gone: "update" }, settle: 300 }, // `/debug` copies with `c` under the new designs, as the footer says. { keys: "/debug", until: { screen: "/debug" }, settle: 300 }, { keys: "\r", until: { screen: "copy c" }, settle: 300, checkpoint: "debug" }, - { keys: "\x1b", settle: 300 }, - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + { keys: "\x1b", until: { gone: "copy c" }, settle: 300 }, + // Ctrl+C on the empty prompt exits; a second press could land once the terminal is restored, as a SIGINT. + { keys: "\x03", until: { exit: true } }, ], masks: [ { pattern: /Date\s+\S+/, reason: "the time the dialog opened" }, diff --git a/packages/cli-rs/parity/scenarios/D131/plugins.ts b/packages/cli-rs/parity/scenarios/D131/plugins.ts index a530f98f506..b275d5292b4 100644 --- a/packages/cli-rs/parity/scenarios/D131/plugins.ts +++ b/packages/cli-rs/parity/scenarios/D131/plugins.ts @@ -33,9 +33,9 @@ export function plugins(config: object): PtyCase { { keys: "\r", until: { screen: "alpha" }, settle: 500, checkpoint: "plugins" }, // Up from the top shows the end of the list. { keys: "\x1b[A", settle: 300, checkpoint: "end" }, - { keys: "\x1b", settle: 300 }, - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + // Escape waits for the list to close, and the one Ctrl+C on the empty prompt for the exit. + { keys: "\x1b", until: { gone: "check for updates" }, settle: 300 }, + { keys: "\x03", until: { exit: true } }, ], exits: true, } diff --git a/packages/cli-rs/parity/scenarios/E.1/epilogue.pty.ts b/packages/cli-rs/parity/scenarios/E.1/epilogue.pty.ts index f4479602492..652571d0fed 100644 --- a/packages/cli-rs/parity/scenarios/E.1/epilogue.pty.ts +++ b/packages/cli-rs/parity/scenarios/E.1/epilogue.pty.ts @@ -27,9 +27,8 @@ export default definePty({ }, steps: [ { until: { screen: "Fix the parser" }, settle: 500, timeout: 30_000 }, - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, - { until: { screen: "opencode -s ses_b" }, settle: 300, checkpoint: "epilogue", timeout: 10_000 }, + // One Ctrl+C on the empty prompt exits; a second press could land once the terminal is restored, as a SIGINT. + { keys: "\x03", until: { screen: "opencode -s ses_b" }, settle: 300, checkpoint: "epilogue", timeout: 10_000 }, ], osc: [], exits: true, diff --git a/packages/cli-rs/parity/scenarios/E.15a/ctrl-c.pty.ts b/packages/cli-rs/parity/scenarios/E.15a/ctrl-c.pty.ts index a6f0d999fbf..89823326aa8 100644 --- a/packages/cli-rs/parity/scenarios/E.15a/ctrl-c.pty.ts +++ b/packages/cli-rs/parity/scenarios/E.15a/ctrl-c.pty.ts @@ -44,7 +44,7 @@ export default definePty({ { keys: "/diff", until: { screen: "/diff" }, settle: 300 }, { keys: "\r", until: { screen: "≡ lexer.ts" }, settle: 500, checkpoint: "open" }, { keys: "\x03", until: { screen: "█▀▀█" }, settle: 1000, checkpoint: "home" }, - { keys: "\x03" }, + { keys: "\x03", until: { exit: true } }, ], masks: homeMasks, exits: true, diff --git a/packages/cli-rs/parity/scenarios/E.15a/route.pty.ts b/packages/cli-rs/parity/scenarios/E.15a/route.pty.ts index 3b7454cfb78..055355f2bea 100644 --- a/packages/cli-rs/parity/scenarios/E.15a/route.pty.ts +++ b/packages/cli-rs/parity/scenarios/E.15a/route.pty.ts @@ -48,8 +48,8 @@ export default definePty({ { keys: release(10, 5).replace("<0;", "<2;"), settle: 300, checkpoint: "menu" }, { keys: "\r", until: { screen: "1/2" }, settle: 500, checkpoint: "complete" }, { keys: "q", until: { screen: "█▀▀█" }, settle: 500, checkpoint: "home" }, - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + // Ctrl+C on the empty prompt exits; a second press could land once the terminal is restored, as a SIGINT. + { keys: "\x03", until: { exit: true } }, ], masks: homeMasks, exits: true, diff --git a/packages/cli-rs/parity/scenarios/E.18a/channel.pty.ts b/packages/cli-rs/parity/scenarios/E.18a/channel.pty.ts index f2fe46b3496..048b74898bc 100644 --- a/packages/cli-rs/parity/scenarios/E.18a/channel.pty.ts +++ b/packages/cli-rs/parity/scenarios/E.18a/channel.pty.ts @@ -11,8 +11,8 @@ export const home = { server: { fallback: "tui" as const }, steps: [ { until: { screen: "█▀▀█" }, settle: 800, timeout: 30_000, checkpoint: "home" }, - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + // Ctrl+C on the empty prompt exits; a second press could land once the terminal is restored, as a SIGINT. + { keys: "\x03", until: { exit: true } }, ], exits: true, masks: [{ pattern: /Ask anything… .*$/, reason: "the placeholder is picked at random" }], diff --git a/packages/cli-rs/parity/scenarios/E.19a/attention.pty.ts b/packages/cli-rs/parity/scenarios/E.19a/attention.pty.ts index f5e136995ce..6ba735340c7 100644 --- a/packages/cli-rs/parity/scenarios/E.19a/attention.pty.ts +++ b/packages/cli-rs/parity/scenarios/E.19a/attention.pty.ts @@ -80,8 +80,8 @@ export default definePty({ until: { screen: "Session failed" }, settle: 300, }, - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + // Ctrl+C on the empty prompt exits; a second press could land once the terminal is restored, as a SIGINT. + { keys: "\x03", until: { exit: true } }, ], osc: ["status", "notify"], // Deviation N03-status-order: the order between a notification and a status record is not fixed in Rust. diff --git a/packages/cli-rs/parity/scenarios/E.20/copy.pty.ts b/packages/cli-rs/parity/scenarios/E.20/copy.pty.ts index 0aa3771f4d4..16d6f131ab5 100644 --- a/packages/cli-rs/parity/scenarios/E.20/copy.pty.ts +++ b/packages/cli-rs/parity/scenarios/E.20/copy.pty.ts @@ -23,11 +23,13 @@ export default definePty({ { keys: "\x1b[<32;21;17M\x1b[<32;25;17M", settle: 50 }, { keys: "\x1b[<0;25;17m" }, { until: { osc: "52;" }, settle: 300, timeout: 10_000, checkpoint: "copied" }, - // Escape clears the selection; Ctrl+U empties the prompt so Ctrl+C exits. - { keys: "\x1b", settle: 300 }, - { keys: "\x15", settle: 300 }, + // Escape, then Ctrl+U empties the prompt. Escape shows no text to wait for, so it goes as the Kitty keyboard sends + // it (the TUI turned it on): a lone ESC the program had not yet timed out would join Ctrl+U. The mouse selection + // stays on both sides, so the first Ctrl+C ends it (copy on select) and the second exits. + { keys: "\x1b[27u", settle: 300 }, + { keys: "\x15", until: { gone: "copy this text" }, settle: 300 }, { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + { keys: "\x03", until: { exit: true } }, ], osc: ["clipboard"], masks: [ diff --git a/packages/cli-rs/parity/scenarios/E.5/editor.pty.ts b/packages/cli-rs/parity/scenarios/E.5/editor.pty.ts index 7886f340562..b453ed01a87 100644 --- a/packages/cli-rs/parity/scenarios/E.5/editor.pty.ts +++ b/packages/cli-rs/parity/scenarios/E.5/editor.pty.ts @@ -21,8 +21,8 @@ export default definePty({ { keys: "hello", until: { screen: "hello" }, settle: 200 }, { keys: "\x18e", until: { screen: "second line" }, settle: 300, timeout: 10_000, checkpoint: "edited" }, // Ctrl+C clears the prompt, then exits. - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + { keys: "\x03", until: { gone: "second line" }, settle: 300 }, + { keys: "\x03", until: { exit: true } }, ], osc: [], masks: [ diff --git a/packages/cli-rs/parity/scenarios/E.5/leader-timeout-config.pty.ts b/packages/cli-rs/parity/scenarios/E.5/leader-timeout-config.pty.ts index b5c232ff6f0..12e9536d74d 100644 --- a/packages/cli-rs/parity/scenarios/E.5/leader-timeout-config.pty.ts +++ b/packages/cli-rs/parity/scenarios/E.5/leader-timeout-config.pty.ts @@ -18,7 +18,8 @@ export default definePty({ { until: { screen: "█▀▀█" }, settle: 500, timeout: 30_000 }, { keys: "\x18", settle: 200 }, { keys: "l", until: { screen: "Search sessions" }, settle: 300, checkpoint: "completed" }, - { keys: "\x1b", settle: 300 }, + // Escape waits for the list to close: a lone ESC not yet read would join the leader key. + { keys: "\x1b", until: { gone: "Search sessions" }, settle: 300 }, { keys: "\x18", settle: 1600 }, { keys: "l", settle: 300, absent: "Search sessions", checkpoint: "expired" }, ], diff --git a/packages/cli-rs/parity/scenarios/E.5/leader-timeout.pty.ts b/packages/cli-rs/parity/scenarios/E.5/leader-timeout.pty.ts index e42621818f1..361c0571291 100644 --- a/packages/cli-rs/parity/scenarios/E.5/leader-timeout.pty.ts +++ b/packages/cli-rs/parity/scenarios/E.5/leader-timeout.pty.ts @@ -15,7 +15,8 @@ export default definePty({ { until: { screen: "█▀▀█" }, settle: 500, timeout: 30_000 }, { keys: "\x18", settle: 1000 }, { keys: "l", until: { screen: "Search sessions" }, settle: 300, checkpoint: "completed" }, - { keys: "\x1b", settle: 300 }, + // Escape waits for the list to close: a lone ESC not yet read would join the leader key. + { keys: "\x1b", until: { gone: "Search sessions" }, settle: 300 }, { keys: "\x18", settle: 2600 }, { keys: "l", settle: 300, absent: "Search sessions", checkpoint: "expired" }, ], diff --git a/packages/cli-rs/parity/scenarios/H.3/title.pty.ts b/packages/cli-rs/parity/scenarios/H.3/title.pty.ts index 426e422980e..e5e01ca21e8 100644 --- a/packages/cli-rs/parity/scenarios/H.3/title.pty.ts +++ b/packages/cli-rs/parity/scenarios/H.3/title.pty.ts @@ -12,8 +12,8 @@ export default definePty({ steps: [ // The title can come before the first paint, so wait for the logo as well. { until: { osc: "OpenCode", screen: "█▀▀█" }, settle: 500, timeout: 30_000 }, - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + // Ctrl+C on the empty prompt exits; a second press could land once the terminal is restored, as a SIGINT. + { keys: "\x03", until: { exit: true } }, ], exits: true, }) diff --git a/packages/cli-rs/parity/scenarios/M.2/interrupt.pty.ts b/packages/cli-rs/parity/scenarios/M.2/interrupt.pty.ts index 45bfc12e2ad..0d8abfc76dd 100644 --- a/packages/cli-rs/parity/scenarios/M.2/interrupt.pty.ts +++ b/packages/cli-rs/parity/scenarios/M.2/interrupt.pty.ts @@ -29,8 +29,10 @@ export default definePty({ opened, { keys: "first", settle: 200 }, { keys: "\r", settle: 600 }, - { keys: "\x1b", settle: 200 }, - { keys: "\x1b", settle: 600 }, + // The interrupt's first Escape shows no text to wait for, so each goes as the Kitty keyboard sends it (Mini turned it + // on): a lone ESC the program had not yet timed out would join the next key. + { keys: "\x1b[27u", settle: 200 }, + { keys: "\x1b[27u", settle: 600 }, ...leave, ], exits: true, diff --git a/packages/cli-rs/parity/scenarios/M.2/queue.pty.ts b/packages/cli-rs/parity/scenarios/M.2/queue.pty.ts index edfc2520138..ca695a0fa36 100644 --- a/packages/cli-rs/parity/scenarios/M.2/queue.pty.ts +++ b/packages/cli-rs/parity/scenarios/M.2/queue.pty.ts @@ -35,7 +35,9 @@ export default definePty({ { keys: "!", settle: 100 }, { keys: "ls", settle: 100 }, { keys: "\x18\r", settle: 400, checkpoint: "refused" }, - { keys: "\x1b", settle: 100 }, + // Escape shows no text to wait for, so it goes as the Kitty keyboard sends it (Mini turned it on): a lone ESC the + // program had not yet timed out would join Ctrl+L. + { keys: "\x1b[27u", settle: 100 }, { keys: "\x0c", settle: 600, checkpoint: "cleared" }, // The first Ctrl+C clears the draft. { keys: "\x03", settle: 200 }, diff --git a/packages/cli-rs/parity/scenarios/M.2/shell-interrupt.pty.ts b/packages/cli-rs/parity/scenarios/M.2/shell-interrupt.pty.ts index b47122ef6f4..b8227e31646 100644 --- a/packages/cli-rs/parity/scenarios/M.2/shell-interrupt.pty.ts +++ b/packages/cli-rs/parity/scenarios/M.2/shell-interrupt.pty.ts @@ -26,8 +26,10 @@ export default definePty({ opened, { keys: "!sleep 5", settle: 300 }, { keys: "\r", settle: 500, checkpoint: "running" }, - { keys: "\x1b", settle: 200 }, - { keys: "\x1b", settle: 600, checkpoint: "interrupted" }, + // The interrupt's first Escape shows no text to wait for, so each goes as the Kitty keyboard sends it (Mini turned it + // on): a lone ESC the program had not yet timed out would join the next key. + { keys: "\x1b[27u", settle: 200 }, + { keys: "\x1b[27u", until: { gone: "esc interrupt" }, settle: 600, checkpoint: "interrupted" }, ...leave, ], exits: true, diff --git a/packages/cli-rs/parity/scenarios/M.2/shell.pty.ts b/packages/cli-rs/parity/scenarios/M.2/shell.pty.ts index be8179ac1af..d0e47abec79 100644 --- a/packages/cli-rs/parity/scenarios/M.2/shell.pty.ts +++ b/packages/cli-rs/parity/scenarios/M.2/shell.pty.ts @@ -12,7 +12,8 @@ export default definePty({ steps: [ opened, { keys: "!", settle: 300, checkpoint: "shell" }, - { keys: "\x1b", settle: 300, checkpoint: "normal" }, + // Escape waits for shell mode to end: a lone ESC not yet read would join the next key. + { keys: "\x1b", until: { gone: "Shell ·" }, settle: 300, checkpoint: "normal" }, { keys: "!", settle: 200 }, { keys: "\x7f", settle: 300, checkpoint: "backspace" }, { keys: "!ls -la", settle: 300, checkpoint: "typed" }, diff --git a/packages/cli-rs/parity/scenarios/M.2/slash.pty.ts b/packages/cli-rs/parity/scenarios/M.2/slash.pty.ts index 3750c66509c..e7db5c67583 100644 --- a/packages/cli-rs/parity/scenarios/M.2/slash.pty.ts +++ b/packages/cli-rs/parity/scenarios/M.2/slash.pty.ts @@ -14,7 +14,8 @@ export default definePty({ { keys: "/", settle: 400, checkpoint: "slash" }, { keys: "\x1b[B\x1b[B", settle: 300, checkpoint: "moved" }, { keys: "re", settle: 400, checkpoint: "filtered" }, - { keys: "\x1b", settle: 300, checkpoint: "hidden" }, + // Escape waits for the list to close: a lone ESC not yet read would join the next key. + { keys: "\x1b", until: { gone: "Review the working tree" }, settle: 300, checkpoint: "hidden" }, { keys: "/rev", settle: 300 }, { keys: "\r", settle: 800, checkpoint: "sent" }, { keys: "/compact ", settle: 300 }, diff --git a/packages/cli-rs/parity/scenarios/M.3/permission.pty.ts b/packages/cli-rs/parity/scenarios/M.3/permission.pty.ts index 6eaa6d92a74..b7c881d9b7d 100644 --- a/packages/cli-rs/parity/scenarios/M.3/permission.pty.ts +++ b/packages/cli-rs/parity/scenarios/M.3/permission.pty.ts @@ -14,10 +14,11 @@ export default definePty({ { ...opened, until: { screen: "Permission required" }, checkpoint: "asked" }, { keys: "\x1b[C", settle: 300, checkpoint: "moved" }, { keys: "\r", settle: 300, checkpoint: "always" }, - { keys: "\x1b", settle: 300 }, + // Each Escape waits for the stage it opens: a lone ESC not yet read would join the next key as Alt+key. + { keys: "\x1b", until: { gone: "This will always allow" }, settle: 300 }, { keys: "\x1b[D", settle: 300 }, { keys: "\r", until: { screen: "WebFetch" }, settle: 400, checkpoint: "next" }, - { keys: "\x1b", settle: 300, checkpoint: "reject" }, + { keys: "\x1b", until: { screen: "Reject permission" }, settle: 300, checkpoint: "reject" }, { keys: "use the cache", settle: 300 }, { keys: "\r", until: { screen: "ctrl+p menu" }, settle: 600, checkpoint: "replied" }, ...leave, diff --git a/packages/cli-rs/parity/scenarios/M.4/cold-catalog.pty.ts b/packages/cli-rs/parity/scenarios/M.4/cold-catalog.pty.ts index 5f400b31991..aa6274d7202 100644 --- a/packages/cli-rs/parity/scenarios/M.4/cold-catalog.pty.ts +++ b/packages/cli-rs/parity/scenarios/M.4/cold-catalog.pty.ts @@ -46,10 +46,11 @@ export default definePty({ steps: [ { until: { screen: "Third answer" }, settle: 800, timeout: 30_000, checkpoint: "cold" }, { keys: "/rev", settle: 400, checkpoint: "cold-slash" }, - { keys: "\x1b", settle: 300 }, + // Each Escape waits for the list to close: a lone ESC not yet read would join the next key. + { keys: "\x1b", until: { gone: "No matching items" }, settle: 300 }, { keys: "hello\r", until: { screen: "Demo Model" }, settle: 800, checkpoint: "warm" }, { keys: "/rev", settle: 400, checkpoint: "warm-slash" }, - { keys: "\x1b", settle: 300 }, + { keys: "\x1b", until: { gone: "Review the working tree" }, settle: 300 }, ...leave, ], exits: true, diff --git a/packages/cli-rs/parity/scenarios/M.4/models.pty.ts b/packages/cli-rs/parity/scenarios/M.4/models.pty.ts index 050d84c5a38..68e3e0fe15e 100644 --- a/packages/cli-rs/parity/scenarios/M.4/models.pty.ts +++ b/packages/cli-rs/parity/scenarios/M.4/models.pty.ts @@ -24,7 +24,8 @@ export default definePty({ { keys: "/settings", settle: 300 }, { keys: "\r", until: { screen: "Settings" }, settle: 500, checkpoint: "settings" }, { keys: "\x1b[C", settle: 800, checkpoint: "everything" }, - { keys: "\x1b", settle: 400 }, + // Escape waits for the settings to close: a lone ESC not yet read would join the next key. + { keys: "\x1b", until: { gone: "left/right change" }, settle: 400 }, ...leave, ], exits: true, diff --git a/packages/cli-rs/parity/scenarios/M.4/mono-keyboard.pty.ts b/packages/cli-rs/parity/scenarios/M.4/mono-keyboard.pty.ts index 0b699dd3e3d..a4003023890 100644 --- a/packages/cli-rs/parity/scenarios/M.4/mono-keyboard.pty.ts +++ b/packages/cli-rs/parity/scenarios/M.4/mono-keyboard.pty.ts @@ -16,7 +16,9 @@ export default definePty({ ...Array.from({ length: 7 }, () => ({ keys: "\x1b[B", settle: 150 })), // TS's open panel animates its spinner preview once mono is on, so the screen does not settle. { keys: "\x1b[C", until: { screen: /Monochrome UI +on/ } }, - { keys: "\x1b", settle: 600, checkpoint: "mono" }, + // Escape waits for the settings to close: with mono the Kitty keyboard is off, and a lone ESC not yet read would + // join the next key. + { keys: "\x1b", until: { gone: "Monochrome UI" }, settle: 600, checkpoint: "mono" }, ...leave, ], exits: true, diff --git a/packages/cli-rs/parity/scenarios/M.5/subagents.pty.ts b/packages/cli-rs/parity/scenarios/M.5/subagents.pty.ts index f19d64a2403..d6beb6f1182 100644 --- a/packages/cli-rs/parity/scenarios/M.5/subagents.pty.ts +++ b/packages/cli-rs/parity/scenarios/M.5/subagents.pty.ts @@ -14,7 +14,8 @@ export default definePty({ steps: [ { ...opened, checkpoint: "hints" }, { keys: "\x10", until: { screen: "View subagents" }, settle: 400, checkpoint: "menu" }, - { keys: "\x1b", settle: 300 }, + // Escape waits for the menu to close: a lone ESC not yet read would join the arrow as Alt+Down. + { keys: "\x1b", until: { gone: "View subagents" }, settle: 300 }, { keys: "\x1b[B", until: { screen: "Select subagent" }, settle: 400, checkpoint: "panel" }, { keys: "\t", settle: 300, checkpoint: "inactive" }, { keys: "\r", until: { screen: "The docs cover" }, settle: 500, checkpoint: "inspector" }, diff --git a/packages/cli-rs/parity/scenarios/OT/text-sizing-tui.pty.ts b/packages/cli-rs/parity/scenarios/OT/text-sizing-tui.pty.ts index 53c082cbd24..7fb66547b35 100644 --- a/packages/cli-rs/parity/scenarios/OT/text-sizing-tui.pty.ts +++ b/packages/cli-rs/parity/scenarios/OT/text-sizing-tui.pty.ts @@ -16,8 +16,8 @@ export default definePty({ terminal: "kitty", steps: [ { until: { screen: "█▀▀█" }, settle: 500, timeout: 30_000, checkpoint: "home" }, - { keys: "\x03", settle: 300 }, - { keys: "\x03", settle: 800, checkpoint: "exit", deviation }, + // One Ctrl+C on the empty prompt exits; a second press could land once the terminal is restored, as a SIGINT. + { keys: "\x03", until: { exit: true }, settle: 800, checkpoint: "exit", deviation }, ], exits: true, masks: homeMasks, diff --git a/packages/cli-rs/parity/scenarios/P.0b/fixture.ts b/packages/cli-rs/parity/scenarios/P.0b/fixture.ts index 23457415fe7..aeadfa9d9e0 100644 --- a/packages/cli-rs/parity/scenarios/P.0b/fixture.ts +++ b/packages/cli-rs/parity/scenarios/P.0b/fixture.ts @@ -41,8 +41,8 @@ export async function install(root: string, config?: object) { export const home: PtyStep[] = [ { until: { screen: "█▀▀█" }, settle: 500, timeout: 30_000 }, { keys: "/p0brun", until: { screen: "Run a program" }, settle: 200, timeout: 30_000 }, - { keys: "\x1b", settle: 200 }, - { keys: "\x15", settle: 200 }, + { keys: "\x1b", until: { gone: "Run a program" }, settle: 200 }, + { keys: "\x15", until: { gone: "/p0brun" }, settle: 200 }, ] // Runs `command` through `/p0brun`, which first prints `ready-`, and waits for that: text the command itself @@ -54,15 +54,14 @@ export function run(command: string, n: number): PtyStep[] { ] } -// Two Ctrl+C: the TUI exits. -export const leave: PtyStep[] = [{ keys: "\x03", settle: 300 }, { keys: "\x03" }] +// Ctrl+C on the empty prompt: the TUI exits. A second press could land once the terminal is restored, as a SIGINT. +export const leave: PtyStep[] = [{ keys: "\x03", until: { exit: true } }] -// Home, then `/p0btitle` once both clients list it, then two Ctrl+C to exit. +// Home, then `/p0btitle` once both clients list it, then Ctrl+C to exit. export const steps: PtyStep[] = [ // The title can come before the first paint, so wait for the logo as well. { until: { screen: "█▀▀█" }, settle: 500, timeout: 30_000 }, { keys: "/p0btitle", until: { screen: "Set the title" }, settle: 300, timeout: 30_000 }, { keys: "\r", until: { osc: "p0b title" }, settle: 300 }, - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + ...leave, ] diff --git a/packages/cli-rs/parity/scenarios/P.0b/foreground-signals.pty.ts b/packages/cli-rs/parity/scenarios/P.0b/foreground-signals.pty.ts index 75e23773621..d0fb607ab2b 100644 --- a/packages/cli-rs/parity/scenarios/P.0b/foreground-signals.pty.ts +++ b/packages/cli-rs/parity/scenarios/P.0b/foreground-signals.pty.ts @@ -21,7 +21,7 @@ export default definePty({ ...run("sleep 1; exit 4", 3), { keys: "\x1a", until: { osc: 'p0b exit {"code":4}' }, settle: 300, timeout: 15_000 }, { keys: "still here", until: { screen: "still here" }, settle: 300 }, - { keys: "\x15", settle: 200 }, + { keys: "\x15", until: { gone: "still here" }, settle: 200 }, ...leave, ], osc: ["title"], diff --git a/packages/cli-rs/parity/scenarios/P.0b/title-long.pty.ts b/packages/cli-rs/parity/scenarios/P.0b/title-long.pty.ts index f93a959e0b3..633dfad54b6 100644 --- a/packages/cli-rs/parity/scenarios/P.0b/title-long.pty.ts +++ b/packages/cli-rs/parity/scenarios/P.0b/title-long.pty.ts @@ -14,7 +14,7 @@ export default definePty({ { keys: "/p0blong", until: { screen: "Set a long title" }, settle: 300 }, { keys: "\r", until: { osc: "p0b long éé" }, settle: 300 }, { keys: "still here", until: { screen: "still here" }, settle: 300 }, - { keys: "\x15", settle: 200 }, + { keys: "\x15", until: { gone: "still here" }, settle: 200 }, ...leave, ], osc: ["title"], diff --git a/packages/cli-rs/parity/scenarios/P.0b/title-off-exit.pty.ts b/packages/cli-rs/parity/scenarios/P.0b/title-off-exit.pty.ts index 4c5e869ab06..17aafe36c75 100644 --- a/packages/cli-rs/parity/scenarios/P.0b/title-off-exit.pty.ts +++ b/packages/cli-rs/parity/scenarios/P.0b/title-off-exit.pty.ts @@ -4,6 +4,7 @@ import { mkdir, writeFile } from "node:fs/promises" import path from "node:path" import { definePty } from "../../pty/run" +import { leave } from "./fixture" export default definePty({ args: [], @@ -15,7 +16,7 @@ export default definePty({ await mkdir(config, { recursive: true }) await writeFile(path.join(config, "cli.json"), JSON.stringify({ terminal: { title: false } })) }, - steps: [{ until: { screen: "█▀▀█" }, settle: 500, timeout: 30_000 }, { keys: "\x03", settle: 300 }, { keys: "\x03" }], + steps: [{ until: { screen: "█▀▀█" }, settle: 500, timeout: 30_000 }, ...leave], osc: ["title"], exits: true, }) diff --git a/packages/cli-rs/parity/scenarios/P.luau/hello.luau-pty.ts b/packages/cli-rs/parity/scenarios/P.luau/hello.luau-pty.ts index e1ebe459353..b5c0863b0f8 100644 --- a/packages/cli-rs/parity/scenarios/P.luau/hello.luau-pty.ts +++ b/packages/cli-rs/parity/scenarios/P.luau/hello.luau-pty.ts @@ -29,8 +29,8 @@ export default definePty({ { until: { screen: /hello\s*$/m }, settle: 300, timeout: 30_000, checkpoint: "home" }, { keys: "/hello", until: { screen: "Say hello" }, settle: 300 }, { keys: "\r", until: { screen: "Hello from a plugin" }, settle: 300, checkpoint: "toast" }, - { keys: "\x03", settle: 300 }, - { keys: "\x03" }, + // Ctrl+C on the empty prompt exits; a second press could land once the terminal is restored, as a SIGINT. + { keys: "\x03", until: { exit: true } }, ], masks: [{ pattern: /Ask anything… .*$/, reason: "the placeholder is picked at random" }], exits: true, diff --git a/packages/cli-rs/parity/scenarios/P4c/give-up.pty.ts b/packages/cli-rs/parity/scenarios/P4c/give-up.pty.ts index ba49d3c0e21..b183a05d016 100644 --- a/packages/cli-rs/parity/scenarios/P4c/give-up.pty.ts +++ b/packages/cli-rs/parity/scenarios/P4c/give-up.pty.ts @@ -17,7 +17,8 @@ export default definePty({ { until: { screen: "fault plugin c" }, settle: 500, timeout: 30_000 }, ...palette("Fault in render: segv"), { until: { screen: /crashed the client in `render-slot`[\s\S]*fault plugin c/ }, settle: 500, timeout: 20_000 }, - { keys: "\x1b", settle: 300 }, + // Each Escape waits for its toast to close: a lone ESC not yet read would join the palette's Ctrl+P. + { keys: "\x1b", until: { gone: "crashed the client" }, settle: 300 }, ...palette("Fault B in render: segv"), // The third client holds both: `example.fault` by the crash list, `example.fault.b` by the handoff. { @@ -25,7 +26,7 @@ export default definePty({ settle: 500, timeout: 20_000, }, - { keys: "\x1b", settle: 300 }, + { keys: "\x1b", until: { gone: "example.fault.b" }, settle: 300 }, ...palette("Fault C in render: segv"), { until: { screen: /\$ opencode-native -s ses_b[\s\S]*crashed 3 times in 60 s \(last in plugin example\.fault\.c\)/ }, diff --git a/packages/cli-rs/parity/scenarios/P4c/second-crash.pty.ts b/packages/cli-rs/parity/scenarios/P4c/second-crash.pty.ts index efe680da234..47bfd10b3d8 100644 --- a/packages/cli-rs/parity/scenarios/P4c/second-crash.pty.ts +++ b/packages/cli-rs/parity/scenarios/P4c/second-crash.pty.ts @@ -20,7 +20,8 @@ export default definePty({ checkpoint: "first", timeout: 20_000, }, - { keys: "\x1b", settle: 300 }, + // Escape waits for the toast to close: a lone ESC not yet read would join the palette's Ctrl+P. + { keys: "\x1b", until: { gone: "restarted" }, settle: 300 }, ...palette("Fault on a thread: segv"), { until: { screen: /^(?![\s\S]*fault plugin)[\s\S]*opencode-native crashed twice/ },