|
1 | 1 | import { expect, test, vi } from 'vitest'; |
2 | 2 | import { captureSnapshot, captureSnapshotData } from '../snapshot-capture.ts'; |
3 | | -import { summarizeSnapshotDiagnostics } from '@agent-device/contracts/capture'; |
| 3 | +import { |
| 4 | + attachSnapshotClickabilityEvidence, |
| 5 | + attachSnapshotOcclusionContextEvidence, |
| 6 | + readSnapshotClickabilityEvidence, |
| 7 | + readSnapshotOcclusionContextEvidence, |
| 8 | + summarizeSnapshotDiagnostics, |
| 9 | +} from '@agent-device/contracts/capture'; |
4 | 10 | import { buildSnapshotVisibility } from '@agent-device/capture-kit/snapshot-visibility'; |
5 | 11 | import { ANDROID_EMULATOR, buildNodes, IOS_SIMULATOR, MACOS_DEVICE } from '@agent-device/test-kit'; |
6 | 12 | import { |
@@ -68,6 +74,59 @@ test('snapshot capture preserves scope for every other platform projection', asy |
68 | 74 | ]); |
69 | 75 | }); |
70 | 76 |
|
| 77 | +test('snapshot capture retains Android facts at their normalized node indices', async () => { |
| 78 | + const data = { |
| 79 | + backend: 'android' as const, |
| 80 | + producer: 'android-uiautomator' as const, |
| 81 | + nodes: [ |
| 82 | + { index: 10, depth: 0, type: 'Button', label: 'Save' }, |
| 83 | + { index: 20, depth: 0, type: 'Button', label: 'Cancel' }, |
| 84 | + ], |
| 85 | + }; |
| 86 | + attachSnapshotClickabilityEvidence(data, { |
| 87 | + kind: 'exact', |
| 88 | + provider: 'android-helper', |
| 89 | + clickableByNodeIndex: new Map([ |
| 90 | + [10, true], |
| 91 | + [20, false], |
| 92 | + ]), |
| 93 | + }); |
| 94 | + attachSnapshotOcclusionContextEvidence(data, { |
| 95 | + nodes: [{ index: 100 }, { index: 200 }], |
| 96 | + sourceIndexByNodeIndex: new Map([ |
| 97 | + [10, 100], |
| 98 | + [20, 200], |
| 99 | + ]), |
| 100 | + }); |
| 101 | + |
| 102 | + const { snapshot } = await captureSnapshot({ |
| 103 | + device: ANDROID_EMULATOR, |
| 104 | + session: undefined, |
| 105 | + flags: { snapshotRaw: true }, |
| 106 | + logPath: '/tmp/snapshot-capture-test.log', |
| 107 | + captureData: async () => data, |
| 108 | + }); |
| 109 | + |
| 110 | + expect(snapshot.nodes.map((node) => [node.index, node.label])).toEqual([ |
| 111 | + [0, 'Save'], |
| 112 | + [1, 'Cancel'], |
| 113 | + ]); |
| 114 | + expect(readSnapshotClickabilityEvidence(snapshot)).toEqual({ |
| 115 | + kind: 'exact', |
| 116 | + provider: 'android-helper', |
| 117 | + clickableByNodeIndex: new Map([ |
| 118 | + [0, true], |
| 119 | + [1, false], |
| 120 | + ]), |
| 121 | + }); |
| 122 | + expect(readSnapshotOcclusionContextEvidence(snapshot)?.sourceIndexByNodeIndex).toEqual( |
| 123 | + new Map([ |
| 124 | + [0, 100], |
| 125 | + [1, 200], |
| 126 | + ]), |
| 127 | + ); |
| 128 | +}); |
| 129 | + |
71 | 130 | test('buildSnapshotVisibility returns non-partial for empty node list', () => { |
72 | 131 | const vis = buildSnapshotVisibility({ nodes: [], backend: 'android' }); |
73 | 132 | expect(vis.partial).toBe(false); |
|
0 commit comments