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.mjs 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
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -1835,7 +1835,7 @@ async function waitForSootsimIdle({
1835
1835
  pollMs = 50,
1836
1836
  stablePolls = 3,
1837
1837
  strict = false,
1838
- paintStill = false,
1838
+ screenStill = false,
1839
1839
  maestro = false,
1840
1840
  motionOnly = false,
1841
1841
  readyPlayback = false,
@@ -1873,7 +1873,7 @@ async function waitForSootsimIdle({
1873
1873
  let deadline = start + budgetMs
1874
1874
  const pollMs = ${Math.max(1, Math.round(pollMs))}
1875
1875
  const strict = ${strict ? "true" : "false"}
1876
- const paintStill = ${paintStill ? "true" : "false"}
1876
+ const screenStill = ${screenStill ? "true" : "false"}
1877
1877
  const maestro = ${maestro ? "true" : "false"}
1878
1878
  const accessibilityBounds = ${accessibilityBounds.toString()}
1879
1879
  const sameNativeAccessibilityShape = ${sameNativeAccessibilityShape.toString()}
@@ -1883,541 +1883,525 @@ async function waitForSootsimIdle({
1883
1883
  // tight budgets (auto-wait) settle on worker stillness plus root
1884
1884
  // membership, generous ones confirm the geometry too.
1885
1885
  const fullGeometry = ${!maestro && maxMs >= 1e3 ? "true" : "false"}
1886
- const requiredStillMs = paintStill ? 0 : ${Math.max(1, Math.round(stablePolls)) * Math.max(1, Math.round(pollMs))}
1887
- const minimumStablePolls = paintStill ? 1 : ${Math.min(2, Math.max(1, Math.round(stablePolls)))}
1888
- const composite = paintStill ? globalThis.SootSim?.bridges?.liveComposite : null
1889
- if (paintStill && !composite) {
1890
- return { settled: false, elapsed: clockNow() - start, blockedBy: 'screen pixels unavailable' }
1891
- }
1892
- // subscribe to presented frames; authoritative screenshots force a
1893
- // worker render, which changes the very counter we used to inspect.
1894
- const unsubscribe = composite?.subscribe(() => {})
1886
+ const requiredStillMs = screenStill ? 0 : ${Math.max(1, Math.round(stablePolls)) * Math.max(1, Math.round(pollMs))}
1887
+ const minimumStablePolls = screenStill ? 1 : ${Math.min(2, Math.max(1, Math.round(stablePolls)))}
1895
1888
  let transitionEndedAt = null
1896
- let pixelFrameToken = -1
1897
- let screenPixels = null
1898
1889
  // the hierarchy read last taken and the geometry revision it answered.
1899
1890
  // it outlives this wait: a revision still current when a later wait
1900
1891
  // polls names the same geometry, so a step that follows a settled one
1901
1892
  // proves an unchanged screen without walking the tree again.
1902
1893
  const geometry = (globalThis.__peachSettleGeometry ??= { revision: null, hierarchy: null })
1903
- try {
1904
-
1905
- // discover transitions while observing layout. when motion starts,
1906
- // observations from before its completion cannot prove the new screen;
1907
- // those that began after it drained still can. a loaded host runs a
1908
- // push past a tap's budget, so the transition gets its own timeout and
1909
- // the budget restarts once it drains.
1910
- let transitionWait = (async () => {
1911
- try {
1912
- const wfst = globalThis.__sootsimTest?.waitForScreenTransitions
1913
- if (typeof wfst === 'function' && budgetMs > 120) {
1914
- const transition = await wfst({
1915
- timeoutMs: ${Math.max(0, Math.round(transitionTimeoutMs))},
1916
- settleMs: 64,
1917
- startWindowMs: ${Math.max(0, Math.round(transitionStartWindowMs))},
1918
- })
1919
- if (transition?.started !== true) return false
1920
- // a loaded worker replies long after the motion stopped; it
1921
- // reports how long ago, so polls begun since still count. a
1922
- // runtime without the field ends the transition at the reply.
1923
- const rested = typeof transition.restedMs === 'number' ? Math.max(0, transition.restedMs) : 0
1924
- transitionEndedAt = clockNow() - rested
1925
- deadline = Math.max(deadline, transitionEndedAt + budgetMs)
1926
- return true
1927
- }
1928
- } catch {}
1929
- return false
1930
- })()
1894
+ // discover transitions while observing layout. when motion starts,
1895
+ // observations from before its completion cannot prove the new screen;
1896
+ // those that began after it drained still can. a loaded host runs a
1897
+ // push past a tap's budget, so the transition gets its own timeout and
1898
+ // the budget restarts once it drains.
1899
+ let transitionWait = (async () => {
1900
+ try {
1901
+ const wfst = globalThis.__sootsimTest?.waitForScreenTransitions
1902
+ if (typeof wfst === 'function' && budgetMs > 120) {
1903
+ const transition = await wfst({
1904
+ timeoutMs: ${Math.max(0, Math.round(transitionTimeoutMs))},
1905
+ settleMs: 64,
1906
+ startWindowMs: ${Math.max(0, Math.round(transitionStartWindowMs))},
1907
+ })
1908
+ if (transition?.started !== true) return false
1909
+ // a loaded worker replies long after the motion stopped; it
1910
+ // reports how long ago, so polls begun since still count. a
1911
+ // runtime without the field ends the transition at the reply.
1912
+ const rested = typeof transition.restedMs === 'number' ? Math.max(0, transition.restedMs) : 0
1913
+ transitionEndedAt = clockNow() - rested
1914
+ deadline = Math.max(deadline, transitionEndedAt + budgetMs)
1915
+ return true
1916
+ }
1917
+ } catch {}
1918
+ return false
1919
+ })()
1931
1920
 
1932
- // a worker that cannot answer within the remaining budget is busy, not
1933
- // idle: its poll reads as unsettled. bounding each read by the budget
1934
- // keeps a busy worker from holding a poll past the deadline.
1935
- const BUSY = { busy: true }
1936
- const answer = (read) =>
1937
- Promise.race([
1938
- Promise.resolve().then(read),
1939
- new Promise((resolve) =>
1940
- setTimeout(() => resolve(BUSY), Math.max(deadline - clockNow(), 100)),
1941
- ),
1942
- ])
1921
+ // a worker that cannot answer within the remaining budget is busy, not
1922
+ // idle: its poll reads as unsettled. bounding each read by the budget
1923
+ // keeps a busy worker from holding a poll past the deadline.
1924
+ const BUSY = { busy: true }
1925
+ const answer = (read) =>
1926
+ Promise.race([
1927
+ Promise.resolve().then(read),
1928
+ new Promise((resolve) =>
1929
+ setTimeout(() => resolve(BUSY), Math.max(deadline - clockNow(), 100)),
1930
+ ),
1931
+ ])
1943
1932
 
1944
- const readSnapshot = async () => {
1945
- let animating = false
1946
- let animatingBy = ''
1947
- let layoutDirty = false
1948
- let pendingFetches = 0
1949
- let workerBusy = false
1950
- let requestTotal = 0
1951
- let requestInFlight = 0
1952
- let appCommits = null
1953
- let nodeCount = null
1954
- let renderStatsAvailable = false
1955
- let shellAnimating = false
1956
- let shellBlockers = ''
1957
- let webViewStarting = false
1958
- let webViewBlocker = ''
1959
- // the reads are independent, so they run concurrently: a loaded sim
1960
- // answers each one late, and a poll that waits for them in turn
1961
- // costs their sum, which fits too few polls in the budget to settle.
1962
- // the window node count is the exception: it launches after the
1963
- // motion read, so a poll motion already fails skips that walk.
1964
- // strict reads also wait out shell motion. pixel reads inspect finite
1965
- // animations in both realms: a worklet can move the app while the
1966
- // tenant's basic animation flag and last presented pixels read still.
1967
- const accessibilityRead = maestro
1968
- ? answer(() => globalThis.__sootsimTest.captureAccessibilityTree()).catch(() => null)
1969
- : null
1970
- const motionRead = strict || paintStill
1971
- ? answer(() => globalThis.__sootsimTest?.listAnimations?.()).catch(() => null)
1933
+ const readSnapshot = async () => {
1934
+ let animating = false
1935
+ let animatingBy = ''
1936
+ let layoutDirty = false
1937
+ let pendingFetches = 0
1938
+ let workerBusy = false
1939
+ let requestTotal = 0
1940
+ let requestInFlight = 0
1941
+ let appCommits = null
1942
+ let nodeCount = null
1943
+ let renderStatsAvailable = false
1944
+ let shellAnimating = false
1945
+ let shellBlockers = ''
1946
+ let webViewStarting = false
1947
+ let webViewBlocker = ''
1948
+ let visibleMotion = false
1949
+ let visibleMotionBy = ''
1950
+ // the reads are independent, so they run concurrently: a loaded sim
1951
+ // answers each one late, and a poll that waits for them in turn
1952
+ // costs their sum, which fits too few polls in the budget to settle.
1953
+ // the window node count is the exception: it launches after the
1954
+ // motion read, so a poll motion already fails skips that walk.
1955
+ // strict reads also wait out shell motion. pixel reads inspect finite
1956
+ // animations in both realms: a worklet can move the app while the
1957
+ // tenant's basic animation flag and last presented pixels read still.
1958
+ const accessibilityRead = maestro
1959
+ ? answer(() => globalThis.__sootsimTest.captureAccessibilityTree()).catch(() => null)
1960
+ : null
1961
+ const motionRead = strict || screenStill
1962
+ ? answer(() => globalThis.__sootsimTest?.listAnimations?.()).catch(() => null)
1963
+ : null
1964
+ const statsRead = answer(() => globalThis.__sootsimRenderHost?.queryStats?.()).catch(() => null)
1965
+ // image preparation ends in the tenant before the compositor decodes
1966
+ // and realizes its pixels. both owners must finish before settling.
1967
+ // the compositor rejects a stats request it is too busy to answer.
1968
+ const compositorRead = answer(() => globalThis.__sootsimCompositor.getStats({ detail: 'readiness' })).catch(() => BUSY)
1969
+ const countsRead = answer(() => globalThis.__sootsimTest?.getRequestCounts?.()).catch(() => null)
1970
+ // the mounted hierarchy in render-worker mode comes from the test
1971
+ // bridge: globalThis.__sootsimRoot is an empty placeholder there, so a
1972
+ // walk over it hashes every screen to the same empty string while
1973
+ // it moves. listInspectable is the worker-backed read describe
1974
+ // uses; a worker too busy to answer it reads as unsettled. tight
1975
+ // budgets skip this read and settle on the cheaper signals above.
1976
+ // it walks every node, so a poll whose geometry revision matches the
1977
+ // last read, in this wait or an earlier one, reuses that read.
1978
+ const hierarchyRead =
1979
+ fullGeometry && typeof globalThis.__sootsimTest?.listInspectable === 'function'
1980
+ ? answer(() => globalThis.__sootsimTest.getGeometryRevision?.())
1981
+ .catch(() => null)
1982
+ .then((revision) => {
1983
+ if (revision === BUSY) return BUSY
1984
+ if (typeof revision === 'string' && geometry.revision === revision) return geometry.hierarchy
1985
+ return answer(() => globalThis.__sootsimTest.listInspectable({}))
1986
+ .catch(() => null)
1987
+ .then((hierarchy) => {
1988
+ const kept = typeof revision === 'string' && Array.isArray(hierarchy)
1989
+ geometry.revision = kept ? revision : null
1990
+ geometry.hierarchy = kept ? hierarchy : null
1991
+ return hierarchy
1992
+ })
1993
+ })
1972
1994
  : null
1973
- const statsRead = answer(() => globalThis.__sootsimRenderHost?.queryStats?.()).catch(() => null)
1974
- // image preparation ends in the tenant before the compositor decodes
1975
- // and realizes its pixels. both owners must finish before settling.
1976
- // the compositor rejects a stats request it is too busy to answer.
1977
- const compositorRead = answer(() => globalThis.__sootsimCompositor.getStats({ detail: 'readiness' })).catch(() => BUSY)
1978
- const countsRead = answer(() => globalThis.__sootsimTest?.getRequestCounts?.()).catch(() => null)
1979
- // the mounted hierarchy in render-worker mode comes from the test
1980
- // bridge: globalThis.__sootsimRoot is an empty placeholder there, so a
1981
- // walk over it hashes every screen to the same empty string while
1982
- // it moves. listInspectable is the worker-backed read describe
1983
- // uses; a worker too busy to answer it reads as unsettled. tight
1984
- // budgets skip this read and settle on the cheaper signals above.
1985
- // it walks every node, so a poll whose geometry revision matches the
1986
- // last read, in this wait or an earlier one, reuses that read.
1987
- const hierarchyRead =
1988
- fullGeometry && typeof globalThis.__sootsimTest?.listInspectable === 'function'
1989
- ? answer(() => globalThis.__sootsimTest.getGeometryRevision?.())
1990
- .catch(() => null)
1991
- .then((revision) => {
1992
- if (revision === BUSY) return BUSY
1993
- if (typeof revision === 'string' && geometry.revision === revision) return geometry.hierarchy
1994
- return answer(() => globalThis.__sootsimTest.listInspectable({}))
1995
- .catch(() => null)
1996
- .then((hierarchy) => {
1997
- const kept = typeof revision === 'string' && Array.isArray(hierarchy)
1998
- geometry.revision = kept ? revision : null
1999
- geometry.hierarchy = kept ? hierarchy : null
2000
- return hierarchy
2001
- })
2002
- })
2003
- : null
2004
- if (motionRead) {
2005
- const motion = await motionRead
2006
- if (motion === BUSY) workerBusy = true
2007
- else if (Array.isArray(motion)) {
2008
- const blocking = motion.filter((anim) =>
2009
- (anim.realm === 'shell' || paintStill) &&
2010
- anim.priority !== 'low' && anim.visible !== false &&
2011
- (!paintStill || anim.loop !== true))
2012
- shellAnimating = blocking.length > 0
2013
- // name what holds the settle so a timeout points at its owner.
2014
- shellBlockers = blocking
2015
- .slice(0, 4)
2016
- .map((anim) => anim.source + '/' + anim.kind + '#' + anim.id + ' at ' + anim.current + (anim.loop ? ' loop' : ''))
2017
- .join(', ')
2018
- }
1995
+ if (motionRead) {
1996
+ const motion = await motionRead
1997
+ if (motion === BUSY) workerBusy = true
1998
+ else if (Array.isArray(motion)) {
1999
+ const blocking = motion.filter((anim) =>
2000
+ (anim.realm === 'shell' || screenStill) &&
2001
+ anim.priority !== 'low' && anim.visible !== false &&
2002
+ (!screenStill || anim.loop !== true))
2003
+ shellAnimating = blocking.length > 0
2004
+ // what blocking leaves out still moves the screen while visible;
2005
+ // it ends a screen-still wait only at maestro's hierarchy check
2006
+ // or the deadline, as a screen that never holds still does on ios.
2007
+ const moving = screenStill
2008
+ ? motion.filter((anim) => anim.visible !== false && !blocking.includes(anim))
2009
+ : []
2010
+ visibleMotion = moving.length > 0
2011
+ visibleMotionBy = moving
2012
+ .slice(0, 4)
2013
+ .map((anim) => anim.source + '/' + anim.kind + '#' + anim.id + (anim.loop ? ' loop' : '') + (anim.priority === 'low' ? ' low' : ''))
2014
+ .join(', ')
2015
+ // name what holds the settle so a timeout points at its owner.
2016
+ shellBlockers = blocking
2017
+ .slice(0, 4)
2018
+ .map((anim) => anim.source + '/' + anim.kind + '#' + anim.id + ' at ' + anim.current + (anim.loop ? ' loop' : ''))
2019
+ .join(', ')
2019
2020
  }
2020
- const stats = await statsRead
2021
- if (stats === BUSY) {
2022
- workerBusy = true
2023
- } else if (!stats && readyPlayback) {
2024
- workerBusy = true
2025
- } else if (stats) {
2026
- renderStatsAvailable = true
2027
- const missingFields = ['hasActiveBlockingNativeAnimations', 'hasPendingBlockingAnimationFrames']
2028
- .filter((field) => typeof stats[field] !== 'boolean')
2029
- if (readyPlayback && typeof stats.hasPendingReadinessAnimationFrames !== 'boolean') missingFields.push('hasPendingReadinessAnimationFrames')
2030
- if ((strict || readyPlayback) && missingFields.length > 0) {
2031
- return {
2032
- runtimeUnsupported: {
2033
- error: 'runtime_readiness_unsupported',
2034
- runtimeVersion: globalThis.__sootsimRuntimeVersion || 'unknown',
2035
- missingFields,
2036
- },
2037
- }
2021
+ }
2022
+ const stats = await statsRead
2023
+ if (stats === BUSY) {
2024
+ workerBusy = true
2025
+ } else if (!stats && readyPlayback) {
2026
+ workerBusy = true
2027
+ } else if (stats) {
2028
+ renderStatsAvailable = true
2029
+ const missingFields = ['hasActiveBlockingNativeAnimations', 'hasPendingBlockingAnimationFrames']
2030
+ .filter((field) => typeof stats[field] !== 'boolean')
2031
+ if (readyPlayback && typeof stats.hasPendingReadinessAnimationFrames !== 'boolean') missingFields.push('hasPendingReadinessAnimationFrames')
2032
+ if ((strict || readyPlayback) && missingFields.length > 0) {
2033
+ return {
2034
+ runtimeUnsupported: {
2035
+ error: 'runtime_readiness_unsupported',
2036
+ runtimeVersion: globalThis.__sootsimRuntimeVersion || 'unknown',
2037
+ missingFields,
2038
+ },
2038
2039
  }
2039
- // positive checks only: an older runtime without the blocking
2040
- // fields reads as still, and strict rejects that runtime above
2041
- // instead of ever settling on unknown motion.
2042
- animating =
2043
- stats.hasActiveAnims === true ||
2044
- stats.hasActiveBlockingNativeAnimations === true ||
2045
- (!paintStill && (readyPlayback ? stats.hasPendingReadinessAnimationFrames : stats.hasPendingBlockingAnimationFrames) === true)
2046
- if (animating)
2047
- animatingBy = [
2048
- stats.hasActiveAnims === true && 'activeAnims',
2049
- stats.hasActiveBlockingNativeAnimations === true && 'blockingNative',
2050
- !paintStill && stats.hasPendingBlockingAnimationFrames === true && 'pendingFrames',
2051
- !paintStill && stats.hasPendingReadinessAnimationFrames === true && 'pendingReadinessFrames',
2052
- ].filter(Boolean).join('+')
2053
- // the runtime reports only layout work that can reach the window:
2054
- // a covered screen or inactive tab committing does not hold it.
2055
- layoutDirty =
2056
- stats.layoutDirty === true && stats.renderRequested === true
2057
- // a freshly-pushed screen showing a skeleton is layout-stable
2058
- // but not actually settled \u2014 its data/images are still in
2059
- // flight. treat bounded image-loader fetches as not-idle so
2060
- // settle waits for real content, capped by the budget.
2061
- const pf = stats.memory && stats.memory.imageLoader
2062
- ? stats.memory.imageLoader.pendingFetches
2063
- : 0
2064
- pendingFetches = typeof pf === 'number' ? pf : 0
2065
- // tenant layout commits: a screen that keeps committing is still
2066
- // mounting or remounting, even with no animation flag raised.
2067
- appCommits = typeof stats.appCommitCount === 'number' ? stats.appCommitCount : null
2068
2040
  }
2069
- // mounted-root membership: the count of nodes that can reach the
2070
- // window moves while the screen mounts, unmounts or recycles, in
2071
- // either render mode. a screen a pushed one covers or an inactive
2072
- // tab stays mounted out of the window, so what it mounts is not
2073
- // screen motion. the worker rebuilds the membership set while the
2074
- // wire moves on every animated frame, so a poll the motion read
2075
- // already fails skips it: the motion flags alone prove this poll
2076
- // unsettled, and the carried count hands the first still poll the
2077
- // pre-motion baseline to compare against.
2078
- const motionStill = !workerBusy && !animating && !layoutDirty && !shellAnimating
2079
- const nodeCountRead = motionStill
2080
- ? answer(() => globalThis.__sootsimTest?.getWindowNodeCount?.()).catch(() => null)
2081
- : null
2082
- const compositor = await compositorRead
2083
- if (compositor === BUSY) {
2084
- workerBusy = true
2085
- } else {
2086
- pendingFetches += compositor.images.pendingFetches
2087
- pendingFetches += compositor.imageRealization.pending
2088
- if (compositor.webViewCaptureSettled === false) {
2089
- webViewStarting = true
2090
- webViewBlocker = 'compositor webView capture not settled'
2091
- }
2041
+ // positive checks only: an older runtime without the blocking
2042
+ // fields reads as still, and strict rejects that runtime above
2043
+ // instead of ever settling on unknown motion.
2044
+ animating =
2045
+ stats.hasActiveAnims === true ||
2046
+ stats.hasActiveBlockingNativeAnimations === true ||
2047
+ (!screenStill && (readyPlayback ? stats.hasPendingReadinessAnimationFrames : stats.hasPendingBlockingAnimationFrames) === true)
2048
+ if (animating)
2049
+ animatingBy = [
2050
+ stats.hasActiveAnims === true && 'activeAnims',
2051
+ stats.hasActiveBlockingNativeAnimations === true && 'blockingNative',
2052
+ !screenStill && stats.hasPendingBlockingAnimationFrames === true && 'pendingFrames',
2053
+ !screenStill && stats.hasPendingReadinessAnimationFrames === true && 'pendingReadinessFrames',
2054
+ ].filter(Boolean).join('+')
2055
+ // the runtime reports only layout work that can reach the window:
2056
+ // a covered screen or inactive tab committing does not hold it.
2057
+ layoutDirty =
2058
+ stats.layoutDirty === true && stats.renderRequested === true
2059
+ // a freshly-pushed screen showing a skeleton is layout-stable
2060
+ // but not actually settled \u2014 its data/images are still in
2061
+ // flight. treat bounded image-loader fetches as not-idle so
2062
+ // settle waits for real content, capped by the budget.
2063
+ const pf = stats.memory && stats.memory.imageLoader
2064
+ ? stats.memory.imageLoader.pendingFetches
2065
+ : 0
2066
+ pendingFetches = typeof pf === 'number' ? pf : 0
2067
+ // tenant layout commits: a screen that keeps committing is still
2068
+ // mounting or remounting, even with no animation flag raised.
2069
+ appCommits = typeof stats.appCommitCount === 'number' ? stats.appCommitCount : null
2070
+ }
2071
+ // mounted-root membership: the count of nodes that can reach the
2072
+ // window moves while the screen mounts, unmounts or recycles, in
2073
+ // either render mode. a screen a pushed one covers or an inactive
2074
+ // tab stays mounted out of the window, so what it mounts is not
2075
+ // screen motion. the worker rebuilds the membership set while the
2076
+ // wire moves on every animated frame, so a poll the motion read
2077
+ // already fails skips it: the motion flags alone prove this poll
2078
+ // unsettled, and the carried count hands the first still poll the
2079
+ // pre-motion baseline to compare against.
2080
+ const motionStill = !workerBusy && !animating && !layoutDirty && !shellAnimating
2081
+ const nodeCountRead = motionStill
2082
+ ? answer(() => globalThis.__sootsimTest?.getWindowNodeCount?.()).catch(() => null)
2083
+ : null
2084
+ const compositor = await compositorRead
2085
+ if (compositor === BUSY) {
2086
+ workerBusy = true
2087
+ } else {
2088
+ pendingFetches += compositor.images.pendingFetches
2089
+ pendingFetches += compositor.imageRealization.pending
2090
+ if (compositor.webViewCaptureSettled === false) {
2091
+ webViewStarting = true
2092
+ webViewBlocker = 'compositor webView capture not settled'
2092
2093
  }
2093
- const counts = await countsRead
2094
- if (counts === BUSY) workerBusy = true
2095
- // <Image> loads are left to the image loader, which counts only those
2096
- // that can reach the window. a runtime older than the CLI reports none.
2097
- const imageLoads = counts?.imageLoads ?? { total: 0, inFlight: 0 }
2098
- requestTotal = typeof counts?.total === 'number' ? counts.total - imageLoads.total : 0
2099
- requestInFlight = typeof counts?.inFlight === 'number' ? counts.inFlight - imageLoads.inFlight : 0
2100
- // a skipped read carries the last count: mounts during motion still
2101
- // break the first still poll after it, instead of a blank baseline
2102
- // reading them as stable.
2103
- const total = nodeCountRead ? await nodeCountRead : lastNodeCount
2104
- if (total === BUSY) workerBusy = true
2105
- nodeCount = typeof total === 'number' ? total : null
2106
- const accessibility = accessibilityRead ? await accessibilityRead : null
2107
- const nativeHierarchy = Array.isArray(accessibility) && accessibility.length > 0
2108
- ? accessibility
2109
- : null
2110
- if (accessibility === BUSY) workerBusy = true
2111
- let hierarchy = hierarchyRead ? await hierarchyRead : null
2112
- if (hierarchy === BUSY) {
2113
- workerBusy = true
2114
- hierarchy = null
2115
- } else if (!Array.isArray(hierarchy)) {
2116
- hierarchy = null
2094
+ }
2095
+ const counts = await countsRead
2096
+ if (counts === BUSY) workerBusy = true
2097
+ // <Image> loads are left to the image loader, which counts only those
2098
+ // that can reach the window. a runtime older than the CLI reports none.
2099
+ const imageLoads = counts?.imageLoads ?? { total: 0, inFlight: 0 }
2100
+ requestTotal = typeof counts?.total === 'number' ? counts.total - imageLoads.total : 0
2101
+ requestInFlight = typeof counts?.inFlight === 'number' ? counts.inFlight - imageLoads.inFlight : 0
2102
+ // a skipped read carries the last count: mounts during motion still
2103
+ // break the first still poll after it, instead of a blank baseline
2104
+ // reading them as stable.
2105
+ const total = nodeCountRead ? await nodeCountRead : lastNodeCount
2106
+ if (total === BUSY) workerBusy = true
2107
+ nodeCount = typeof total === 'number' ? total : null
2108
+ const accessibility = accessibilityRead ? await accessibilityRead : null
2109
+ const nativeHierarchy = Array.isArray(accessibility) && accessibility.length > 0
2110
+ ? accessibility
2111
+ : null
2112
+ if (accessibility === BUSY) workerBusy = true
2113
+ let hierarchy = hierarchyRead ? await hierarchyRead : null
2114
+ if (hierarchy === BUSY) {
2115
+ workerBusy = true
2116
+ hierarchy = null
2117
+ } else if (!Array.isArray(hierarchy)) {
2118
+ hierarchy = null
2119
+ }
2120
+ const nodes = []
2121
+ // identity beside each geometry entry, from the rows already read,
2122
+ // so a changed layout can name the nodes that moved.
2123
+ const nodeRows = []
2124
+ 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
2125
+ const noteLoading = (state, text) => {
2126
+ if (state?.busy === true) {
2127
+ webViewStarting = true
2128
+ if (!webViewBlocker) webViewBlocker = 'accessibility busy state active'
2117
2129
  }
2118
- const nodes = []
2119
- // identity beside each geometry entry, from the rows already read,
2120
- // so a changed layout can name the nodes that moved.
2121
- const nodeRows = []
2122
- 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
2123
- const noteLoading = (state, text) => {
2124
- if (state?.busy === true) {
2125
- webViewStarting = true
2126
- if (!webViewBlocker) webViewBlocker = 'accessibility busy state active'
2127
- }
2128
- if (typeof text === 'string' && LOADING_TEXT_REGEX.test(text.trim())) {
2129
- webViewStarting = true
2130
- if (!webViewBlocker) webViewBlocker = 'webView startup in progress ("' + text.trim() + '")'
2130
+ if (typeof text === 'string' && LOADING_TEXT_REGEX.test(text.trim())) {
2131
+ webViewStarting = true
2132
+ if (!webViewBlocker) webViewBlocker = 'webView startup in progress ("' + text.trim() + '")'
2133
+ }
2134
+ }
2135
+ if (hierarchy) {
2136
+ for (const n of hierarchy) {
2137
+ const layout = n && n.layout
2138
+ if (layout && layout.width > 0) {
2139
+ // painted bounds catch a scroll fling. background playback
2140
+ // keeps a view's painted bounds moving forever, so it and its
2141
+ // subtree count by their own layout; the rest of the screen
2142
+ // still catches the fling.
2143
+ const abs = n.backgroundPlayback ? layout : n.absolute || n.absolutePosition || layout
2144
+ const geometry = Math.round(abs.x) + ',' + Math.round(abs.y) + ',' + Math.round(layout.width)
2145
+ nodes.push(geometry)
2146
+ nodeRows.push([String(n.nodeId ?? nodes.length - 1), (n.type || '?') + (n.testId ? '#' + n.testId : ''), geometry])
2131
2147
  }
2148
+ noteLoading(
2149
+ n.accessibilityState,
2150
+ typeof n.text === 'string' ? n.text : '',
2151
+ )
2132
2152
  }
2133
- if (hierarchy) {
2134
- for (const n of hierarchy) {
2135
- const layout = n && n.layout
2136
- if (layout && layout.width > 0) {
2137
- // painted bounds catch a scroll fling. background playback
2138
- // keeps a view's painted bounds moving forever, so it and its
2139
- // subtree count by their own layout; the rest of the screen
2140
- // still catches the fling.
2141
- const abs = n.backgroundPlayback ? layout : n.absolute || n.absolutePosition || layout
2142
- const geometry = Math.round(abs.x) + ',' + Math.round(abs.y) + ',' + Math.round(layout.width)
2153
+ } else {
2154
+ const root = globalThis.__sootsimRoot
2155
+ if (root) {
2156
+ const walk = (n) => {
2157
+ if (n.layout && n.layout.width > 0) {
2158
+ const geometry = Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width)
2143
2159
  nodes.push(geometry)
2144
- nodeRows.push([String(n.nodeId ?? nodes.length - 1), (n.type || '?') + (n.testId ? '#' + n.testId : ''), geometry])
2160
+ nodeRows.push([String(n.id ?? nodes.length - 1), (n.type || '?') + (n.props?.testID ? '#' + n.props.testID : ''), geometry])
2145
2161
  }
2146
2162
  noteLoading(
2147
- n.accessibilityState,
2148
- typeof n.text === 'string' ? n.text : '',
2163
+ n.props?.accessibilityState,
2164
+ n.textContent || (typeof n.props?.children === 'string' ? n.props.children : ''),
2149
2165
  )
2166
+ for (const c of n.children || []) walk(c)
2150
2167
  }
2151
- } else {
2152
- const root = globalThis.__sootsimRoot
2153
- if (root) {
2154
- const walk = (n) => {
2155
- if (n.layout && n.layout.width > 0) {
2156
- const geometry = Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width)
2157
- nodes.push(geometry)
2158
- nodeRows.push([String(n.id ?? nodes.length - 1), (n.type || '?') + (n.props?.testID ? '#' + n.props.testID : ''), geometry])
2159
- }
2160
- noteLoading(
2161
- n.props?.accessibilityState,
2162
- n.textContent || (typeof n.props?.children === 'string' ? n.props.children : ''),
2163
- )
2164
- for (const c of n.children || []) walk(c)
2165
- }
2166
- walk(root)
2167
- }
2168
+ walk(root)
2168
2169
  }
2169
- if (!webViewStarting && typeof document !== 'undefined') {
2170
- const busyEl = [...document.querySelectorAll('[aria-busy="true"]')].find((element) => {
2171
- const bounds = element.getBoundingClientRect()
2172
- return element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) &&
2173
- bounds.width > 0 && bounds.height > 0 && bounds.right > 0 && bounds.bottom > 0 &&
2174
- bounds.left < globalThis.innerWidth && bounds.top < globalThis.innerHeight
2170
+ }
2171
+ if (!webViewStarting && typeof document !== 'undefined') {
2172
+ const busyEl = [...document.querySelectorAll('[aria-busy="true"]')].find((element) => {
2173
+ const bounds = element.getBoundingClientRect()
2174
+ return element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) &&
2175
+ bounds.width > 0 && bounds.height > 0 && bounds.right > 0 && bounds.bottom > 0 &&
2176
+ bounds.left < globalThis.innerWidth && bounds.top < globalThis.innerHeight
2177
+ })
2178
+ if (busyEl) {
2179
+ webViewStarting = true
2180
+ webViewBlocker = 'accessibility busy element displayed'
2181
+ } else {
2182
+ // a loading document with no area (an app's hidden worker or
2183
+ // executor frame) paints nothing, and a screenshot on device
2184
+ // does not wait for it.
2185
+ const unreadyWebView = [...document.querySelectorAll(
2186
+ '[data-sootsim-webview-loading="true"], [data-sootsim-webview-mode="placeholder"]'
2187
+ )].find((view) => {
2188
+ const frame = view.querySelector('iframe')
2189
+ return !frame || frame.clientWidth > 0 || frame.clientHeight > 0
2175
2190
  })
2176
- if (busyEl) {
2191
+ if (unreadyWebView) {
2177
2192
  webViewStarting = true
2178
- webViewBlocker = 'accessibility busy element displayed'
2179
- } else {
2180
- // a loading document with no area (an app's hidden worker or
2181
- // executor frame) paints nothing, and a screenshot on device
2182
- // does not wait for it.
2183
- const unreadyWebView = [...document.querySelectorAll(
2184
- '[data-sootsim-webview-loading="true"], [data-sootsim-webview-mode="placeholder"]'
2185
- )].find((view) => {
2186
- const frame = view.querySelector('iframe')
2187
- return !frame || frame.clientWidth > 0 || frame.clientHeight > 0
2188
- })
2189
- if (unreadyWebView) {
2190
- webViewStarting = true
2191
- webViewBlocker = 'webView document still loading'
2192
- }
2193
+ webViewBlocker = 'webView document still loading'
2193
2194
  }
2194
2195
  }
2195
- if (paintStill) {
2196
- const canvas = composite.getCanvas()
2197
- const token = composite.getFrameToken()
2198
- if (!canvas || canvas.width <= 1 || canvas.height <= 1) {
2199
- screenPixels = null
2200
- } else if (token !== pixelFrameToken || canvas.width !== screenPixels?.width || canvas.height !== screenPixels?.height) {
2201
- const context = canvas.getContext('2d')
2202
- const image = context?.getImageData(0, 0, canvas.width, canvas.height)
2203
- screenPixels = image ? { width: image.width, height: image.height, data: new Uint32Array(image.data.buffer) } : null
2204
- pixelFrameToken = token
2205
- }
2206
- }
2207
- return { layout: nodes.join(';'), nodeRows, nativeHierarchy, screenPixels, animating, animatingBy, shellAnimating, shellBlockers, layoutDirty, pendingFetches, workerBusy, webViewStarting, webViewBlocker, renderStatsAvailable, requestTotal, requestInFlight, appCommits, nodeCount }
2208
2196
  }
2197
+ return { layout: nodes.join(';'), nodeRows, nativeHierarchy, visibleMotion, visibleMotionBy, animating, animatingBy, shellAnimating, shellBlockers, layoutDirty, pendingFetches, workerBusy, webViewStarting, webViewBlocker, renderStatsAvailable, requestTotal, requestInFlight, appCommits, nodeCount }
2198
+ }
2209
2199
 
2210
- // how long generic background network is allowed to keep us waiting AFTER
2211
- // the screen is otherwise visually settled. apps with continuous traffic
2212
- // (polling, realtime sockets, a tap that fires 20-50 fetches) never reach
2213
- // requestInFlight===0 / a stable requestTotal, so requiring full network
2214
- // quiet burns the ENTIRE budget on every command \u2014 the leading idle that
2215
- // failed PR-preview recordings for network-heavy apps (3pc fight-pulse).
2216
- // layout-stability + the image-loader already prove visible content
2217
- // loaded (a data load changes layout; an image load shows in the loader),
2218
- // so the generic request counters are a courtesy, not a gate: honor them
2219
- // only within this grace once the screen is visually still.
2220
- const networkQuietGraceMs = 1200
2221
- let lastNativeHierarchy = null
2222
- let lastLayout = ''
2223
- let lastNodeRows = []
2224
- // what moved between the last two differing polls, bounded; names the
2225
- // nodes behind "layout changed" without keeping any poll history.
2226
- let lastLayoutChange = null
2227
- const describeLayoutChange = (before, after) => {
2228
- const previous = new Map(before.map(([key, label, geometry]) => [key, [label, geometry]]))
2229
- const moved = []
2230
- const added = []
2231
- const short = (label, key) => String(label).slice(0, 48) + ' [' + String(key).slice(0, 24) + ']'
2232
- for (const [key, label, geometry] of after) {
2233
- const was = previous.get(key)
2234
- previous.delete(key)
2235
- if (!was) added.push(short(label, key) + ' ' + geometry)
2236
- else if (was[1] !== geometry) moved.push(short(label, key) + ' ' + was[1] + '->' + geometry)
2237
- }
2238
- const removed = [...previous].map(([key, [label, geometry]]) => short(label, key) + ' ' + geometry)
2239
- return {
2240
- moved: moved.length, added: added.length, removed: removed.length,
2241
- movedSample: moved.slice(0, 3), addedSample: added.slice(0, 3), removedSample: removed.slice(0, 3),
2242
- }
2200
+ // how long generic background network is allowed to keep us waiting AFTER
2201
+ // the screen is otherwise visually settled. apps with continuous traffic
2202
+ // (polling, realtime sockets, a tap that fires 20-50 fetches) never reach
2203
+ // requestInFlight===0 / a stable requestTotal, so requiring full network
2204
+ // quiet burns the ENTIRE budget on every command \u2014 the leading idle that
2205
+ // failed PR-preview recordings for network-heavy apps (3pc fight-pulse).
2206
+ // layout-stability + the image-loader already prove visible content
2207
+ // loaded (a data load changes layout; an image load shows in the loader),
2208
+ // so the generic request counters are a courtesy, not a gate: honor them
2209
+ // only within this grace once the screen is visually still.
2210
+ const networkQuietGraceMs = 1200
2211
+ let lastNativeHierarchy = null
2212
+ let lastLayout = ''
2213
+ let lastNodeRows = []
2214
+ // what moved between the last two differing polls, bounded; names the
2215
+ // nodes behind "layout changed" without keeping any poll history.
2216
+ let lastLayoutChange = null
2217
+ const describeLayoutChange = (before, after) => {
2218
+ const previous = new Map(before.map(([key, label, geometry]) => [key, [label, geometry]]))
2219
+ const moved = []
2220
+ const added = []
2221
+ const short = (label, key) => String(label).slice(0, 48) + ' [' + String(key).slice(0, 24) + ']'
2222
+ for (const [key, label, geometry] of after) {
2223
+ const was = previous.get(key)
2224
+ previous.delete(key)
2225
+ if (!was) added.push(short(label, key) + ' ' + geometry)
2226
+ else if (was[1] !== geometry) moved.push(short(label, key) + ' ' + was[1] + '->' + geometry)
2243
2227
  }
2244
- let lastScreenPixels = null
2245
- let screenChangedPolls = 0
2246
- let lastRequestTotal = -1
2247
- let lastAppCommits = null
2248
- let lastNodeCount = null
2249
- // the last completed poll and the values it was compared against.
2250
- let report = null
2251
- // the still polls of the current run, when each began and answered
2252
- let stillPolls = []
2253
- let lastIdlePoll = null
2254
- let visuallyStillSince = 0
2255
- // counts across the whole budget: a flag that is true on every poll is a
2256
- // different bug from one that is true intermittently, and the two need
2257
- // opposite fixes (engine vs budget).
2258
- let polls = 0
2259
- let dirtyPolls = 0
2260
- let animatingPolls = 0
2261
- let layoutChangedPolls = 0
2262
- let webViewStartingPolls = 0
2263
- const screenUnchanged = (pixels, previous) => {
2264
- if (!pixels || !previous || pixels.width !== previous.width || pixels.height !== previous.height) return false
2265
- if (pixels === previous) return true
2266
- for (let i = 0; i < pixels.data.length; i++) {
2267
- if (pixels.data[i] !== previous.data[i]) return false
2268
- }
2269
- return true
2228
+ const removed = [...previous].map(([key, [label, geometry]]) => short(label, key) + ' ' + geometry)
2229
+ return {
2230
+ moved: moved.length, added: added.length, removed: removed.length,
2231
+ movedSample: moved.slice(0, 3), addedSample: added.slice(0, 3), removedSample: removed.slice(0, 3),
2270
2232
  }
2271
- const hierarchyUnchanged = (current, previous) =>
2272
- current !== null && previous !== null && current.length === previous.length &&
2273
- current.every((node, index) => sameNativeAccessibilityShape(node, previous[index], accessibilityBounds))
2274
- while (true) {
2275
- if (clockNow() >= deadline) {
2276
- if (!transitionWait) break
2277
- await transitionWait
2278
- transitionWait = null
2279
- // nothing polled while parked on the transition, and a loaded
2280
- // worker's late reply would spend the restarted budget unobserved.
2281
- if (transitionEndedAt !== null) deadline = Math.max(deadline, clockNow() + budgetMs)
2282
- if (clockNow() >= deadline) break
2283
- }
2284
- const pollStarted = clockNow()
2285
- const snapshot = await readSnapshot()
2286
- if (snapshot.runtimeUnsupported) return snapshot.runtimeUnsupported
2287
- // a read the deadline cut short observed nothing: the last full poll
2288
- // names what held the settle, not a worker that ran out of budget.
2289
- // the loop head drains a transition still in flight before it ends.
2290
- if (snapshot.workerBusy && clockNow() >= deadline && report) continue
2291
- polls++
2292
- report = { snapshot, nativeHierarchy: lastNativeHierarchy, layout: lastLayout, screenPixels: lastScreenPixels, requestTotal: lastRequestTotal, appCommits: lastAppCommits, nodeCount: lastNodeCount }
2293
- if (snapshot.layoutDirty) dirtyPolls++
2294
- if (snapshot.animating || snapshot.shellAnimating) animatingPolls++
2295
- if (snapshot.webViewStarting) webViewStartingPolls++
2296
- if (polls > 1 && snapshot.layout !== lastLayout) {
2297
- layoutChangedPolls++
2298
- lastLayoutChange = describeLayoutChange(lastNodeRows, snapshot.nodeRows)
2299
- }
2300
- const screenChanged = paintStill && !screenUnchanged(snapshot.screenPixels, lastScreenPixels)
2301
- if (polls > 1 && screenChanged) screenChangedPolls++
2302
- const strictOk =
2303
- !strict ||
2304
- (snapshot.renderStatsAvailable &&
2305
- !snapshot.animating &&
2306
- !snapshot.shellAnimating &&
2307
- !snapshot.layoutDirty)
2308
- // visually settled: no worker motion or layout work, no new layout
2309
- // commits, a stable mounted node count, no image content loading
2310
- // (unless motion alone is asked), no webview startup in progress,
2311
- // layout unchanged since the last poll. both modes wait out finite
2312
- // worker motion now; strict additionally implies the flags through
2313
- // strictOk and adds shell motion plus the blocking-stats floor. a
2314
- // null count or commit reading means the runtime does not report
2315
- // it, which reads as stable the way a missing stats block does.
2316
- // equal presented pixels can precede pending worker motion or layout.
2317
- // after that work drains, iOS's 3 s pixel phase may accept two equal
2318
- // native TreeNodes while paint-only playback continues. overlap
2319
- // hierarchy reads so neither the gesture nor screenshot deadline grows.
2320
- const maestroStill = snapshot.screenPixels !== null && !snapshot.workerBusy && snapshot.pendingFetches === 0 && snapshot.requestInFlight === 0 && !snapshot.webViewStarting &&
2321
- !snapshot.animating && !snapshot.shellAnimating && !snapshot.layoutDirty && (
2322
- !screenChanged || (clockNow() - start >= 3000 &&
2323
- hierarchyUnchanged(snapshot.nativeHierarchy, lastNativeHierarchy))
2324
- )
2325
- const idleSnapshot =
2326
- strictOk &&
2233
+ }
2234
+ let screenChangedPolls = 0
2235
+ let lastRequestTotal = -1
2236
+ let lastAppCommits = null
2237
+ let lastNodeCount = null
2238
+ // the last completed poll and the values it was compared against.
2239
+ let report = null
2240
+ // the still polls of the current run, when each began and answered
2241
+ let stillPolls = []
2242
+ let lastIdlePoll = null
2243
+ let visuallyStillSince = 0
2244
+ // counts across the whole budget: a flag that is true on every poll is a
2245
+ // different bug from one that is true intermittently, and the two need
2246
+ // opposite fixes (engine vs budget).
2247
+ let polls = 0
2248
+ let dirtyPolls = 0
2249
+ let animatingPolls = 0
2250
+ let layoutChangedPolls = 0
2251
+ let webViewStartingPolls = 0
2252
+ const hierarchyUnchanged = (current, previous) =>
2253
+ current !== null && previous !== null && current.length === previous.length &&
2254
+ current.every((node, index) => sameNativeAccessibilityShape(node, previous[index], accessibilityBounds))
2255
+ while (true) {
2256
+ if (clockNow() >= deadline) {
2257
+ if (!transitionWait) break
2258
+ await transitionWait
2259
+ transitionWait = null
2260
+ // nothing polled while parked on the transition, and a loaded
2261
+ // worker's late reply would spend the restarted budget unobserved.
2262
+ if (transitionEndedAt !== null) deadline = Math.max(deadline, clockNow() + budgetMs)
2263
+ if (clockNow() >= deadline) break
2264
+ }
2265
+ const pollStarted = clockNow()
2266
+ const snapshot = await readSnapshot()
2267
+ if (snapshot.runtimeUnsupported) return snapshot.runtimeUnsupported
2268
+ // a read the deadline cut short observed nothing: the last full poll
2269
+ // names what held the settle, not a worker that ran out of budget.
2270
+ // the loop head drains a transition still in flight before it ends.
2271
+ if (snapshot.workerBusy && clockNow() >= deadline && report) continue
2272
+ polls++
2273
+ report = { snapshot, nativeHierarchy: lastNativeHierarchy, layout: lastLayout, requestTotal: lastRequestTotal, appCommits: lastAppCommits, nodeCount: lastNodeCount }
2274
+ if (snapshot.layoutDirty) dirtyPolls++
2275
+ if (snapshot.animating || snapshot.shellAnimating) animatingPolls++
2276
+ if (snapshot.webViewStarting) webViewStartingPolls++
2277
+ if (polls > 1 && snapshot.layout !== lastLayout) {
2278
+ layoutChangedPolls++
2279
+ lastLayoutChange = describeLayoutChange(lastNodeRows, snapshot.nodeRows)
2280
+ }
2281
+ // the first poll has nothing to compare, so it cannot prove a still screen
2282
+ const screenChanged = screenStill && (
2283
+ polls === 1 ||
2284
+ snapshot.visibleMotion ||
2285
+ (snapshot.appCommits !== null && lastAppCommits !== null && snapshot.appCommits !== lastAppCommits) ||
2286
+ (snapshot.nodeCount !== null && lastNodeCount !== null && snapshot.nodeCount !== lastNodeCount) ||
2287
+ snapshot.layout !== lastLayout ||
2288
+ (maestro && !hierarchyUnchanged(snapshot.nativeHierarchy, lastNativeHierarchy))
2289
+ )
2290
+ if (polls > 1 && screenChanged) screenChangedPolls++
2291
+ const strictOk =
2292
+ !strict ||
2293
+ (snapshot.renderStatsAvailable &&
2327
2294
  !snapshot.animating &&
2328
2295
  !snapshot.shellAnimating &&
2329
- !snapshot.layoutDirty &&
2330
- snapshot.pendingFetches === 0 &&
2331
- !snapshot.workerBusy &&
2332
- !snapshot.webViewStarting
2333
- const visuallyStill = maestro ? maestroStill :
2334
- idleSnapshot &&
2335
- (snapshot.appCommits === null || lastAppCommits === null || snapshot.appCommits === lastAppCommits) &&
2336
- (snapshot.nodeCount === null || lastNodeCount === null || snapshot.nodeCount === lastNodeCount) &&
2337
- !screenChanged &&
2338
- snapshot.layout === lastLayout
2339
- // generic network quiet: nothing in flight and no new requests issued.
2340
- const networkQuiet =
2341
- snapshot.requestInFlight === 0 && snapshot.requestTotal === lastRequestTotal
2342
- if (visuallyStill) {
2343
- if (visuallyStillSince === 0) visuallyStillSince = clockNow()
2344
- // two equal idle observations prove the interval between them.
2345
- // discarding the first requires a third worker round trip, which
2346
- // can exhaust the budget after a late image on a loaded host.
2347
- if (!maestro && !paintStill && stillPolls.length === 0 && lastIdlePoll) {
2348
- stillPolls.push(lastIdlePoll)
2349
- }
2350
- stillPolls.push({ started: pollStarted, answered: clockNow() })
2351
- // still long enough, counting only polls that began after a started
2352
- // transition drained.
2353
- const stillProven = () => {
2354
- const proving = stillPolls.filter((poll) => transitionEndedAt === null || poll.started >= transitionEndedAt)
2355
- return proving.length >= minimumStablePolls && clockNow() - proving[0].answered >= requiredStillMs
2356
- }
2357
- // settle once the screen has held still long enough AND either the
2358
- // network is genuinely quiet OR it has refused to quiet within the
2359
- // grace (continuous background traffic must not block forever).
2360
- if (
2361
- stillProven() &&
2362
- (maestro || networkQuiet || clockNow() - visuallyStillSince >= networkQuietGraceMs)
2363
- ) {
2364
- if (transitionWait) {
2365
- await transitionWait
2366
- transitionWait = null
2367
- }
2368
- if (stillProven()) return { settled: true, elapsed: clockNow() - start, blockedBy: '' }
2296
+ !snapshot.layoutDirty)
2297
+ // visually settled: no worker motion or layout work, no new layout
2298
+ // commits, a stable mounted node count, no image content loading
2299
+ // (unless motion alone is asked), no webview startup in progress,
2300
+ // layout unchanged since the last poll. both modes wait out finite
2301
+ // worker motion now; strict additionally implies the flags through
2302
+ // strictOk and adds shell motion plus the blocking-stats floor. a
2303
+ // null count or commit reading means the runtime does not report
2304
+ // it, which reads as stable the way a missing stats block does.
2305
+ // equal presented pixels can precede pending worker motion or layout.
2306
+ // after that work drains, iOS's 3 s pixel phase may accept two equal
2307
+ // native TreeNodes while paint-only playback continues. overlap
2308
+ // hierarchy reads so neither the gesture nor screenshot deadline grows.
2309
+ const maestroStill = !snapshot.workerBusy && snapshot.pendingFetches === 0 && snapshot.requestInFlight === 0 && !snapshot.webViewStarting &&
2310
+ !snapshot.animating && !snapshot.shellAnimating && !snapshot.layoutDirty && (
2311
+ !screenChanged || (clockNow() - start >= 3000 &&
2312
+ hierarchyUnchanged(snapshot.nativeHierarchy, lastNativeHierarchy))
2313
+ )
2314
+ const idleSnapshot =
2315
+ strictOk &&
2316
+ !snapshot.animating &&
2317
+ !snapshot.shellAnimating &&
2318
+ !snapshot.layoutDirty &&
2319
+ snapshot.pendingFetches === 0 &&
2320
+ !snapshot.workerBusy &&
2321
+ !snapshot.webViewStarting
2322
+ const visuallyStill = maestro ? maestroStill :
2323
+ idleSnapshot &&
2324
+ (snapshot.appCommits === null || lastAppCommits === null || snapshot.appCommits === lastAppCommits) &&
2325
+ (snapshot.nodeCount === null || lastNodeCount === null || snapshot.nodeCount === lastNodeCount) &&
2326
+ !screenChanged &&
2327
+ snapshot.layout === lastLayout
2328
+ // generic network quiet: nothing in flight and no new requests issued.
2329
+ const networkQuiet =
2330
+ snapshot.requestInFlight === 0 && snapshot.requestTotal === lastRequestTotal
2331
+ if (visuallyStill) {
2332
+ if (visuallyStillSince === 0) visuallyStillSince = clockNow()
2333
+ // two equal idle observations prove the interval between them.
2334
+ // discarding the first requires a third worker round trip, which
2335
+ // can exhaust the budget after a late image on a loaded host.
2336
+ if (!maestro && !screenStill && stillPolls.length === 0 && lastIdlePoll) {
2337
+ stillPolls.push(lastIdlePoll)
2338
+ }
2339
+ stillPolls.push({ started: pollStarted, answered: clockNow() })
2340
+ // still long enough, counting only polls that began after a started
2341
+ // transition drained.
2342
+ const stillProven = () => {
2343
+ const proving = stillPolls.filter((poll) => transitionEndedAt === null || poll.started >= transitionEndedAt)
2344
+ return proving.length >= minimumStablePolls && clockNow() - proving[0].answered >= requiredStillMs
2345
+ }
2346
+ // settle once the screen has held still long enough AND either the
2347
+ // network is genuinely quiet OR it has refused to quiet within the
2348
+ // grace (continuous background traffic must not block forever).
2349
+ if (
2350
+ stillProven() &&
2351
+ (maestro || networkQuiet || clockNow() - visuallyStillSince >= networkQuietGraceMs)
2352
+ ) {
2353
+ if (transitionWait) {
2354
+ await transitionWait
2355
+ transitionWait = null
2369
2356
  }
2370
- } else {
2371
- stillPolls = []
2372
- visuallyStillSince = 0
2357
+ if (stillProven()) return { settled: true, elapsed: clockNow() - start, blockedBy: '' }
2373
2358
  }
2374
- lastIdlePoll = idleSnapshot ? { started: pollStarted, answered: clockNow() } : null
2375
- lastNativeHierarchy = snapshot.nativeHierarchy
2376
- lastLayout = snapshot.layout
2377
- lastNodeRows = snapshot.nodeRows
2378
- lastScreenPixels = snapshot.screenPixels
2379
- lastRequestTotal = snapshot.requestTotal
2380
- lastAppCommits = snapshot.appCommits
2381
- lastNodeCount = snapshot.nodeCount
2382
- // reply latency belongs inside the poll interval; the stillness window
2383
- // above remains measured from completed observations.
2384
- const remainingPollMs = pollMs - (clockNow() - pollStarted)
2385
- if (remainingPollMs > 0) await clockSleep(remainingPollMs)
2386
- }
2387
- if (!report) {
2388
- return { settled: false, elapsed: clockNow() - start, blockedBy: 'no poll fit the budget' }
2389
- }
2390
- const last = report.snapshot
2391
- const blockers = []
2392
- if (!maestro && strict && !last.renderStatsAvailable) blockers.push('render stats unavailable')
2393
- if (!maestro && last.animating) blockers.push('animations still running' + (last.animatingBy ? ' (' + last.animatingBy + ')' : ''))
2394
- if (last.shellAnimating) blockers.push('animations still running (' + last.shellBlockers + ')')
2395
- if (!maestro && last.layoutDirty) blockers.push('layout still dirty')
2396
- if (!maestro && last.appCommits !== null && report.appCommits !== null && last.appCommits !== report.appCommits) blockers.push('layout commits still landing')
2397
- if (!maestro && last.nodeCount !== null && report.nodeCount !== null && last.nodeCount !== report.nodeCount) blockers.push('node count still changing')
2398
- if (last.pendingFetches > 0) blockers.push(last.pendingFetches + ' image fetches pending')
2399
- if (last.workerBusy) blockers.push('a render worker too busy to report')
2400
- if (last.webViewStarting) blockers.push(last.webViewBlocker || 'webView still starting')
2401
- if (!maestro && last.layout !== report.layout) blockers.push('layout still changing')
2402
- if (maestro && !hierarchyUnchanged(last.nativeHierarchy, report.nativeHierarchy)) blockers.push(last.nativeHierarchy === null ? 'native accessibility hierarchy unavailable' : 'native accessibility hierarchy still changing')
2403
- if (paintStill && !last.screenPixels) blockers.push('screen pixels unavailable')
2404
- else if (paintStill && !screenUnchanged(last.screenPixels, report.screenPixels)) blockers.push('screen pixels still changing')
2405
- if (last.requestInFlight > 0) blockers.push(last.requestInFlight + ' requests in flight')
2406
- else if (!maestro && last.requestTotal !== report.requestTotal) blockers.push('new requests issued')
2407
- if (polls < 2) blockers.push('sim too busy to poll twice')
2408
- // the last read is still: motion ended too near the deadline for the
2409
- // stillness window to hold before it.
2410
- if (!blockers.length) blockers.push('motion ended before stillness was proven')
2411
- return {
2412
- settled: false,
2413
- elapsed: clockNow() - start,
2414
- blockedBy:
2415
- blockers.join(', ') + ' over ' + polls + ' polls (layout changed ' + layoutChangedPolls +
2416
- 'x, layoutDirty ' + dirtyPolls + 'x, animating ' + animatingPolls + 'x, webViewStarting ' + webViewStartingPolls + 'x, screen changed ' + screenChangedPolls + 'x)' +
2417
- (lastLayoutChange ? '; last layout change ' + JSON.stringify(lastLayoutChange) : ''),
2359
+ } else {
2360
+ stillPolls = []
2361
+ visuallyStillSince = 0
2418
2362
  }
2419
- } finally {
2420
- unsubscribe?.()
2363
+ lastIdlePoll = idleSnapshot ? { started: pollStarted, answered: clockNow() } : null
2364
+ lastNativeHierarchy = snapshot.nativeHierarchy
2365
+ lastLayout = snapshot.layout
2366
+ lastNodeRows = snapshot.nodeRows
2367
+ lastRequestTotal = snapshot.requestTotal
2368
+ lastAppCommits = snapshot.appCommits
2369
+ lastNodeCount = snapshot.nodeCount
2370
+ // reply latency belongs inside the poll interval; the stillness window
2371
+ // above remains measured from completed observations.
2372
+ const remainingPollMs = pollMs - (clockNow() - pollStarted)
2373
+ if (remainingPollMs > 0) await clockSleep(remainingPollMs)
2374
+ }
2375
+ if (!report) {
2376
+ return { settled: false, elapsed: clockNow() - start, blockedBy: 'no poll fit the budget' }
2377
+ }
2378
+ const last = report.snapshot
2379
+ const blockers = []
2380
+ if (!maestro && strict && !last.renderStatsAvailable) blockers.push('render stats unavailable')
2381
+ if (!maestro && last.animating) blockers.push('animations still running' + (last.animatingBy ? ' (' + last.animatingBy + ')' : ''))
2382
+ if (last.shellAnimating) blockers.push('animations still running (' + last.shellBlockers + ')')
2383
+ if (!maestro && last.layoutDirty) blockers.push('layout still dirty')
2384
+ if (!maestro && last.appCommits !== null && report.appCommits !== null && last.appCommits !== report.appCommits) blockers.push('layout commits still landing')
2385
+ if (!maestro && last.nodeCount !== null && report.nodeCount !== null && last.nodeCount !== report.nodeCount) blockers.push('node count still changing')
2386
+ if (last.pendingFetches > 0) blockers.push(last.pendingFetches + ' image fetches pending')
2387
+ if (last.workerBusy) blockers.push('a render worker too busy to report')
2388
+ if (last.webViewStarting) blockers.push(last.webViewBlocker || 'webView still starting')
2389
+ if (!maestro && last.layout !== report.layout) blockers.push('layout still changing')
2390
+ if (maestro && !hierarchyUnchanged(last.nativeHierarchy, report.nativeHierarchy)) blockers.push(last.nativeHierarchy === null ? 'native accessibility hierarchy unavailable' : 'native accessibility hierarchy still changing')
2391
+ if (screenStill && last.visibleMotion) blockers.push('visible motion continues (' + last.visibleMotionBy + ')')
2392
+ if (last.requestInFlight > 0) blockers.push(last.requestInFlight + ' requests in flight')
2393
+ else if (!maestro && last.requestTotal !== report.requestTotal) blockers.push('new requests issued')
2394
+ if (polls < 2) blockers.push('sim too busy to poll twice')
2395
+ // the last read is still: motion ended too near the deadline for the
2396
+ // stillness window to hold before it.
2397
+ if (!blockers.length) blockers.push('motion ended before stillness was proven')
2398
+ return {
2399
+ settled: false,
2400
+ elapsed: clockNow() - start,
2401
+ blockedBy:
2402
+ blockers.join(', ') + ' over ' + polls + ' polls (layout changed ' + layoutChangedPolls +
2403
+ 'x, layoutDirty ' + dirtyPolls + 'x, animating ' + animatingPolls + 'x, webViewStarting ' + webViewStartingPolls + 'x, screen changed ' + screenChangedPolls + 'x)' +
2404
+ (lastLayoutChange ? '; last layout change ' + JSON.stringify(lastLayoutChange) : ''),
2421
2405
  }
2422
2406
  })()`
2423
2407
  },