Skip to content

ADFA-7258: Wait for the editor's async layout in IDEEditorAccessibilityTest - #2301

Open
davidschachterADFA wants to merge 2 commits into
stagefrom
fix/ADFA-7258-a11y-soft-keyboard
Open

davidschachterADFA wants to merge 2 commits into
stagefrom
fix/ADFA-7258-a11y-soft-keyboard

Conversation

@davidschachterADFA

@davidschachterADFA davidschachterADFA commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

ADFA-7258

Fixes IDEEditorAccessibilityTest's "accessibility click requests soft keyboard when editable", which has failed since it was added in d0bdfa8 (ADFA-4605, PR #2171). The test was wrong; the editor is right. Test-only change, one file, (+36 / -1), in two commits; the second answers the independent review.

Why it failed

  • IDEEditor's accessibility click calls sora's CodeEditor.showSoftInput(). That reaches InputMethodManager.showSoftInput() only when isEditable() is true.
  • isEditable() is editable && !layoutBusy && !isFormatting. After setText(), sora measures the text in a task on a background executor (AbstractLayout.executor). The task sets layoutBusy when it starts (LineBreakLayout, WordwrapLayout) and clears it in a callback it posts to the main looper.
  • Robolectric runs that callback only when the test idles the main looper. setUp() idled once, right after setText(), usually before the background layout finished. So the click hit a busy editor, and the IMM was never called.

A temporary print at click time showed layoutBusy true, and the IMM's showSoftInput never ran. A temporary 100-run stress test failed 99/100 before this change and 0/100 after it. The test also fails at d0bdfa8 itself, so no later commit broke it.

The change

  • setUp() calls a new awaitEditorLayout() in place of the single idle(). It polls until sora's layout executor has no queued or running task and editor.isEditable is true, twice in a row, idling the main looper each time. Checking only isEditable isn't enough: it can read true before the layout task starts and sets layoutBusy. The second poll makes it unlikely, though not impossible, to miss a task that has left the queue but not yet started. After 10 s it fails with a message giving the executor's queue size and active count, isEditable and isFormatting.
  • The keyboard test asserts editor.isEditable before the click, with a message, so a future failure points at the precondition rather than at the IMM.

awaitEditorLayout() reads sora's private static AbstractLayout.executor by reflection, because sora exposes no "layout finished" signal. If a sora upgrade renames that field, setUp() fails at once with NoSuchFieldException in all 5 tests, rather than becoming flaky; a type change fails fast too. The one quiet case is sora keeping the field but no longer using it: the helper then rests on isEditable alone.

Not in this PR

The same race can happen on a phone, though I've only found it by reading the code. A TalkBack double-tap (or an ordinary tap) that lands while the editor is re-laying out its text, such as when a file opens, the text size or word wrap changes, or the phone rotates, brings up no keyboard. A second tap works. Changing the editor to wait for the layout is a separate change, tracked in ADFA-7270.

Sibling tests checked. The only other unit test that builds a real sora editor is StaleWordwrapRowsTest (ADFA-6543). It has the same single idle() after setText(), and in the review's probe its layout was still running after that idle in 50/50 runs. Its pending word-wrap callback may then rebuild rowTable during the test's last idle, so its final assertion might pass even without the fix's relayout step (rebuildLayout()). That isn't proven, and it's left alone here: ADFA-7271 tracks checking and fixing it. EditorCloseTabTest mocks its editors, and the instrumented IDEEditorTest runs on a real looper.

Testing

  • ./gradlew :editor:testV8DebugUnitTest --tests '*IDEEditorAccessibilityTest*': 5/5 pass (4/5 before).
  • ./gradlew spotlessCheck: passes.
  • No CI check gates on :editor unit tests (ADFA-5328): PR CI doesn't run them, and the nightly Analyze run, which does, ignores their failures. So the run above is the check. The stress test isn't committed.
  • The independent review reran the class (5/5), reproduced the stage failure (4/5, at the IMM assertion), and probed 300 rounds: 0 failures with this helper, 291 with the old single idle().

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw

davidschachterADFA and others added 2 commits November 22, 2026 18:41
…tyTest

"accessibility click requests soft keyboard when editable" failed since it
was added in d0bdfa8. The editor is right; the test raced a background
thread.

