peachsim 0.1.2238 → 0.1.2242

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/cli/bridge-flow-runner.ts +10 -9
  2. package/cli/commands/inspect/settling.ts +491 -506
  3. package/cli/commands/platform.ts +2 -0
  4. package/cli/drivers/playwright-provisioning.ts +160 -37
  5. package/cli/internal-child.ts +5 -79
  6. package/dist-lib/agent-daemon-client.cjs +1 -1
  7. package/dist-lib/agent-events.cjs +1 -1
  8. package/dist-lib/attached-projects.cjs +1 -1
  9. package/dist-lib/auth/shared-session.cjs +1 -1
  10. package/dist-lib/backend-origin.cjs +1 -1
  11. package/dist-lib/beta.cjs +1 -1
  12. package/dist-lib/beta.mjs +1 -1
  13. package/dist-lib/bridge-constants.cjs +1 -1
  14. package/dist-lib/bridge-contract-input.cjs +1 -1
  15. package/dist-lib/bridge-contract-input.mjs +1 -1
  16. package/dist-lib/bridge-contract.cjs +1 -1
  17. package/dist-lib/bridge-contract.mjs +1 -1
  18. package/dist-lib/bundle-channel.cjs +115 -89
  19. package/dist-lib/capture-contract.cjs +1 -1
  20. package/dist-lib/capture-contract.mjs +1 -1
  21. package/dist-lib/cloud-contract.cjs +1 -1
  22. package/dist-lib/cloud-contract.mjs +1 -1
  23. package/dist-lib/cloud-test-args.cjs +1 -1
  24. package/dist-lib/cloud-test-args.mjs +1 -1
  25. package/dist-lib/cloud.cjs +1 -1
  26. package/dist-lib/cloud.mjs +1 -1
  27. package/dist-lib/config.cjs +1 -1
  28. package/dist-lib/config.mjs +1 -1
  29. package/dist-lib/detox/index.cjs +494 -510
  30. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  31. package/dist-lib/expo-swift-bundle.cjs +101 -75
  32. package/dist-lib/expo-swift-metadata.cjs +1 -1
  33. package/dist-lib/expo-swift-metadata.mjs +1 -1
  34. package/dist-lib/home-paths.cjs +1 -1
  35. package/dist-lib/host/bridge-host.cjs +119 -93
  36. package/dist-lib/host/fetch-proxy-handler.cjs +4 -4
  37. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  38. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  39. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  40. package/dist-lib/host/websocket-proxy.cjs +1 -1
  41. package/dist-lib/index.cjs +492 -508
  42. package/dist-lib/jump-to-source-babel.cjs +1 -1
  43. package/dist-lib/jump-to-source-native.cjs +1 -1
  44. package/dist-lib/kotlin-host.cjs +1 -1
  45. package/dist-lib/menu.cjs +1 -1
  46. package/dist-lib/menu.mjs +1 -1
  47. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  48. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  49. package/dist-lib/metro-production-bundle.cjs +1 -1
  50. package/dist-lib/metro-production-bundle.mjs +1 -1
  51. package/dist-lib/metro.cjs +4 -4
  52. package/dist-lib/native-app-identity-project.cjs +2 -2
  53. package/dist-lib/native-app-identity-project.mjs +7 -8
  54. package/dist-lib/native-app-identity.cjs +1 -1
  55. package/dist-lib/native-app-identity.mjs +1 -1
  56. package/dist-lib/native-firebase-metadata.cjs +1 -1
  57. package/dist-lib/native-firebase-metadata.mjs +1 -1
  58. package/dist-lib/pdfium-raster.cjs +1 -1
  59. package/dist-lib/pdfium-raster.mjs +1 -1
  60. package/dist-lib/plist.cjs +1 -1
  61. package/dist-lib/plist.mjs +1 -1
  62. package/dist-lib/profiles.cjs +1 -1
  63. package/dist-lib/public-brand.cjs +1 -1
  64. package/dist-lib/public-origins-lib-esm.json +24 -24
  65. package/dist-lib/public-origins-lib.json +53 -53
  66. package/dist-lib/react-native-host-modules.cjs +1 -1
  67. package/dist-lib/react-native-host-modules.mjs +1 -1
  68. package/dist-lib/reap-browser.cjs +1 -1
  69. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  70. package/dist-lib/sdk.cjs +487 -503
  71. package/dist-lib/sdk.mjs +487 -503
  72. package/dist-lib/skills.cjs +1327 -1235
  73. package/dist-lib/swift-compile.cjs +46 -27
  74. package/dist-lib/swift-compile.mjs +42 -23
  75. package/dist-lib/swift-package.cjs +1 -1
  76. package/dist-lib/swift-package.mjs +1 -1
  77. package/dist-lib/swift-submit.cjs +2 -2
  78. package/dist-lib/swift-submit.mjs +2 -2
  79. package/dist-lib/swift-toolchain.cjs +1 -1
  80. package/dist-lib/swift.cjs +1 -1
  81. package/dist-lib/vite-swift.cjs +89 -64
  82. package/dist-lib/vite.cjs +4 -4
  83. package/dist-lib/worklet-executable.cjs +1 -1
  84. package/dist-lib/worklet-executable.mjs +1 -1
  85. package/dist-types/packages/peach-engine/src/engine/node.d.ts +1 -0
  86. package/dist-types/packages/peach-engine/src/engine/secureItemHostContract.d.ts +5 -1
  87. package/dist-types/packages/peach-engine/src/engine/types.d.ts +1 -0
  88. package/dist-types/packages/peach-engine/src/ios/chrome-metrics.d.ts +6 -0
  89. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +4 -1
  90. package/dist-types/packages/peach-engine/src/render-worker/webview-capture-protocol.d.ts +14 -0
  91. package/dist-types/packages/peach-globals/src/nativeSurfaceContract.d.ts +1 -0
  92. package/dist-types/packages/peach-globals/src/secure-item-store.d.ts +2 -0
  93. package/kotlin/sdk.tar.gz +0 -0
  94. package/package.json +1 -1
  95. package/runtime-companion.json +1 -1
  96. package/src/native-static-libraries.ts +20 -20
  97. package/src/native-swift-slices.ts +1 -0
  98. package/src/nitro-adapter.lock.json +253 -253
  99. package/src/nitro-superset.lock.json +4 -4
  100. package/src/swift-compile.ts +10 -3
  101. package/src/swift-distribution.lock.json +11 -11
  102. package/src/swift-host.ts +2 -1
  103. package/src/swift-shared-sdk.ts +10 -1
  104. package/src/swift-standins.ts +5 -2
  105. package/src/swift-submit.ts +3 -1
  106. package/src/swift-wasm-prune.ts +23 -14
  107. package/src/turbo-runtime.lock.json +22 -22
