test(terminal): cover live macOS Korean syllable flush (#12284)

This commit is contained in:
Jinjing 2026-08-03 03:07:52 -07:00 committed by GitHub
parent 40d5f36608
commit e08eba674c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 61 additions and 2 deletions

View File

@ -32,13 +32,47 @@ function typeNativeTwoSetKorean(processId: number, keyCodes: readonly number[]):
])
}
function typeNativeTwoSetKoreanPreedit(processId: number, keyCodes: readonly number[]): void {
execFileSync('osascript', [
'-e',
`tell application "System Events" to set frontmost of first application process whose unix id is ${processId} to true`,
'-e',
'tell application "System Events"',
'-e',
`repeat with currentKeyCode in {${keyCodes.join(', ')}}`,
'-e',
'key code (currentKeyCode as integer)',
'-e',
'delay 0.1',
'-e',
'end repeat',
'-e',
'end tell'
])
}
function commitNativeComposition(): void {
execFileSync('osascript', ['-e', 'tell application "System Events" to key code 36'])
}
async function readActiveComposition(page: Page): Promise<string | null> {
return page.evaluate(() => {
const textarea = document.querySelector<HTMLTextAreaElement>('.xterm-helper-textarea:focus')
const composition = textarea?.parentElement?.querySelector<HTMLElement>(
'.composition-view.active'
)
return composition?.textContent?.replaceAll('\u200e', '') ?? null
})
}
async function runNativeScenario(
page: Page,
testInfo: TestInfo,
testRepoPath: string,
processId: number,
keyCodes: readonly number[],
expectedText: string
expectedText: string,
preCommit?: { committedText: string; preeditText: string }
): Promise<void> {
await waitForSessionReady(page)
await waitForActiveWorktree(page)
@ -55,7 +89,16 @@ async function runNativeScenario(
await startTerminalImeByteReader(page, ptyId, reader)
await focusActiveTerminalInput(page)
await installTerminalImeBoundaryProbe(page)
typeNativeTwoSetKorean(processId, keyCodes)
if (preCommit) {
typeNativeTwoSetKoreanPreedit(processId, keyCodes)
await expect.poll(() => readActiveComposition(page)).toBe(preCommit.preeditText)
await expect
.poll(async () => (await readTerminalImeBoundaryTrace(page)).onData.join(''))
.toBe(preCommit.committedText)
commitNativeComposition()
} else {
typeNativeTwoSetKorean(processId, keyCodes)
}
const receivedBytes = await waitForTerminalImeBytes(page, reader)
expect(receivedBytes).toEqual([Buffer.from(`${expectedText}\n`).toString('hex')])
@ -109,4 +152,20 @@ test.describe('Native macOS 2-Set Korean terminal input @headful', () => {
'ㅐㅏ묘'
)
})
test('flushes each syllable while the next remains in preedit', async ({
electronApp,
orcaPage,
testRepoPath
}, testInfo) => {
await runNativeScenario(
orcaPage,
testInfo,
testRepoPath,
electronApp.process().pid!,
[15, 40, 1, 40, 14, 40],
'가나다',
{ committedText: '가나', preeditText: '다' }
)
})
})