Skip to content

feat(mobile): add device.isKeyboardShown() - #1893

Merged
okwasniewski merged 13 commits into
e2e-inc:mainfrom
leszko11:feat/device-is-keyboard-shown
Nov 21, 2026
Merged

okwasniewski merged 13 commits into
e2e-inc:mainfrom
leszko11:feat/device-is-keyboard-shown

Conversation

@leszko11

@leszko11 leszko11 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What and why

  • Adds device.isKeyboardShown(): Promise<boolean> to @e2e-dev/mobile, the Appium isKeyboardShown() row from the umbrella issue.

  • It reads one capture (a sparse tree is captured again first) and answers from what agent-device reports for the keyboard, else from visible keyboard elements in the tree: the same band observations hide covered nodes under (keyboardBand, packages/mobile/src/nodes.ts).

    agent-device keyboard fact answer
    visible, derived true
    absent false
    visibility-only, tree-rejected with visible that visible
    tree-rejected without visible true for a keyboard element drawn on screen. With none, the keyboard is moving: it is captured again briefly, then ENGINE_FAILURE (which expect.poll retries)
    unmeasurable, or no reading true for a keyboard element drawn on screen. With none: ENGINE_FAILURE for a sparse or cut tree, else UNSUPPORTED_CAPABILITY. Only absent (or a hidden probe) answers false
  • It is a recorded step (device.isKeyboardShown), bounded by actionTimeout, and changes nothing on the device. It reads the screen as it is now, so after an action that closes the keyboard the docs say to poll it:

    await screen.getByTestId('email-input').fill('jane@example.com');
    await device.dismissKeyboard();
    await expect.poll(() => device.isKeyboardShown()).toBe(false);
  • dismissKeyboard(), and the wait before acting on a control after the keyboard opened or closed, decide whether the keyboard is up by the same rule (keyboardShownIn in packages/mobile/src/keyboard.ts): a reading that cannot answer means no drag. The dismissing drag starts above the highest keyboard element drawn on screen, suggestion strip included (keyboardElementsTop), so a capture that lists only the strip (a hardware keyboard) drags from above it. A keyboard reported up with no frame and no keyboard element on screen gets no drag: UNSUPPORTED_CAPABILITY, since no point is known to be above it.

  • Docs: docs/reference/mobile.mdx (summary row, entry, Throws), the Appium guide row moves from "What e2e doesn't have yet" to "Map each command", and the ja and zh pages get the new heading and code so their outline still matches. The mobile README lists the method.

Issue

Part of #1855, checklist item device.isKeyboardShown() (Device and app).

Verified

Ran it locally: yes

  • iOS 27.2 simulator (iPhone 18 Pro), Xcode 27.2, the built CLI from this branch in a scratch project on Contacts: open a new contact, type a first name, close and discard it, so nothing is saved.
on the contact list: false
after typing a first name: true
after discarding the form: true
after discarding the form: true
after discarding the form: true
after discarding the form: true
after discarding the form: true
after discarding the form: false
   ✓ |ios| keyboard.e2e.ts > isKeyboardShown follows the soft keyboard on a new contact form 27.18s
      Tests  1 passed (1)

The true reads after the discard are real: the sheet and the keyboard animate out for about 2.5 s on that machine.

  • A second run passed the same way. On this simulator agent-device reports tree-rejected without visible right after fill, while the keyboard slides in. Such a reading is now captured again until the keyboard lands.
  • The same check in Safari (address bar, then dismissKeyboard()) read false, true, false on an earlier build.
  • apps/mobile-benchmark/tests/device.e2e.ts on the iOS 27.2 simulator, with the benchmark app built after fix(mobile-benchmark): adopt UIKit scenes so the app launches on iOS 27 #1898: the new keyboard test and both onboarding tests pass, twice. isKeyboardShown polling read 4 settling captures before true, and the phone step dismisses. That run also carried the separate iOS 27 toolbar fix for dismissKeyboard, which comes as its own PR; without it, iOS 27 refuses the first drag. Some runs failed earlier, reading the home list, while the Mac's load average was 30 to 200. Android was not run locally. The Android emulator in CI draws no soft keyboard, even for a tapped field, so the keyboard reads are their own iOS-only test (isKeyboardShown follows the keyboard up and through a dismissal), and the onboarding test is unchanged from main.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed (packages/mobile/dist/device.d.ts). tests/types/sdk-types.ts covers e2e, not the mobile Device interface, so it is unchanged; no wire change.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

🤖 Generated with Claude Code

View guided diff