package/dist-lib/sdk.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2238 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2242 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1948,7 +1948,7 @@ async function waitForSootsimIdle({
1948
1948
  pollMs = 50,
1949
1949
  stablePolls = 3,
1950
1950
  strict = false,
1951
- paintStill = false,
1951
+ screenStill = false,
1952
1952
  maestro = false,
1953
1953
  motionOnly = false,
1954
1954
  readyPlayback = false,
@@ -1986,7 +1986,7 @@ async function waitForSootsimIdle({
1986
1986
  let deadline = start + budgetMs
1987
1987
  const pollMs = ${Math.max(1, Math.round(pollMs))}
1988
1988
  const strict = ${strict ? "true" : "false"}
1989
- const paintStill = ${paintStill ? "true" : "false"}
1989
+ const screenStill = ${screenStill ? "true" : "false"}
1990
1990
  const maestro = ${maestro ? "true" : "false"}
1991
1991
  const accessibilityBounds = ${accessibilityBounds.toString()}
1992
1992
  const sameNativeAccessibilityShape = ${sameNativeAccessibilityShape.toString()}
@@ -1996,541 +1996,525 @@ async function waitForSootsimIdle({
1996
1996
  // tight budgets (auto-wait) settle on worker stillness plus root
1997
1997
  // membership, generous ones confirm the geometry too.
1998
1998
  const fullGeometry = ${!maestro && maxMs >= 1e3 ? "true" : "false"}
1999
- const requiredStillMs = paintStill ? 0 : ${Math.max(1, Math.round(stablePolls)) * Math.max(1, Math.round(pollMs))}
2000
- const minimumStablePolls = paintStill ? 1 : ${Math.min(2, Math.max(1, Math.round(stablePolls)))}
2001
- const composite = paintStill ? globalThis.SootSim?.bridges?.liveComposite : null
2002
- if (paintStill && !composite) {
2003
- return { settled: false, elapsed: clockNow() - start, blockedBy: 'screen pixels unavailable' }
2004
- }
2005
- // subscribe to presented frames; authoritative screenshots force a
2006
- // worker render, which changes the very counter we used to inspect.
2007
- const unsubscribe = composite?.subscribe(() => {})
1999
+ const requiredStillMs = screenStill ? 0 : ${Math.max(1, Math.round(stablePolls)) * Math.max(1, Math.round(pollMs))}
2000
+ const minimumStablePolls = screenStill ? 1 : ${Math.min(2, Math.max(1, Math.round(stablePolls)))}
2008
2001
  let transitionEndedAt = null
2009
- let pixelFrameToken = -1
2010
- let screenPixels = null
2011
2002
  // the hierarchy read last taken and the geometry revision it answered.
2012
2003
  // it outlives this wait: a revision still current when a later wait
2013
2004
  // polls names the same geometry, so a step that follows a settled one
2014
2005
  // proves an unchanged screen without walking the tree again.
2015
2006
  const geometry = (globalThis.__peachSettleGeometry ??= { revision: null, hierarchy: null })
2016
- try {
2017
-
2018
- // discover transitions while observing layout. when motion starts,
2019
- // observations from before its completion cannot prove the new screen;
2020
- // those that began after it drained still can. a loaded host runs a
2021
- // push past a tap's budget, so the transition gets its own timeout and
2022
- // the budget restarts once it drains.
2023
- let transitionWait = (async () => {
2024
- try {
2025
- const wfst = globalThis.__sootsimTest?.waitForScreenTransitions
2026
- if (typeof wfst === 'function' && budgetMs > 120) {
2027
- const transition = await wfst({
2028
- timeoutMs: ${Math.max(0, Math.round(transitionTimeoutMs))},
2029
- settleMs: 64,
2030
- startWindowMs: ${Math.max(0, Math.round(transitionStartWindowMs))},
2031
- })
2032
- if (transition?.started !== true) return false
2033
- // a loaded worker replies long after the motion stopped; it
2034
- // reports how long ago, so polls begun since still count. a
2035
- // runtime without the field ends the transition at the reply.
2036
- const rested = typeof transition.restedMs === 'number' ? Math.max(0, transition.restedMs) : 0
2037
- transitionEndedAt = clockNow() - rested
2038
- deadline = Math.max(deadline, transitionEndedAt + budgetMs)
2039
- return true
2040
- }
2041
- } catch {}
2042
- return false
2043
- })()
2007
+ // discover transitions while observing layout. when motion starts,
2008
+ // observations from before its completion cannot prove the new screen;
2009
+ // those that began after it drained still can. a loaded host runs a
2010
+ // push past a tap's budget, so the transition gets its own timeout and
2011
+ // the budget restarts once it drains.
2012
+ let transitionWait = (async () => {
2013
+ try {
2014
+ const wfst = globalThis.__sootsimTest?.waitForScreenTransitions
2015
+ if (typeof wfst === 'function' && budgetMs > 120) {
2016
+ const transition = await wfst({
2017
+ timeoutMs: ${Math.max(0, Math.round(transitionTimeoutMs))},
2018
+ settleMs: 64,
2019
+ startWindowMs: ${Math.max(0, Math.round(transitionStartWindowMs))},
2020
+ })
2021
+ if (transition?.started !== true) return false
2022
+ // a loaded worker replies long after the motion stopped; it
2023
+ // reports how long ago, so polls begun since still count. a
2024
+ // runtime without the field ends the transition at the reply.
2025
+ const rested = typeof transition.restedMs === 'number' ? Math.max(0, transition.restedMs) : 0
2026
+ transitionEndedAt = clockNow() - rested
2027
+ deadline = Math.max(deadline, transitionEndedAt + budgetMs)
2028
+ return true
2029
+ }
2030
+ } catch {}
2031
+ return false
2032
+ })()
2044
2033
 
2045
- // a worker that cannot answer within the remaining budget is busy, not
2046
- // idle: its poll reads as unsettled. bounding each read by the budget
2047
- // keeps a busy worker from holding a poll past the deadline.
2048
- const BUSY = { busy: true }
2049
- const answer = (read) =>
2050
- Promise.race([
2051
- Promise.resolve().then(read),
2052
- new Promise((resolve) =>
2053
- setTimeout(() => resolve(BUSY), Math.max(deadline - clockNow(), 100)),
2054
- ),
2055
- ])
2034
+ // a worker that cannot answer within the remaining budget is busy, not
2035
+ // idle: its poll reads as unsettled. bounding each read by the budget
2036
+ // keeps a busy worker from holding a poll past the deadline.
2037
+ const BUSY = { busy: true }
2038
+ const answer = (read) =>
2039
+ Promise.race([
2040
+ Promise.resolve().then(read),
2041
+ new Promise((resolve) =>
2042
+ setTimeout(() => resolve(BUSY), Math.max(deadline - clockNow(), 100)),
2043
+ ),
2044
+ ])
2056
2045
 
2057
- const readSnapshot = async () => {
2058
- let animating = false
2059
- let animatingBy = ''
2060
- let layoutDirty = false
2061
- let pendingFetches = 0
2062
- let workerBusy = false
2063
- let requestTotal = 0
2064
- let requestInFlight = 0
2065
- let appCommits = null
2066
- let nodeCount = null
2067
- let renderStatsAvailable = false
2068
- let shellAnimating = false
2069
- let shellBlockers = ''
2070
- let webViewStarting = false
2071
- let webViewBlocker = ''
2072
- // the reads are independent, so they run concurrently: a loaded sim
2073
- // answers each one late, and a poll that waits for them in turn
2074
- // costs their sum, which fits too few polls in the budget to settle.
2075
- // the window node count is the exception: it launches after the
2076
- // motion read, so a poll motion already fails skips that walk.
2077
- // strict reads also wait out shell motion. pixel reads inspect finite
2078
- // animations in both realms: a worklet can move the app while the
2079
- // tenant's basic animation flag and last presented pixels read still.
2080
- const accessibilityRead = maestro
2081
- ? answer(() => globalThis.__sootsimTest.captureAccessibilityTree()).catch(() => null)
2082
- : null
2083
- const motionRead = strict || paintStill
2084
- ? answer(() => globalThis.__sootsimTest?.listAnimations?.()).catch(() => null)
2046
+ const readSnapshot = async () => {
2047
+ let animating = false
2048
+ let animatingBy = ''
2049
+ let layoutDirty = false
2050
+ let pendingFetches = 0
2051
+ let workerBusy = false
2052
+ let requestTotal = 0
2053
+ let requestInFlight = 0
2054
+ let appCommits = null
2055
+ let nodeCount = null
2056
+ let renderStatsAvailable = false
2057
+ let shellAnimating = false
2058
+ let shellBlockers = ''
2059
+ let webViewStarting = false
2060
+ let webViewBlocker = ''
2061
+ let visibleMotion = false
2062
+ let visibleMotionBy = ''
2063
+ // the reads are independent, so they run concurrently: a loaded sim
2064
+ // answers each one late, and a poll that waits for them in turn
2065
+ // costs their sum, which fits too few polls in the budget to settle.
2066
+ // the window node count is the exception: it launches after the
2067
+ // motion read, so a poll motion already fails skips that walk.
2068
+ // strict reads also wait out shell motion. pixel reads inspect finite
2069
+ // animations in both realms: a worklet can move the app while the
2070
+ // tenant's basic animation flag and last presented pixels read still.
2071
+ const accessibilityRead = maestro
2072
+ ? answer(() => globalThis.__sootsimTest.captureAccessibilityTree()).catch(() => null)
2073
+ : null
2074
+ const motionRead = strict || screenStill
2075
+ ? answer(() => globalThis.__sootsimTest?.listAnimations?.()).catch(() => null)
2076
+ : null
2077
+ const statsRead = answer(() => globalThis.__sootsimRenderHost?.queryStats?.()).catch(() => null)
2078
+ // image preparation ends in the tenant before the compositor decodes
2079
+ // and realizes its pixels. both owners must finish before settling.
2080
+ // the compositor rejects a stats request it is too busy to answer.
2081
+ const compositorRead = answer(() => globalThis.__sootsimCompositor.getStats({ detail: 'readiness' })).catch(() => BUSY)
2082
+ const countsRead = answer(() => globalThis.__sootsimTest?.getRequestCounts?.()).catch(() => null)
2083
+ // the mounted hierarchy in render-worker mode comes from the test
2084
+ // bridge: globalThis.__sootsimRoot is an empty placeholder there, so a
2085
+ // walk over it hashes every screen to the same empty string while
2086
+ // it moves. listInspectable is the worker-backed read describe
2087
+ // uses; a worker too busy to answer it reads as unsettled. tight
2088
+ // budgets skip this read and settle on the cheaper signals above.
2089
+ // it walks every node, so a poll whose geometry revision matches the
2090
+ // last read, in this wait or an earlier one, reuses that read.
2091
+ const hierarchyRead =
2092
+ fullGeometry && typeof globalThis.__sootsimTest?.listInspectable === 'function'
2093
+ ? answer(() => globalThis.__sootsimTest.getGeometryRevision?.())
2094
+ .catch(() => null)
2095
+ .then((revision) => {
2096
+ if (revision === BUSY) return BUSY
2097
+ if (typeof revision === 'string' && geometry.revision === revision) return geometry.hierarchy
2098
+ return answer(() => globalThis.__sootsimTest.listInspectable({}))
2099
+ .catch(() => null)
2100
+ .then((hierarchy) => {
2101
+ const kept = typeof revision === 'string' && Array.isArray(hierarchy)
2102
+ geometry.revision = kept ? revision : null
2103
+ geometry.hierarchy = kept ? hierarchy : null
2104
+ return hierarchy
2105
+ })
2106
+ })
2085
2107
  : null
2086
- const statsRead = answer(() => globalThis.__sootsimRenderHost?.queryStats?.()).catch(() => null)
2087
- // image preparation ends in the tenant before the compositor decodes
2088
- // and realizes its pixels. both owners must finish before settling.
2089
- // the compositor rejects a stats request it is too busy to answer.
2090
- const compositorRead = answer(() => globalThis.__sootsimCompositor.getStats({ detail: 'readiness' })).catch(() => BUSY)
2091
- const countsRead = answer(() => globalThis.__sootsimTest?.getRequestCounts?.()).catch(() => null)
2092
- // the mounted hierarchy in render-worker mode comes from the test
2093
- // bridge: globalThis.__sootsimRoot is an empty placeholder there, so a
2094
- // walk over it hashes every screen to the same empty string while
2095
- // it moves. listInspectable is the worker-backed read describe
2096
- // uses; a worker too busy to answer it reads as unsettled. tight
2097
- // budgets skip this read and settle on the cheaper signals above.
2098
- // it walks every node, so a poll whose geometry revision matches the
2099
- // last read, in this wait or an earlier one, reuses that read.
2100
- const hierarchyRead =
2101
- fullGeometry && typeof globalThis.__sootsimTest?.listInspectable === 'function'
2102
- ? answer(() => globalThis.__sootsimTest.getGeometryRevision?.())
2103
- .catch(() => null)
2104
- .then((revision) => {
2105
- if (revision === BUSY) return BUSY
2106
- if (typeof revision === 'string' && geometry.revision === revision) return geometry.hierarchy
2107
- return answer(() => globalThis.__sootsimTest.listInspectable({}))
2108
- .catch(() => null)
2109
- .then((hierarchy) => {
2110
- const kept = typeof revision === 'string' && Array.isArray(hierarchy)
2111
- geometry.revision = kept ? revision : null
2112
- geometry.hierarchy = kept ? hierarchy : null
2113
- return hierarchy
2114
- })
2115
- })
2116
- : null
2117
- if (motionRead) {
2118
- const motion = await motionRead
2119
- if (motion === BUSY) workerBusy = true
2120
- else if (Array.isArray(motion)) {
2121
- const blocking = motion.filter((anim) =>
2122
- (anim.realm === 'shell' || paintStill) &&
2123
- anim.priority !== 'low' && anim.visible !== false &&
2124
- (!paintStill || anim.loop !== true))
2125
- shellAnimating = blocking.length > 0
2126
- // name what holds the settle so a timeout points at its owner.
2127
- shellBlockers = blocking
2128
- .slice(0, 4)
2129
- .map((anim) => anim.source + '/' + anim.kind + '#' + anim.id + ' at ' + anim.current + (anim.loop ? ' loop' : ''))
2130
- .join(', ')
2131
- }
2108
+ if (motionRead) {
2109
+ const motion = await motionRead
2110
+ if (motion === BUSY) workerBusy = true
2111
+ else if (Array.isArray(motion)) {
2112
+ const blocking = motion.filter((anim) =>
2113
+ (anim.realm === 'shell' || screenStill) &&
2114
+ anim.priority !== 'low' && anim.visible !== false &&
2115
+ (!screenStill || anim.loop !== true))
2116
+ shellAnimating = blocking.length > 0
2117
+ // what blocking leaves out still moves the screen while visible;
2118
+ // it ends a screen-still wait only at maestro's hierarchy check
2119
+ // or the deadline, as a screen that never holds still does on ios.
2120
+ const moving = screenStill
2121
+ ? motion.filter((anim) => anim.visible !== false && !blocking.includes(anim))
2122
+ : []
2123
+ visibleMotion = moving.length > 0
2124
+ visibleMotionBy = moving
2125
+ .slice(0, 4)
2126
+ .map((anim) => anim.source + '/' + anim.kind + '#' + anim.id + (anim.loop ? ' loop' : '') + (anim.priority === 'low' ? ' low' : ''))
2127
+ .join(', ')
2128
+ // name what holds the settle so a timeout points at its owner.
2129
+ shellBlockers = blocking
2130
+ .slice(0, 4)
2131
+ .map((anim) => anim.source + '/' + anim.kind + '#' + anim.id + ' at ' + anim.current + (anim.loop ? ' loop' : ''))
2132
+ .join(', ')
2132
2133
  }
2133
- const stats = await statsRead
2134
- if (stats === BUSY) {
2135
- workerBusy = true
2136
- } else if (!stats && readyPlayback) {
2137
- workerBusy = true
2138
- } else if (stats) {
2139
- renderStatsAvailable = true
2140
- const missingFields = ['hasActiveBlockingNativeAnimations', 'hasPendingBlockingAnimationFrames']
2141
- .filter((field) => typeof stats[field] !== 'boolean')
2142
- if (readyPlayback && typeof stats.hasPendingReadinessAnimationFrames !== 'boolean') missingFields.push('hasPendingReadinessAnimationFrames')
2143
- if ((strict || readyPlayback) && missingFields.length > 0) {
2144
- return {
2145
- runtimeUnsupported: {
2146
- error: 'runtime_readiness_unsupported',
2147
- runtimeVersion: globalThis.__sootsimRuntimeVersion || 'unknown',
2148
- missingFields,
2149
- },
2150
- }
2134
+ }
2135
+ const stats = await statsRead
2136
+ if (stats === BUSY) {
2137
+ workerBusy = true
2138
+ } else if (!stats && readyPlayback) {
2139
+ workerBusy = true
2140
+ } else if (stats) {
2141
+ renderStatsAvailable = true
2142
+ const missingFields = ['hasActiveBlockingNativeAnimations', 'hasPendingBlockingAnimationFrames']
2143
+ .filter((field) => typeof stats[field] !== 'boolean')
2144
+ if (readyPlayback && typeof stats.hasPendingReadinessAnimationFrames !== 'boolean') missingFields.push('hasPendingReadinessAnimationFrames')
2145
+ if ((strict || readyPlayback) && missingFields.length > 0) {
2146
+ return {
2147
+ runtimeUnsupported: {
2148
+ error: 'runtime_readiness_unsupported',
2149
+ runtimeVersion: globalThis.__sootsimRuntimeVersion || 'unknown',
2150
+ missingFields,
2151
+ },
2151
2152
  }
2152
- // positive checks only: an older runtime without the blocking
2153
- // fields reads as still, and strict rejects that runtime above
2154
- // instead of ever settling on unknown motion.
2155
- animating =
2156
- stats.hasActiveAnims === true ||
2157
- stats.hasActiveBlockingNativeAnimations === true ||
2158
- (!paintStill && (readyPlayback ? stats.hasPendingReadinessAnimationFrames : stats.hasPendingBlockingAnimationFrames) === true)
2159
- if (animating)
2160
- animatingBy = [
2161
- stats.hasActiveAnims === true && 'activeAnims',
2162
- stats.hasActiveBlockingNativeAnimations === true && 'blockingNative',
2163
- !paintStill && stats.hasPendingBlockingAnimationFrames === true && 'pendingFrames',
2164
- !paintStill && stats.hasPendingReadinessAnimationFrames === true && 'pendingReadinessFrames',
2165
- ].filter(Boolean).join('+')
2166
- // the runtime reports only layout work that can reach the window:
2167
- // a covered screen or inactive tab committing does not hold it.
2168
- layoutDirty =
2169
- stats.layoutDirty === true && stats.renderRequested === true
2170
- // a freshly-pushed screen showing a skeleton is layout-stable
2171
- // but not actually settled \u2014 its data/images are still in
2172
- // flight. treat bounded image-loader fetches as not-idle so
2173
- // settle waits for real content, capped by the budget.
2174
- const pf = stats.memory && stats.memory.imageLoader
2175
- ? stats.memory.imageLoader.pendingFetches
2176
- : 0
2177
- pendingFetches = typeof pf === 'number' ? pf : 0
2178
- // tenant layout commits: a screen that keeps committing is still
2179
- // mounting or remounting, even with no animation flag raised.
2180
- appCommits = typeof stats.appCommitCount === 'number' ? stats.appCommitCount : null
2181
2153
  }
2182
- // mounted-root membership: the count of nodes that can reach the
2183
- // window moves while the screen mounts, unmounts or recycles, in
2184
- // either render mode. a screen a pushed one covers or an inactive
2185
- // tab stays mounted out of the window, so what it mounts is not
2186
- // screen motion. the worker rebuilds the membership set while the
2187
- // wire moves on every animated frame, so a poll the motion read
2188
- // already fails skips it: the motion flags alone prove this poll
2189
- // unsettled, and the carried count hands the first still poll the
2190
- // pre-motion baseline to compare against.
2191
- const motionStill = !workerBusy && !animating && !layoutDirty && !shellAnimating
2192
- const nodeCountRead = motionStill
2193
- ? answer(() => globalThis.__sootsimTest?.getWindowNodeCount?.()).catch(() => null)
2194
- : null
2195
- const compositor = await compositorRead
2196
- if (compositor === BUSY) {
2197
- workerBusy = true
2198
- } else {
2199
- pendingFetches += compositor.images.pendingFetches
2200
- pendingFetches += compositor.imageRealization.pending
2201
- if (compositor.webViewCaptureSettled === false) {
2202
- webViewStarting = true
2203
- webViewBlocker = 'compositor webView capture not settled'
2204
- }
2154
+ // positive checks only: an older runtime without the blocking
2155
+ // fields reads as still, and strict rejects that runtime above
2156
+ // instead of ever settling on unknown motion.
2157
+ animating =
2158
+ stats.hasActiveAnims === true ||
2159
+ stats.hasActiveBlockingNativeAnimations === true ||
2160
+ (!screenStill && (readyPlayback ? stats.hasPendingReadinessAnimationFrames : stats.hasPendingBlockingAnimationFrames) === true)
2161
+ if (animating)
2162
+ animatingBy = [
2163
+ stats.hasActiveAnims === true && 'activeAnims',
2164
+ stats.hasActiveBlockingNativeAnimations === true && 'blockingNative',
2165
+ !screenStill && stats.hasPendingBlockingAnimationFrames === true && 'pendingFrames',
2166
+ !screenStill && stats.hasPendingReadinessAnimationFrames === true && 'pendingReadinessFrames',
2167
+ ].filter(Boolean).join('+')
2168
+ // the runtime reports only layout work that can reach the window:
2169
+ // a covered screen or inactive tab committing does not hold it.
2170
+ layoutDirty =
2171
+ stats.layoutDirty === true && stats.renderRequested === true
2172
+ // a freshly-pushed screen showing a skeleton is layout-stable
2173
+ // but not actually settled \u2014 its data/images are still in
2174
+ // flight. treat bounded image-loader fetches as not-idle so
2175
+ // settle waits for real content, capped by the budget.
2176
+ const pf = stats.memory && stats.memory.imageLoader
2177
+ ? stats.memory.imageLoader.pendingFetches
2178
+ : 0
2179
+ pendingFetches = typeof pf === 'number' ? pf : 0
2180
+ // tenant layout commits: a screen that keeps committing is still
2181
+ // mounting or remounting, even with no animation flag raised.
2182
+ appCommits = typeof stats.appCommitCount === 'number' ? stats.appCommitCount : null
2183
+ }
2184
+ // mounted-root membership: the count of nodes that can reach the
2185
+ // window moves while the screen mounts, unmounts or recycles, in
2186
+ // either render mode. a screen a pushed one covers or an inactive
2187
+ // tab stays mounted out of the window, so what it mounts is not
2188
+ // screen motion. the worker rebuilds the membership set while the
2189
+ // wire moves on every animated frame, so a poll the motion read
2190
+ // already fails skips it: the motion flags alone prove this poll
2191
+ // unsettled, and the carried count hands the first still poll the
2192
+ // pre-motion baseline to compare against.
2193
+ const motionStill = !workerBusy && !animating && !layoutDirty && !shellAnimating
2194
+ const nodeCountRead = motionStill
2195
+ ? answer(() => globalThis.__sootsimTest?.getWindowNodeCount?.()).catch(() => null)
2196
+ : null
2197
+ const compositor = await compositorRead
2198
+ if (compositor === BUSY) {
2199
+ workerBusy = true
2200
+ } else {
2201
+ pendingFetches += compositor.images.pendingFetches
2202
+ pendingFetches += compositor.imageRealization.pending
2203
+ if (compositor.webViewCaptureSettled === false) {
2204
+ webViewStarting = true
2205
+ webViewBlocker = 'compositor webView capture not settled'
2205
2206
  }
2206
- const counts = await countsRead
2207
- if (counts === BUSY) workerBusy = true
2208
- // <Image> loads are left to the image loader, which counts only those
2209
- // that can reach the window. a runtime older than the CLI reports none.
2210
- const imageLoads = counts?.imageLoads ?? { total: 0, inFlight: 0 }
2211
- requestTotal = typeof counts?.total === 'number' ? counts.total - imageLoads.total : 0
2212
- requestInFlight = typeof counts?.inFlight === 'number' ? counts.inFlight - imageLoads.inFlight : 0
2213
- // a skipped read carries the last count: mounts during motion still
2214
- // break the first still poll after it, instead of a blank baseline
2215
- // reading them as stable.
2216
- const total = nodeCountRead ? await nodeCountRead : lastNodeCount
2217
- if (total === BUSY) workerBusy = true
2218
- nodeCount = typeof total === 'number' ? total : null
2219
- const accessibility = accessibilityRead ? await accessibilityRead : null
2220
- const nativeHierarchy = Array.isArray(accessibility) && accessibility.length > 0
2221
- ? accessibility
2222
- : null
2223
- if (accessibility === BUSY) workerBusy = true
2224
- let hierarchy = hierarchyRead ? await hierarchyRead : null
2225
- if (hierarchy === BUSY) {
2226
- workerBusy = true
2227
- hierarchy = null
2228
- } else if (!Array.isArray(hierarchy)) {
2229
- hierarchy = null
2207
+ }
2208
+ const counts = await countsRead
2209
+ if (counts === BUSY) workerBusy = true
2210
+ // <Image> loads are left to the image loader, which counts only those
2211
+ // that can reach the window. a runtime older than the CLI reports none.
2212
+ const imageLoads = counts?.imageLoads ?? { total: 0, inFlight: 0 }
2213
+ requestTotal = typeof counts?.total === 'number' ? counts.total - imageLoads.total : 0
2214
+ requestInFlight = typeof counts?.inFlight === 'number' ? counts.inFlight - imageLoads.inFlight : 0
2215
+ // a skipped read carries the last count: mounts during motion still
2216
+ // break the first still poll after it, instead of a blank baseline
2217
+ // reading them as stable.
2218
+ const total = nodeCountRead ? await nodeCountRead : lastNodeCount
2219
+ if (total === BUSY) workerBusy = true
2220
+ nodeCount = typeof total === 'number' ? total : null
2221
+ const accessibility = accessibilityRead ? await accessibilityRead : null
2222
+ const nativeHierarchy = Array.isArray(accessibility) && accessibility.length > 0
2223
+ ? accessibility
2224
+ : null
2225
+ if (accessibility === BUSY) workerBusy = true
2226
+ let hierarchy = hierarchyRead ? await hierarchyRead : null
2227
+ if (hierarchy === BUSY) {
2228
+ workerBusy = true
2229
+ hierarchy = null
2230
+ } else if (!Array.isArray(hierarchy)) {
2231
+ hierarchy = null
2232
+ }
2233
+ const nodes = []
2234
+ // identity beside each geometry entry, from the rows already read,
2235
+ // so a changed layout can name the nodes that moved.
2236
+ const nodeRows = []
2237
+ const LOADING_TEXT_REGEX = /^(creating webview|loading html|fetching bundle|waiting for first render|starting preview|loading simulator|fetching app code|waiting for native preview|starting design|loading canvas|fetching screens|painting the canvas|waiting for webview|waiting for preview|waiting for canvas|preview stalled)/i
2238
+ const noteLoading = (state, text) => {
2239
+ if (state?.busy === true) {
2240
+ webViewStarting = true
2241
+ if (!webViewBlocker) webViewBlocker = 'accessibility busy state active'
2230
2242
  }
2231
- const nodes = []
2232
- // identity beside each geometry entry, from the rows already read,
2233
- // so a changed layout can name the nodes that moved.
2234
- const nodeRows = []
2235
- const LOADING_TEXT_REGEX = /^(creating webview|loading html|fetching bundle|waiting for first render|starting preview|loading simulator|fetching app code|waiting for native preview|starting design|loading canvas|fetching screens|painting the canvas|waiting for webview|waiting for preview|waiting for canvas|preview stalled)/i
2236
- const noteLoading = (state, text) => {
2237
- if (state?.busy === true) {
2238
- webViewStarting = true
2239
- if (!webViewBlocker) webViewBlocker = 'accessibility busy state active'
2240
- }
2241
- if (typeof text === 'string' && LOADING_TEXT_REGEX.test(text.trim())) {
2242
- webViewStarting = true
2243
- if (!webViewBlocker) webViewBlocker = 'webView startup in progress ("' + text.trim() + '")'
2243
+ if (typeof text === 'string' && LOADING_TEXT_REGEX.test(text.trim())) {
2244
+ webViewStarting = true
2245
+ if (!webViewBlocker) webViewBlocker = 'webView startup in progress ("' + text.trim() + '")'
2246
+ }
2247
+ }
2248
+ if (hierarchy) {
2249
+ for (const n of hierarchy) {
2250
+ const layout = n && n.layout
2251
+ if (layout && layout.width > 0) {
2252
+ // painted bounds catch a scroll fling. background playback
2253
+ // keeps a view's painted bounds moving forever, so it and its
2254
+ // subtree count by their own layout; the rest of the screen
2255
+ // still catches the fling.
2256
+ const abs = n.backgroundPlayback ? layout : n.absolute || n.absolutePosition || layout
2257
+ const geometry = Math.round(abs.x) + ',' + Math.round(abs.y) + ',' + Math.round(layout.width)
2258
+ nodes.push(geometry)
2259
+ nodeRows.push([String(n.nodeId ?? nodes.length - 1), (n.type || '?') + (n.testId ? '#' + n.testId : ''), geometry])
2244
2260
  }
2261
+ noteLoading(
2262
+ n.accessibilityState,
2263
+ typeof n.text === 'string' ? n.text : '',
2264
+ )
2245
2265
  }
2246
- if (hierarchy) {
2247
- for (const n of hierarchy) {
2248
- const layout = n && n.layout
2249
- if (layout && layout.width > 0) {
2250
- // painted bounds catch a scroll fling. background playback
2251
- // keeps a view's painted bounds moving forever, so it and its
2252
- // subtree count by their own layout; the rest of the screen
2253
- // still catches the fling.
2254
- const abs = n.backgroundPlayback ? layout : n.absolute || n.absolutePosition || layout
2255
- const geometry = Math.round(abs.x) + ',' + Math.round(abs.y) + ',' + Math.round(layout.width)
2266
+ } else {
2267
+ const root = globalThis.__sootsimRoot
2268
+ if (root) {
2269
+ const walk = (n) => {
2270
+ if (n.layout && n.layout.width > 0) {
2271
+ const geometry = Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width)
2256
2272
  nodes.push(geometry)
2257
- nodeRows.push([String(n.nodeId ?? nodes.length - 1), (n.type || '?') + (n.testId ? '#' + n.testId : ''), geometry])
2273
+ nodeRows.push([String(n.id ?? nodes.length - 1), (n.type || '?') + (n.props?.testID ? '#' + n.props.testID : ''), geometry])
2258
2274
  }
2259
2275
  noteLoading(
2260
- n.accessibilityState,
2261
- typeof n.text === 'string' ? n.text : '',
2276
+ n.props?.accessibilityState,
2277
+ n.textContent || (typeof n.props?.children === 'string' ? n.props.children : ''),
2262
2278
  )
2279
+ for (const c of n.children || []) walk(c)
2263
2280
  }
2264
- } else {
2265
- const root = globalThis.__sootsimRoot
2266
- if (root) {
2267
- const walk = (n) => {
2268
- if (n.layout && n.layout.width > 0) {
2269
- const geometry = Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width)
2270
- nodes.push(geometry)
2271
- nodeRows.push([String(n.id ?? nodes.length - 1), (n.type || '?') + (n.props?.testID ? '#' + n.props.testID : ''), geometry])
2272
- }
2273
- noteLoading(
2274
- n.props?.accessibilityState,
2275
- n.textContent || (typeof n.props?.children === 'string' ? n.props.children : ''),
2276
- )
2277
- for (const c of n.children || []) walk(c)
2278
- }
2279
- walk(root)
2280
- }
2281
+ walk(root)
2281
2282
  }
2282
- if (!webViewStarting && typeof document !== 'undefined') {
2283
- const busyEl = [...document.querySelectorAll('[aria-busy="true"]')].find((element) => {
2284
- const bounds = element.getBoundingClientRect()
2285
- return element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) &&
2286
- bounds.width > 0 && bounds.height > 0 && bounds.right > 0 && bounds.bottom > 0 &&
2287
- bounds.left < globalThis.innerWidth && bounds.top < globalThis.innerHeight
2283
+ }
2284
+ if (!webViewStarting && typeof document !== 'undefined') {
2285
+ const busyEl = [...document.querySelectorAll('[aria-busy="true"]')].find((element) => {
2286
+ const bounds = element.getBoundingClientRect()
2287
+ return element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) &&
2288
+ bounds.width > 0 && bounds.height > 0 && bounds.right > 0 && bounds.bottom > 0 &&
2289
+ bounds.left < globalThis.innerWidth && bounds.top < globalThis.innerHeight
2290
+ })
2291
+ if (busyEl) {
2292
+ webViewStarting = true
2293
+ webViewBlocker = 'accessibility busy element displayed'
2294
+ } else {
2295
+ // a loading document with no area (an app's hidden worker or
2296
+ // executor frame) paints nothing, and a screenshot on device
2297
+ // does not wait for it.
2298
+ const unreadyWebView = [...document.querySelectorAll(
2299
+ '[data-sootsim-webview-loading="true"], [data-sootsim-webview-mode="placeholder"]'
2300
+ )].find((view) => {
2301
+ const frame = view.querySelector('iframe')
2302
+ return !frame || frame.clientWidth > 0 || frame.clientHeight > 0
2288
2303
  })
2289
- if (busyEl) {
2304
+ if (unreadyWebView) {
2290
2305
  webViewStarting = true
2291
- webViewBlocker = 'accessibility busy element displayed'
2292
- } else {
2293
- // a loading document with no area (an app's hidden worker or
2294
- // executor frame) paints nothing, and a screenshot on device
2295
- // does not wait for it.
2296
- const unreadyWebView = [...document.querySelectorAll(
2297
- '[data-sootsim-webview-loading="true"], [data-sootsim-webview-mode="placeholder"]'
2298
- )].find((view) => {
2299
- const frame = view.querySelector('iframe')
2300
- return !frame || frame.clientWidth > 0 || frame.clientHeight > 0
2301
- })
2302
- if (unreadyWebView) {
2303
- webViewStarting = true
2304
- webViewBlocker = 'webView document still loading'
2305
- }
2306
+ webViewBlocker = 'webView document still loading'
2306
2307
  }
2307
2308
  }
2308
- if (paintStill) {
2309
- const canvas = composite.getCanvas()
2310
- const token = composite.getFrameToken()
2311
- if (!canvas || canvas.width <= 1 || canvas.height <= 1) {
2312
- screenPixels = null
2313
- } else if (token !== pixelFrameToken || canvas.width !== screenPixels?.width || canvas.height !== screenPixels?.height) {
2314
- const context = canvas.getContext('2d')
2315
- const image = context?.getImageData(0, 0, canvas.width, canvas.height)
2316
- screenPixels = image ? { width: image.width, height: image.height, data: new Uint32Array(image.data.buffer) } : null
2317
- pixelFrameToken = token
2318
- }
2319
- }
2320
- return { layout: nodes.join(';'), nodeRows, nativeHierarchy, screenPixels, animating, animatingBy, shellAnimating, shellBlockers, layoutDirty, pendingFetches, workerBusy, webViewStarting, webViewBlocker, renderStatsAvailable, requestTotal, requestInFlight, appCommits, nodeCount }
2321
2309
  }
2310
+ return { layout: nodes.join(';'), nodeRows, nativeHierarchy, visibleMotion, visibleMotionBy, animating, animatingBy, shellAnimating, shellBlockers, layoutDirty, pendingFetches, workerBusy, webViewStarting, webViewBlocker, renderStatsAvailable, requestTotal, requestInFlight, appCommits, nodeCount }
2311
+ }
2322
2312
 
2323
- // how long generic background network is allowed to keep us waiting AFTER
2324
- // the screen is otherwise visually settled. apps with continuous traffic
2325
- // (polling, realtime sockets, a tap that fires 20-50 fetches) never reach
2326
- // requestInFlight===0 / a stable requestTotal, so requiring full network
2327
- // quiet burns the ENTIRE budget on every command \u2014 the leading idle that
2328
- // failed PR-preview recordings for network-heavy apps (3pc fight-pulse).
2329
- // layout-stability + the image-loader already prove visible content
2330
- // loaded (a data load changes layout; an image load shows in the loader),
2331
- // so the generic request counters are a courtesy, not a gate: honor them
2332
- // only within this grace once the screen is visually still.
2333
- const networkQuietGraceMs = 1200
2334
- let lastNativeHierarchy = null
2335
- let lastLayout = ''
2336
- let lastNodeRows = []
2337
- // what moved between the last two differing polls, bounded; names the
2338
- // nodes behind "layout changed" without keeping any poll history.
2339
- let lastLayoutChange = null
2340
- const describeLayoutChange = (before, after) => {
2341
- const previous = new Map(before.map(([key, label, geometry]) => [key, [label, geometry]]))
2342
- const moved = []
2343
- const added = []
2344
- const short = (label, key) => String(label).slice(0, 48) + ' [' + String(key).slice(0, 24) + ']'
2345
- for (const [key, label, geometry] of after) {
2346
- const was = previous.get(key)
2347
- previous.delete(key)
2348
- if (!was) added.push(short(label, key) + ' ' + geometry)
2349
- else if (was[1] !== geometry) moved.push(short(label, key) + ' ' + was[1] + '->' + geometry)
2350
- }
2351
- const removed = [...previous].map(([key, [label, geometry]]) => short(label, key) + ' ' + geometry)
2352
- return {
2353
- moved: moved.length, added: added.length, removed: removed.length,
2354
- movedSample: moved.slice(0, 3), addedSample: added.slice(0, 3), removedSample: removed.slice(0, 3),
2355
- }
2313
+ // how long generic background network is allowed to keep us waiting AFTER
2314
+ // the screen is otherwise visually settled. apps with continuous traffic
2315
+ // (polling, realtime sockets, a tap that fires 20-50 fetches) never reach
2316
+ // requestInFlight===0 / a stable requestTotal, so requiring full network
2317
+ // quiet burns the ENTIRE budget on every command \u2014 the leading idle that
2318
+ // failed PR-preview recordings for network-heavy apps (3pc fight-pulse).
2319
+ // layout-stability + the image-loader already prove visible content
2320
+ // loaded (a data load changes layout; an image load shows in the loader),
2321
+ // so the generic request counters are a courtesy, not a gate: honor them
2322
+ // only within this grace once the screen is visually still.
2323
+ const networkQuietGraceMs = 1200
2324
+ let lastNativeHierarchy = null
2325
+ let lastLayout = ''
2326
+ let lastNodeRows = []
2327
+ // what moved between the last two differing polls, bounded; names the
2328
+ // nodes behind "layout changed" without keeping any poll history.
2329
+ let lastLayoutChange = null
2330
+ const describeLayoutChange = (before, after) => {
2331
+ const previous = new Map(before.map(([key, label, geometry]) => [key, [label, geometry]]))
2332
+ const moved = []
2333
+ const added = []
2334
+ const short = (label, key) => String(label).slice(0, 48) + ' [' + String(key).slice(0, 24) + ']'
2335
+ for (const [key, label, geometry] of after) {
2336
+ const was = previous.get(key)
2337
+ previous.delete(key)
2338
+ if (!was) added.push(short(label, key) + ' ' + geometry)
2339
+ else if (was[1] !== geometry) moved.push(short(label, key) + ' ' + was[1] + '->' + geometry)
2356
2340
  }
2357
- let lastScreenPixels = null
2358
- let screenChangedPolls = 0
2359
- let lastRequestTotal = -1
2360
- let lastAppCommits = null
2361
- let lastNodeCount = null
2362
- // the last completed poll and the values it was compared against.
2363
- let report = null
2364
- // the still polls of the current run, when each began and answered
2365
- let stillPolls = []
2366
- let lastIdlePoll = null
2367
- let visuallyStillSince = 0
2368
- // counts across the whole budget: a flag that is true on every poll is a
2369
- // different bug from one that is true intermittently, and the two need
2370
- // opposite fixes (engine vs budget).
2371
- let polls = 0
2372
- let dirtyPolls = 0
2373
- let animatingPolls = 0
2374
- let layoutChangedPolls = 0
2375
- let webViewStartingPolls = 0
2376
- const screenUnchanged = (pixels, previous) => {
2377
- if (!pixels || !previous || pixels.width !== previous.width || pixels.height !== previous.height) return false
2378
- if (pixels === previous) return true
2379
- for (let i = 0; i < pixels.data.length; i++) {
2380
- if (pixels.data[i] !== previous.data[i]) return false
2381
- }
2382
- return true
2341
+ const removed = [...previous].map(([key, [label, geometry]]) => short(label, key) + ' ' + geometry)
2342
+ return {
2343
+ moved: moved.length, added: added.length, removed: removed.length,
2344
+ movedSample: moved.slice(0, 3), addedSample: added.slice(0, 3), removedSample: removed.slice(0, 3),
2383
2345
  }
2384
- const hierarchyUnchanged = (current, previous) =>
2385
- current !== null && previous !== null && current.length === previous.length &&
2386
- current.every((node, index) => sameNativeAccessibilityShape(node, previous[index], accessibilityBounds))
2387
- while (true) {
2388
- if (clockNow() >= deadline) {
2389
- if (!transitionWait) break
2390
- await transitionWait
2391
- transitionWait = null
2392
- // nothing polled while parked on the transition, and a loaded
2393
- // worker's late reply would spend the restarted budget unobserved.
2394
- if (transitionEndedAt !== null) deadline = Math.max(deadline, clockNow() + budgetMs)
2395
- if (clockNow() >= deadline) break
2396
- }
2397
- const pollStarted = clockNow()
2398
- const snapshot = await readSnapshot()
2399
- if (snapshot.runtimeUnsupported) return snapshot.runtimeUnsupported
2400
- // a read the deadline cut short observed nothing: the last full poll
2401
- // names what held the settle, not a worker that ran out of budget.
2402
- // the loop head drains a transition still in flight before it ends.
2403
- if (snapshot.workerBusy && clockNow() >= deadline && report) continue
2404
- polls++
2405
- report = { snapshot, nativeHierarchy: lastNativeHierarchy, layout: lastLayout, screenPixels: lastScreenPixels, requestTotal: lastRequestTotal, appCommits: lastAppCommits, nodeCount: lastNodeCount }
2406
- if (snapshot.layoutDirty) dirtyPolls++
2407
- if (snapshot.animating || snapshot.shellAnimating) animatingPolls++
2408
- if (snapshot.webViewStarting) webViewStartingPolls++
2409
- if (polls > 1 && snapshot.layout !== lastLayout) {
2410
- layoutChangedPolls++
2411
- lastLayoutChange = describeLayoutChange(lastNodeRows, snapshot.nodeRows)
2412
- }
2413
- const screenChanged = paintStill && !screenUnchanged(snapshot.screenPixels, lastScreenPixels)
2414
- if (polls > 1 && screenChanged) screenChangedPolls++
2415
- const strictOk =
2416
- !strict ||
2417
- (snapshot.renderStatsAvailable &&
2418
- !snapshot.animating &&
2419
- !snapshot.shellAnimating &&
2420
- !snapshot.layoutDirty)
2421
- // visually settled: no worker motion or layout work, no new layout
2422
- // commits, a stable mounted node count, no image content loading
2423
- // (unless motion alone is asked), no webview startup in progress,
2424
- // layout unchanged since the last poll. both modes wait out finite
2425
- // worker motion now; strict additionally implies the flags through
2426
- // strictOk and adds shell motion plus the blocking-stats floor. a
2427
- // null count or commit reading means the runtime does not report
2428
- // it, which reads as stable the way a missing stats block does.
2429
- // equal presented pixels can precede pending worker motion or layout.
2430
- // after that work drains, iOS's 3 s pixel phase may accept two equal
2431
- // native TreeNodes while paint-only playback continues. overlap
2432
- // hierarchy reads so neither the gesture nor screenshot deadline grows.
2433
- const maestroStill = snapshot.screenPixels !== null && !snapshot.workerBusy && snapshot.pendingFetches === 0 && snapshot.requestInFlight === 0 && !snapshot.webViewStarting &&
2434
- !snapshot.animating && !snapshot.shellAnimating && !snapshot.layoutDirty && (
2435
- !screenChanged || (clockNow() - start >= 3000 &&
2436
- hierarchyUnchanged(snapshot.nativeHierarchy, lastNativeHierarchy))
2437
- )
2438
- const idleSnapshot =
2439
- strictOk &&
2346
+ }
2347
+ let screenChangedPolls = 0
2348
+ let lastRequestTotal = -1
2349
+ let lastAppCommits = null
2350
+ let lastNodeCount = null
2351
+ // the last completed poll and the values it was compared against.
2352
+ let report = null
2353
+ // the still polls of the current run, when each began and answered
2354
+ let stillPolls = []
2355
+ let lastIdlePoll = null
2356
+ let visuallyStillSince = 0
2357
+ // counts across the whole budget: a flag that is true on every poll is a
2358
+ // different bug from one that is true intermittently, and the two need
2359
+ // opposite fixes (engine vs budget).
2360
+ let polls = 0
2361
+ let dirtyPolls = 0
2362
+ let animatingPolls = 0
2363
+ let layoutChangedPolls = 0
2364
+ let webViewStartingPolls = 0
2365
+ const hierarchyUnchanged = (current, previous) =>
2366
+ current !== null && previous !== null && current.length === previous.length &&
2367
+ current.every((node, index) => sameNativeAccessibilityShape(node, previous[index], accessibilityBounds))
2368
+ while (true) {
2369
+ if (clockNow() >= deadline) {
2370
+ if (!transitionWait) break
2371
+ await transitionWait
2372
+ transitionWait = null
2373
+ // nothing polled while parked on the transition, and a loaded
2374
+ // worker's late reply would spend the restarted budget unobserved.
2375
+ if (transitionEndedAt !== null) deadline = Math.max(deadline, clockNow() + budgetMs)
2376
+ if (clockNow() >= deadline) break
2377
+ }
2378
+ const pollStarted = clockNow()
2379
+ const snapshot = await readSnapshot()
2380
+ if (snapshot.runtimeUnsupported) return snapshot.runtimeUnsupported
2381
+ // a read the deadline cut short observed nothing: the last full poll
2382
+ // names what held the settle, not a worker that ran out of budget.
2383
+ // the loop head drains a transition still in flight before it ends.
2384
+ if (snapshot.workerBusy && clockNow() >= deadline && report) continue
2385
+ polls++
2386
+ report = { snapshot, nativeHierarchy: lastNativeHierarchy, layout: lastLayout, requestTotal: lastRequestTotal, appCommits: lastAppCommits, nodeCount: lastNodeCount }
2387
+ if (snapshot.layoutDirty) dirtyPolls++
2388
+ if (snapshot.animating || snapshot.shellAnimating) animatingPolls++
2389
+ if (snapshot.webViewStarting) webViewStartingPolls++
2390
+ if (polls > 1 && snapshot.layout !== lastLayout) {
2391
+ layoutChangedPolls++
2392
+ lastLayoutChange = describeLayoutChange(lastNodeRows, snapshot.nodeRows)
2393
+ }
2394
+ // the first poll has nothing to compare, so it cannot prove a still screen
2395
+ const screenChanged = screenStill && (
2396
+ polls === 1 ||
2397
+ snapshot.visibleMotion ||
2398
+ (snapshot.appCommits !== null && lastAppCommits !== null && snapshot.appCommits !== lastAppCommits) ||
2399
+ (snapshot.nodeCount !== null && lastNodeCount !== null && snapshot.nodeCount !== lastNodeCount) ||
2400
+ snapshot.layout !== lastLayout ||
2401
+ (maestro && !hierarchyUnchanged(snapshot.nativeHierarchy, lastNativeHierarchy))
2402
+ )
2403
+ if (polls > 1 && screenChanged) screenChangedPolls++
2404
+ const strictOk =
2405
+ !strict ||
2406
+ (snapshot.renderStatsAvailable &&
2440
2407
  !snapshot.animating &&
2441
2408
  !snapshot.shellAnimating &&
2442
- !snapshot.layoutDirty &&
2443
- snapshot.pendingFetches === 0 &&
2444
- !snapshot.workerBusy &&
2445
- !snapshot.webViewStarting
2446
- const visuallyStill = maestro ? maestroStill :
2447
- idleSnapshot &&
2448
- (snapshot.appCommits === null || lastAppCommits === null || snapshot.appCommits === lastAppCommits) &&
2449
- (snapshot.nodeCount === null || lastNodeCount === null || snapshot.nodeCount === lastNodeCount) &&
2450
- !screenChanged &&
2451
- snapshot.layout === lastLayout
2452
- // generic network quiet: nothing in flight and no new requests issued.
2453
- const networkQuiet =
2454
- snapshot.requestInFlight === 0 && snapshot.requestTotal === lastRequestTotal
2455
- if (visuallyStill) {
2456
- if (visuallyStillSince === 0) visuallyStillSince = clockNow()
2457
- // two equal idle observations prove the interval between them.
2458
- // discarding the first requires a third worker round trip, which
2459
- // can exhaust the budget after a late image on a loaded host.
2460
- if (!maestro && !paintStill && stillPolls.length === 0 && lastIdlePoll) {
2461
- stillPolls.push(lastIdlePoll)
2462
- }
2463
- stillPolls.push({ started: pollStarted, answered: clockNow() })
2464
- // still long enough, counting only polls that began after a started
2465
- // transition drained.
2466
- const stillProven = () => {
2467
- const proving = stillPolls.filter((poll) => transitionEndedAt === null || poll.started >= transitionEndedAt)
2468
- return proving.length >= minimumStablePolls && clockNow() - proving[0].answered >= requiredStillMs
2469
- }
2470
- // settle once the screen has held still long enough AND either the
2471
- // network is genuinely quiet OR it has refused to quiet within the
2472
- // grace (continuous background traffic must not block forever).
2473
- if (
2474
- stillProven() &&
2475
- (maestro || networkQuiet || clockNow() - visuallyStillSince >= networkQuietGraceMs)
2476
- ) {
2477
- if (transitionWait) {
2478
- await transitionWait
2479
- transitionWait = null
2480
- }
2481
- if (stillProven()) return { settled: true, elapsed: clockNow() - start, blockedBy: '' }
2409
+ !snapshot.layoutDirty)
2410
+ // visually settled: no worker motion or layout work, no new layout
2411
+ // commits, a stable mounted node count, no image content loading
2412
+ // (unless motion alone is asked), no webview startup in progress,
2413
+ // layout unchanged since the last poll. both modes wait out finite
2414
+ // worker motion now; strict additionally implies the flags through
2415
+ // strictOk and adds shell motion plus the blocking-stats floor. a
2416
+ // null count or commit reading means the runtime does not report
2417
+ // it, which reads as stable the way a missing stats block does.
2418
+ // equal presented pixels can precede pending worker motion or layout.
2419
+ // after that work drains, iOS's 3 s pixel phase may accept two equal
2420
+ // native TreeNodes while paint-only playback continues. overlap
2421
+ // hierarchy reads so neither the gesture nor screenshot deadline grows.
2422
+ const maestroStill = !snapshot.workerBusy && snapshot.pendingFetches === 0 && snapshot.requestInFlight === 0 && !snapshot.webViewStarting &&
2423
+ !snapshot.animating && !snapshot.shellAnimating && !snapshot.layoutDirty && (
2424
+ !screenChanged || (clockNow() - start >= 3000 &&
2425
+ hierarchyUnchanged(snapshot.nativeHierarchy, lastNativeHierarchy))
2426
+ )
2427
+ const idleSnapshot =
2428
+ strictOk &&
2429
+ !snapshot.animating &&
2430
+ !snapshot.shellAnimating &&
2431
+ !snapshot.layoutDirty &&
2432
+ snapshot.pendingFetches === 0 &&
2433
+ !snapshot.workerBusy &&
2434
+ !snapshot.webViewStarting
2435
+ const visuallyStill = maestro ? maestroStill :
2436
+ idleSnapshot &&
2437
+ (snapshot.appCommits === null || lastAppCommits === null || snapshot.appCommits === lastAppCommits) &&
2438
+ (snapshot.nodeCount === null || lastNodeCount === null || snapshot.nodeCount === lastNodeCount) &&
2439
+ !screenChanged &&
2440
+ snapshot.layout === lastLayout
2441
+ // generic network quiet: nothing in flight and no new requests issued.
2442
+ const networkQuiet =
2443
+ snapshot.requestInFlight === 0 && snapshot.requestTotal === lastRequestTotal
2444
+ if (visuallyStill) {
2445
+ if (visuallyStillSince === 0) visuallyStillSince = clockNow()
2446
+ // two equal idle observations prove the interval between them.
2447
+ // discarding the first requires a third worker round trip, which
2448
+ // can exhaust the budget after a late image on a loaded host.
2449
+ if (!maestro && !screenStill && stillPolls.length === 0 && lastIdlePoll) {
2450
+ stillPolls.push(lastIdlePoll)
2451
+ }
2452
+ stillPolls.push({ started: pollStarted, answered: clockNow() })
2453
+ // still long enough, counting only polls that began after a started
2454
+ // transition drained.
2455
+ const stillProven = () => {
2456
+ const proving = stillPolls.filter((poll) => transitionEndedAt === null || poll.started >= transitionEndedAt)
2457
+ return proving.length >= minimumStablePolls && clockNow() - proving[0].answered >= requiredStillMs
2458
+ }
2459
+ // settle once the screen has held still long enough AND either the
2460
+ // network is genuinely quiet OR it has refused to quiet within the
2461
+ // grace (continuous background traffic must not block forever).
2462
+ if (
2463
+ stillProven() &&
2464
+ (maestro || networkQuiet || clockNow() - visuallyStillSince >= networkQuietGraceMs)
2465
+ ) {
2466
+ if (transitionWait) {
2467
+ await transitionWait
2468
+ transitionWait = null
2482
2469
  }
2483
- } else {
2484
- stillPolls = []
2485
- visuallyStillSince = 0
2470
+ if (stillProven()) return { settled: true, elapsed: clockNow() - start, blockedBy: '' }
2486
2471
  }
2487
- lastIdlePoll = idleSnapshot ? { started: pollStarted, answered: clockNow() } : null
2488
- lastNativeHierarchy = snapshot.nativeHierarchy
2489
- lastLayout = snapshot.layout
2490
- lastNodeRows = snapshot.nodeRows
2491
- lastScreenPixels = snapshot.screenPixels
2492
- lastRequestTotal = snapshot.requestTotal
2493
- lastAppCommits = snapshot.appCommits
2494
- lastNodeCount = snapshot.nodeCount
2495
- // reply latency belongs inside the poll interval; the stillness window
2496
- // above remains measured from completed observations.
2497
- const remainingPollMs = pollMs - (clockNow() - pollStarted)
2498
- if (remainingPollMs > 0) await clockSleep(remainingPollMs)
2499
- }
2500
- if (!report) {
2501
- return { settled: false, elapsed: clockNow() - start, blockedBy: 'no poll fit the budget' }
2502
- }
2503
- const last = report.snapshot
2504
- const blockers = []
2505
- if (!maestro && strict && !last.renderStatsAvailable) blockers.push('render stats unavailable')
2506
- if (!maestro && last.animating) blockers.push('animations still running' + (last.animatingBy ? ' (' + last.animatingBy + ')' : ''))
2507
- if (last.shellAnimating) blockers.push('animations still running (' + last.shellBlockers + ')')
2508
- if (!maestro && last.layoutDirty) blockers.push('layout still dirty')
2509
- if (!maestro && last.appCommits !== null && report.appCommits !== null && last.appCommits !== report.appCommits) blockers.push('layout commits still landing')
2510
- if (!maestro && last.nodeCount !== null && report.nodeCount !== null && last.nodeCount !== report.nodeCount) blockers.push('node count still changing')
2511
- if (last.pendingFetches > 0) blockers.push(last.pendingFetches + ' image fetches pending')
2512
- if (last.workerBusy) blockers.push('a render worker too busy to report')
2513
- if (last.webViewStarting) blockers.push(last.webViewBlocker || 'webView still starting')
2514
- if (!maestro && last.layout !== report.layout) blockers.push('layout still changing')
2515
- if (maestro && !hierarchyUnchanged(last.nativeHierarchy, report.nativeHierarchy)) blockers.push(last.nativeHierarchy === null ? 'native accessibility hierarchy unavailable' : 'native accessibility hierarchy still changing')
2516
- if (paintStill && !last.screenPixels) blockers.push('screen pixels unavailable')
2517
- else if (paintStill && !screenUnchanged(last.screenPixels, report.screenPixels)) blockers.push('screen pixels still changing')
2518
- if (last.requestInFlight > 0) blockers.push(last.requestInFlight + ' requests in flight')
2519
- else if (!maestro && last.requestTotal !== report.requestTotal) blockers.push('new requests issued')
2520
- if (polls < 2) blockers.push('sim too busy to poll twice')
2521
- // the last read is still: motion ended too near the deadline for the
2522
- // stillness window to hold before it.
2523
- if (!blockers.length) blockers.push('motion ended before stillness was proven')
2524
- return {
2525
- settled: false,
2526
- elapsed: clockNow() - start,
2527
- blockedBy:
2528
- blockers.join(', ') + ' over ' + polls + ' polls (layout changed ' + layoutChangedPolls +
2529
- 'x, layoutDirty ' + dirtyPolls + 'x, animating ' + animatingPolls + 'x, webViewStarting ' + webViewStartingPolls + 'x, screen changed ' + screenChangedPolls + 'x)' +
2530
- (lastLayoutChange ? '; last layout change ' + JSON.stringify(lastLayoutChange) : ''),
2472
+ } else {
2473
+ stillPolls = []
2474
+ visuallyStillSince = 0
2531
2475
  }
2532
- } finally {
2533
- unsubscribe?.()
2476
+ lastIdlePoll = idleSnapshot ? { started: pollStarted, answered: clockNow() } : null
2477
+ lastNativeHierarchy = snapshot.nativeHierarchy
2478
+ lastLayout = snapshot.layout
2479
+ lastNodeRows = snapshot.nodeRows
2480
+ lastRequestTotal = snapshot.requestTotal
2481
+ lastAppCommits = snapshot.appCommits
2482
+ lastNodeCount = snapshot.nodeCount
2483
+ // reply latency belongs inside the poll interval; the stillness window
2484
+ // above remains measured from completed observations.
2485
+ const remainingPollMs = pollMs - (clockNow() - pollStarted)
2486
+ if (remainingPollMs > 0) await clockSleep(remainingPollMs)
2487
+ }
2488
+ if (!report) {
2489
+ return { settled: false, elapsed: clockNow() - start, blockedBy: 'no poll fit the budget' }
2490
+ }
2491
+ const last = report.snapshot
2492
+ const blockers = []
2493
+ if (!maestro && strict && !last.renderStatsAvailable) blockers.push('render stats unavailable')
2494
+ if (!maestro && last.animating) blockers.push('animations still running' + (last.animatingBy ? ' (' + last.animatingBy + ')' : ''))
2495
+ if (last.shellAnimating) blockers.push('animations still running (' + last.shellBlockers + ')')
2496
+ if (!maestro && last.layoutDirty) blockers.push('layout still dirty')
2497
+ if (!maestro && last.appCommits !== null && report.appCommits !== null && last.appCommits !== report.appCommits) blockers.push('layout commits still landing')
2498
+ if (!maestro && last.nodeCount !== null && report.nodeCount !== null && last.nodeCount !== report.nodeCount) blockers.push('node count still changing')
2499
+ if (last.pendingFetches > 0) blockers.push(last.pendingFetches + ' image fetches pending')
2500
+ if (last.workerBusy) blockers.push('a render worker too busy to report')
2501
+ if (last.webViewStarting) blockers.push(last.webViewBlocker || 'webView still starting')
2502
+ if (!maestro && last.layout !== report.layout) blockers.push('layout still changing')
2503
+ if (maestro && !hierarchyUnchanged(last.nativeHierarchy, report.nativeHierarchy)) blockers.push(last.nativeHierarchy === null ? 'native accessibility hierarchy unavailable' : 'native accessibility hierarchy still changing')
2504
+ if (screenStill && last.visibleMotion) blockers.push('visible motion continues (' + last.visibleMotionBy + ')')
2505
+ if (last.requestInFlight > 0) blockers.push(last.requestInFlight + ' requests in flight')
2506
+ else if (!maestro && last.requestTotal !== report.requestTotal) blockers.push('new requests issued')
2507
+ if (polls < 2) blockers.push('sim too busy to poll twice')
2508
+ // the last read is still: motion ended too near the deadline for the
2509
+ // stillness window to hold before it.
2510
+ if (!blockers.length) blockers.push('motion ended before stillness was proven')
2511
+ return {
2512
+ settled: false,
2513
+ elapsed: clockNow() - start,
2514
+ blockedBy:
2515
+ blockers.join(', ') + ' over ' + polls + ' polls (layout changed ' + layoutChangedPolls +
2516
+ 'x, layoutDirty ' + dirtyPolls + 'x, animating ' + animatingPolls + 'x, webViewStarting ' + webViewStartingPolls + 'x, screen changed ' + screenChangedPolls + 'x)' +
2517
+ (lastLayoutChange ? '; last layout change ' + JSON.stringify(lastLayoutChange) : ''),
2534
2518
  }
2535
2519
  })()`
2536
2520
  },