Repository navigation
test(tui): wait for each key's effect in the line and color editor tests - #788
Merged
Merged
Conversation
The line editor and color menu tests slept a fixed 25ms after rendering and after each key, then asserted. Ink redraws, and React re-attaches Ink's input listener, on their own schedule. On a loaded machine the assertion ran before the redraw, or the next key reached the listener left from before the last redraw and was applied to the old state. Under load these tests failed intermittently, the number style and label tests most often. Each wait now retries until the key's visible effect shows (the row's new suffix, the label editor's draft, the picker's search text, the moved highlight), then yields two setImmediate turns before the next key, through the shared helper in src/tui/__tests__/helpers/wait-for-ink.ts. Assertions that only restated a wait move into it; the rest are unchanged.
This was referenced Nov 7, 2026
Closed
Closed
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.
What
The line editor tests (
ItemsEditor.test.ts) and the bold/dim test inColorMenu.test.tsxno longer sleep a fixed 25ms after rendering and after each key. Each step now waits for the key's visible effect, then lets React catch up before the next key, the same way #652 converted the other Ink tests. The tests still check everything they checked before, and they no longer fail when the machine is busy.Why
These tests wrote a key, slept 25ms, then asserted (26 sleeps in
ItemsEditor.test.ts, 2 inColorMenu.test.tsx). Ink redraws on its own schedule. ItsuseInputalso swaps in each render's handler from a passive effect, so a key that arrives before that effect runs goes to the previous render's handler and is applied to the old state. Under load, 25ms is sometimes not enough for either step.Measured with Bun 1.4.2 on a 10-core Mac. Each run is
bun teston the two files (16 tests). Runs were started N at a time, for 10 rounds (5 at 48):mainThe failing tests on
mainat 32 in parallel, by count: number styles 106, label edit and raw value 45, reselecting Model 12, every key typed 8, reselecting Session Cost 3 (some runs failed more than one). A typical failure, the number style test after its second.:The frame drawn after the second
.still shows(compact).How
flushInkis gone from both files. Each use is nowwaitForfromsrc/tui/__tests__/helpers/wait-for-ink.ts, which both files already import.waitForretries its assertions every 10ms for up to 3s, then yields twosetImmediateturns so React can swap in the new input handler before the next key.., the saved label after Enter,(raw value)afterr, the row again after Tab.(default: …)prompt aftere, then the draft after each backspace or typed key. The cursor at the end shows as a trailing space, so after the first backspace the editor shows"Model: " (default: "Model: ").Search: (none)after →, then theSearch:row after each typed character.▶ 2: Cache Read) before the current-style line is read from that frame.Left as is:
setImmediateapart, with no wait between them. That gap is what the test covers. It now waits for both edits to show before pressing Enter.main's versions didn't check. A change to how the editor shows the draft now fails those tests as well as the joined-emoji test, which already checks that format.Demo
No demo: only tests change, so nothing in the TUI or the status line looks or works differently.
Testing
mainas of fix: use env override and settings for usable context ratio calculation #407 (71e8b42): merges cleanly,bun run lintis clean, andbun testgives 3938 pass, 0 fail. The built CLI under Bun 1.4.4 and Node 26.13.0 matchesmainin plain and Powerline mode with the baseline configs, and the TUI opens and exits cleanly. It adds no JavaScript or Node API newer than Node 14, the build's target.bun test: 3168 pass, 0 fail (178 files), the same asmain.bun run lintis clean.mainand on this branch.main.main. The TUI opens and exits cleanly under both.