Skip to content

test(ime): add a local trace recorder for platforms CI cannot cover - #11927

Draft
nwparker wants to merge 2 commits into
nwparker/ime-ci-matrixfrom
nwparker/ime-trace-recorder
Draft

nwparker wants to merge 2 commits into
nwparker/ime-ci-matrixfrom
nwparker/ime-trace-recorder

Conversation

@nwparker

@nwparker nwparker commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds pnpm ime:record — a localhost page that captures a real IME composition trace from your own machine and your own input method, in the exact JSON shape the fixture loader already consumes.

This exists because of a hard limit: CDP-dispatched keystrokes bypass the OS input-method layer, so no amount of page.keyboard.type() produces a real compositionstart → compositionend pair. The Linux matrix in #11898 gets around this by driving ibus through X11 with xdotool, which works — but there is no macOS or Windows IME CI, and there is unlikely to be one soon. On those platforms a human typing into a page is the only way to get a trace that can honestly be labelled recorded rather than derived.

The page records the same field set as tests/e2e/terminal-ime-boundary-probe.ts, including the target's value, selectionStart and selectionEnd at each event. Those offsets are the whole point: they are what distinguishes a recorded trace from a reconstructed one. A real engine sends compositionupdate with the preedit character selected (selectionStart: 0, selectionEnd: 1) so it can replace it, and no hand-written fixture guesses that.

isComposing is stored as the engine reported it and is deliberately not coerced — Safari reports undefined rather than false, and the trace type models that distinction.

An earlier revision of this PR made that claim while not delivering it. The recorder did read event.isComposing uncoerced, but the trace is POSTed with JSON.stringify, which omits undefined-valued keys outright — so the written file had no isComposing key at all, and the bit was gone before the payload left the browser. It is now carried as null, which JSON can express, and transcribed back to undefined in the fixture. The replayer half of the same round trip is fixed in #11895.

Two more fields the page now captures, both added because a trace recorded without them cannot reproduce the quirk it was recorded for:

  • repeat — the accent panel a macOS press-and-hold opens is recognisable by nothing else. Since macOS press-and-hold is the single quirk most in need of a hand-recorded trace, a recorder that flattened it would have undercut the PR's own purpose.
  • selectionDirection — without it no trace can express a backward selection, so a preedit replacement range is only ever representable as a collapsed caret.

Two fields are emitted as explicit TODOs, because the page genuinely cannot observe them: the input method's name, and a description of what the human typed.

Everything is served from 127.0.0.1 and written to test-results/ime-recordings/ (already gitignored). Nothing is uploaded.

Screenshots

Terminal-only; the recorder page is a local dev tool, not app UI.

Testing

  • pnpm lint — oxlint clean
  • pnpm typecheck
  • pnpm test — record-ime-trace.test.mjs (new) holds the recorder and the fixture schema in lockstep: it fails if the page starts capturing a field the schema cannot express, which is exactly the drift that produced the isComposing bug above
  • pnpm build — not run
  • Exercised end to end: served the page, POSTed a trace, confirmed the written JSON deserializes through the same loader as the CI-captured recording
  • The page script is inside a template literal, so node --check on the module does not validate it; extracted and syntax-checked separately

Stated plainly: the recorder's browser-side record() runs in a page string and is not executed by any test. The contract test checks which fields it captures, not that a real browser hands them over correctly — only an actual recording session does that, which is the manual step this tool exists for.

AI Review Report

The captured schema is intentionally identical to the CI probe's, so traces from either source deserialize through one loader. Its shape is what faithful replay requires: environment + initial state + event list + final state, with per-event observed buffer state, and isComposing typed boolean | undefined so Safari reproduces faithfully.

Cross-platform: pure Node http plus path.join; no shell-out, so no open/xdg-open/start divergence. The URL is printed rather than auto-opened for that reason. Platform and browser are inferred from the user agent, with WebKit and Gecko checked before Chromium because Electron reports a Chrome token too.