@github-actions github-actions Bot added the size:L Up to 499 changed lines, not counting tests, fixtures, translated docs, or the lockfile label Nov 17, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 12 files

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread docs/ja/migrate/appium.mdx Resolved
Comment thread packages/mobile/src/surface.ts Resolved
Comment thread docs/ja/reference/mobile.mdx Resolved
Comment thread docs/zh/reference/mobile.mdx Resolved

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Reviewed at 6577433 against main: code, unit tests, the agent-device 0.21.38 keyboard producers, and the failing Android CI job. Assignment is fine (#1855, assigned to @leszko11).

Must fix

  • apps/mobile-benchmark/tests/device.e2e.ts:49 - android deterministic (and so mobile gate) fails on this PR. The new expect(await device.isKeyboardShown()).toBe(true) reads false on all 4 attempts. The failure screenshot shows no soft keyboard after fill on the Android emulator, so isKeyboardShown() answered correctly and the assertion is what's wrong. Fix: tap the field before asserting so it opens the keyboard, then await expect.poll(() => device.isKeyboardShown()).toBe(true), because it slides in. Or keep the true assertion iOS-only. The immediate read on iOS also depends on the keyboard having appeared already, so poll there too.

  • packages/mobile/src/surface.ts:197 (KEYBOARD_NOT_IN_TREE) - mapping keyboard-not-observed and keyboard-visibility-probe-unsupported to false contradicts agent-device's own contract (SnapshotKeyboardBandFact in sdk-contracts.d.ts: "A full pre-projection iOS root scan proves absence; projected or partial nodes and omitted facts never do"). In 0.21.38:

    • keyboard-not-observed comes from acquireProviderKeyboard/observeCompleteTreeKeyboard. A complete tree with no keyboard evidence gets absent. This reason shows up only when the tree is incomplete, or when it holds keyboard evidence (a UIRemoteKeyboardWindow role, KB key or prediction cells) but no element e2e counts as a keyboard. That is exactly the case where agent-device refused to claim "no keyboard".
    • keyboard-visibility-probe-unsupported comes from the WebDriver providers when Appium has no is_keyboard_shown route. That includes Android (runtime13.js, backend: android), where the page source does not hold the IME window, so a cloud Android session with the keyboard up answers false. The comment's "(iOS)" premise is not checked anywhere.

    Fix: delete the set and let these reasons fall through to UNSUPPORTED_CAPABILITY. absent is the proof of absence. If a real iOS screen comes back as keyboard-not-observed with no keyboard showing, that gap belongs in agent-device, not a reinterpretation here. Please say which fact your post-discard false reads on the iOS 27 sim came from.

Should fix

  • surface.ts now holds three definitions of "keyboard is up": measuredKeyboard, keyboardShowing (used by dismissKeyboard), and keyboardShownIn, plus keyboardBand in nodes.ts. They already disagree. With visibility-only: false plus keys in the tree, for example, isKeyboardShown() says false while dismissKeyboard() drags. Make keyboardShowing(raw) keyboardShownIn(raw) === true (unknown stays "don't drag") so there is one rule. It's a one-line change and removes the drift this PR adds.
  • keyboardShownIn is a pure function of the capture, the same kind of logic as keyboardBand. Move it next to keyboardBand in nodes.ts (or a small keyboard.ts) instead of growing surface.ts, which is already 1967 lines.
  • tree-rejected without visible returns true without checking the keys. agent-device emits it when any keyboard element is in the tree, so a keyboard element left off-screen after dismissal would read true forever. Answer from visible, on-screen keyboard elements there, the way keyboardBand filters them.

Nits

  • docs/ja/reference/mobile.mdx:870, docs/zh/reference/mobile.mdx - the new Throws table keeps English headers (Throws | When), but the other tables on those pages are translated (エラー | 発生条件). The cubic P3s are valid.
  • Reference Throws row for ENGINE_FAILURE says "agent-device reported no keyboard". It reported no reading. "measured nothing" is closer.
  • Cubic P2 on surface.ts:217 (a negative visibility-only should yield to tree keys) is not a real issue: that probe is Appium's own isKeyboardShown, and keyboardBand treats it the same way.

Verified

  • tsc --noEmit (mobile), oxlint, and check-docs-translations pass. vitest tests/unit passes 554/554. The one failing suite, provider-example, needs a built mobile dist and is environment-only.
  • Mutation testing: flipping tree-rejected to ?? false, dropping the isTruncated branch, flipping the KEYBOARD_NOT_IN_TREE answer, and forcing visibility-only to true each fail the new tests.
  • CI: ios deterministic passes. android deterministic fails at device.e2e.ts:49 on attempt 1, attempt 2, and rerun 1 (screenshot shows no keyboard). That failure is caused by this PR, not a flake.
  • Parity: Appium XCUITest isKeyboardShown checks for a keyboard element in the tree. UiAutomator2 uses the IME probe (dumpsys input_method), and agent-device exposes that as keyboard status on Android only (unsupported on iOS in 0.21.38). Detox has no keyboard-visibility API.

@leszko11
leszko11 force-pushed the feat/device-is-keyboard-shown branch from 6577433 to 66e7e7b Compare November 18, 2026 16:59
@leszko11

Copy link
Copy Markdown
Contributor Author

[claude-opus-5-5] responding on behalf of @leszko11

Thanks. Addressed in 66e7e7b, rebased on main:

  • Android CI. The test now taps the field before fill, since a fill on Android sets the text without opening the input method. Both reads poll (expect.poll(...).toBe(true), then .toBe(false)).
  • KEYBOARD_NOT_IN_TREE removed. Only absent, or a probe that says hidden, answers false. keyboard-not-observed and keyboard-visibility-probe-unsupported now fail with UNSUPPORTED_CAPABILITY. On the iOS 27.2 simulator, the benchmark home list and Contacts with no keyboard both read { kind: 'absent', treeBound: true }, so the post-discard false reads came from absent.
  • One rule. keyboardShownIn moved to keyboard.ts, and keyboardShowing(raw) is now keyboardShownIn(...) === true. A test checks that a hidden visibility-only probe over listed keys gives false and no drag.
  • tree-rejected without visible. It now answers from keyboard elements drawn on screen (keyboardOnScreen in nodes.ts). The unmeasurable and no-reading fallback uses the same check, so a keyboard left in the tree off screen no longer reads as shown.
    • With no on-screen key, the keyboard is still moving. On the iOS 27 simulator the first capture after a fill reads like this for a few hundred ms, and a number pad lists no key in that window.
    • isKeyboardShown and dismissKeyboard therefore capture again, briefly, before they answer (KEYBOARD_SETTLE_BACKOFF_MS, budget-bounded). If the keyboard is still moving after that, isKeyboardShown fails with an ENGINE_FAILURE that expect.poll retries, and dismissKeyboard does not drag.
  • Nits. The ja and zh Throws tables are translated, the ENGINE_FAILURE row says "measured nothing", and the Appium guide row says to poll after opening or closing the keyboard.

Verified on an iPhone 18 Pro simulator with iOS 27.2: the onboarding test passes, isKeyboardShown polling went through 4 settling reads before it read true, and the phone step dismisses. That run also carried the separate iOS 27 toolbar fix for dismissKeyboard, which I'll open as its own PR. Without it, iOS 27 refuses the first drag. Android was not run locally, so CI is the check there.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 13 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread packages/mobile/src/surface.ts Resolved
Comment thread packages/mobile/src/keyboard.ts Resolved
Comment thread packages/mobile/src/keyboard.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 6 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/reference/mobile.mdx">

<violation number="1" location="docs/reference/mobile.mdx:938">
P2: The example reads `isKeyboardShown()` right after `fill`, but this section says to poll after an action that opens the keyboard. The PR notes that `fill` on Android does not open the input method, so the example should tap the field first and poll the read.</violation>
</file>

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread docs/reference/mobile.mdx Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-checked at c419d99 against main 9d240ac: the code, unit tests, mutants, the cubic threads, and the Android/iOS CI runs at 3c8b3bd and c419d99.

Earlier asks, all done:

  • KEYBOARD_NOT_IN_TREE is gone. Only absent, or a probe or rejected frame that says hidden, answers false. keyboard-not-observed and keyboard-visibility-probe-unsupported fail with UNSUPPORTED_CAPABILITY.
  • One rule: keyboardShownIn lives in keyboard.ts, keyboardShowing(raw) is keyboardShownIn(...) === true, and the dismiss drag reads reading.shown.
  • tree-rejected without visible answers from on-screen keyboard elements (keyboardOnScreen), else a settling ENGINE_FAILURE that gets a short, budget-bounded recapture.
  • ja/zh Throws tables are translated, and the ENGINE_FAILURE row says "measured nothing".
  • Android test: the 3c8b3bd run shows the tap did not help. The failure screenshot has the email field focused and no soft keyboard drawn, and isKeyboardShown() read false 38 times. So false was the right answer, and keeping the keyboard test iOS-only is justified.

Must fix

None.

Should fix

  • packages/mobile/src/keyboard.ts:148 / surface.ts:162 - keyboardOnScreen counts SystemInputAssistantView as the keyboard, but keyboardTop only looks at KEYBOARD_KINDS. If a capture lists only the assistant bar (for example with a hardware keyboard connected), dismissKeyboardByGesture now drags with keyboardTop = viewport.height. That puts the drag start band over the bar. On main this case never dragged. Fix: compute the top from keyboardBand(...), which already includes the strip. Or leave the assistant bar out of the drag decision.
  • docs/reference/mobile.mdx:957 (open cubic P2, real): the example reads isKeyboardShown() once, right after fill, while the text above says to poll after an action that opens or closes the keyboard. Mid-slide that single read throws ENGINE_FAILURE. Show the documented pattern instead, e.g. await device.dismissKeyboard(); await expect.poll(() => device.isKeyboardShown()).toBe(false);.

Nits

  • keyboardShowing now also feeds the projection's keyboardVisible, which waitForTransition compares. No test covers that path: putting the old rule back in keyboardShowing keeps all 252 engine tests green. Worth one test, or a line in the changeset, since the transition wait changes for visibility-only and derived captures.

Verified

  • tsc --noEmit (mobile) and oxlint pass. vitest tests/unit passes 559/559. provider-example needs a built mobile dist, so its failure is environment-only.
  • Mutants, each failing the new tests: counting off-screen keyboard elements, unknown facts answering false, no settle recapture, tree-rejected answering true with no key on screen, and ignoring truncated. The one that survives is the keyboardShowing rule (see the nit).
  • CI at c419d99: ios deterministic passes, including the new iOS-only test. android deterministic fails 57/57 at the home-screen toBeVisible in openScenario. All 57 failure traces show the emulator's "System UI isn't responding" dialog, so this is an emulator infra flake and not this PR. At 3c8b3bd, the same job passed everything except the test that has since moved to iOS only. Needs a rerun of android deterministic.

@okwasniewski
okwasniewski dismissed their stale review November 18, 2026 22:23

Asks done, see latest automated re-check.

@leszko11

Copy link
Copy Markdown
Contributor Author

[claude-opus-5-5] responding on behalf of @leszko11

Thanks. Addressed in feb461e:

  • Drag over the suggestion strip. keyboardTop now falls back to keyboardElementsTop in nodes.ts: the highest keyboard element drawn on screen, using the predicate keyboardOnScreen uses, strip included. A capture that lists only the strip now drags from above it. A new engine test fails without the fix (the drag started at y=519.5, under the strip). KEYBOARD_KINDS and normalizeKind are module-private now.
  • Reference example. It now polls after dismissKeyboard(), in en, ja and zh. The cubic thread has the details.
  • keyboardVisible in the transition wait. I chose the changeset line over a test: the changeset now says the wait before acting on a control follows the same rule.

pnpm check passes, and so do the 562 mobile unit tests. The android deterministic rerun on c419d99 passed, so mobile gate was green before this push.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-checked at e8f8d02 (feb461e + e8f8d02 on top of c419d99, merges cleanly into main 402a615) against the review at c419d99 and the cubic threads.

Earlier asks: all done.

  • Drag over the strip: keyboardTop now falls back to keyboardElementsTop, the highest on-screen keyboard element under the same predicate keyboardOnScreen (and so keyboardShownIn) uses, strip included. Building on this rather than on keyboardBand is the right call: keyboardBand returns undefined for tree-rejected, which keyboardShownIn can still answer true for from drawn keys. keyboardTop has one caller, dismissKeyboardByGesture; swipe, scroll and covered-node checks still go through keyboardBand and do not change.
  • Reference example now dismisses, then polls isKeyboardShown() to false (en, ja, zh). The cubic P2 is resolved.
  • keyboardVisible in the transition wait: covered by the changeset line, fine.
  • e8f8d02 answers cubic's P3 on the test comment. No open cubic findings.

Must fix

None.

Should fix

  • packages/mobile/tests/unit/engine.test.ts:1784 - the new test lists only the strip, so it cannot tell "highest element" from "any element": changing Math.min(top, rect.y) to Math.max in keyboardElementsTop keeps all 253 engine tests green. With keys plus a strip (the common iOS capture with no measured band), max would start the drag at the keys' top, over the strip. This commit also changes that case (main only counted keys), so add the strip above a row of keys and assert the drag starts above the strip.

Nits

  • packages/mobile/src/nodes.ts - the "drawn keyboard element" predicate (rect nonzero, visibleToUser !== false, isKeyboardElement) is now written out in both keyboardBand and keyboardElementsTop. One small drawnKeyboardRects(nodes) helper both read from would keep them from drifting.

Verified

  • @e2e-dev/mobile tsc --noEmit clean, pnpm lint clean, mobile unit tests 560/560 (provider-example.test.ts only fails to import @e2e-dev/mobile/lease without mobile's dist, unrelated).
  • Mutants: keyboardTop ignoring tree elements fails the new test; restoring main's keys-only keyboardTop fails it; dropping the on-screen filter fails 2 existing tests. min -> max survives (above).
  • CI on e8f8d02: all green, including android deterministic, ios deterministic and mobile gate.

@okwasniewski okwasniewski added the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Nov 19, 2026
@leszko11

Copy link
Copy Markdown
Contributor Author

[claude-opus-5-5] responding on behalf of @leszko11

Thanks. Addressed in 8d3dfca:

  • Should fix. The test now runs two layouts: the strip alone, and the strip above the keys. In both, the drag must start above the strip. In the strip-only layout the strip itself was a control (a leaf), so it blocked the point under it and hid the mutant. The strip now holds only text, so it is not a control and only the keyboard's top keeps the drag off it. Math.min -> Math.max now fails: with the keys present, the drag started on the strip.
  • Nit. drawnKeyboardRects(nodes) holds the predicate, and keyboardBand and keyboardElementsTop both read from it.

pnpm check and the 562 mobile unit tests pass.

@github-actions github-actions Bot removed the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Nov 19, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-checked at 8d3dfca (one commit on top of e8f8d02, merges cleanly into main 5e9b82e) against the review at e8f8d02.

Earlier asks: all done.

  • Should fix (test cannot tell "highest" from "any"): the test now runs the strip alone and the strip over the keys, and the strip holds only text, so it is no control and cannot hide the mutant. Math.min -> Math.max in keyboardElementsTop now fails it (confirmed).
  • Nit: drawnKeyboardRects(nodes) holds the drawn-keyboard predicate, and keyboardBand and keyboardElementsTop both read from it. keyboardBand behavior is unchanged.

No regressions: the commit touches only nodes.ts (pure refactor) and the test. keyboardShownIn in keyboard.ts is untouched, so keyboard-not-observed and keyboard-visibility-probe-unsupported still fail with UNSUPPORTED_CAPABILITY and never map to false. cubic reports 0 issues on this push.

Must fix

None.

Should fix

None.

Nits

  • packages/mobile/tests/unit/engine.test.ts:1802 - expect([keyboard.length, from.y < 200]).toEqual([keyboard.length, true]) labels the case but hides the actual y on failure. expect(from.y, `${keyboard.length} keyboard elements`).toBeLessThan(200) (or it.each over the two layouts) reports both.

Verified

  • @e2e-dev/mobile tsc --noEmit clean, oxlint clean, mobile unit tests 560/560 (provider-example.test.ts only fails to import @e2e-dev/mobile/lease without mobile's dist, unrelated).
  • Mutants: Math.min -> Math.max in keyboardElementsTop fails the new test; dropping its on-screen filter fails 2 existing tests.
  • CI on 8d3dfca: all green, including android deterministic, ios deterministic and mobile gate.

@okwasniewski okwasniewski added the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Nov 19, 2026
@KrzysztofMoch

Copy link
Copy Markdown
Member

🤖 gpt-6.2-sol responding on behalf of Krzysztof

dismissKeyboard() can swipe through the keyboard when the driver reports { kind: 'visibility-only', visible: true } without a frame or on-screen keyboard elements. If native dismissal is unsupported, the gesture fallback treats the bottom of the viewport as the keyboard’s top and can pick a point inside the keyboard. With a mocked 844 × 390 landscape capture, this PR sent a swipe from (422, 195). The same test sent no swipe on the PR base. Can we require usable keyboard bounds before swiping and return UNSUPPORTED_CAPABILITY when the bounds are unavailable? Gesture fallback

All four targeted iOS 26.5 benchmark tests passed with the built CLI, including the new isKeyboardShown() test.

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Post-release check at 8d3dfca against main 8eb3cc2: merges clean, mobile typecheck and unit tests pass on the merged tree, CI green, and no peer floor is needed (mobile only, agent-device 0.21.40 from #1975 typechecks).

Open item: Krzysztof's comment from after the last review is not answered yet. When the probe reports { kind: 'visibility-only', visible: true } with no frame and no keyboard elements, dismissKeyboardByGesture (packages/mobile/src/surface.ts:1728-1749) falls back to the bottom of the viewport as keyboardTop, so it can start a swipe inside the keyboard. Please require usable keyboard bounds before swiping (else UNSUPPORTED_CAPABILITY) and add his landscape 844 x 390 case as a unit test.

@okwasniewski okwasniewski removed the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Nov 19, 2026
@leszko11

leszko11 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

[claude-opus-5-5] responding on behalf of @leszko11

@KrzysztofMoch thanks, real. Fixed in c215e05 (rebased on main after #1975). keyboardTop now returns nothing when no measured frame and no keyboard element on screen bound the keyboard. In that case dismissKeyboardByGesture sends no swipe and fails with UNSUPPORTED_CAPABILITY, naming the alternatives (the app's own Done or close control, or Enter on the field). Your 844 x 390 landscape case is now a unit test. It sent a swipe before the fix and sends none after. The dismissKeyboard JSDoc, the reference pages (en, ja, zh) and the changeset name the new case.

@okwasniewski's nit is in the same commit: the strip test's assertion now reports the actual y.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 7 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

@leszko11
leszko11 force-pushed the feat/device-is-keyboard-shown branch from 035a718 to c215e05 Compare November 19, 2026 20:00

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-checked at c215e05 (rebased onto main 309f690 after #1975, plus one new commit) against the post-release check at 8d3dfca and Krzysztof's comment.

Earlier asks: all done.

  • Krzysztof's visibility-only swipe: keyboardTop (packages/mobile/src/surface.ts:162) now returns undefined when the capture has no measured frame and no keyboard element on screen, and dismissKeyboardByGesture (surface.ts:1752-1759) throws UNSUPPORTED_CAPABILITY with the usual alternatives before any swipe. It covers visibility-only and tree-rejected with visible: true alike, and the re-read after the first drag goes through the same check. The 844 x 390 landscape case is a unit test that asserts the code, the message, and zero interactions.swipe calls.
  • The nit on the strip test is done: the assertion now reports the actual y with the element count as its message.
  • JSDoc, the en reference Throws row and the changeset name the new case. ja and zh match it.
  • Range-diff against 8d3dfca: the 10 earlier commits change only through the rebase. No regressions in them.

Must fix: none.

Should fix: none.

Verified:

  • pnpm --filter @e2e-dev/mobile typecheck passes. Mobile unit tests: 569/569 (after building core, e2e and mobile dist).
  • Mutant: I put back the old fallback (top ?? viewport.height) and the new landscape test failed. With the fix restored it passes.
  • No em or en dashes in the added lines. Peer floors are unchanged and none are needed: the change is mobile only, with no new action kind or core contract, and agent-device stays at 0.21.40 from #1975.
  • CI at c215e05 is all green. ios deterministic ran isKeyboardShown follows the keyboard up and through a dismissal and it passed (57 passed, 1 skipped). android deterministic had 57 passed and 1 flaky: a label query resolves a labeled text field, which is the known first-test Android cold-launch retry and not this PR's fault. Merge state is clean, no rebase needed.

kdy1
kdy1 previously requested changes Nov 20, 2026

@kdy1 kdy1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

This text was drafted with AI and posted after human approval.

  • Harness: T3 Code
  • AI agents: Claude Opus 5.5 (claude-opus-5-5), GPT-6.2 Astra (gpt-6.2-astra), GPT-6.2 Sol (gpt-6.2-sol), Claude Sonnet 5.5 (claude-sonnet-5-5)

Requesting changes for two bugs that this PR adds. Both are fixable without a redesign. I also left 4 smaller comments inline (7 inline comments in total).

Must fix

  1. keyboardReading can start its last capture with almost no budget left. A dismissKeyboard() that worked on main can then fail with ACTION_MAY_HAVE_COMMITTED (see surface.ts:1693).
  2. When the suggestion strip is the only keyboard element in the tree, isKeyboardShown() returns true and dismissKeyboard() drags (see nodes.ts:145).

Should fix

  1. A derived keyboard frame still puts the drag start on the strip. This is not new, but it is the same class of bug that this PR fixes for the tree-only case (see surface.ts:163).
  2. The docs say that expect.poll retries through ENGINE_FAILURE. In fact it retries every error (see device.ts:211).

Low priority

These two need inputs that are unlikely in practice: an off-screen keyboard counted as on screen when the capture has no screen bounds (see nodes.ts:156), and a sparse capture's absent reading dropped by the sparse retry (see surface.ts:1696).

How this was checked

  • Four independent reviewers (two GPT models and two Claude models) reviewed the diff at c215e05. I then checked each finding against the code.
  • Each behavior claim comes from a scripted-client unit probe that a reviewer or I ran on main 309f690 and on this head. No simulator or emulator was used, so how often (1)–(3) happen with real agent-device captures is not measured.
  • At this head, @e2e-dev/mobile typecheck passes, vitest tests/unit passes 569 of 569, and pnpm run lint passes.

I rejected two findings:

  • The capture in isKeyboardShown() makes refs held from an earlier capture stale (NODE_STALE). This is the existing design, and locate does the same.
  • The iOS benchmark test was not verified. ios deterministic passed at this head.

Comment thread packages/mobile/src/surface.ts Resolved
Comment thread packages/mobile/src/nodes.ts Resolved
Comment thread packages/mobile/src/surface.ts Resolved
Comment thread packages/mobile/src/device.ts Resolved
Comment thread docs/reference/mobile.mdx Resolved
Comment thread packages/mobile/src/nodes.ts Resolved
Comment thread packages/mobile/src/surface.ts Resolved
@okwasniewski okwasniewski removed the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Nov 20, 2026
leszko11 and others added 13 commits November 20, 2026 19:28
Returns whether the soft keyboard is on screen from one capture: the
keyboard agent-device reports (a measured or derived frame, or a
visibility probe), else visible keyboard elements in the tree, the same
band observations hide covered nodes under. A capture that cannot answer
(no keyboard in a sparse or cut tree, or keyboard elements agent-device
rejected with no probe) fails with ENGINE_FAILURE instead of guessing.

Refs e2e-inc#1855

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- An unmeasurable keyboard reading answers false only for the reasons that
  say agent-device read the whole tree; a capture that could not see the
  keyboard's window fails with UNSUPPORTED_CAPABILITY.
- A rejected docked frame with no probe reads as shown: agent-device
  rejects one only for a tree that lists keyboard elements, as a keyboard
  still sliding in does on an iPhone.
- The incomplete-tree failure no longer claims a retryable flag that
  EngineError drops for ENGINE_FAILURE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…roof

Review follow-up for isKeyboardShown:

- keyboardShownIn moves to keyboard.ts and is the one rule:
  dismissKeyboard's check is keyboardShownIn === true.
- Only agent-device's `absent` (or a probe that says hidden) answers
  false. keyboard-not-observed and keyboard-visibility-probe-unsupported
  now fail with UNSUPPORTED_CAPABILITY.
- Tree answers count keyboard elements drawn on screen only, so a
  keyboard left in the tree off screen does not read as shown.
- A tree-rejected reading with no on-screen key is the keyboard moving:
  both isKeyboardShown and dismissKeyboard capture again, briefly, before
  they answer.
- The benchmark test taps the field first, since a fill on Android opens
  no input method, and polls both reads.
- The ja and zh Throws tables are translated, and the Appium guide notes
  that the call reads the screen as it is now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
isKeyboardShown's JSDoc and the reference said one capture, but a
keyboard still moving is captured again. keyboardShownIn's comment now
names what it decides instead of every keyboard check (observations
report measured state only), and the unsupported message says the tree
shows no keyboard drawn on screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Android emulator in CI draws no soft keyboard, even for a tapped
field, so isKeyboardShown polled false until it timed out. The keyboard
reads move to their own iOS-only test, and the onboarding test is back
to what main has.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e keyboard is up

The drag's top edge came from keys alone, while isKeyboardShown also counts
the suggestion strip, so a capture that lists only the strip (a hardware
keyboard) dragged from under it. The reference example now polls the read
after dismissKeyboard, and the changeset notes the transition wait follows
the same rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The strip-only test could not tell the highest keyboard element from any
of them. It now also lists the strip above the keys, with the strip holding
only text so nothing but the keyboard's top keeps the drag off it. The
drawn-keyboard predicate is one helper that keyboardBand and
keyboardElementsTop both read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A visibility probe that says the keyboard is up, with no frame and no
keyboard element on screen, left keyboardTop at the bottom of the screen, so
the drag could start on the keyboard. dismissKeyboard now fails with
UNSUPPORTED_CAPABILITY there instead of guessing. The strip test's
assertion names the failing y.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the budget

The suggestion strip alone, as XCTest lists it with a hardware keyboard, no
longer reads as the soft keyboard shown; it still bounds where the
dismissing drag may start, now also above a measured or derived frame. The
settle loop reserves the last capture's time along with its backoff, so a
slow capture after the drag no longer times the dismissal out. A capture
with no viewport and no window places no keyboard on screen, since the
tree's own extent holds the keyboard it is asked about.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rror

A lasting UNSUPPORTED_CAPABILITY makes the poll wait out its timeout; the
docs implied only ENGINE_FAILURE was read again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leszko11
leszko11 force-pushed the feat/device-is-keyboard-shown branch from fa408f8 to 3ae4c7d Compare November 20, 2026 18:28
@leszko11

Copy link
Copy Markdown
Contributor Author

[claude-opus-5-5] responding on behalf of @leszko11

@kdy1 thanks, all seven threads are answered. The branch is rebased on main 3e7d19d, with a conflict with #1919 resolved in surface.ts and README.md.

  • Must fix 1 and 2: fixed in faca3e8. The settle loop reserves the capture's own time. The suggestion strip alone no longer reads as the soft keyboard and only bounds where the drag starts.
  • Should fix 3: fixed in faca3e8. The drag starts above the strip over a measured or derived frame too.
  • Should fix 4: fixed in 3ae4c7d. The docs now say expect.poll reads again after any error, and that a lasting UNSUPPORTED_CAPABILITY waits out the poll's timeout.
  • Low priority: the no-screen-bounds case is changed as you suggested. The sparse retry is left as is: the newer capture wins, as on main. The reason is in the thread.

Each fix has a unit test that fails on c215e05. @e2e-dev/mobile passes 577 of 577 unit tests, and pnpm check passes.

Not verified on a device yet: my local iOS 27.2 simulator showed no soft keyboard for a focused field, so isKeyboardShown follows the keyboard up failed there on both c215e05 and this head. The ios deterministic job on this push is the device check.

@kdy1
kdy1 dismissed their stale review November 20, 2026 19:12

All requested changes are in as of 3ae4c7d. Checked and dismissed by a T3 Code automation (Claude) for @kdy1.

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-checked at 3ae4c7d (rebased onto main 3e7d19d, 2 new commits on top of the 11 reviewed at c215e05) against kdy1's review and his 7 inline comments.

Range-diff against c215e05: commits 1-11 change only through the rebase (the #1919 conflict in surface.ts / README.md, resolved cleanly). The new work is faca3e8 and 3ae4c7d.

kdy1's asks: all done.

  • Must fix 1 (settle loop budget): keyboardReading (packages/mobile/src/surface.ts:1748-1757) now reserves backoffMs + captureMs, with the last capture's duration, as snapshot() does. The slow-capture test runs both of his probes (800 ms dismissKeyboard() resolves after one swipe, 1000 ms isKeyboardShown() ends in the settling ENGINE_FAILURE, not a timeout).
  • Must fix 2 (strip alone reads as the keyboard): keyboardOnScreen (packages/mobile/src/nodes.ts:145) counts only keyboard and key kinds. The strip only bounds the drag start, through keyboardElementsTop. A strip-only tree with no fact now fails isKeyboardShown() with UNSUPPORTED_CAPABILITY and dismissKeyboard() sends no drag, as on main. The transition wait's keyboardShowing uses the same rule.
  • Should fix 3 (derived frame under the strip): keyboardTop (surface.ts:173) takes the higher of the frame top and the highest on-screen keyboard element. The strip test covers keys in the tree and a derived frame.
  • Should fix 4 (poll docs): the JSDoc in device.ts, the en reference and the UNSUPPORTED_CAPABILITY row now say a poll reads again after any error and that a lasting UNSUPPORTED_CAPABILITY waits out the timeout. ja and zh match.
  • Low priority, no screen bounds: keyboardOnScreen takes bounds only from the viewport or a window/application node (screenOf). With neither, no keyboard counts. This case has a test now.
  • Low priority, sparse retry dropping absent: left as is on purpose, and the reason holds. The retry is the newer capture, and mixing its tree with the older capture's fact would answer from two moments. Main's snapshot() does the same. I agree with leaving it.

Krzysztof's visibility-only swipe ask is still in place: keyboardTop returns undefined with no frame and no element on screen, and the landscape 844 x 390 test passes.

No heuristics added. Every true comes from an agent-device fact or a keyboard/key element on screen. false comes only from absent. The retry loop runs only while the capture itself reports the keyboard as moving (tree-rejected with nothing on screen). It does not wait on a timer.

Must fix: none.

Should fix: none.

Nits:

  • packages/mobile/src/nodes.ts:166 - drawnKeyboardRects(nodes, include = isKeyboardElement) has one caller that overrides the default and one that does not. Two named calls, drawnKeyboardRects(nodes) and a drawnRects(nodes, isSoftKeyboard), or passing the predicate at both sites, would make the strip/no-strip split visible at the call site. Optional.

Verified:

  • @e2e-dev/mobile typecheck passes, oxlint is clean, and mobile unit tests pass 577/577 (core, e2e and mobile dist built first).
  • Mutants, each caught by exactly one test: budget check back to backoffMs only (slow-capture test fails), strip counted in keyboardOnScreen (strip-alone test fails), frame-only keyboardTop (derived-frame strip test fails), screenOf back to the viewportOf extent fallback (the no-viewport isKeyboardShown case fails).
  • No em or en dashes in added lines. No peer floor is needed: the change is mobile only, adds no new action kind or core contract, and does not change any dependency.
  • CI at 3ae4c7d is all green. ios deterministic ran isKeyboardShown follows the keyboard up and through a dismissal and it passed (59 passed, 1 skipped). android deterministic had 60 passed and 1 skipped. Merge state is clean, so no rebase is needed.

@okwasniewski okwasniewski added the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Nov 20, 2026

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@okwasniewski
okwasniewski merged commit 1d28ac0 into e2e-inc:main Nov 21, 2026
28 checks passed
kblok added a commit to hardkoded/e2e-dotnet that referenced this pull request Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. size:L Up to 499 changed lines, not counting tests, fixtures, translated docs, or the lockfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants