test(js): read the cursor next to the state it is compared against - #99
Open
Ayman Bagabas (aymanbagabas) wants to merge 1 commit into
Open
test(js): read the cursor next to the state it is compared against#99Ayman Bagabas (aymanbagabas) wants to merge 1 commit into
Ayman Bagabas (aymanbagabas) wants to merge 1 commit into
Conversation
`echo roundtrip drives a real session` compared `getCursor()` against a
`state.cursor` captured five calls earlier. The shell draws its next
prompt after the command finishes, which moves the cursor, so a prompt
landing between the two reads made them differ by its width: macOS CI saw
`{x: 0}` against `{x: 2}`.
Reading them next to each other narrows that window about sixfold, from
the five intervening round trips to one.
It narrows rather than closes it. The reason a window exists at all is
that `wait command` falls back to "the prompt came back and the screen is
idle" when a session has no shell integration, and an idle screen is
indistinguishable from a prompt that has not started. `waitIdle` is no
help for the same reason: measured against a shell with a deliberately
slow prompt, it returned with the cursor still at column 0, because the
screen was quiet precisely because the prompt had not begun. That root
cause is tracked in #98.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
This was referenced Aug 5, 2026
Ayman Bagabas (aymanbagabas)
requested review from
cpendery (cpendery)
and
a lite review from Copilot
and removed request for
cpendery (cpendery)
August 5, 2026 23:31
Copilot started reviewing on behalf of
Ayman Bagabas (aymanbagabas)
August 5, 2026 23:32
View session
There was a problem hiding this comment.
Pull request overview
This PR reduces flakiness in the JS bindings integration test by comparing the cursor position against the captured state.cursor immediately after the snapshot is taken, minimizing the chance that the shell prompt redraw moves the cursor between reads.
Changes:
- Move
getCursor()vsstate.cursorcomparison to be adjacent tosu.state()inecho roundtrip drives a real session. - Add an explanatory comment documenting the underlying prompt redraw timing/race and why
waitIdle()is not a reliable barrier in this scenario.
Show a summary per file
| File | Description |
|---|---|
| bindings/js/test/integration.test.mjs | Reorders cursor assertions to reduce prompt redraw timing window and documents the rationale. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
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.
echo roundtrip drives a real sessionfails intermittently on CI, most often on macOS:It compared
getCursor()against astate.cursorcaptured five calls earlier:The shell draws its next prompt after the command finishes, and that moves the cursor. A prompt landing between the two reads makes them differ by exactly its width, which is what
x: 0againstx: 2is.Reading them next to each other narrows the window about sixfold, from the five intervening round trips to one:
This narrows the window rather than closing it
Worth being plain about, since the title says "race".
The window exists because
wait commandfalls back to "the prompt came back and the screen is idle" when a session has no shell integration, and an idle screen cannot be told apart from a prompt that has not started yet.My first attempt was
await su.waitIdle()before the snapshot, which looks like the right barrier and is the idiom already used by the snapshot test in this file. I measured it against a shell with a deliberately slow prompt (PROMPT_COMMAND='sleep 0.4') before trusting it:waitIdlereturned with the cursor still at column 0, because the screen was quiet precisely because the prompt had not begun. So I dropped it rather than ship a barrier that does nothing, and left a comment so the next person does not reach for it either.With shell integration working,
wait commandleaves the cursor already settled and there is no window to speak of — so the underlying question is why integration was not in play on the CI runner that failed. That, and two sibling flakes in the Rust lifecycle suite, are tracked in #98.Testing
43/43 JS binding tests, three consecutive runs. The change is test-only.