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