Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/scripts/terminal-ime-engagement-receipt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const IME_ENGAGEMENT_RECEIPT_ENV = 'ORCA_E2E_IME_ENGAGEMENT_RECEIPT'
export const EXPECTED_NATIVE_IME_TESTS = [
'forwards the issue exact-byte sequence without loss or duplication',
'forwards the issue sentence stress sequence without leaked ASCII',
'a digit typed right after a Hangul syllable reaches the pty'
'a digit typed right after a Hangul syllable reaches the pty',
'confirms native Hangul notes before a deliberate Enter saves'
]

function parseReceipts(text) {
Expand Down
31 changes: 23 additions & 8 deletions config/scripts/terminal-ime-engagement-receipt.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
verifyImeEngagementReceipts
} from './terminal-ime-engagement-receipt.mjs'

const [firstTest, secondTest, thirdTest] = EXPECTED_NATIVE_IME_TESTS
const [firstTest, secondTest, thirdTest, notesTest] = EXPECTED_NATIVE_IME_TESTS

function receipt(test, overrides = {}) {
return JSON.stringify({
Expand All @@ -20,7 +20,7 @@ describe('verifyImeEngagementReceipts', () => {
it('accepts a run where every expected test observed real composition', () => {
expect(
verifyImeEngagementReceipts(
`${receipt(firstTest)}\n${receipt(secondTest)}\n${receipt(thirdTest)}\n`
`${receipt(firstTest)}\n${receipt(secondTest)}\n${receipt(thirdTest)}\n${receipt(notesTest, { onDataChunks: 0 })}\n`
)
).toEqual([])
})
Expand All @@ -38,19 +38,34 @@ describe('verifyImeEngagementReceipts', () => {
it('rejects a partial run where only one test reached the engine', () => {
expect(verifyImeEngagementReceipts(`${receipt(firstTest)}\n`)).toEqual([
`no engagement receipt for "${secondTest}" — it was skipped, filtered out, or renamed`,
`no engagement receipt for "${thirdTest}" — it was skipped, filtered out, or renamed`
`no engagement receipt for "${thirdTest}" — it was skipped, filtered out, or renamed`,
`no engagement receipt for "${notesTest}" — it was skipped, filtered out, or renamed`
])
})

it('requires the digit receipt even when both original native tests passed', () => {
expect(verifyImeEngagementReceipts(`${receipt(firstTest)}\n${receipt(secondTest)}\n`)).toEqual([
expect(
verifyImeEngagementReceipts(
`${receipt(firstTest)}\n${receipt(secondTest)}\n${receipt(notesTest, { onDataChunks: 0 })}\n`
)
).toEqual([
`no engagement receipt for "${thirdTest}" — it was skipped, filtered out, or renamed`
])
})

it('requires the Notes receipt even when the terminal scenarios passed', () => {
expect(
verifyImeEngagementReceipts(
`${receipt(firstTest)}\n${receipt(secondTest)}\n${receipt(thirdTest)}\n`
)
).toEqual([
`no engagement receipt for "${notesTest}" — it was skipped, filtered out, or renamed`
])
})

it('rejects a run that typed keys but never opened a composition', () => {
const problems = verifyImeEngagementReceipts(
`${receipt(firstTest, { compositionStart: 0 })}\n${receipt(secondTest)}\n${receipt(thirdTest)}\n`
`${receipt(firstTest, { compositionStart: 0 })}\n${receipt(secondTest)}\n${receipt(thirdTest)}\n${receipt(notesTest, { onDataChunks: 0 })}\n`
)
expect(problems).toEqual([
`"${firstTest}" recorded no compositionstart — the IME never engaged`
Expand All @@ -59,7 +74,7 @@ describe('verifyImeEngagementReceipts', () => {

it('rejects a composition that produced no Hangul, which a latin passthrough would satisfy', () => {
const problems = verifyImeEngagementReceipts(
`${receipt(firstTest, { hangulComposition: 0 })}\n${receipt(secondTest)}\n${receipt(thirdTest)}\n`
`${receipt(firstTest, { hangulComposition: 0 })}\n${receipt(secondTest)}\n${receipt(thirdTest)}\n${receipt(notesTest, { onDataChunks: 0 })}\n`
)
expect(problems).toEqual([
`"${firstTest}" recorded no Hangul composition data — the engine produced no syllables`
Expand All @@ -68,7 +83,7 @@ describe('verifyImeEngagementReceipts', () => {

it('rejects a renamed test rather than counting it toward coverage', () => {
const problems = verifyImeEngagementReceipts(
`${receipt(firstTest)}\n${receipt(secondTest)}\n${receipt(thirdTest)}\n${receipt('some new scenario')}\n`
`${receipt(firstTest)}\n${receipt(secondTest)}\n${receipt(thirdTest)}\n${receipt(notesTest, { onDataChunks: 0 })}\n${receipt('some new scenario')}\n`
)
expect(problems).toEqual([
'unexpected engagement receipt for "some new scenario" — update EXPECTED_NATIVE_IME_TESTS'
Expand All @@ -77,7 +92,7 @@ describe('verifyImeEngagementReceipts', () => {

it('reports a truncated receipt rather than parsing around it', () => {
const problems = verifyImeEngagementReceipts(
`${receipt(firstTest)}\n{"test":"trunc\n${receipt(secondTest)}\n${receipt(thirdTest)}\n`
`${receipt(firstTest)}\n{"test":"trunc\n${receipt(secondTest)}\n${receipt(thirdTest)}\n${receipt(notesTest, { onDataChunks: 0 })}\n`
)
expect(problems).toEqual(['malformed receipt line: {"test":"trunc'])
})
Expand Down
17 changes: 16 additions & 1 deletion src/renderer/src/components/sidebar/WorktreeDisplayNameField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { Label } from '@/components/ui/label'
import { WorkspaceEmojiSuggestionPopover } from '@/components/workspace-emoji/WorkspaceEmojiSuggestionPopover'
import { useWorkspaceEmojiShortcodeInput } from '@/components/workspace-emoji/useWorkspaceEmojiShortcodeInput'
import { translate } from '@/i18n/i18n'
import {
isImeOwnedKeyboardEvent,
useImeEnterGestureOwnership
} from '@/lib/ime-composition-keyboard-event'

type WorktreeDisplayNameFieldProps = {
disabled: boolean
Expand All @@ -23,6 +27,7 @@ export function WorktreeDisplayNameField({
value
}: WorktreeDisplayNameFieldProps): React.JSX.Element {
const inputId = useId()
const enterGesture = useImeEnterGestureOwnership()
const emojiInput = useWorkspaceEmojiShortcodeInput({
disabled,
inputRef,
Expand All @@ -42,9 +47,19 @@ export function WorktreeDisplayNameField({
onChange={(event) =>
emojiInput.handleValueChange(event.target.value, event.target.selectionStart)
}
onCompositionStart={() => enterGesture.setComposing(true)}
onCompositionEnd={() => enterGesture.setComposing(false)}
onKeyUp={enterGesture.onKeyUp}
onBlur={enterGesture.reset}
onSelect={(event) => emojiInput.syncCursor(event.currentTarget)}
onKeyDown={(event) => {
if (emojiInput.handleKeyDown(event) || event.key !== 'Enter') {
if (
enterGesture.ownsKeyDown(event) ||
enterGesture.isComposing() ||
isImeOwnedKeyboardEvent(event) ||
emojiInput.handleKeyDown(event) ||
event.key !== 'Enter'
) {
return
}
event.preventDefault()
Expand Down
20 changes: 19 additions & 1 deletion src/renderer/src/components/sidebar/WorktreeIssueLinkField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React, { useCallback, useId, useMemo } from 'react'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import {
isImeOwnedKeyboardEvent,
useImeEnterGestureOwnership
} from '@/lib/ime-composition-keyboard-event'
import {
DropdownMenu,
DropdownMenuContent,
Expand Down Expand Up @@ -88,6 +92,7 @@ export function WorktreeIssueLinkField(props: WorktreeIssueLinkFieldProps): Reac
onKeyDown
} = props

const enterGesture = useImeEnterGestureOwnership()
// Why: the helper `<p>` is the only surface for the invalid and displacement
// states, so it has to be announced with the field rather than just seen.
const helperId = useId()
Expand Down Expand Up @@ -172,7 +177,20 @@ export function WorktreeIssueLinkField(props: WorktreeIssueLinkFieldProps): Reac
aria-describedby={helperId}
value={value}
onChange={(e) => onValueChange(e.target.value)}
onKeyDown={onKeyDown}
onCompositionStart={() => enterGesture.setComposing(true)}
onCompositionEnd={() => enterGesture.setComposing(false)}
onKeyUp={enterGesture.onKeyUp}
onBlur={enterGesture.reset}
onKeyDown={(event) => {
if (
enterGesture.ownsKeyDown(event) ||
enterGesture.isComposing() ||
isImeOwnedKeyboardEvent(event)
) {
return
}
onKeyDown(event)
}}
disabled={isReadOnly}
aria-invalid={isInvalid || undefined}
placeholder={translate(
Expand Down
177 changes: 177 additions & 0 deletions src/renderer/src/components/sidebar/WorktreeMetaDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ import WorktreeMetaDialog from './WorktreeMetaDialog'
const REPO_ID = 'repo-1'
const WORKTREE_ID = 'repo-1::/repo/worktrees/feature'

const IME_FIELDS = [
{
placeholder: 'Notes about this worktree...',
value: '日本語',
updates: { comment: '日本語' }
},
{
placeholder: 'Custom display name...',
value: '日本語の名前',
updates: { displayName: '日本語の名前' }
},
{
placeholder: 'Issue #, or a GitHub or Linear URL',
value: '42',
updates: { linkedIssue: 42 }
},
{ placeholder: 'PR # or GitHub URL', value: '43', updates: { linkedPR: 43 } },
{ placeholder: 'MR ! or GitLab URL', value: '!44', updates: { linkedGitLabMR: 44 } }
] as const

const initialState = useAppStore.getInitialState()
const updateWorktreeMeta =
vi.fn<
Expand Down Expand Up @@ -223,9 +243,166 @@ describe('WorktreeMetaDialog issue link row', () => {

afterEach(() => {
cleanup()
vi.restoreAllMocks()
useAppStore.setState(initialState, true)
})

it.each(IME_FIELDS)(
'ignores IME Enter and resets on blur in $placeholder',
async ({ placeholder, value, updates }) => {
openDialog(placeholder === 'MR ! or GitLab URL' ? { modalReviewProvider: 'gitlab' } : {})
const input = screen.getByPlaceholderText(placeholder)
fireEvent.change(input, { target: { value } })
for (const marker of [{ isComposing: true, keyCode: 13 }, { keyCode: 229 }]) {
expect(fireEvent.keyDown(input, { key: 'Enter', ...marker })).toBe(true)
expect(updateWorktreeMeta).not.toHaveBeenCalled()
expect(useAppStore.getState().activeModal).toBe('edit-meta')
}
fireEvent.compositionStart(input)
expect(fireEvent.keyDown(input, { key: 'Enter', keyCode: 13 })).toBe(true)
expect(updateWorktreeMeta).not.toHaveBeenCalled()
fireEvent.blur(input)
await act(async () => {
fireEvent.keyDown(input, { key: 'Enter', keyCode: 13 })
})
expect(updateWorktreeMeta).toHaveBeenCalledTimes(1)
expect(updateWorktreeMeta.mock.calls[0]?.[1]).toEqual(expect.objectContaining(updates))
expect(useAppStore.getState().activeModal).toBe('none')
}
)

it.each(
['before keyup', 'after keyup'].flatMap((order) =>
IME_FIELDS.map((field) => ({ ...field, order }))
)
)(
'ignores the IME Enter redispatch $order in $placeholder',
async ({ order, placeholder, value, updates }) => {
openDialog(placeholder === 'MR ! or GitLab URL' ? { modalReviewProvider: 'gitlab' } : {})
const input = screen.getByPlaceholderText(placeholder)
const frames: FrameRequestCallback[] = []
vi.spyOn(window, 'requestAnimationFrame').mockImplementation((callback) =>
frames.push(callback)
)
fireEvent.compositionStart(input)
fireEvent.keyDown(input, { key: 'Process', keyCode: 229, isComposing: true })
fireEvent.change(input, { target: { value } })
fireEvent.compositionEnd(input)
if (order === 'after keyup') {
fireEvent.keyUp(input, { key: 'Enter', keyCode: 13 })
}
expect(fireEvent.keyDown(input, { key: 'Enter', keyCode: 13 })).toBe(false)
expect(updateWorktreeMeta).not.toHaveBeenCalled()
expect(useAppStore.getState().activeModal).toBe('edit-meta')
fireEvent.keyUp(input, { key: 'Enter', keyCode: 13 })
act(() => frames.forEach((callback) => callback(0)))
await act(async () => {
fireEvent.keyDown(input, { key: 'Enter', keyCode: 13 })
})
expect(updateWorktreeMeta.mock.calls[0]?.[1]).toEqual(expect.objectContaining(updates))
expect(updateWorktreeMeta).toHaveBeenCalledTimes(1)
expect(useAppStore.getState().activeModal).toBe('none')
}
)

it.each(IME_FIELDS)(
'expires an IME gesture without redispatch in $placeholder',
async ({ placeholder }) => {
openDialog(placeholder === 'MR ! or GitLab URL' ? { modalReviewProvider: 'gitlab' } : {})
const input = screen.getByPlaceholderText(placeholder)
const frames: FrameRequestCallback[] = []
vi.spyOn(window, 'requestAnimationFrame').mockImplementation((callback) =>
frames.push(callback)
)
fireEvent.compositionStart(input)
fireEvent.keyDown(input, { key: 'Enter', keyCode: 229 })
fireEvent.compositionEnd(input)
fireEvent.keyUp(input, { key: 'Enter', keyCode: 13 })
act(() => frames.forEach((callback) => callback(0)))
await act(async () => {
fireEvent.keyDown(input, { key: 'Enter', keyCode: 13 })
})
expect(updateWorktreeMeta).toHaveBeenCalledTimes(1)
expect(useAppStore.getState().activeModal).toBe('none')
}
)

it.each(
['active composition', 'pending confirmation'].flatMap((phase) =>
IME_FIELDS.map((field) => ({ ...field, phase }))
)
)(
'allows a deliberate save after closing with $phase in $placeholder',
async ({ phase, placeholder, value, updates }) => {
openDialog(placeholder === 'MR ! or GitLab URL' ? { modalReviewProvider: 'gitlab' } : {})
const input = screen.getByPlaceholderText(placeholder)
const modalData = useAppStore.getState().modalData
fireEvent.compositionStart(input)
if (phase === 'pending confirmation') {
fireEvent.keyDown(input, { key: 'Enter', keyCode: 229 })
fireEvent.compositionEnd(input)
}
act(() => useAppStore.getState().closeModal())
expect(screen.queryByPlaceholderText(placeholder)).toBeNull()
act(() => useAppStore.setState({ activeModal: 'edit-meta', modalData }))
const reopenedInput = screen.getByPlaceholderText(placeholder)
fireEvent.change(reopenedInput, { target: { value } })
await act(async () => {
fireEvent.keyDown(reopenedInput, { key: 'Enter', keyCode: 13 })
})
expect(updateWorktreeMeta).toHaveBeenCalledTimes(1)
expect(updateWorktreeMeta.mock.calls[0]?.[1]).toEqual(expect.objectContaining(updates))
expect(useAppStore.getState().activeModal).toBe('none')
}
)

it('keeps a folder workspace note open through composition confirmation', async () => {
const worktreeId = folderWorkspaceKey('fw-1')
openDialog({ worktreeId, folderWorkspace: {} })
const input = screen.getByPlaceholderText('Notes about this worktree...')
fireEvent.change(input, { target: { value: '日本語' } })
fireEvent.compositionStart(input)
fireEvent.keyDown(input, { key: 'Enter', keyCode: 229 })
fireEvent.compositionEnd(input)
fireEvent.keyDown(input, { key: 'Enter', keyCode: 13 })
expect(updateWorktreeMeta).not.toHaveBeenCalled()
expect(useAppStore.getState().activeModal).toBe('edit-meta')
await act(async () => {
fireEvent.keyDown(input, { key: 'Enter', keyCode: 13 })
})
expect(updateWorktreeMeta).toHaveBeenCalledExactlyOnceWith(worktreeId, { comment: '日本語' })
expect(useAppStore.getState().activeModal).toBe('none')
})

it.each([
{ userAgent: 'Macintosh', modifier: { metaKey: true } },
{ userAgent: 'Windows', modifier: { ctrlKey: true } },
{ userAgent: 'Linux', modifier: { ctrlKey: true } }
])(
'keeps the save shortcut outside composition on $userAgent',
async ({ userAgent, modifier }) => {
vi.spyOn(navigator, 'userAgent', 'get').mockReturnValue(userAgent)
openDialog()
const input = screen.getByPlaceholderText('Notes about this worktree...')
fireEvent.compositionStart(input)
fireEvent.keyDown(input, { key: 'Enter', keyCode: 13, ...modifier })
expect(updateWorktreeMeta).not.toHaveBeenCalled()
fireEvent.compositionEnd(input)
await act(async () => {
fireEvent.keyDown(input, { key: 'Enter', keyCode: 13, ...modifier })
})
expect(updateWorktreeMeta).toHaveBeenCalledTimes(1)
}
)

it('leaves Shift+Enter available for a newline', () => {
openDialog()
const input = screen.getByPlaceholderText('Notes about this worktree...')
expect(fireEvent.keyDown(input, { key: 'Enter', keyCode: 13, shiftKey: true })).toBe(true)
expect(updateWorktreeMeta).not.toHaveBeenCalled()
expect(useAppStore.getState().activeModal).toBe('edit-meta')
})

it('seeds the chip and value from a GitHub link', () => {
openDialog({ worktree: { linkedIssue: 42 } })

Expand Down
Loading
Loading