-
-
Notifications
You must be signed in to change notification settings - Fork 313
fix(android): carry the checked state of a checkable control on the snapshot node #2913
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
thymikee
merged 5 commits into
callstack:main
from
okwasniewski:oskar/android-checked-state
Sep 24, 2026
+384
−41
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
867268b
fix(android): carry the checked state of a checkable control on the s…
okwasniewski 1ceb6ba
fix(daemon): the interaction outcome weighs the states stateMarkers p…
okwasniewski ad8d7a3
test(daemon): the capture-retry fixtures spell the interaction key wi…
okwasniewski 0358c80
fix(daemon): a surface entry carries a state-free content key, so an …
okwasniewski 6dae0a1
fix(maestro): the snapshot signature weighs checked, so a toggle tap …
okwasniewski 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
49 changes: 49 additions & 0 deletions
49
packages/capture-kit/src/snapshot/__tests__/snapshot-diff-checked.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,49 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { test } from 'vitest'; | ||
| import type { SnapshotNode } from '@agent-device/kernel/snapshot'; | ||
| import { buildSnapshotDiff } from '../snapshot-diff.ts'; | ||
|
|
||
| function toggle(checked?: boolean): SnapshotNode { | ||
| return { | ||
| ref: 'e12', | ||
| index: 0, | ||
| depth: 0, | ||
| type: 'android.widget.Switch', | ||
| label: 'Wi-Fi switch', | ||
| enabled: true, | ||
| hittable: true, | ||
| ...(checked === undefined ? {} : { checked }), | ||
| }; | ||
| } | ||
|
|
||
| test('a checked-only flip diffs as changed lines that read differently', () => { | ||
| const diff = buildSnapshotDiff([toggle(false)], [toggle(true)]); | ||
| const changed = diff.lines.filter((line) => line.kind !== 'unchanged'); | ||
|
|
||
| assert.equal(diff.summary.unchanged, 0); | ||
| assert.equal(changed.length > 0, true); | ||
| // The comparable key carries the checked state, so the rendered line has to as well, and both | ||
| // answers render: the pair reads `[unchecked]` -> `[checked]`, not two identical lines. | ||
| assert.match(changed[0]!.text, /\[unchecked\]/); | ||
| assert.match(changed.at(-1)!.text, /\[checked\]/); | ||
| }); | ||
|
|
||
| test.each([ | ||
| ['both unchecked', [toggle(false)], [toggle(false)]], | ||
| ['both unreported', [toggle()], [toggle()]], | ||
| ])('a still toggle with %s diffs as unchanged', (_label, previous, current) => { | ||
| const diff = buildSnapshotDiff(previous, current); | ||
|
|
||
| assert.equal( | ||
| diff.lines.every((line) => line.kind === 'unchanged'), | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| test('a node that cannot be checked never reads as unchecked', () => { | ||
| const diff = buildSnapshotDiff([toggle()], [toggle()]); | ||
| assert.equal( | ||
| diff.lines.every((line) => !line.text.includes('checked')), | ||
| true, | ||
| ); | ||
| }); |
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
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
70 changes: 70 additions & 0 deletions
70
packages/platform-android/src/__tests__/ui-hierarchy-checked.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,70 @@ | ||
| import { expect, test } from 'vitest'; | ||
| import { buildUiHierarchySnapshot, parseUiHierarchyTree } from '../ui-hierarchy.ts'; | ||
|
|
||
| // A settings row: a switch the helper reports as checkable beside a label that is not. The helper | ||
| // writes `checked` only on the checkable node, with both answers. | ||
| function togglesXml(wifiChecked: boolean): string { | ||
| return `<hierarchy> | ||
| <node class="android.widget.LinearLayout" resource-id="toggles" bounds="[0,0][400,200]" | ||
| window-index="0" window-type="1" window-layer="1" window-active="true" window-focused="true" | ||
| window-bounds="[0,0][400,800]" visible-to-user="true" enabled="true"> | ||
| <node class="android.widget.TextView" resource-id="wifi-label" text="Wi-Fi" | ||
| bounds="[0,0][200,100]" enabled="true" visible-to-user="true" /> | ||
| <node class="android.widget.Switch" resource-id="wifi-switch" content-desc="Wi-Fi switch" | ||
| bounds="[200,0][400,100]" clickable="true" enabled="true" visible-to-user="true" | ||
| checked="${wifiChecked}" /> | ||
| <node class="android.widget.RadioButton" resource-id="size-small" text="Small" | ||
| bounds="[0,100][400,200]" clickable="true" enabled="true" visible-to-user="true" | ||
| checked="false" /> | ||
| </node> | ||
| </hierarchy>`; | ||
| } | ||
|
|
||
| // A helper older than the `checked` attribute, or a switch it did not report as checkable. | ||
| const UNREPORTED_CHECKED_XML = | ||
| '<hierarchy><node class="android.widget.Switch" resource-id="legacy-switch" content-desc="Wi-Fi"' + | ||
| ' bounds="[200,0][400,100]" clickable="true" enabled="true" visible-to-user="true" /></hierarchy>'; | ||
|
|
||
| function toggleNodes(raw: boolean, interactiveOnly = false, wifiChecked = true) { | ||
| const { nodes } = buildUiHierarchySnapshot( | ||
| parseUiHierarchyTree(togglesXml(wifiChecked)), | ||
| undefined, | ||
| { raw, interactiveOnly }, | ||
| ); | ||
| const byId = (identifier: string) => nodes.find((node) => node.identifier === identifier); | ||
| return { label: byId('wifi-label'), wifi: byId('wifi-switch'), small: byId('size-small') }; | ||
| } | ||
|
|
||
| test.each([ | ||
| { raw: false, interactiveOnly: false }, | ||
| { raw: false, interactiveOnly: true }, | ||
| { raw: true, interactiveOnly: false }, | ||
| { raw: true, interactiveOnly: true }, | ||
| ])( | ||
| 'checked state reaches snapshot nodes in every projection (raw=$raw, -i=$interactiveOnly)', | ||
| ({ raw, interactiveOnly }) => { | ||
| const { wifi, small } = toggleNodes(raw, interactiveOnly); | ||
| expect(wifi?.checked).toBe(true); | ||
| expect(small?.checked).toBe(false); | ||
| }, | ||
| ); | ||
|
|
||
| test.each([true, false])('the switch answers the state the helper observed (%s)', (wifiChecked) => { | ||
| expect(toggleNodes(false, false, wifiChecked).wifi?.checked).toBe(wifiChecked); | ||
| }); | ||
|
|
||
| test('attrs answer explicit false where a node that cannot be checked answers nothing', () => { | ||
| // Serialized, because that is the answer an agent reads: an unavailable fact drops the key | ||
| // while JSON encodes an observed `false`. | ||
| const { label, small } = toggleNodes(false); | ||
| expect(JSON.parse(JSON.stringify(small)).checked).toBe(false); | ||
| expect(JSON.parse(JSON.stringify(label))).not.toHaveProperty('checked'); | ||
| }); | ||
|
|
||
| test('an unreported checked state stays unknown instead of becoming false', () => { | ||
| const node = buildUiHierarchySnapshot(parseUiHierarchyTree(UNREPORTED_CHECKED_XML), undefined, { | ||
| raw: false, | ||
| }).nodes.find((node) => node.identifier === 'legacy-switch'); | ||
| expect(node).toBeDefined(); | ||
| expect(node?.checked).toBeUndefined(); | ||
| }); |
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
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 |
|---|---|---|
|
|
@@ -111,6 +111,7 @@ const PRESENTATION_SCALAR_FIELDS = { | |
| identifier: true, | ||
| enabled: true, | ||
| selected: true, | ||
| checked: true, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in e5bba1b: |
||
| focused: true, | ||
| heading: true, | ||
| roleDescription: true, | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stateMarkers now declares which states a comparison weighs, and this PR applies that answer in snapshot-unchanged.ts and the Android freshness comment. A third state signature still disagrees: interactionSurfaceSemanticKey in src/daemon/interaction-outcome-policy.ts:595 folds enabled, selected, and hittable but not checked. Android is checked's only producer, so a tap whose only effect is a toggle can be changed on the diff lane but unchanged on the interaction-outcome lane, causing retry or delayed-recheck work for a gesture that actually worked. Please either fold checked into that key, or make the exclusion explicit and test it. If including it, also account for discriminatingSurfaceChangedWithinRect in src/daemon/scroll-movement.ts:385, where an unrelated in-container toggle now counts as scroll movement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Folded in, e5bba1b.
interactionSurfaceSemanticKeynow spreadsstateMarkers(node)for its state segments, so the outcome lane, the unchanged-snapshot comparison, and the diff weigh one list; a checked-only flip classifieschangedinstead of feeding a no-change retry that would tap the switch back.For the scroll lane: the flip alone never reaches
discriminatingSurfaceChangedWithinRect, sinceclassifyBaselineSurfaceEvidencematches on the flip-tolerant identity and reads it as unchanged. It does reach it beside an unrelated change, such as the status clock ticking, and there a key-matched view read the flipped switch as content moving inside the container. The function now matches entries onidentitywhere one exists, told apart by document order when repeated, and onkeyotherwise, so a state flip at the same rect is not movement.haveIdenticalDiscriminatingSurfaceskeeps its key-matched veto, as its comment asks.Tests: a checked-only flip is
changedon the outcome lane; a flip at the same rect is no movement while a moved row is; the scroll claim is withheld (change-outside-container) for a flipped toggle inside the container beside a clock tick; both checked answers invalidate snapshot reuse and survive the selector digest.