|
1 | 1 | import { AppError } from '@agent-device/kernel/errors'; |
2 | 2 | import assert from 'node:assert/strict'; |
3 | 3 | import { test } from 'vitest'; |
| 4 | +import type { RawSnapshotNode } from '@agent-device/kernel/snapshot'; |
| 5 | +import type { IosSystemSurfaceProvenance } from '@agent-device/contracts/ios-system-surface'; |
4 | 6 | import type { AppleRunnerSnapshotResult } from '../snapshot-presentation.ts'; |
5 | | -import { presentAppleRunnerSnapshot } from '../snapshot-presentation.ts'; |
| 7 | +import { presentAppleRunnerSnapshot, readAppleSnapshotResult } from '../snapshot-presentation.ts'; |
6 | 8 |
|
7 | 9 | const NO_VIEWPORT_ROOT = { index: 0, type: 'Application', label: 'App' }; |
8 | 10 |
|
@@ -73,6 +75,10 @@ test('a sparse capture of a presented system surface names the surface host', () |
73 | 75 | String(error.details?.hint), |
74 | 76 | /com\.apple\.SafariViewService hosts the surface presented over the app/, |
75 | 77 | ); |
| 78 | + assert.deepEqual(error.details?.systemSurface, { |
| 79 | + bundleId: 'com.apple.SafariViewService', |
| 80 | + kind: 'web-auth', |
| 81 | + }); |
76 | 82 | }); |
77 | 83 |
|
78 | 84 | test('a sparse payload failing another invariant still carries the verdict', () => { |
@@ -125,3 +131,61 @@ test('a sparse verdict still presents the nodes it did read', () => { |
125 | 131 | ['App', 'Not Now'], |
126 | 132 | ); |
127 | 133 | }); |
| 134 | + |
| 135 | +const SYSTEM_SHEET: IosSystemSurfaceProvenance = { |
| 136 | + bundleId: 'com.apple.SafariViewService', |
| 137 | + kind: 'web-auth', |
| 138 | +}; |
| 139 | + |
| 140 | +test('a presented system surface travels with an undeclared-payload refusal as typed provenance', () => { |
| 141 | + try { |
| 142 | + presentAppleRunnerSnapshot('device-1', undefined, { |
| 143 | + nodes: [NO_VIEWPORT_ROOT], |
| 144 | + quality: { state: 'healthy', backend: 'tree' }, |
| 145 | + systemSurface: SYSTEM_SHEET, |
| 146 | + }); |
| 147 | + } catch (error) { |
| 148 | + assert.ok(error instanceof AppError); |
| 149 | + assert.deepEqual((error.details as Record<string, unknown>).systemSurface, SYSTEM_SHEET); |
| 150 | + assert.equal((error.details as Record<string, unknown>).snapshotQuality, undefined); |
| 151 | + return; |
| 152 | + } |
| 153 | + assert.fail('expected the presentation to refuse the payload'); |
| 154 | +}); |
| 155 | + |
| 156 | +test('readAppleSnapshotResult keeps registry-known system surface provenance only', () => { |
| 157 | + const known = readAppleSnapshotResult({ |
| 158 | + nodes: [], |
| 159 | + systemSurface: { bundleId: 'com.apple.SafariViewService', kind: 'web-auth' }, |
| 160 | + }); |
| 161 | + assert.deepEqual(known.systemSurface, SYSTEM_SHEET); |
| 162 | + |
| 163 | + const unknown = readAppleSnapshotResult({ |
| 164 | + nodes: [], |
| 165 | + systemSurface: { bundleId: 'com.example.PhishingService', kind: 'web-auth' }, |
| 166 | + }); |
| 167 | + assert.equal(unknown.systemSurface, undefined); |
| 168 | +}); |
| 169 | + |
| 170 | +test('a healthy payload with valid viewport roots still presents', () => { |
| 171 | + const screen: RawSnapshotNode = { |
| 172 | + index: 0, |
| 173 | + type: 'Application', |
| 174 | + rect: { x: 0, y: 0, width: 390, height: 844 }, |
| 175 | + }; |
| 176 | + const button: RawSnapshotNode = { |
| 177 | + index: 1, |
| 178 | + parentIndex: 0, |
| 179 | + type: 'Button', |
| 180 | + label: 'Not Now', |
| 181 | + rect: { x: 16, y: 400, width: 80, height: 32 }, |
| 182 | + hittable: true, |
| 183 | + }; |
| 184 | + const nodes = presentAppleRunnerSnapshot('device-1', undefined, { |
| 185 | + nodes: [screen, button], |
| 186 | + }); |
| 187 | + assert.deepEqual( |
| 188 | + nodes.map((node) => node.index), |
| 189 | + [0, 1], |
| 190 | + ); |
| 191 | +}); |
0 commit comments