Security Audit

  • Network: binds 127.0.0.1 only, on a port overridable via ORCA_IME_RECORDER_PORT. No outbound requests.
  • Path handling: the trace name is sanitized to [a-z0-9-] before being used as a filename, so a crafted name cannot traverse out of the output directory.
  • Data: writes only under test-results/, which is gitignored. Note the recorded value fields contain whatever the operator typed — review a trace before committing it as a fixture.
  • No auth, secrets, IPC, dependency, or git changes.

Notes

Top of stack #11899, on #11898. Companion to the ibus matrix rather than a replacement: CI covers hangul/libpinyin/anthy/unikey on Linux, this covers everything else.

@nwparker
nwparker force-pushed the nwparker/ime-trace-recorder branch from 4dd0475 to a801aef Compare August 1, 2026 10:21
@nwparker
nwparker force-pushed the nwparker/ime-trace-recorder branch from a801aef to 2765621 Compare August 1, 2026 10:27
@nwparker
nwparker force-pushed the nwparker/ime-trace-recorder branch 2 times, most recently from 0d0667c to 35c4e37 Compare August 2, 2026 02:34
@nwparker
nwparker force-pushed the nwparker/ime-trace-recorder branch from 35c4e37 to 8ee0087 Compare August 2, 2026 03:16
@nwparker nwparker closed this Aug 2, 2026
@nwparker nwparker reopened this Aug 2, 2026
@nwparker
nwparker force-pushed the nwparker/ime-trace-recorder branch from 8ee0087 to 85930b3 Compare August 2, 2026 03:31
@nwparker
nwparker force-pushed the nwparker/ime-trace-recorder branch from 85930b3 to 7e56fff Compare August 2, 2026 03:51
@nwparker
nwparker force-pushed the nwparker/ime-trace-recorder branch 3 times, most recently from 5e91f4b to ca2ef24 Compare August 2, 2026 04:25
nwparker and others added 2 commits August 1, 2026 21:47
CDP-dispatched keystrokes bypass the OS input-method layer, so no amount of
page.keyboard.type() produces a real composition. The Linux matrix drives ibus
through X11, but there is no macOS or Windows IME CI, and on those platforms a
human typing into a page is the only way to get a trace that can honestly be
labelled recorded.

pnpm ime:record serves a localhost page that captures the same field set as
tests/e2e/terminal-ime-boundary-probe.ts — including the selection offsets at
each event, which are what distinguish a recorded trace from a reconstructed
one — and writes it in the shape the fixture loader already consumes. Nothing
leaves the machine.

The engine name and the description of what the human typed are left as TODOs
in the output, because the page cannot observe either.

Co-authored-by: Orca <[email protected]>
The recorder captured isComposing faithfully and then lost it at the POST:
JSON.stringify omits an undefined value, so the written trace had no such
key at all. null carries it instead.

Adds repeat and selectionDirection, and a contract test so a field the
recorder learns about cannot again go somewhere the schema cannot hold it.

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker force-pushed the nwparker/ime-trace-recorder branch from ca2ef24 to eeba5e6 Compare August 2, 2026 04:49
@nwparker

nwparker commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Leaving this open — not superseded. #13128 (17b3dff) removed the first-party composition layer, but a trace recorder is orthogonal to which layer owns composition, and config/scripts/record-ime-trace.mjs never landed on main.

If anything this got more valuable, not less. The recurring lesson across this whole stack was that hand-written event sequences encode what we assume an IME does, and real ones disagree — a CJK source rewrites event.key while event.code keeps the physical key (#12171, #13033), and wScan=0 injection produces code:'' with a single keyup where Chromium dispatches two. Synthetic events would have hidden all of that.

Needs a rebase onto the new baseline. Worth carrying two rules the recorder should enforce, both learned the hard way: report keys-requested vs keys-inserted so a silent no-op cannot pass as a null result, and match controls by column, not character count — Hangul is two cells per syllable.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant