Repository navigation
fix(find): refuse a focus match behind the visible keyboard (#2622) #3727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b4413ec
refactor(move): relocate the keyboard guard to @agent-device/selectors
thymikee a5c9be8
fix(find): run the keyboard guard before find focus dispatches
thymikee 8fe670b
chore(gates): register the new selectors subpaths and the find-focus-…
thymikee 72c771f
fix(selectors): name every interaction action in the refusal verb
thymikee c2117ad
test(selectors): pin the typed refusal, not just its message
thymikee 0f42856
fix(contracts): say what find-focus-dispatch actually enforces
thymikee ebb9561
refactor(find): drop the dead payload fallback and share the refusal …
thymikee a0135d0
docs(contracts): point the find-focus-dispatch gaps at their own issue
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
93 changes: 93 additions & 0 deletions
93
packages/daemon/src/execution/interaction/internal/__tests__/find-keyboard-occlusion.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { test, expect, vi, beforeEach } from 'vitest'; | ||
| import { keyboardCoveredTabBarSnapshot } from '@agent-device/test-kit'; | ||
| import type { SnapshotState } from '@agent-device/kernel/snapshot'; | ||
| import { | ||
| mockFocusPoint, | ||
| resetFindTouchRuntimeFixture, | ||
| runFindClickScenario, | ||
| } from './find-touch-runtime-fixture.ts'; | ||
| import { mockTypeText } from '../../../__tests__/interaction-get-runtime-fixture.ts'; | ||
| import { refFrameState } from '../../../../core/ref-frame.ts'; | ||
|
|
||
| vi.mock('../../../../core/snapshot-interactor-capture.ts', async () => { | ||
| const fixture = await import('../../../../__tests__/support/legacy-snapshot-capture-fixture.ts'); | ||
| return { captureSnapshotWithInteractor: fixture.captureSnapshotThroughLegacyDispatchFixture }; | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| resetFindTouchRuntimeFixture(); | ||
| }); | ||
|
|
||
| function keyboardTree(targetRect?: SnapshotState['nodes'][number]['rect']): SnapshotState { | ||
| return keyboardCoveredTabBarSnapshot(targetRect ? { targetRect } : {}); | ||
| } | ||
|
|
||
| type Refusal = { | ||
| code?: string; | ||
| message?: string; | ||
| hint?: string; | ||
| details?: Record<string, unknown>; | ||
| }; | ||
|
|
||
| function assertKeyboardRefusal( | ||
| response: { ok: boolean; error?: Refusal }, | ||
| verb: string, | ||
| ): asserts response { | ||
| expect(response.ok).toBe(false); | ||
| const error = response.error as Refusal; | ||
| expect(error.code).toBe('COMMAND_FAILED'); | ||
| expect(error.message).toBe(`Ref @e2 is behind the visible keyboard and cannot ${verb} safely`); | ||
| expect(error.details?.reason).toBe('tap_keyboard_occludes_target'); | ||
| expect(error.details?.ref).toBe('@e2'); | ||
| expect(error.details?.rect).toEqual({ x: 148, y: 791, width: 104, height: 83 }); | ||
| expect(error.details?.keyboardFrame).toEqual({ x: 0, y: 583, width: 402, height: 291 }); | ||
| expect(error.details?.dispatched).toBe('no'); | ||
| expect(error.hint).toMatch(/End editing first/); | ||
| } | ||
|
|
||
| test('find focus refuses a match whose tap point sits behind the visible keyboard', async () => { | ||
| const { response, session } = await runFindClickScenario({ | ||
| positionals: ['Form', 'focus'], | ||
| nodes: keyboardTree().nodes, | ||
| }); | ||
|
|
||
| assertKeyboardRefusal(response, 'be focused'); | ||
| expect(mockFocusPoint).not.toHaveBeenCalled(); | ||
| // ADR 0014: the refusal is pre-action, so the captured frame stays pinnable. | ||
| expect(refFrameState(session)).toBe('active'); | ||
| }); | ||
|
|
||
| test('find type refuses before the focus or the text dispatch', async () => { | ||
| const { response, session } = await runFindClickScenario({ | ||
| positionals: ['Form', 'type', 'hello'], | ||
| nodes: keyboardTree().nodes, | ||
| }); | ||
|
|
||
| assertKeyboardRefusal(response, 'be focused'); | ||
| expect(mockFocusPoint).not.toHaveBeenCalled(); | ||
| expect(mockTypeText).not.toHaveBeenCalled(); | ||
| expect(refFrameState(session)).toBe('active'); | ||
| }); | ||
|
|
||
| test('find focus on a match above the keyboard band still focuses', async () => { | ||
| const { response, session } = await runFindClickScenario({ | ||
| positionals: ['Form', 'focus'], | ||
| nodes: keyboardTree({ x: 148, y: 470, width: 104, height: 110 }).nodes, | ||
| }); | ||
|
|
||
| expect(response.ok).toBe(true); | ||
| expect(mockFocusPoint).toHaveBeenCalledTimes(1); | ||
| expect(refFrameState(session)).toBe('expired'); | ||
| }); | ||
|
|
||
| test('find focus on a reported keyboard key still focuses it', async () => { | ||
| // The closest negative: the same guard excuses the keyboard's own control, which sits inside the | ||
| // band it would otherwise refuse. | ||
| const { response } = await runFindClickScenario({ | ||
| positionals: ['label', 'space', 'focus'], | ||
| nodes: keyboardTree().nodes, | ||
| }); | ||
|
|
||
| expect(response.ok).toBe(true); | ||
| expect(mockFocusPoint).toHaveBeenCalledTimes(1); | ||
| }); |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { test } from 'vitest'; | ||
| import assert from 'node:assert/strict'; | ||
| import { interactionVerb, type InteractionAction } from './interaction-action.ts'; | ||
|
|
||
| // Exhaustive mapping over `InteractionAction` is the compiler's check. This pins the words | ||
| // themselves, so a refusal that starts describing a non-tap gesture as a tap — which is what the | ||
| // catch-all used to do for `drag` — is a deliberate change here, not an accident inside the map. | ||
| test('every action names itself in the refusal', () => { | ||
| const verbs: Array<[InteractionAction, string]> = [ | ||
| ['click', 'be tapped'], | ||
| ['press', 'be tapped'], | ||
| ['fill', 'be filled'], | ||
| ['focus', 'be focused'], | ||
| ['longPress', 'be long-pressed'], | ||
| ['hover', 'be hovered'], | ||
| ['scroll', 'be scrolled'], | ||
| ['swipe', 'be swiped'], | ||
| ['pinch', 'be pinched'], | ||
| ['pan', 'be panned'], | ||
| ['drag', 'be dragged'], | ||
| ['fling', 'be flung'], | ||
| ['rotate', 'be rotated'], | ||
| ['transform', 'be transformed'], | ||
| ]; | ||
| for (const [action, verb] of verbs) { | ||
| assert.equal(interactionVerb(action), verb, action); | ||
| } | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.