IDEEditor's a11y click calls sora's CodeEditor.showSoftInput(), which only
reaches InputMethodManager.showSoftInput() when isEditable() is true.
isEditable() is false while layoutBusy: sora measures text on a background
executor and clears the flag in a callback it posts to the main looper.
Robolectric runs that callback only when the test idles the looper, and
setUp() idled once, right after setText(), before the layout finished. The
click then hit a busy editor and the IMM was never called.

setUp() now waits until sora's layout executor is idle and the editor is
editable, and the keyboard test asserts that precondition. A temporary
100-iteration stress test failed 99/100 with the old setUp and 0/100 with
the new one. The wait reads sora's private static AbstractLayout.executor by
reflection; if sora renames it, setUp fails loudly rather than flakily.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
From the independent review of #2301:
- The KDoc said isEditable() stays false until the layout callback runs.
  In fact sora's layout task sets layoutBusy itself when it starts, so
  isEditable() can read true before then. That is why the helper also
  waits for the executor to be idle. The second settled poll makes a
  missed task unlikely, not impossible.
- The timeout message now gives the executor's queue size and active
  count, isEditable and isFormatting, and names the limit once.
- The isEditable assertion before the click now says what failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
@davidschachterADFA
davidschachterADFA marked this pull request as ready for review November 23, 2026 06:25

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Release notes:

  • Fixes a race in the IDEEditorAccessibilityTest setup. Setup now waits for editor layout through the new awaitEditorLayout helper.
  • The helper checks sora's layout executor and editor.isEditable. It requires two consecutive settled polls and fails after 10 seconds.
  • Adds an editability assertion before the soft-keyboard accessibility click.
  • Test-only change. No editor runtime behavior changes.

Risks and best-practice violations:

  • The helper uses reflection on sora's private AbstractLayout.executor. A renamed or retyped field fails the test. If the field stays but is unused, the helper relies only on isEditable().
  • Two settled polls make a missed layout task unlikely, not impossible. Some flakiness may remain.
  • The real-device keyboard race is not fixed (ADFA-7270). The StaleWordwrapRowsTest race is unproven (ADFA-7271).
  • PR CI does not run editor unit tests. The nightly Analyze run ignores their failures. Verification depends on the reported local test run.

The accessibility test setup now waits for editor layout work to settle. A new helper checks executor and editor state, and the soft-keyboard accessibility-click test verifies that the editor is editable before clicking.

Changes: Editor accessibility test

Layer / File(s) Summary
Wait for editor layout and verify editability
editor/src/test/java/com/itsaky/androidide/editor/ui/IDEEditorAccessibilityTest.kt
Setup waits for two consecutive settled layout polls, with a 10-second timeout and state details on failure. The soft-keyboard accessibility-click test asserts that the editor is editable before clicking.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: dara-abijo-adfa, itsaky-adfa

Merge Risk: Minimal · up to 96518

This change makes an editor accessibility unit test wait for layout work to settle before it runs. It does not touch production behavior. A small residual chance of test flakiness remains, but it does not block merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the test now waits for the editor's async layout in IDEEditorAccessibilityTest. It is specific, short, and matches the raw summary, which describes the new awaitEditor…
Description check Passed The description explains the failing test, the root cause in sora's asynchronous layout, the test-only fix (awaitEditorLayout and an editability assertion), the reflection risk, related follow-up tick…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the test now waits for the editor's async layout in IDEEditorAccessibilityTest. It is specific, short, and matches the raw summary, which describes the new awaitEditorLayout helper replacing the single idle in setUp.

Full details: Description check

Explanation

The description explains the failing test, the root cause in sora's asynchronous layout, the test-only fix (awaitEditorLayout and an editability assertion), the reflection risk, related follow-up tickets, and the validation run. It matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit waits while layouts run,
Then checks the editor before the click.
Two quiet polls, and work is done,
The keyboard test can proceed.
No busy state slips past the gate.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: cf2089ae-c4d3-41de-a8f3-cb6f60890305
Commits

Reviewing files that changed from the base of the PR and between 5a49afd and 965184c.

Files selected for processing: 1

  • editor/src/test/java/com/itsaky/androidide/editor/ui/IDEEditorAccessibilityTest.kt

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 2 remain after this review.

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