|
1 | 1 | import { test } from 'vitest'; |
2 | 2 | import assert from 'node:assert/strict'; |
3 | 3 | import type { RawSnapshotNode } from '@agent-device/kernel/snapshot'; |
4 | | -import { annotateCoveredSnapshotNodes } from './snapshot-occlusion.ts'; |
| 4 | +import { SNAPSHOT_COVERING_LABEL_MAX_LENGTH } from '@agent-device/kernel/snapshot'; |
| 5 | +import { |
| 6 | + annotateCoveredSnapshotNodes, |
| 7 | + annotateSnapshotNodesCoveredByPolicy, |
| 8 | +} from './snapshot-occlusion.ts'; |
5 | 9 |
|
6 | 10 | // #1478 P5 codec-extraction regression: `annotateCoveredSnapshotNodes` marks |
7 | 11 | // a touch candidate `interactionBlocked: 'covered'` when a later, floating |
@@ -93,6 +97,72 @@ test('annotateCoveredSnapshotNodes still marks a touch target covered by a later |
93 | 97 | assert.equal(result[0]?.hittable, false); |
94 | 98 | }); |
95 | 99 |
|
| 100 | +test('annotateCoveredSnapshotNodes carries a bounded description of the covering node', () => { |
| 101 | + const target: RawSnapshotNode = { |
| 102 | + index: 0, |
| 103 | + type: 'button', |
| 104 | + role: 'button', |
| 105 | + hittable: true, |
| 106 | + label: 'Save', |
| 107 | + rect: { x: 10, y: 10, width: 100, height: 40 }, |
| 108 | + }; |
| 109 | + const overlay: RawSnapshotNode = { |
| 110 | + index: 1, |
| 111 | + type: 'XCUIElementTypeDialog', |
| 112 | + label: ' Cookie banner ', |
| 113 | + rect: { x: 0, y: 0, width: 200, height: 200 }, |
| 114 | + }; |
| 115 | + |
| 116 | + const result = annotateCoveredSnapshotNodes([target, overlay]); |
| 117 | + |
| 118 | + // The description is the presented role + a trimmed label + the cover's rect, and it carries no |
| 119 | + // ref: naming the culprit is diagnosis, never an actionable re-target. |
| 120 | + assert.deepEqual(result[0]?.coveredBy, { |
| 121 | + kind: 'dialog', |
| 122 | + label: 'Cookie banner', |
| 123 | + rect: { x: 0, y: 0, width: 200, height: 200 }, |
| 124 | + }); |
| 125 | +}); |
| 126 | + |
| 127 | +test('annotateCoveredSnapshotNodes clips a covering label to the bounded length', () => { |
| 128 | + const target: RawSnapshotNode = { |
| 129 | + index: 0, |
| 130 | + type: 'button', |
| 131 | + role: 'button', |
| 132 | + hittable: true, |
| 133 | + label: 'Save', |
| 134 | + rect: { x: 10, y: 10, width: 100, height: 40 }, |
| 135 | + }; |
| 136 | + const overlay: RawSnapshotNode = { |
| 137 | + index: 1, |
| 138 | + type: 'dialog', |
| 139 | + label: 'x'.repeat(SNAPSHOT_COVERING_LABEL_MAX_LENGTH + 40), |
| 140 | + rect: { x: 0, y: 0, width: 200, height: 200 }, |
| 141 | + }; |
| 142 | + |
| 143 | + const result = annotateCoveredSnapshotNodes([target, overlay]); |
| 144 | + |
| 145 | + assert.equal(result[0]?.coveredBy?.label?.length, SNAPSHOT_COVERING_LABEL_MAX_LENGTH); |
| 146 | +}); |
| 147 | + |
| 148 | +test('annotateSnapshotNodesCoveredByPolicy refuses without guessing a cover', () => { |
| 149 | + // The Android replacement-surface lane reports only the covered boolean; the refusal must not |
| 150 | + // invent a culprit it never observed. |
| 151 | + const target: RawSnapshotNode = { |
| 152 | + index: 0, |
| 153 | + type: 'button', |
| 154 | + role: 'button', |
| 155 | + hittable: true, |
| 156 | + label: 'Save', |
| 157 | + rect: { x: 10, y: 10, width: 100, height: 40 }, |
| 158 | + }; |
| 159 | + |
| 160 | + const result = annotateSnapshotNodesCoveredByPolicy([target], (node) => node.index === 0); |
| 161 | + |
| 162 | + assert.equal(result[0]?.interactionBlocked, 'covered'); |
| 163 | + assert.equal(result[0]?.coveredBy, undefined); |
| 164 | +}); |
| 165 | + |
96 | 166 | test('annotateCoveredSnapshotNodes leaves an uncovered touch target unchanged', () => { |
97 | 167 | const target: RawSnapshotNode = { |
98 | 168 | index: 0, |
|
0 commit comments