Repository navigation
test(terminal): make the arrows and clicks browser check deterministic - #2219
Conversation
…not arrive in the arrows and clicks check The check raced the server's 40 ms key settle, a margin herdr gives no barrier for (#634), and clicked before xterm reported the mouse. It now waits for each letter before the arrow after it, waits for mouse reporting before clicking, and proves nothing arrived by typing a mark instead of sleeping. server/core/key-settle.test.ts proves the settle.
…n a wait times out The settle test now runs the lane with the values the server ships, exported from server/index.ts, against herdr's measured ESC hold and pty pipeline, so a lowered or zeroed settle fails it. The browser check prints what it read when a wait times out, checks nothing follows the Escape and ArrowUp, and logs (without asserting) whether an arrow pressed right after a letter outran the settle margin.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 11 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…step Its first letter goes through the attach pty and the rest may go through herdr, so a mark typed after them could return before a stalled letter, which then broke the Escape and ArrowUp assertion. Wait for all five bytes, in any order, instead.
|
Fixed in e160d43. The merge pass's MEDIUM (the at-once diagnostic) is confirmed: its I checked every other Verified at e160d43: |
|
Merging e160d43: it makes the arrows-and-clicks browser check deterministic, the check that flaked on #2192. On 39c26af both reviewers reproduced one race: the optional diagnostic's marker, sent over the RPC lane, could return before its first letter arrived over the attach PTY, breaking the next assertion. e160d43 reads all five diagnostic bytes before continuing. Codex passes that change: the delayed-delivery scenario and all 120 byte orderings pass, the wait is bounded, and no fixed sleep was added. omo passed the rest of the PR. |
Problem
scripts/terminal-arrows-clicks-regression.ts(Browser regression, other scripts) failed in the first CI attempt of PRs that touch no terminal code, and passed on rerun:an arrow between two letters arrives between them, gota←←bab←aba←ba←b.every held key received in order(28 of 69, left over←←x←…: two repeats overtook the letterx); its retrytimed out: left click received as press and release.Two causes:
pane.send_keysRPC, around the attach pty the letter was just typed into. herdr offers no barrier for bytes in that pty, soserver/core/input.tsholds the arrowKEY_SETTLE_MS(40 ms) after the last pty keystroke (TYPED_SETTLE_MSafter an ESC). fix(terminal): arrows reach full-screen programs, and a click reaches one that reads the mouse #634 documents this as a known limit: "the 40 ms settle is a margin, not a delivery acknowledgement". A stall longer than that on a busy runner (6 browser workers, Node PTY host) lets the arrow arrive first, and both failures in the letter/arrow sections are that. herdr 0.9.5 still has no barrier and no report of the program's cursor-key mode (checked its CLI and the generated API), so the product cannot make this exact. The check asserted an order the product only reaches by a margin.useTerminalMounthands a press on as a click only whenterm.modes.mouseTrackingModeis on at mousedown. The check clicked right afterinput-ready, and the attach's first output, which turns xterm's mouse reporting on, can be parsed after that. The press was then a plain selection and nothing was sent.Change (test only)
a ← brounds, after Escape, and after each letter between held repeats. An arrow followed at once by a letter stays back to back: the lane queues typing that arrives while a key waits, so that order is exact.server/core/key-settle.test.ts. It drivescreateInputLanewith a fake attach and proves the hold that the browser check no longer races. The key goes out at leastKEY_SETTLE_MSafter a letter typed into the pty, andTYPED_SETTLE_MSafter an ESC. A letter typed while the key waits goes behind it through herdr, not into the pty.Bun.sleep(400)is replaced bymark(): it typeszafter the action and waits until the program has read it and its frame is reported. Anything the action sent went out first on the same socket and pty (or herdr queue, on a mirror), so what came before the mark is all it sent. The file's entry leavesscripts/fixed-sleeps.json(9 → 0). The only sleep left is the autorepeat pacing, marked// fixed wait..xterm.enable-mouse-events, the state the page reads to decide that a press is a click.Evidence
Mutations, each run through the browser check and the unit test, then restored:
paneQueues.has(...) || stop→stop)an arrow between two letters arrives between them; unit FAIL (letter behind key)forwardClickdroppedtimed out: left click received as press and release!onLinkremoved)a click on a link sends the program no button, actual\x1b[<0;7;1M\x1b[<0;7;1m: the mark catches bytes that do arriveReproduction. A pty stall longer than the settle, simulated with
KEY_SETTLE_MS = 0on 4 pinned busy cores: main's check failed 1 of 5 runs with CI's exact assertion,an arrow between two letters arrives between them. This branch's check passed 5 of 5.Under load, main's check and this one alternating (pr-policy's flake rule), each run through
dori heavyandbun run check run:bun run check fastloop ran in another checkout: this branch 12/12, main 12/12.tasksetto 4 cores alongside 6 CPU hogs, to imitate a 4-core runner: this branch 20/20, main 20/20.This PC's spare cores rarely reproduce the CI stall unaided, so the pass counts show the check holds up under load. The mutations and the stall reproduction above are what show it can still fail.
Review
Test-only, so the omo reviewer alone (notes/pr-policy.md): omo-native-code-reviewer APPROVE, with no CRITICAL or HIGH findings. Its MEDIUM finding was that the unit test ran with its own settle values, so a lowered
KEY_SETTLE_MSorTYPED_SETTLE_MSwould have slipped through. Fixed in the second commit: the two constants are now exported fromserver/index.ts(no behaviour change), and the test runs the lane with the shipped values against herdr's measured floors (a ~2 ms pty pipeline and a ~150 ms ESC hold).KEY_SETTLE_MS = 0andTYPED_SETTLE_MS = 100each fail it. The review's LOW findings are also fixed: a timed-out wait prints what was read, the mark checks that nothing came after it, and the check confirms that nothing follows the Escape and ArrowUp. The browser check also logs, without asserting, whether an arrow pressed right after a letter outran the margin. A third LOW (the queue test names the send_text path) is kept on purpose, because that path is intended.bun run check fast: green on 39c26af (typecheck, build, unit tests and actionlint).