Repository navigation
test(e2e): headless preedit-geometry coverage for Korean and CJK terminal input - #14500
Conversation
…inal input Both IME defects that shipped and were reverted passed a suite of ~3000 IME assertions, because every one of them checked bytes reaching the pty and a preedit rendered into a hidden overlay satisfies all of them while the user composes blind. The one arm that asserted real geometry was headful-gated and macOS-only, so it never ran in CI. Drives composition through CDP Input.imeSetComposition rather than a native input source, which removes the accessibility grant, the system input source and the visible window that forced that gate, so this runs in the ordinary electron-headless project. The load-bearing assertion is the composition overlay's real bounding rect. Verified to have teeth: with max-width 0 and overflow hidden injected, the active class, the textContent, display block and checkVisibility all still pass, and only the rect assertion fails.
The trimmed copy on main kept only the key-dispatch helpers, so the composition drivers the geometry specs import were missing. Adds them back: setImeComposition, commitImeText, dispatchImeProcessKey, composeHangulSyllable and dispatchResumedCompositionUpdate. The shared helpers are unchanged. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughAdded reusable CDP helpers for IME composition, text commitment, process-key events, resumed composition, and Hangul input. Added preedit overlay sampling and recorded DOM trace replay with terminal output capture. Added a Windows WSL Korean trace fixture. Added end-to-end tests for Japanese, Chinese, macOS full-width input, Windows/Linux punctuation, Korean Hangul composition, resumed composition, rapid commits, overlay geometry, and PTY byte ordering. Merge Risk: 🔵 Low · up to This PR adds end-to-end IME coverage without changing product behavior. It is mergeable with owner follow-up for two bounded test-helper risks: non-BMP composition text may receive an incorrect caret range, and repeated trace capture could duplicate input and produce misleading test results. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
tests/e2e/terminal-ime-cdp-composition.ts (1)
142-152: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueTrim the multi-paragraph rationale comments. Both helpers carry a narrative doc block of more than ten lines. The coding guidelines require comments to be concise and brief, preferring one line. The non-obvious facts in each block are worth keeping; the walkthrough around them is not. Keep the constraint, drop the narration.
tests/e2e/terminal-ime-cdp-composition.ts#L142-L152: reduce to the two load-bearing facts — the recorded corpus contains no barecompositionupdate, andInput.imeSetCompositionalways opens a session first, so direct dispatch is required.tests/e2e/terminal-ime-recorded-dom-trace-replay.ts#L130-L142: reduce to the reason the commit tail is fused — a task boundary betweencompositionendand itsinputlets xterm's deferred finalizer read a textarea the committed text has not reached.As per coding guidelines: "Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code."
Source: Coding guidelines
tests/e2e/terminal-ime-preedit-overlay-probe.ts (1)
51-52: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReplace the literal LRM with an escape sequence.
Line 52 contains a raw U+200E character inside the string argument. The character is invisible in review, in diffs, and in most editors. If any tool strips or replaces it, every overlay text assertion breaks with no visible cause. Use the escape form.
♻️ Proposed change
- // The overlay wraps its text in LRM marks; strip them so assertions read as the user sees it. - text: (view.textContent ?? '').replaceAll('', ''), + // xterm wraps the preedit in LRM marks; strip them so assertions match what the user sees. + text: (view.textContent ?? '').replaceAll('\u200E', ''),tests/e2e/terminal-ime-recorded-dom-trace-replay.ts (1)
54-73: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDispose the
onDatasubscription, or reject a second capture.
pane.terminal.onDatareturns a disposable that this helper discards. The current specs replay one trace per page, so behavior is correct today. If a spec ever replays two traces on the same page, the second call attaches a second listener while resetting__recordedTraceOnData, and every chunk is then captured twice. The reset hides the cause, so the failure looks like duplicated terminal output.♻️ Proposed change: keep the disposable and dispose a previous capture
async function startRecordedTraceOnDataCapture(page: Page): Promise<void> { await page.evaluate(() => { - const target = window as unknown as { __recordedTraceOnData: string[] } + const target = window as unknown as { + __recordedTraceOnData: string[] + __recordedTraceOnDataDispose?: () => void + } + // A second capture on the same page would otherwise double every chunk. + target.__recordedTraceOnDataDispose?.() target.__recordedTraceOnData = []- pane.terminal.onData((data) => target.__recordedTraceOnData.push(data)) + const subscription = pane.terminal.onData((data) => target.__recordedTraceOnData.push(data)) + target.__recordedTraceOnDataDispose = () => subscription.dispose()
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 27e9af94-b3f9-4b14-a4e7-06209982b4ce
📒 Files selected for processing (6)
tests/e2e/fixtures/windows-wsl-2set-hangul-dom-trace.jsontests/e2e/terminal-cjk-ime-committed-text.spec.tstests/e2e/terminal-ime-cdp-composition.tstests/e2e/terminal-ime-preedit-overlay-probe.tstests/e2e/terminal-ime-recorded-dom-trace-replay.tstests/e2e/terminal-korean-preedit-visibility.spec.ts
| /** | ||
| * Headless end-to-end coverage for Japanese and Chinese terminal input. | ||
| * | ||
| * Three shapes are covered, and the second is the one the whole suite used to be blind to: | ||
| * | ||
| * 1. Phrase-level composition — a Japanese preedit that grows to several characters and converts | ||
| * to kanji, and a pinyin preedit that spends most of its life as multi-letter romanisation. | ||
| * Both are asserted on the overlay's real geometry rather than on the bytes they later emit. | ||
| * 2. Committed text that arrives with **no composition session at all**. Full-width punctuation | ||
| * (`,` `。` `、`) and full-width digits are typed as a single keystroke that the input source | ||
| * rewrites; there is no compositionstart/update/end around them. Every IME test in the repo | ||
| * was composition-session-shaped, so this shape was invisible to the suite by construction — | ||
| * which is how `,` reaching the shell as an ASCII `,` shipped to users. This is the macOS | ||
| * shape, and the tests for it pin the macOS ownership policy. | ||
| * 3. The same full-width punctuation arriving **inside** a composition session, which is how the | ||
| * Windows and Linux frameworks deliver it. Same user-facing guarantee, different ordering. | ||
| * | ||
| * The assertion for shapes 2 and 3 is deliberately "the ASCII byte never appears" rather than "the | ||
| * substitution was applied": the correct design never manufactures the ASCII byte in the first | ||
| * place, so pinning its absence stays true under a forwarder rewrite as well as under a | ||
| * structural one. | ||
| */ |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Reduce source-comment detail.
Move the detailed regression narratives to test documentation or the PR description. Keep only short comments that explain non-obvious test intent.
tests/e2e/terminal-cjk-ime-committed-text.spec.ts#L1-L22: Replace the multi-paragraph test overview with a brief purpose statement.tests/e2e/terminal-korean-preedit-visibility.spec.ts#L1-L13: Replace the historical incident narrative with a brief purpose statement.
As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
📍 Affects 2 files
tests/e2e/terminal-cjk-ime-committed-text.spec.ts#L1-L22(this comment)tests/e2e/terminal-korean-preedit-visibility.spec.ts#L1-L13
Source: Coding guidelines
| export async function setImeComposition(session: CDPSession, text: string): Promise<void> { | ||
| const length = Array.from(text).length | ||
| await session.send('Input.imeSetComposition', { | ||
| text, | ||
| selectionStart: length, | ||
| selectionEnd: length | ||
| }) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
Chrome DevTools Protocol Input.imeSetComposition selectionStart selectionEnd offset units UTF-16
💡 Result:
The Chrome DevTools Protocol (CDP) method Input.imeSetComposition is used to set the current composition text for an Input Method Editor (IME) [1][2]. The selectionStart and selectionEnd parameters in Input.imeSetComposition (as well as related Chrome APIs like chrome.input.ime or the EditContext API) define the selection range within the provided composition text [1][3][4]. These offsets are specified in units of UTF-16 code units [5][4]. Key technical details regarding these parameters include: 1. Unit Consistency: Similar to the standard selectionStart and selectionEnd properties on HTMLInputElement and HTMLTextAreaElement, these values represent the index of UTF-16 code units [5][4]. For characters within the Basic Multilingual Plane (BMP), this corresponds to a one-to-one mapping with characters. For supplementary characters (such as certain emojis or specialized symbols) which are represented as surrogate pairs in UTF-16, these offsets will increment by two for each such character [6][4]. 2. Usage: When calling Input.imeSetComposition, the text parameter provides the string to be inserted as the composition [1][7]. The selectionStart and selectionEnd parameters indicate the position of the caret or selection within that specific composition string [1][3][4]. 3. Implementation Context: While the CDP documentation [1] describes these as simple integers, the underlying implementation in the Chromium rendering engine (Blink) consistently treats text offsets and selection ranges in terms of UTF-16 code units [6]. This aligns with modern Web Platform standards, such as the EditContext API, which explicitly defines its selection offsets as the count of UTF-16 code units [4].
Citations:
- 1: https://chromedevtools.github.io/devtools-protocol/tot/Input/
- 2: https://cdpstatus.reactnative.dev/devtools-protocol/tot/Input
- 3: https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/chrome/common/extensions/api/input_ime.json
- 4: https://www.w3.org/TR/edit-context/
- 5: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/OpaqueRange/explainer.md
- 6: https://android.googlesource.com/platform/external/chromium_org/third_party/WebKit/+/20e637e67a0c272870ae4d78466a68bcb77af041/Source/core/editing/InputMethodController.cpp
- 7: https://github.com/chromedp/cdproto/blob/master/input/input.go
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- file outline ---'
ast-grep outline tests/e2e/terminal-ime-cdp-composition.ts
printf '%s\n' '--- setImeComposition references ---'
rg -n -C 3 'setImeComposition|composeHangul|Kana|Han|imeSetComposition' tests/e2e/terminal-ime-cdp-composition.ts tests/e2e || true
printf '%s\n' '--- relevant source ---'
sed -n '80,115p' tests/e2e/terminal-ime-cdp-composition.tsRepository: stablyai/orca
Length of output: 50370
Use UTF-16 offsets for Input.imeSetComposition. Replace Array.from(text).length with text.length so non-BMP composition text receives the correct caret range.
…inal input (stablyai#14500) * test(e2e): headless preedit-geometry coverage for Korean and CJK terminal input Both IME defects that shipped and were reverted passed a suite of ~3000 IME assertions, because every one of them checked bytes reaching the pty and a preedit rendered into a hidden overlay satisfies all of them while the user composes blind. The one arm that asserted real geometry was headful-gated and macOS-only, so it never ran in CI. Drives composition through CDP Input.imeSetComposition rather than a native input source, which removes the accessibility grant, the system input source and the visible window that forced that gate, so this runs in the ordinary electron-headless project. The load-bearing assertion is the composition overlay's real bounding rect. Verified to have teeth: with max-width 0 and overflow hidden injected, the active class, the textContent, display block and checkVisibility all still pass, and only the rect assertion fails. * test(e2e): restore the CDP composition drivers the preedit specs need The trimmed copy on main kept only the key-dispatch helpers, so the composition drivers the geometry specs import were missing. Adds them back: setImeComposition, commitImeText, dispatchImeProcessKey, composeHangulSyllable and dispatchResumedCompositionUpdate. The shared helpers are unchanged. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
Supersedes #13290, which was parked as
[NOT FOR MERGE]because three of its tests were red onmainon purpose, waiting on fixes that have since landed (#13284, #13288). All 12 tests pass now.Why this coverage
Both IME defects that shipped and were reverted walked through a suite of ~3000 passing IME assertions. Every one of those checked bytes reaching the pty — and a preedit rendered into a hidden overlay satisfies all of them while the user composes blind. The one arm that asserted real geometry was
@headful, env-gated and macOS-only, so it never ran in CI.Composition here is driven through CDP
Input.imeSetComposition, which opens a genuine Chromium composition session with no native input source, no accessibility grant and no visible window. That is what lets the geometry assertions run in the ordinaryelectron-headlessproject.The assertion has teeth — re-verified, not inherited
I mutation-tested it rather than trusting the original claim. Injecting
.composition-view.active { max-width: 0; overflow: hidden }— invisible on screen — leaves theactiveclass, thetextContent,display: blockandcheckVisibility() === trueall passing. The suite still fails:That is the assertion that would have caught the regression.
Results
12 passed, 1.2m,
--workers=1on macOS.terminal-korean-preedit-visibility.spec.tsterminal-cjk-ime-committed-text.spec.tsNot a rebase of #13290
That branch still carried the preedit product commit, which already landed as #13284, so replaying it onto
mainconflicted immediately — and it had drifted 152 files behind, which made its diff meaningless. This takes only the 5 files it genuinely contributes, on a fresh branch offmain.One real problem found while doing it
The specs failed on first run against today's
main:terminal-ime-cdp-composition.tslanded onmainin a trimmed form — key-dispatch helpers only, without the composition drivers. The second commit restoressetImeComposition,commitImeText,dispatchImeProcessKey,composeHangulSyllableanddispatchResumedCompositionUpdate. The shared helpers were diffed function-by-function first and are byte-identical apart from one comment rewording, whichmain's copy keeps.Scope
Test-only. No product code, no behaviour change.
Made with Orca 🐋