11import type { BackendSnapshotResult } from '../backend.ts' ;
2- import type { AndroidSnapshotBackendMetadata } from '../platforms/android/snapshot-types.ts' ;
32import type { AgentDeviceRuntime , CommandSessionRecord } from '../runtime-contract.ts' ;
43import {
5- renderSnapshotQualityWarnings ,
6- type SnapshotQualityVerdict ,
7- } from '../utils/snapshot-quality.ts' ;
4+ publicSnapshotCaptureAnnotations ,
5+ snapshotCaptureAnnotationsFrom ,
6+ type PublicSnapshotCaptureAnnotations ,
7+ type SnapshotCaptureAnnotations ,
8+ } from '../snapshot-capture-annotations.ts' ;
9+ import { renderSnapshotQualityWarnings } from '../utils/snapshot-quality.ts' ;
810import { AppError } from '../utils/errors.ts' ;
911import { buildSnapshotDiff , countSnapshotComparableLines } from '../utils/snapshot-diff.ts' ;
1012import type { SnapshotDiffLine , SnapshotDiffSummary } from '../utils/snapshot-diff.ts' ;
@@ -35,11 +37,8 @@ export type SnapshotCommandResult = {
3537 appName ?: string ;
3638 appBundleId ?: string ;
3739 visibility ?: SnapshotVisibility ;
38- androidSnapshot ?: AndroidSnapshotBackendMetadata ;
39- warnings ?: string [ ] ;
4040 unchanged ?: SnapshotUnchanged ;
41- snapshotQuality ?: SnapshotQualityVerdict ;
42- } ;
41+ } & PublicSnapshotCaptureAnnotations ;
4342
4443export type DiffSnapshotCommandResult = {
4544 mode : 'snapshot' ;
@@ -53,6 +52,7 @@ type SnapshotCapture = {
5352 snapshot : SnapshotState ;
5453 result : BackendSnapshotResult ;
5554 session : CommandSessionRecord | undefined ;
55+ annotations : SnapshotCaptureAnnotations ;
5656 warnings : string [ ] ;
5757} ;
5858
@@ -79,9 +79,10 @@ export const snapshotCommand: RuntimeCommand<
7979 backend : capture . snapshot . backend ,
8080 snapshotRaw : options . raw ,
8181 } ) ,
82- ...( capture . result . androidSnapshot ? { androidSnapshot : capture . result . androidSnapshot } : { } ) ,
83- ...( capture . result . quality ? { snapshotQuality : capture . result . quality } : { } ) ,
84- ...( capture . warnings . length > 0 ? { warnings : capture . warnings } : { } ) ,
82+ ...publicSnapshotCaptureAnnotations ( {
83+ ...capture . annotations ,
84+ warnings : capture . warnings ,
85+ } ) ,
8586 ...( unchanged ? { unchanged } : { } ) ,
8687 ...snapshotAppFields ( capture ) ,
8788 } ;
@@ -158,13 +159,16 @@ async function captureRuntimeSnapshot(
158159 normalizeBackendSnapshot ( result , runtime ) ,
159160 options ,
160161 ) ;
162+ const annotations = snapshotCaptureAnnotationsFrom ( result ) ;
161163 const warningTime = now ( runtime ) ;
162164 return {
163165 snapshot,
164166 result,
165167 session,
168+ annotations,
166169 warnings : buildSnapshotWarnings ( {
167170 result,
171+ annotations,
168172 snapshot,
169173 options,
170174 session,
@@ -215,24 +219,29 @@ function snapshotAppFields(capture: SnapshotCapture): {
215219
216220function buildSnapshotWarnings ( params : {
217221 result : BackendSnapshotResult ;
222+ annotations : SnapshotCaptureAnnotations ;
218223 snapshot : SnapshotState ;
219224 options : SnapshotCommandOptions ;
220225 session : CommandSessionRecord | undefined ;
221226 capturedAt : number ;
222227 runtimeNow : number ;
223228} ) : string [ ] {
224- const warnings = [ ...( params . result . warnings ?? [ ] ) ] ;
225- if ( params . result . quality ) {
226- warnings . push ( ...renderSnapshotQualityWarnings ( params . result . quality , params . snapshot . nodes ) ) ;
229+ const warnings = [ ...( params . annotations . warnings ?? [ ] ) ] ;
230+ if ( params . annotations . quality ) {
231+ warnings . push (
232+ ...renderSnapshotQualityWarnings ( params . annotations . quality , params . snapshot . nodes ) ,
233+ ) ;
227234 }
228235 warnings . push ( ...buildEmptyAndroidInteractiveWarnings ( params ) ) ;
229- if ( ! params . result . quality ) {
236+ if ( ! params . annotations . quality ) {
230237 // Legacy runners without a structured verdict keep the old daemon-side heuristics.
231238 warnings . push ( ...buildSparseIosInteractiveWarnings ( params ) ) ;
232239 warnings . push ( ...buildMergedAccessibilityLeafWarnings ( params . snapshot . nodes ) ) ;
233240 }
234241
235- const helperFallbackWarning = formatAndroidHelperFallbackWarning ( params . result . androidSnapshot ) ;
242+ const helperFallbackWarning = formatAndroidHelperFallbackWarning (
243+ params . annotations . androidSnapshot ,
244+ ) ;
236245 if ( helperFallbackWarning ) warnings . push ( helperFallbackWarning ) ;
237246
238247 const reactNativeOverlayWarning = formatReactNativeOverlayWarning ( params . snapshot . nodes ) ;
@@ -241,7 +250,7 @@ function buildSnapshotWarnings(params: {
241250 const recentDropWarning = formatRecentSnapshotDropWarning ( params ) ;
242251 if ( recentDropWarning ) warnings . push ( recentDropWarning ) ;
243252
244- warnings . push ( ...formatFreshnessWarnings ( params . result . freshness , params . snapshot . backend ) ) ;
253+ warnings . push ( ...formatFreshnessWarnings ( params . annotations . freshness , params . snapshot . backend ) ) ;
245254 return Array . from ( new Set ( warnings ) ) ;
246255}
247256
@@ -295,11 +304,11 @@ function buildMergedAccessibilityLeafWarnings(nodes: SnapshotState['nodes']): st
295304}
296305
297306function buildEmptyAndroidInteractiveWarnings ( params : {
298- result : BackendSnapshotResult ;
307+ annotations : SnapshotCaptureAnnotations ;
299308 snapshot : SnapshotState ;
300309 options : SnapshotCommandOptions ;
301310} ) : string [ ] {
302- const analysis = params . result . analysis ;
311+ const analysis = params . annotations . analysis ;
303312 if (
304313 params . snapshot . backend !== 'android' ||
305314 params . options . interactiveOnly !== true ||
@@ -326,23 +335,23 @@ function buildEmptyAndroidInteractiveWarnings(params: {
326335}
327336
328337function formatAndroidHelperFallbackWarning (
329- androidSnapshot : AndroidSnapshotBackendMetadata | undefined ,
338+ androidSnapshot : SnapshotCaptureAnnotations [ 'androidSnapshot' ] ,
330339) : string | undefined {
331340 if ( androidSnapshot ?. backend !== 'uiautomator-dump' ) return undefined ;
332341 const reason = androidSnapshot . fallbackReason ? ` Reason: ${ androidSnapshot . fallbackReason } ` : '' ;
333342 return `Android snapshot helper unavailable; using stock UIAutomator dump, which can time out on busy React Native UIs.${ reason } ` ;
334343}
335344
336345function formatRecentSnapshotDropWarning ( params : {
337- result : BackendSnapshotResult ;
346+ annotations : SnapshotCaptureAnnotations ;
338347 snapshot : SnapshotState ;
339348 session : CommandSessionRecord | undefined ;
340349 capturedAt : number ;
341350 runtimeNow : number ;
342351} ) : string | undefined {
343352 const previousSnapshot = params . session ?. snapshot ;
344353 if (
345- ! params . result . freshness &&
354+ ! params . annotations . freshness &&
346355 previousSnapshot &&
347356 hasSameSnapshotPresentation ( previousSnapshot , params . snapshot ) &&
348357 isRecentSnapshot ( previousSnapshot , params . capturedAt , params . runtimeNow ) &&
0 commit comments