Add ptywright wait revisions and mode-aware special keys - #81
Merged
Conversation
Fix waitFor lost-wakeups with a revision counter, and encode SpecialKey presses from Ghostty's live terminal modes without changing press() raw-string behavior.
Recheck the session revision after once("update") so a PTY
update between snapshot and sleep cannot be missed. Drop the
silent CSI fallback, write encoded bytes through one helper,
and run ptywright tests in CI.
Contributor
Author
|
addressed the review:
|
One input method: strings stay raw, SpecialKey values encode from live terminal modes.
Contributor
Author
|
folded pressKey into press(string | SpecialKey). strings stay raw; SpecialArrowUp and friends encode from live modes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ptywright waits could miss a PTY update that arrived between the snapshot check and
once("update"). Each session now bumps a revision on I/O/exit/resize and rechecks before sleeping.press()is still raw bytes (KeyArrowUpstays CSIA). NewSpecialKeyvalues pluspressKey()encode arrows/home/end/page/insert/delete/escape/backtab from Ghostty's live modes (setopt_from_terminal), so DECCKM application cursor keys produce SS3.Test plan
npx tsx --test packages/ptywright/src/test/*.test.tspress(KeyArrowUp)still writes1b5b41;pressKey(SpecialArrowUp)follows DECCKMNote
Medium Risk
Touches native Ghostty key encoding and session wait timing used by CLI/TUI tests; behavior change is intentional but could affect flaky-test assumptions if callers relied on raw Key* for app-cursor modes.
Overview
PtySession wait helpers no longer miss updates that land between a snapshot check and subscribing to
update: each session bumps a revision on PTY I/O, resize, exit, and close, andwaitForUpdaterechecks before sleeping.press()now accepts either rawKey*strings (unchanged pass-through) or newSpecialKey/Special*tokens. Special keys are encoded through Ghostty’s key encoder withsetopt_from_terminal, so sequences follow live modes (e.g. DECCKM: SS3 vs CSI for arrows). The native bridge addsencodeSpecialKey, a per-terminal key encoder, and C APIptywright_ghostty_terminal_encode_special_key.CI runs
npm test --workspace @onkernel/ptywright; tests run viatsx --test src/test/*.test.tswith coverage for raw vs special arrow keys and DECCKM. README documentsSpecial*vsKey*.Reviewed by Cursor Bugbot for commit 0a267ac. Bugbot is set up for automated code reviews on this repo. Configure here.