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