Repository navigation
fix(snapshot): name the captured Android app in the snapshot header #4499
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
+262
−15
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bd2ceee
fix(snapshot): name the captured Android app in the snapshot header
thymikee 99ab749
test(snapshot): keep the header identity test in its own file
thymikee 80e097e
fix(snapshot): name the header app from Android application windows
thymikee 5eccba6
fix(snapshot): order Android app windows by layer and name one withou…
thymikee f1eb37a
fix(snapshot): name the header app from the foreground application wi…
thymikee 53b5f3c
fix(snapshot): key the unchanged acknowledgement on the header app
thymikee 03ef82a
fix(snapshot): keep main's identity for the unchanged acknowledgement
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
113 changes: 113 additions & 0 deletions
113
packages/command-runtime/src/commands/capture/runtime/snapshot-app-identity.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,113 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { test } from 'vitest'; | ||
| import { createLocalArtifactAdapter } from '@agent-device/host-kit/local-artifact-adapter'; | ||
| import { createAgentDevice } from '../../../runtime.ts'; | ||
| import { localCommandPolicy } from '@agent-device/contracts/command-policy'; | ||
| import type { CommandSessionStore } from '@agent-device/contracts/runtime-contract'; | ||
| import { makeSnapshotState } from '@agent-device/selectors/snapshot-geometry-fixtures'; | ||
|
|
||
| async function snapshotWithForeground( | ||
| foregroundWindowPackage: string | undefined, | ||
| sessionApp: { appName: string; appBundleId: string } | undefined = { | ||
| appName: 'Settings', | ||
| appBundleId: 'com.android.settings', | ||
| }, | ||
| ) { | ||
| let stored: Parameters<CommandSessionStore['set']>[0] | undefined; | ||
| const device = createAgentDevice({ | ||
| backend: { | ||
| platform: 'android', | ||
| captureSnapshot: async () => ({ | ||
| snapshot: makeSnapshotState([{ index: 0, depth: 0, type: 'TextView', label: 'Gmail' }], { | ||
| backend: 'android', | ||
| }), | ||
| androidSnapshot: { | ||
| backend: 'android-helper', | ||
| ...(foregroundWindowPackage ? { foregroundWindowPackage } : {}), | ||
| }, | ||
| ...sessionApp, | ||
| }), | ||
| }, | ||
| artifacts: createLocalArtifactAdapter(), | ||
| sessions: { | ||
| get: () => undefined, | ||
| set: (record) => { | ||
| stored = record; | ||
| }, | ||
| }, | ||
| policy: localCommandPolicy(), | ||
| }); | ||
| const result = await device.capture.snapshot({ session: 'default', interactiveOnly: true }); | ||
| return { result, stored }; | ||
| } | ||
|
|
||
| test('an Android snapshot names the captured foreground app when it is not the session app', async () => { | ||
| const { result, stored } = await snapshotWithForeground('com.google.android.apps.nexuslauncher'); | ||
|
|
||
| // A foreign app has no label of its own here, so the header shows its package. | ||
| assert.equal(result.appName, 'com.google.android.apps.nexuslauncher'); | ||
| assert.equal(result.appBundleId, 'com.google.android.apps.nexuslauncher'); | ||
| assert.equal(stored?.appBundleId, 'com.android.settings'); | ||
| }); | ||
|
|
||
| test('an Android snapshot keeps the session app label when the session app is in front', async () => { | ||
| const { result } = await snapshotWithForeground('com.android.settings'); | ||
|
|
||
| assert.equal(result.appName, 'Settings'); | ||
| assert.equal(result.appBundleId, 'com.android.settings'); | ||
| }); | ||
|
|
||
| test('a snapshot without a foreground window fact names the session app', async () => { | ||
| const { result } = await snapshotWithForeground(undefined); | ||
|
|
||
| assert.equal(result.appName, 'Settings'); | ||
| assert.equal(result.appBundleId, 'com.android.settings'); | ||
| }); | ||
|
|
||
| test('an Android snapshot in a session with no app names the captured foreground app', async () => { | ||
| const { result } = await snapshotWithForeground( | ||
| 'com.google.android.apps.nexuslauncher', | ||
| undefined, | ||
| ); | ||
|
|
||
| assert.equal(result.appName, 'com.google.android.apps.nexuslauncher'); | ||
| assert.equal(result.appBundleId, 'com.google.android.apps.nexuslauncher'); | ||
| }); | ||
|
|
||
| test('a repeated unchanged snapshot of a foreign foreground app is acknowledged under its header', async () => { | ||
| const snapshot = makeSnapshotState([{ index: 0, depth: 0, type: 'TextView', label: 'Gmail' }], { | ||
| backend: 'android', | ||
| }); | ||
| let stored: Parameters<CommandSessionStore['set']>[0] | undefined = { | ||
| name: 'default', | ||
| appBundleId: 'com.android.settings', | ||
| }; | ||
| const device = createAgentDevice({ | ||
| backend: { | ||
| platform: 'android', | ||
| captureSnapshot: async () => ({ | ||
| snapshot, | ||
| androidSnapshot: { | ||
| backend: 'android-helper', | ||
| foregroundWindowPackage: 'com.google.android.apps.nexuslauncher', | ||
| }, | ||
| appBundleId: 'com.android.settings', | ||
| }), | ||
| }, | ||
| artifacts: createLocalArtifactAdapter(), | ||
| sessions: { | ||
| get: () => stored, | ||
| set: (record) => { | ||
| stored = record; | ||
| }, | ||
| }, | ||
| policy: localCommandPolicy(), | ||
| }); | ||
|
|
||
| await device.capture.snapshot({ session: 'default' }); | ||
| const result = await device.capture.snapshot({ session: 'default' }); | ||
|
|
||
| // The acknowledgement compares against the last stored tree, the launcher's, which the header names. | ||
| assert.equal(result.appBundleId, 'com.google.android.apps.nexuslauncher'); | ||
| assert.ok(result.unchanged); | ||
| }); | ||
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
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
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.