peachsim 0.1.2241 → 0.1.2243

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 (92) hide show
  1. package/cli/bridge-flow-runner.ts +10 -9
  2. package/cli/commands/flow.ts +4 -0
  3. package/cli/commands/inspect/settling.ts +496 -515
  4. package/cli/commands/platform.ts +2 -0
  5. package/dist-lib/agent-daemon-client.cjs +1 -1
  6. package/dist-lib/agent-events.cjs +1 -1
  7. package/dist-lib/attached-projects.cjs +1 -1
  8. package/dist-lib/auth/shared-session.cjs +1 -1
  9. package/dist-lib/backend-origin.cjs +1 -1
  10. package/dist-lib/beta.cjs +1 -1
  11. package/dist-lib/beta.mjs +1 -1
  12. package/dist-lib/bridge-constants.cjs +1 -1
  13. package/dist-lib/bridge-contract-input.cjs +1 -1
  14. package/dist-lib/bridge-contract-input.mjs +1 -1
  15. package/dist-lib/bridge-contract.cjs +1 -1
  16. package/dist-lib/bridge-contract.mjs +1 -1
  17. package/dist-lib/bundle-channel.cjs +115 -28
  18. package/dist-lib/capture-contract.cjs +1 -1
  19. package/dist-lib/capture-contract.mjs +1 -1
  20. package/dist-lib/cloud-contract.cjs +1 -1
  21. package/dist-lib/cloud-contract.mjs +1 -1
  22. package/dist-lib/cloud-test-args.cjs +1 -1
  23. package/dist-lib/cloud-test-args.mjs +1 -1
  24. package/dist-lib/cloud.cjs +1 -1
  25. package/dist-lib/cloud.mjs +1 -1
  26. package/dist-lib/config.cjs +1 -1
  27. package/dist-lib/config.mjs +1 -1
  28. package/dist-lib/detox/index.cjs +498 -518
  29. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  30. package/dist-lib/expo-swift-bundle.cjs +114 -27
  31. package/dist-lib/expo-swift-metadata.cjs +1 -1
  32. package/dist-lib/expo-swift-metadata.mjs +1 -1
  33. package/dist-lib/home-paths.cjs +1 -1
  34. package/dist-lib/host/bridge-host.cjs +122 -40
  35. package/dist-lib/host/fetch-proxy-handler.cjs +3 -3
  36. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  37. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  38. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  39. package/dist-lib/host/websocket-proxy.cjs +1 -1
  40. package/dist-lib/index.cjs +496 -516
  41. package/dist-lib/jump-to-source-babel.cjs +1 -1
  42. package/dist-lib/jump-to-source-native.cjs +1 -1
  43. package/dist-lib/kotlin-host.cjs +1 -1
  44. package/dist-lib/menu.cjs +1 -1
  45. package/dist-lib/menu.mjs +1 -1
  46. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  47. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  48. package/dist-lib/metro-production-bundle.cjs +1 -1
  49. package/dist-lib/metro-production-bundle.mjs +1 -1
  50. package/dist-lib/metro.cjs +3 -3
  51. package/dist-lib/native-app-identity-project.cjs +2 -2
  52. package/dist-lib/native-app-identity-project.mjs +2 -2
  53. package/dist-lib/native-app-identity.cjs +1 -1
  54. package/dist-lib/native-app-identity.mjs +1 -1
  55. package/dist-lib/native-firebase-metadata.cjs +1 -1
  56. package/dist-lib/native-firebase-metadata.mjs +1 -1
  57. package/dist-lib/pdfium-raster.cjs +1 -1
  58. package/dist-lib/pdfium-raster.mjs +1 -1
  59. package/dist-lib/plist.cjs +1 -1
  60. package/dist-lib/plist.mjs +1 -1
  61. package/dist-lib/profiles.cjs +1 -1
  62. package/dist-lib/public-brand.cjs +1 -1
  63. package/dist-lib/public-origins-lib-esm.json +24 -24
  64. package/dist-lib/public-origins-lib.json +53 -53
  65. package/dist-lib/react-native-host-modules.cjs +1 -1
  66. package/dist-lib/react-native-host-modules.mjs +1 -1
  67. package/dist-lib/reap-browser.cjs +1 -1
  68. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  69. package/dist-lib/sdk.cjs +492 -512
  70. package/dist-lib/sdk.mjs +492 -512
  71. package/dist-lib/skills.cjs +632 -569
  72. package/dist-lib/swift-compile.cjs +13 -4
  73. package/dist-lib/swift-compile.mjs +13 -4
  74. package/dist-lib/swift-package.cjs +1 -1
  75. package/dist-lib/swift-package.mjs +1 -1
  76. package/dist-lib/swift-submit.cjs +2 -2
  77. package/dist-lib/swift-submit.mjs +2 -2
  78. package/dist-lib/swift-toolchain.cjs +1 -1
  79. package/dist-lib/swift.cjs +1 -1
  80. package/dist-lib/vite-swift.cjs +507 -419
  81. package/dist-lib/vite.cjs +3 -3
  82. package/dist-lib/worklet-executable.cjs +1 -1
  83. package/dist-lib/worklet-executable.mjs +1 -1
  84. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +3 -0
  85. package/kotlin/sdk.tar.gz +0 -0
  86. package/package.json +1 -1
  87. package/src/host/bridge-host.ts +12 -13
  88. package/src/native-static-libraries.ts +98 -17
  89. package/src/swift-shared-sdk.ts +6 -1
  90. package/src/swift-standins.ts +11 -4
  91. package/src/swift-submit.ts +3 -1
  92. package/src/swift-wasm-prune.ts +28 -0
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2241 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2243 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -1732,7 +1732,7 @@ async function waitForSootsimIdle({
1732
1732
  pollMs = 50,
1733
1733
  stablePolls = 3,
1734
1734
  strict = false,
1735
- paintStill = false,
1735
+ screenStill = false,
1736
1736
  maestro = false,
1737
1737
  motionOnly = false,
1738
1738
  readyPlayback = false,
@@ -1770,7 +1770,7 @@ async function waitForSootsimIdle({
1770
1770
  let deadline = start + budgetMs
1771
1771
  const pollMs = ${Math.max(1, Math.round(pollMs))}
1772
1772
  const strict = ${strict ? "true" : "false"}
1773
- const paintStill = ${paintStill ? "true" : "false"}
1773
+ const screenStill = ${screenStill ? "true" : "false"}
1774
1774
  const maestro = ${maestro ? "true" : "false"}
1775
1775
  const accessibilityBounds = ${accessibilityBounds.toString()}
1776
1776
  const sameNativeAccessibilityShape = ${sameNativeAccessibilityShape.toString()}
@@ -1780,550 +1780,530 @@ async function waitForSootsimIdle({
1780
1780
  // tight budgets (auto-wait) settle on worker stillness plus root
1781
1781
  // membership, generous ones confirm the geometry too.
1782
1782
  const fullGeometry = ${!maestro && maxMs >= 1e3 ? "true" : "false"}
1783
- const requiredStillMs = paintStill ? 0 : ${Math.max(1, Math.round(stablePolls)) * Math.max(1, Math.round(pollMs))}
1784
- const minimumStablePolls = paintStill ? 1 : ${Math.min(2, Math.max(1, Math.round(stablePolls)))}
1785
- const composite = paintStill ? globalThis.SootSim?.bridges?.liveComposite : null
1786
- if (paintStill && !composite) {
1787
- return { settled: false, elapsed: clockNow() - start, blockedBy: 'screen pixels unavailable' }
1788
- }
1789
- // subscribe to presented frames; authoritative screenshots force a
1790
- // worker render, which changes the very counter we used to inspect.
1791
- // pixels only decide stillness once motion and layout work drain, so the
1792
- // subscription holds only then: a headless host otherwise reads back
1793
- // every motion frame for a comparison that cannot pass.
1794
- let unsubscribe = null
1783
+ const requiredStillMs = screenStill ? 0 : ${Math.max(1, Math.round(stablePolls)) * Math.max(1, Math.round(pollMs))}
1784
+ const minimumStablePolls = screenStill ? 1 : ${Math.min(2, Math.max(1, Math.round(stablePolls)))}
1795
1785
  let transitionEndedAt = null
1796
- let pixelFrameToken = -1
1797
- let screenPixels = null
1798
1786
  // the hierarchy read last taken and the geometry revision it answered.
1799
1787
  // it outlives this wait: a revision still current when a later wait
1800
1788
  // polls names the same geometry, so a step that follows a settled one
1801
1789
  // proves an unchanged screen without walking the tree again.
1802
1790
  const geometry = (globalThis.__peachSettleGeometry ??= { revision: null, hierarchy: null })
1803
- try {
1804
-
1805
- // discover transitions while observing layout. when motion starts,
1806
- // observations from before its completion cannot prove the new screen;
1807
- // those that began after it drained still can. a loaded host runs a
1808
- // push past a tap's budget, so the transition gets its own timeout and
1809
- // the budget restarts once it drains.
1810
- let transitionWait = (async () => {
1811
- try {
1812
- const wfst = globalThis.__sootsimTest?.waitForScreenTransitions
1813
- if (typeof wfst === 'function' && budgetMs > 120) {
1814
- const transition = await wfst({
1815
- timeoutMs: ${Math.max(0, Math.round(transitionTimeoutMs))},
1816
- settleMs: 64,
1817
- startWindowMs: ${Math.max(0, Math.round(transitionStartWindowMs))},
1818
- })
1819
- if (transition?.started !== true) return false
1820
- // a loaded worker replies long after the motion stopped; it
1821
- // reports how long ago, so polls begun since still count. a
1822
- // runtime without the field ends the transition at the reply.
1823
- const rested = typeof transition.restedMs === 'number' ? Math.max(0, transition.restedMs) : 0
1824
- transitionEndedAt = clockNow() - rested
1825
- deadline = Math.max(deadline, transitionEndedAt + budgetMs)
1826
- return true
1827
- }
1828
- } catch {}
1829
- return false
1830
- })()
1831
-
1832
- // a worker that cannot answer within the remaining budget is busy, not
1833
- // idle: its poll reads as unsettled. bounding each read by the budget
1834
- // keeps a busy worker from holding a poll past the deadline.
1835
- const BUSY = { busy: true }
1836
- const answer = (read) =>
1837
- Promise.race([
1838
- Promise.resolve().then(read),
1839
- new Promise((resolve) =>
1840
- setTimeout(() => resolve(BUSY), Math.max(deadline - clockNow(), 100)),
1841
- ),
1842
- ])
1843
-
1844
- const readSnapshot = async () => {
1845
- let animating = false
1846
- let animatingBy = ''
1847
- let layoutDirty = false
1848
- let pendingFetches = 0
1849
- let workerBusy = false
1850
- let requestTotal = 0
1851
- let requestInFlight = 0
1852
- let appCommits = null
1853
- let nodeCount = null
1854
- let renderStatsAvailable = false
1855
- let shellAnimating = false
1856
- let shellBlockers = ''
1857
- let webViewStarting = false
1858
- let webViewBlocker = ''
1859
- // the reads are independent, so they run concurrently: a loaded sim
1860
- // answers each one late, and a poll that waits for them in turn
1861
- // costs their sum, which fits too few polls in the budget to settle.
1862
- // the window node count is the exception: it launches after the
1863
- // motion read, so a poll motion already fails skips that walk.
1864
- // strict reads also wait out shell motion. pixel reads inspect finite
1865
- // animations in both realms: a worklet can move the app while the
1866
- // tenant's basic animation flag and last presented pixels read still.
1867
- const accessibilityRead = maestro
1868
- ? answer(() => globalThis.__sootsimTest.captureAccessibilityTree()).catch(() => null)
1869
- : null
1870
- const motionRead = strict || paintStill
1871
- ? answer(() => globalThis.__sootsimTest?.listAnimations?.()).catch(() => null)
1872
- : null
1873
- const statsRead = answer(() => globalThis.__sootsimRenderHost?.queryStats?.()).catch(() => null)
1874
- // image preparation ends in the tenant before the compositor decodes
1875
- // and realizes its pixels. both owners must finish before settling.
1876
- // the compositor rejects a stats request it is too busy to answer.
1877
- const compositorRead = answer(() => globalThis.__sootsimCompositor.getStats({ detail: 'readiness' })).catch(() => BUSY)
1878
- const countsRead = answer(() => globalThis.__sootsimTest?.getRequestCounts?.()).catch(() => null)
1879
- // the mounted hierarchy in render-worker mode comes from the test
1880
- // bridge: globalThis.__sootsimRoot is an empty placeholder there, so a
1881
- // walk over it hashes every screen to the same empty string while
1882
- // it moves. listInspectable is the worker-backed read describe
1883
- // uses; a worker too busy to answer it reads as unsettled. tight
1884
- // budgets skip this read and settle on the cheaper signals above.
1885
- // it walks every node, so a poll whose geometry revision matches the
1886
- // last read, in this wait or an earlier one, reuses that read.
1887
- const hierarchyRead =
1888
- fullGeometry && typeof globalThis.__sootsimTest?.listInspectable === 'function'
1889
- ? answer(() => globalThis.__sootsimTest.getGeometryRevision?.())
1890
- .catch(() => null)
1891
- .then((revision) => {
1892
- if (revision === BUSY) return BUSY
1893
- if (typeof revision === 'string' && geometry.revision === revision) return geometry.hierarchy
1894
- return answer(() => globalThis.__sootsimTest.listInspectable({}))
1895
- .catch(() => null)
1896
- .then((hierarchy) => {
1897
- const kept = typeof revision === 'string' && Array.isArray(hierarchy)
1898
- geometry.revision = kept ? revision : null
1899
- geometry.hierarchy = kept ? hierarchy : null
1900
- return hierarchy
1901
- })
1902
- })
1903
- : null
1904
- if (motionRead) {
1905
- const motion = await motionRead
1906
- if (motion === BUSY) workerBusy = true
1907
- else if (Array.isArray(motion)) {
1908
- const blocking = motion.filter((anim) =>
1909
- (anim.realm === 'shell' || paintStill) &&
1910
- anim.priority !== 'low' && anim.visible !== false &&
1911
- (!paintStill || anim.loop !== true))
1912
- shellAnimating = blocking.length > 0
1913
- // name what holds the settle so a timeout points at its owner.
1914
- shellBlockers = blocking
1915
- .slice(0, 4)
1916
- .map((anim) => anim.source + '/' + anim.kind + '#' + anim.id + ' at ' + anim.current + (anim.loop ? ' loop' : ''))
1917
- .join(', ')
1918
- }
1919
- }
1920
- const stats = await statsRead
1921
- if (stats === BUSY) {
1922
- workerBusy = true
1923
- } else if (!stats && readyPlayback) {
1924
- workerBusy = true
1925
- } else if (stats) {
1926
- renderStatsAvailable = true
1927
- const missingFields = ['hasActiveBlockingNativeAnimations', 'hasPendingBlockingAnimationFrames']
1928
- .filter((field) => typeof stats[field] !== 'boolean')
1929
- if (readyPlayback && typeof stats.hasPendingReadinessAnimationFrames !== 'boolean') missingFields.push('hasPendingReadinessAnimationFrames')
1930
- if ((strict || readyPlayback) && missingFields.length > 0) {
1931
- return {
1932
- runtimeUnsupported: {
1933
- error: 'runtime_readiness_unsupported',
1934
- runtimeVersion: globalThis.__sootsimRuntimeVersion || 'unknown',
1935
- missingFields,
1936
- },
1937
- }
1938
- }
1939
- // positive checks only: an older runtime without the blocking
1940
- // fields reads as still, and strict rejects that runtime above
1941
- // instead of ever settling on unknown motion.
1942
- animating =
1943
- stats.hasActiveAnims === true ||
1944
- stats.hasActiveBlockingNativeAnimations === true ||
1945
- (!paintStill && (readyPlayback ? stats.hasPendingReadinessAnimationFrames : stats.hasPendingBlockingAnimationFrames) === true)
1946
- if (animating)
1947
- animatingBy = [
1948
- stats.hasActiveAnims === true && 'activeAnims',
1949
- stats.hasActiveBlockingNativeAnimations === true && 'blockingNative',
1950
- !paintStill && stats.hasPendingBlockingAnimationFrames === true && 'pendingFrames',
1951
- !paintStill && stats.hasPendingReadinessAnimationFrames === true && 'pendingReadinessFrames',
1952
- ].filter(Boolean).join('+')
1953
- // the runtime reports only layout work that can reach the window:
1954
- // a covered screen or inactive tab committing does not hold it.
1955
- layoutDirty =
1956
- stats.layoutDirty === true && stats.renderRequested === true
1957
- // a freshly-pushed screen showing a skeleton is layout-stable
1958
- // but not actually settled \u2014 its data/images are still in
1959
- // flight. treat bounded image-loader fetches as not-idle so
1960
- // settle waits for real content, capped by the budget.
1961
- const pf = stats.memory && stats.memory.imageLoader
1962
- ? stats.memory.imageLoader.pendingFetches
1963
- : 0
1964
- pendingFetches = typeof pf === 'number' ? pf : 0
1965
- // tenant layout commits: a screen that keeps committing is still
1966
- // mounting or remounting, even with no animation flag raised.
1967
- appCommits = typeof stats.appCommitCount === 'number' ? stats.appCommitCount : null
1791
+ // discover transitions while observing layout. when motion starts,
1792
+ // observations from before its completion cannot prove the new screen;
1793
+ // those that began after it drained still can. a loaded host runs a
1794
+ // push past a tap's budget, so the transition gets its own timeout and
1795
+ // the budget restarts once it drains.
1796
+ let transitionWait = (async () => {
1797
+ try {
1798
+ const wfst = globalThis.__sootsimTest?.waitForScreenTransitions
1799
+ if (typeof wfst === 'function' && budgetMs > 120) {
1800
+ const transition = await wfst({
1801
+ timeoutMs: ${Math.max(0, Math.round(transitionTimeoutMs))},
1802
+ settleMs: 64,
1803
+ startWindowMs: ${Math.max(0, Math.round(transitionStartWindowMs))},
1804
+ })
1805
+ if (transition?.started !== true) return false
1806
+ // a loaded worker replies long after the motion stopped; it
1807
+ // reports how long ago, so polls begun since still count. a
1808
+ // runtime without the field ends the transition at the reply.
1809
+ const rested = typeof transition.restedMs === 'number' ? Math.max(0, transition.restedMs) : 0
1810
+ transitionEndedAt = clockNow() - rested
1811
+ deadline = Math.max(deadline, transitionEndedAt + budgetMs)
1812
+ return true
1968
1813
  }
1969
- // mounted-root membership: the count of nodes that can reach the
1970
- // window moves while the screen mounts, unmounts or recycles, in
1971
- // either render mode. a screen a pushed one covers or an inactive
1972
- // tab stays mounted out of the window, so what it mounts is not
1973
- // screen motion. the worker rebuilds the membership set while the
1974
- // wire moves on every animated frame, so a poll the motion read
1975
- // already fails skips it: the motion flags alone prove this poll
1976
- // unsettled, and the carried count hands the first still poll the
1977
- // pre-motion baseline to compare against.
1978
- const motionStill = !workerBusy && !animating && !layoutDirty && !shellAnimating
1979
- const nodeCountRead = motionStill
1980
- ? answer(() => globalThis.__sootsimTest?.getWindowNodeCount?.()).catch(() => null)
1814
+ } catch {}
1815
+ return false
1816
+ })()
1817
+
1818
+ // a worker that cannot answer within the remaining budget is busy, not
1819
+ // idle: its poll reads as unsettled. bounding each read by the budget
1820
+ // keeps a busy worker from holding a poll past the deadline.
1821
+ const BUSY = { busy: true }
1822
+ const answer = (read) =>
1823
+ Promise.race([
1824
+ Promise.resolve().then(read),
1825
+ new Promise((resolve) =>
1826
+ setTimeout(() => resolve(BUSY), Math.max(deadline - clockNow(), 100)),
1827
+ ),
1828
+ ])
1829
+
1830
+ const readSnapshot = async () => {
1831
+ let animating = false
1832
+ let animatingBy = ''
1833
+ let layoutDirty = false
1834
+ let pendingFetches = 0
1835
+ let workerBusy = false
1836
+ let requestTotal = 0
1837
+ let requestInFlight = 0
1838
+ let appCommits = null
1839
+ let nodeCount = null
1840
+ let renderStatsAvailable = false
1841
+ let shellAnimating = false
1842
+ let shellBlockers = ''
1843
+ let webViewStarting = false
1844
+ let webViewBlocker = ''
1845
+ let visibleMotion = false
1846
+ let visibleMotionBy = ''
1847
+ let motionUnavailable = false
1848
+ // the reads are independent, so they run concurrently: a loaded sim
1849
+ // answers each one late, and a poll that waits for them in turn
1850
+ // costs their sum, which fits too few polls in the budget to settle.
1851
+ // the window node count is the exception: it launches after the
1852
+ // motion read, so a poll motion already fails skips that walk.
1853
+ // strict reads also wait out shell motion. pixel reads inspect finite
1854
+ // animations in both realms: a worklet can move the app while the
1855
+ // tenant's basic animation flag and last presented pixels read still.
1856
+ const accessibilityRead = maestro
1857
+ ? answer(() => globalThis.__sootsimTest.captureAccessibilityTree()).catch(() => null)
1858
+ : null
1859
+ const motionRead = strict || screenStill
1860
+ ? answer(() => globalThis.__sootsimTest?.listAnimations?.()).catch(() => null)
1861
+ : null
1862
+ const statsRead = answer(() => globalThis.__sootsimRenderHost?.queryStats?.()).catch(() => null)
1863
+ // image preparation ends in the tenant before the compositor decodes
1864
+ // and realizes its pixels. both owners must finish before settling.
1865
+ // the compositor rejects a stats request it is too busy to answer.
1866
+ const compositorRead = answer(() => globalThis.__sootsimCompositor.getStats({ detail: 'readiness' })).catch(() => BUSY)
1867
+ const countsRead = answer(() => globalThis.__sootsimTest?.getRequestCounts?.()).catch(() => null)
1868
+ // the mounted hierarchy in render-worker mode comes from the test
1869
+ // bridge: globalThis.__sootsimRoot is an empty placeholder there, so a
1870
+ // walk over it hashes every screen to the same empty string while
1871
+ // it moves. listInspectable is the worker-backed read describe
1872
+ // uses; a worker too busy to answer it reads as unsettled. tight
1873
+ // budgets skip this read and settle on the cheaper signals above.
1874
+ // it walks every node, so a poll whose geometry revision matches the
1875
+ // last read, in this wait or an earlier one, reuses that read.
1876
+ const hierarchyRead =
1877
+ fullGeometry && typeof globalThis.__sootsimTest?.listInspectable === 'function'
1878
+ ? answer(() => globalThis.__sootsimTest.getGeometryRevision?.())
1879
+ .catch(() => null)
1880
+ .then((revision) => {
1881
+ if (revision === BUSY) return BUSY
1882
+ if (typeof revision === 'string' && geometry.revision === revision) return geometry.hierarchy
1883
+ return answer(() => globalThis.__sootsimTest.listInspectable({}))
1884
+ .catch(() => null)
1885
+ .then((hierarchy) => {
1886
+ const kept = typeof revision === 'string' && Array.isArray(hierarchy)
1887
+ geometry.revision = kept ? revision : null
1888
+ geometry.hierarchy = kept ? hierarchy : null
1889
+ return hierarchy
1890
+ })
1891
+ })
1981
1892
  : null
1982
- const compositor = await compositorRead
1983
- if (compositor === BUSY) {
1893
+ if (motionRead) {
1894
+ const motion = await motionRead
1895
+ if (motion === BUSY) workerBusy = true
1896
+ else if (Array.isArray(motion)) {
1897
+ const blocking = motion.filter((anim) =>
1898
+ (anim.realm === 'shell' || screenStill) &&
1899
+ anim.priority !== 'low' && anim.visible !== false &&
1900
+ (!screenStill || anim.loop !== true))
1901
+ shellAnimating = blocking.length > 0
1902
+ // what blocking leaves out still moves the screen while visible;
1903
+ // it ends a screen-still wait only at maestro's hierarchy check
1904
+ // or the deadline, as a screen that never holds still does on ios.
1905
+ const moving = screenStill
1906
+ ? motion.filter((anim) => anim.visible !== false && !blocking.includes(anim))
1907
+ : []
1908
+ visibleMotion = moving.length > 0
1909
+ visibleMotionBy = moving
1910
+ .slice(0, 4)
1911
+ .map((anim) => anim.source + '/' + anim.kind + '#' + anim.id + (anim.loop ? ' loop' : '') + (anim.priority === 'low' ? ' low' : ''))
1912
+ .join(', ')
1913
+ // name what holds the settle so a timeout points at its owner.
1914
+ shellBlockers = blocking
1915
+ .slice(0, 4)
1916
+ .map((anim) => anim.source + '/' + anim.kind + '#' + anim.id + ' at ' + anim.current + (anim.loop ? ' loop' : ''))
1917
+ .join(', ')
1918
+ } else if (screenStill) {
1919
+ motionUnavailable = true
1984
1920
  workerBusy = true
1985
- } else {
1986
- pendingFetches += compositor.images.pendingFetches
1987
- pendingFetches += compositor.imageRealization.pending
1988
- if (compositor.webViewCaptureSettled === false) {
1989
- webViewStarting = true
1990
- webViewBlocker = 'compositor webView capture not settled'
1921
+ }
1922
+ }
1923
+ const stats = await statsRead
1924
+ if (stats === BUSY) {
1925
+ workerBusy = true
1926
+ } else if (!stats && readyPlayback) {
1927
+ workerBusy = true
1928
+ } else if (stats) {
1929
+ renderStatsAvailable = true
1930
+ const missingFields = ['hasActiveBlockingNativeAnimations', 'hasPendingBlockingAnimationFrames']
1931
+ .filter((field) => typeof stats[field] !== 'boolean')
1932
+ if (readyPlayback && typeof stats.hasPendingReadinessAnimationFrames !== 'boolean') missingFields.push('hasPendingReadinessAnimationFrames')
1933
+ if ((strict || readyPlayback) && missingFields.length > 0) {
1934
+ return {
1935
+ runtimeUnsupported: {
1936
+ error: 'runtime_readiness_unsupported',
1937
+ runtimeVersion: globalThis.__sootsimRuntimeVersion || 'unknown',
1938
+ missingFields,
1939
+ },
1991
1940
  }
1992
1941
  }
1993
- const counts = await countsRead
1994
- if (counts === BUSY) workerBusy = true
1995
- // <Image> loads are left to the image loader, which counts only those
1996
- // that can reach the window. a runtime older than the CLI reports none.
1997
- const imageLoads = counts?.imageLoads ?? { total: 0, inFlight: 0 }
1998
- requestTotal = typeof counts?.total === 'number' ? counts.total - imageLoads.total : 0
1999
- requestInFlight = typeof counts?.inFlight === 'number' ? counts.inFlight - imageLoads.inFlight : 0
2000
- // a skipped read carries the last count: mounts during motion still
2001
- // break the first still poll after it, instead of a blank baseline
2002
- // reading them as stable.
2003
- const total = nodeCountRead ? await nodeCountRead : lastNodeCount
2004
- if (total === BUSY) workerBusy = true
2005
- nodeCount = typeof total === 'number' ? total : null
2006
- const accessibility = accessibilityRead ? await accessibilityRead : null
2007
- const nativeHierarchy = Array.isArray(accessibility) && accessibility.length > 0
2008
- ? accessibility
2009
- : null
2010
- if (accessibility === BUSY) workerBusy = true
2011
- let hierarchy = hierarchyRead ? await hierarchyRead : null
2012
- if (hierarchy === BUSY) {
2013
- workerBusy = true
2014
- hierarchy = null
2015
- } else if (!Array.isArray(hierarchy)) {
2016
- hierarchy = null
1942
+ // positive checks only: an older runtime without the blocking
1943
+ // fields reads as still, and strict rejects that runtime above
1944
+ // instead of ever settling on unknown motion.
1945
+ animating =
1946
+ stats.hasActiveAnims === true ||
1947
+ stats.hasActiveBlockingNativeAnimations === true ||
1948
+ (!screenStill && (readyPlayback ? stats.hasPendingReadinessAnimationFrames : stats.hasPendingBlockingAnimationFrames) === true)
1949
+ if (animating)
1950
+ animatingBy = [
1951
+ stats.hasActiveAnims === true && 'activeAnims',
1952
+ stats.hasActiveBlockingNativeAnimations === true && 'blockingNative',
1953
+ !screenStill && stats.hasPendingBlockingAnimationFrames === true && 'pendingFrames',
1954
+ !screenStill && stats.hasPendingReadinessAnimationFrames === true && 'pendingReadinessFrames',
1955
+ ].filter(Boolean).join('+')
1956
+ // the runtime reports only layout work that can reach the window:
1957
+ // a covered screen or inactive tab committing does not hold it.
1958
+ layoutDirty =
1959
+ stats.layoutDirty === true && stats.renderRequested === true
1960
+ // a freshly-pushed screen showing a skeleton is layout-stable
1961
+ // but not actually settled \u2014 its data/images are still in
1962
+ // flight. treat bounded image-loader fetches as not-idle so
1963
+ // settle waits for real content, capped by the budget.
1964
+ const pf = stats.memory && stats.memory.imageLoader
1965
+ ? stats.memory.imageLoader.pendingFetches
1966
+ : 0
1967
+ pendingFetches = typeof pf === 'number' ? pf : 0
1968
+ // tenant layout commits: a screen that keeps committing is still
1969
+ // mounting or remounting, even with no animation flag raised.
1970
+ appCommits = typeof stats.appCommitCount === 'number' ? stats.appCommitCount : null
1971
+ }
1972
+ // mounted-root membership: the count of nodes that can reach the
1973
+ // window moves while the screen mounts, unmounts or recycles, in
1974
+ // either render mode. a screen a pushed one covers or an inactive
1975
+ // tab stays mounted out of the window, so what it mounts is not
1976
+ // screen motion. the worker rebuilds the membership set while the
1977
+ // wire moves on every animated frame, so a poll the motion read
1978
+ // already fails skips it: the motion flags alone prove this poll
1979
+ // unsettled, and the carried count hands the first still poll the
1980
+ // pre-motion baseline to compare against.
1981
+ const motionStill = !workerBusy && !animating && !layoutDirty && !shellAnimating
1982
+ const nodeCountRead = motionStill
1983
+ ? answer(() => globalThis.__sootsimTest?.getWindowNodeCount?.()).catch(() => null)
1984
+ : null
1985
+ const compositor = await compositorRead
1986
+ if (compositor === BUSY) {
1987
+ workerBusy = true
1988
+ } else {
1989
+ pendingFetches += compositor.images.pendingFetches
1990
+ pendingFetches += compositor.imageRealization.pending
1991
+ if (compositor.webViewCaptureSettled === false) {
1992
+ webViewStarting = true
1993
+ webViewBlocker = 'compositor webView capture not settled'
2017
1994
  }
2018
- const nodes = []
2019
- // identity beside each geometry entry, from the rows already read,
2020
- // so a changed layout can name the nodes that moved.
2021
- const nodeRows = []
2022
- 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
2023
- const noteLoading = (state, text) => {
2024
- if (state?.busy === true) {
2025
- webViewStarting = true
2026
- if (!webViewBlocker) webViewBlocker = 'accessibility busy state active'
2027
- }
2028
- if (typeof text === 'string' && LOADING_TEXT_REGEX.test(text.trim())) {
2029
- webViewStarting = true
2030
- if (!webViewBlocker) webViewBlocker = 'webView startup in progress ("' + text.trim() + '")'
1995
+ }
1996
+ const counts = await countsRead
1997
+ if (counts === BUSY) workerBusy = true
1998
+ // <Image> loads are left to the image loader, which counts only those
1999
+ // that can reach the window. a runtime older than the CLI reports none.
2000
+ const imageLoads = counts?.imageLoads ?? { total: 0, inFlight: 0 }
2001
+ requestTotal = typeof counts?.total === 'number' ? counts.total - imageLoads.total : 0
2002
+ requestInFlight = typeof counts?.inFlight === 'number' ? counts.inFlight - imageLoads.inFlight : 0
2003
+ // a skipped read carries the last count: mounts during motion still
2004
+ // break the first still poll after it, instead of a blank baseline
2005
+ // reading them as stable.
2006
+ const total = nodeCountRead ? await nodeCountRead : lastNodeCount
2007
+ if (total === BUSY) workerBusy = true
2008
+ nodeCount = typeof total === 'number' ? total : null
2009
+ const accessibility = accessibilityRead ? await accessibilityRead : null
2010
+ const nativeHierarchy = Array.isArray(accessibility) && accessibility.length > 0
2011
+ ? accessibility
2012
+ : null
2013
+ if (accessibility === BUSY) workerBusy = true
2014
+ let hierarchy = hierarchyRead ? await hierarchyRead : null
2015
+ if (hierarchy === BUSY) {
2016
+ workerBusy = true
2017
+ hierarchy = null
2018
+ } else if (!Array.isArray(hierarchy)) {
2019
+ hierarchy = null
2020
+ }
2021
+ const nodes = []
2022
+ // identity beside each geometry entry, from the rows already read,
2023
+ // so a changed layout can name the nodes that moved.
2024
+ const nodeRows = []
2025
+ 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
2026
+ const noteLoading = (state, text) => {
2027
+ if (state?.busy === true) {
2028
+ webViewStarting = true
2029
+ if (!webViewBlocker) webViewBlocker = 'accessibility busy state active'
2030
+ }
2031
+ if (typeof text === 'string' && LOADING_TEXT_REGEX.test(text.trim())) {
2032
+ webViewStarting = true
2033
+ if (!webViewBlocker) webViewBlocker = 'webView startup in progress ("' + text.trim() + '")'
2034
+ }
2035
+ }
2036
+ if (hierarchy) {
2037
+ for (const n of hierarchy) {
2038
+ const layout = n && n.layout
2039
+ if (layout && layout.width > 0) {
2040
+ // painted bounds catch a scroll fling. background playback
2041
+ // keeps a view's painted bounds moving forever, so it and its
2042
+ // subtree count by their own layout; the rest of the screen
2043
+ // still catches the fling.
2044
+ const abs = n.backgroundPlayback ? layout : n.absolute || n.absolutePosition || layout
2045
+ const geometry = Math.round(abs.x) + ',' + Math.round(abs.y) + ',' + Math.round(layout.width)
2046
+ nodes.push(geometry)
2047
+ nodeRows.push([String(n.nodeId ?? nodes.length - 1), (n.type || '?') + (n.testId ? '#' + n.testId : ''), geometry])
2031
2048
  }
2049
+ noteLoading(
2050
+ n.accessibilityState,
2051
+ typeof n.text === 'string' ? n.text : '',
2052
+ )
2032
2053
  }
2033
- if (hierarchy) {
2034
- for (const n of hierarchy) {
2035
- const layout = n && n.layout
2036
- if (layout && layout.width > 0) {
2037
- // painted bounds catch a scroll fling. background playback
2038
- // keeps a view's painted bounds moving forever, so it and its
2039
- // subtree count by their own layout; the rest of the screen
2040
- // still catches the fling.
2041
- const abs = n.backgroundPlayback ? layout : n.absolute || n.absolutePosition || layout
2042
- const geometry = Math.round(abs.x) + ',' + Math.round(abs.y) + ',' + Math.round(layout.width)
2054
+ } else {
2055
+ const root = globalThis.__sootsimRoot
2056
+ if (root) {
2057
+ const walk = (n) => {
2058
+ if (n.layout && n.layout.width > 0) {
2059
+ const geometry = Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width)
2043
2060
  nodes.push(geometry)
2044
- nodeRows.push([String(n.nodeId ?? nodes.length - 1), (n.type || '?') + (n.testId ? '#' + n.testId : ''), geometry])
2061
+ nodeRows.push([String(n.id ?? nodes.length - 1), (n.type || '?') + (n.props?.testID ? '#' + n.props.testID : ''), geometry])
2045
2062
  }
2046
2063
  noteLoading(
2047
- n.accessibilityState,
2048
- typeof n.text === 'string' ? n.text : '',
2064
+ n.props?.accessibilityState,
2065
+ n.textContent || (typeof n.props?.children === 'string' ? n.props.children : ''),
2049
2066
  )
2067
+ for (const c of n.children || []) walk(c)
2050
2068
  }
2051
- } else {
2052
- const root = globalThis.__sootsimRoot
2053
- if (root) {
2054
- const walk = (n) => {
2055
- if (n.layout && n.layout.width > 0) {
2056
- const geometry = Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width)
2057
- nodes.push(geometry)
2058
- nodeRows.push([String(n.id ?? nodes.length - 1), (n.type || '?') + (n.props?.testID ? '#' + n.props.testID : ''), geometry])
2059
- }
2060
- noteLoading(
2061
- n.props?.accessibilityState,
2062
- n.textContent || (typeof n.props?.children === 'string' ? n.props.children : ''),
2063
- )
2064
- for (const c of n.children || []) walk(c)
2065
- }
2066
- walk(root)
2067
- }
2069
+ walk(root)
2068
2070
  }
2069
- if (!webViewStarting && typeof document !== 'undefined') {
2070
- const busyEl = [...document.querySelectorAll('[aria-busy="true"]')].find((element) => {
2071
- const bounds = element.getBoundingClientRect()
2072
- return element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) &&
2073
- bounds.width > 0 && bounds.height > 0 && bounds.right > 0 && bounds.bottom > 0 &&
2074
- bounds.left < globalThis.innerWidth && bounds.top < globalThis.innerHeight
2071
+ }
2072
+ if (!webViewStarting && typeof document !== 'undefined') {
2073
+ const busyEl = [...document.querySelectorAll('[aria-busy="true"]')].find((element) => {
2074
+ const bounds = element.getBoundingClientRect()
2075
+ return element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) &&
2076
+ bounds.width > 0 && bounds.height > 0 && bounds.right > 0 && bounds.bottom > 0 &&
2077
+ bounds.left < globalThis.innerWidth && bounds.top < globalThis.innerHeight
2078
+ })
2079
+ if (busyEl) {
2080
+ webViewStarting = true
2081
+ webViewBlocker = 'accessibility busy element displayed'
2082
+ } else {
2083
+ // a loading document with no area (an app's hidden worker or
2084
+ // executor frame) paints nothing, and a screenshot on device
2085
+ // does not wait for it.
2086
+ const unreadyWebView = [...document.querySelectorAll(
2087
+ '[data-sootsim-webview-loading="true"], [data-sootsim-webview-mode="placeholder"]'
2088
+ )].find((view) => {
2089
+ const frame = view.querySelector('iframe')
2090
+ return !frame || frame.clientWidth > 0 || frame.clientHeight > 0
2075
2091
  })
2076
- if (busyEl) {
2092
+ if (unreadyWebView) {
2077
2093
  webViewStarting = true
2078
- webViewBlocker = 'accessibility busy element displayed'
2079
- } else {
2080
- // a loading document with no area (an app's hidden worker or
2081
- // executor frame) paints nothing, and a screenshot on device
2082
- // does not wait for it.
2083
- const unreadyWebView = [...document.querySelectorAll(
2084
- '[data-sootsim-webview-loading="true"], [data-sootsim-webview-mode="placeholder"]'
2085
- )].find((view) => {
2086
- const frame = view.querySelector('iframe')
2087
- return !frame || frame.clientWidth > 0 || frame.clientHeight > 0
2088
- })
2089
- if (unreadyWebView) {
2090
- webViewStarting = true
2091
- webViewBlocker = 'webView document still loading'
2092
- }
2094
+ webViewBlocker = 'webView document still loading'
2093
2095
  }
2094
2096
  }
2095
- const pixelsDecide = !workerBusy && !animating && !shellAnimating && !layoutDirty && pendingFetches === 0 && !webViewStarting
2096
- if (paintStill && !pixelsDecide && unsubscribe) {
2097
- unsubscribe()
2098
- unsubscribe = null
2099
- }
2100
- if (paintStill && pixelsDecide && !unsubscribe) unsubscribe = composite.subscribe(() => {})
2101
- if (paintStill && pixelsDecide) {
2102
- const canvas = composite.getCanvas()
2103
- const token = composite.getFrameToken()
2104
- if (!canvas || canvas.width <= 1 || canvas.height <= 1) {
2105
- screenPixels = null
2106
- } else if (token !== pixelFrameToken || canvas.width !== screenPixels?.width || canvas.height !== screenPixels?.height) {
2107
- const context = canvas.getContext('2d')
2108
- const image = context?.getImageData(0, 0, canvas.width, canvas.height)
2109
- screenPixels = image ? { width: image.width, height: image.height, data: new Uint32Array(image.data.buffer) } : null
2110
- pixelFrameToken = token
2111
- }
2112
- }
2113
- return { layout: nodes.join(';'), nodeRows, nativeHierarchy, screenPixels, animating, animatingBy, shellAnimating, shellBlockers, layoutDirty, pendingFetches, workerBusy, webViewStarting, webViewBlocker, renderStatsAvailable, requestTotal, requestInFlight, appCommits, nodeCount }
2114
- }
2115
-
2116
- // how long generic background network is allowed to keep us waiting AFTER
2117
- // the screen is otherwise visually settled. apps with continuous traffic
2118
- // (polling, realtime sockets, a tap that fires 20-50 fetches) never reach
2119
- // requestInFlight===0 / a stable requestTotal, so requiring full network
2120
- // quiet burns the ENTIRE budget on every command \u2014 the leading idle that
2121
- // failed PR-preview recordings for network-heavy apps (3pc fight-pulse).
2122
- // layout-stability + the image-loader already prove visible content
2123
- // loaded (a data load changes layout; an image load shows in the loader),
2124
- // so the generic request counters are a courtesy, not a gate: honor them
2125
- // only within this grace once the screen is visually still.
2126
- const networkQuietGraceMs = 1200
2127
- let lastNativeHierarchy = null
2128
- let lastLayout = ''
2129
- let lastNodeRows = []
2130
- // what moved between the last two differing polls, bounded; names the
2131
- // nodes behind "layout changed" without keeping any poll history.
2132
- let lastLayoutChange = null
2133
- const describeLayoutChange = (before, after) => {
2134
- const previous = new Map(before.map(([key, label, geometry]) => [key, [label, geometry]]))
2135
- const moved = []
2136
- const added = []
2137
- const short = (label, key) => String(label).slice(0, 48) + ' [' + String(key).slice(0, 24) + ']'
2138
- for (const [key, label, geometry] of after) {
2139
- const was = previous.get(key)
2140
- previous.delete(key)
2141
- if (!was) added.push(short(label, key) + ' ' + geometry)
2142
- else if (was[1] !== geometry) moved.push(short(label, key) + ' ' + was[1] + '->' + geometry)
2143
- }
2144
- const removed = [...previous].map(([key, [label, geometry]]) => short(label, key) + ' ' + geometry)
2145
- return {
2146
- moved: moved.length, added: added.length, removed: removed.length,
2147
- movedSample: moved.slice(0, 3), addedSample: added.slice(0, 3), removedSample: removed.slice(0, 3),
2148
- }
2149
2097
  }
2150
- let lastScreenPixels = null
2151
- let screenChangedPolls = 0
2152
- let lastRequestTotal = -1
2153
- let lastAppCommits = null
2154
- let lastNodeCount = null
2155
- // the last completed poll and the values it was compared against.
2156
- let report = null
2157
- // the still polls of the current run, when each began and answered
2158
- let stillPolls = []
2159
- let lastIdlePoll = null
2160
- let visuallyStillSince = 0
2161
- // counts across the whole budget: a flag that is true on every poll is a
2162
- // different bug from one that is true intermittently, and the two need
2163
- // opposite fixes (engine vs budget).
2164
- let polls = 0
2165
- let dirtyPolls = 0
2166
- let animatingPolls = 0
2167
- let layoutChangedPolls = 0
2168
- let webViewStartingPolls = 0
2169
- const screenUnchanged = (pixels, previous) => {
2170
- if (!pixels || !previous || pixels.width !== previous.width || pixels.height !== previous.height) return false
2171
- if (pixels === previous) return true
2172
- for (let i = 0; i < pixels.data.length; i++) {
2173
- if (pixels.data[i] !== previous.data[i]) return false
2174
- }
2175
- return true
2176
- }
2177
- const hierarchyUnchanged = (current, previous) =>
2178
- current !== null && previous !== null && current.length === previous.length &&
2179
- current.every((node, index) => sameNativeAccessibilityShape(node, previous[index], accessibilityBounds))
2180
- while (true) {
2181
- if (clockNow() >= deadline) {
2182
- if (!transitionWait) break
2183
- await transitionWait
2184
- transitionWait = null
2185
- // nothing polled while parked on the transition, and a loaded
2186
- // worker's late reply would spend the restarted budget unobserved.
2187
- if (transitionEndedAt !== null) deadline = Math.max(deadline, clockNow() + budgetMs)
2188
- if (clockNow() >= deadline) break
2189
- }
2190
- const pollStarted = clockNow()
2191
- const snapshot = await readSnapshot()
2192
- if (snapshot.runtimeUnsupported) return snapshot.runtimeUnsupported
2193
- // a read the deadline cut short observed nothing: the last full poll
2194
- // names what held the settle, not a worker that ran out of budget.
2195
- // the loop head drains a transition still in flight before it ends.
2196
- if (snapshot.workerBusy && clockNow() >= deadline && report) continue
2197
- polls++
2198
- report = { snapshot, nativeHierarchy: lastNativeHierarchy, layout: lastLayout, screenPixels: lastScreenPixels, requestTotal: lastRequestTotal, appCommits: lastAppCommits, nodeCount: lastNodeCount }
2199
- if (snapshot.layoutDirty) dirtyPolls++
2200
- if (snapshot.animating || snapshot.shellAnimating) animatingPolls++
2201
- if (snapshot.webViewStarting) webViewStartingPolls++
2202
- if (polls > 1 && snapshot.layout !== lastLayout) {
2203
- layoutChangedPolls++
2204
- lastLayoutChange = describeLayoutChange(lastNodeRows, snapshot.nodeRows)
2205
- }
2206
- const screenChanged = paintStill && !screenUnchanged(snapshot.screenPixels, lastScreenPixels)
2207
- if (polls > 1 && screenChanged) screenChangedPolls++
2208
- const strictOk =
2209
- !strict ||
2210
- (snapshot.renderStatsAvailable &&
2211
- !snapshot.animating &&
2212
- !snapshot.shellAnimating &&
2213
- !snapshot.layoutDirty)
2214
- // visually settled: no worker motion or layout work, no new layout
2215
- // commits, a stable mounted node count, no image content loading
2216
- // (unless motion alone is asked), no webview startup in progress,
2217
- // layout unchanged since the last poll. both modes wait out finite
2218
- // worker motion now; strict additionally implies the flags through
2219
- // strictOk and adds shell motion plus the blocking-stats floor. a
2220
- // null count or commit reading means the runtime does not report
2221
- // it, which reads as stable the way a missing stats block does.
2222
- // equal presented pixels can precede pending worker motion or layout.
2223
- // after that work drains, iOS's 3 s pixel phase may accept two equal
2224
- // native TreeNodes while paint-only playback continues. overlap
2225
- // hierarchy reads so neither the gesture nor screenshot deadline grows.
2226
- const maestroStill = snapshot.screenPixels !== null && !snapshot.workerBusy && snapshot.pendingFetches === 0 && snapshot.requestInFlight === 0 && !snapshot.webViewStarting &&
2227
- !snapshot.animating && !snapshot.shellAnimating && !snapshot.layoutDirty && (
2228
- !screenChanged || (clockNow() - start >= 3000 &&
2229
- hierarchyUnchanged(snapshot.nativeHierarchy, lastNativeHierarchy))
2230
- )
2231
- const idleSnapshot =
2232
- strictOk &&
2098
+ return { layout: nodes.join(';'), nodeRows, nativeHierarchy, visibleMotion, visibleMotionBy, animating, animatingBy, shellAnimating, shellBlockers, layoutDirty, pendingFetches, workerBusy, motionUnavailable, webViewStarting, webViewBlocker, renderStatsAvailable, requestTotal, requestInFlight, appCommits, nodeCount }
2099
+ }
2100
+
2101
+ // how long generic background network is allowed to keep us waiting AFTER
2102
+ // the screen is otherwise visually settled. apps with continuous traffic
2103
+ // (polling, realtime sockets, a tap that fires 20-50 fetches) never reach
2104
+ // requestInFlight===0 / a stable requestTotal, so requiring full network
2105
+ // quiet burns the ENTIRE budget on every command \u2014 the leading idle that
2106
+ // failed PR-preview recordings for network-heavy apps (3pc fight-pulse).
2107
+ // layout-stability + the image-loader already prove visible content
2108
+ // loaded (a data load changes layout; an image load shows in the loader),
2109
+ // so the generic request counters are a courtesy, not a gate: honor them
2110
+ // only within this grace once the screen is visually still.
2111
+ const networkQuietGraceMs = 1200
2112
+ let lastNativeHierarchy = null
2113
+ let lastLayout = ''
2114
+ let lastNodeRows = []
2115
+ // what moved between the last two differing polls, bounded; names the
2116
+ // nodes behind "layout changed" without keeping any poll history.
2117
+ let lastLayoutChange = null
2118
+ const describeLayoutChange = (before, after) => {
2119
+ const previous = new Map(before.map(([key, label, geometry]) => [key, [label, geometry]]))
2120
+ const moved = []
2121
+ const added = []
2122
+ const short = (label, key) => String(label).slice(0, 48) + ' [' + String(key).slice(0, 24) + ']'
2123
+ for (const [key, label, geometry] of after) {
2124
+ const was = previous.get(key)
2125
+ previous.delete(key)
2126
+ if (!was) added.push(short(label, key) + ' ' + geometry)
2127
+ else if (was[1] !== geometry) moved.push(short(label, key) + ' ' + was[1] + '->' + geometry)
2128
+ }
2129
+ const removed = [...previous].map(([key, [label, geometry]]) => short(label, key) + ' ' + geometry)
2130
+ return {
2131
+ moved: moved.length, added: added.length, removed: removed.length,
2132
+ movedSample: moved.slice(0, 3), addedSample: added.slice(0, 3), removedSample: removed.slice(0, 3),
2133
+ }
2134
+ }
2135
+ let screenChangedPolls = 0
2136
+ let lastRequestTotal = -1
2137
+ let lastAppCommits = null
2138
+ let lastNodeCount = null
2139
+ // the last completed poll and the values it was compared against.
2140
+ let report = null
2141
+ // the still polls of the current run, when each began and answered
2142
+ let stillPolls = []
2143
+ let lastIdlePoll = null
2144
+ let visuallyStillSince = 0
2145
+ // counts across the whole budget: a flag that is true on every poll is a
2146
+ // different bug from one that is true intermittently, and the two need
2147
+ // opposite fixes (engine vs budget).
2148
+ let polls = 0
2149
+ let dirtyPolls = 0
2150
+ let animatingPolls = 0
2151
+ let layoutChangedPolls = 0
2152
+ let webViewStartingPolls = 0
2153
+ const hierarchyUnchanged = (current, previous) =>
2154
+ current !== null && previous !== null && current.length === previous.length &&
2155
+ current.every((node, index) => sameNativeAccessibilityShape(node, previous[index], accessibilityBounds))
2156
+ while (true) {
2157
+ if (clockNow() >= deadline) {
2158
+ if (!transitionWait) break
2159
+ await transitionWait
2160
+ transitionWait = null
2161
+ // nothing polled while parked on the transition, and a loaded
2162
+ // worker's late reply would spend the restarted budget unobserved.
2163
+ if (transitionEndedAt !== null) deadline = Math.max(deadline, clockNow() + budgetMs)
2164
+ if (clockNow() >= deadline) break
2165
+ }
2166
+ const pollStarted = clockNow()
2167
+ const snapshot = await readSnapshot()
2168
+ if (snapshot.runtimeUnsupported) return snapshot.runtimeUnsupported
2169
+ // a read the deadline cut short observed nothing: the last full poll
2170
+ // names what held the settle, not a worker that ran out of budget.
2171
+ // the loop head drains a transition still in flight before it ends.
2172
+ if (snapshot.workerBusy && clockNow() >= deadline && report) continue
2173
+ polls++
2174
+ report = { snapshot, nativeHierarchy: lastNativeHierarchy, layout: lastLayout, requestTotal: lastRequestTotal, appCommits: lastAppCommits, nodeCount: lastNodeCount }
2175
+ if (snapshot.layoutDirty) dirtyPolls++
2176
+ if (snapshot.animating || snapshot.shellAnimating) animatingPolls++
2177
+ if (snapshot.webViewStarting) webViewStartingPolls++
2178
+ if (polls > 1 && snapshot.layout !== lastLayout) {
2179
+ layoutChangedPolls++
2180
+ lastLayoutChange = describeLayoutChange(lastNodeRows, snapshot.nodeRows)
2181
+ }
2182
+ // the first poll has nothing to compare, so it cannot prove a still screen
2183
+ const screenChanged = screenStill && (
2184
+ polls === 1 ||
2185
+ snapshot.visibleMotion ||
2186
+ (snapshot.appCommits !== null && lastAppCommits !== null && snapshot.appCommits !== lastAppCommits) ||
2187
+ (snapshot.nodeCount !== null && lastNodeCount !== null && snapshot.nodeCount !== lastNodeCount) ||
2188
+ snapshot.layout !== lastLayout ||
2189
+ (maestro && !hierarchyUnchanged(snapshot.nativeHierarchy, lastNativeHierarchy))
2190
+ )
2191
+ if (polls > 1 && screenChanged) screenChangedPolls++
2192
+ const strictOk =
2193
+ !strict ||
2194
+ (snapshot.renderStatsAvailable &&
2233
2195
  !snapshot.animating &&
2234
2196
  !snapshot.shellAnimating &&
2235
- !snapshot.layoutDirty &&
2236
- snapshot.pendingFetches === 0 &&
2237
- !snapshot.workerBusy &&
2238
- !snapshot.webViewStarting
2239
- const visuallyStill = maestro ? maestroStill :
2240
- idleSnapshot &&
2241
- (snapshot.appCommits === null || lastAppCommits === null || snapshot.appCommits === lastAppCommits) &&
2242
- (snapshot.nodeCount === null || lastNodeCount === null || snapshot.nodeCount === lastNodeCount) &&
2243
- !screenChanged &&
2244
- snapshot.layout === lastLayout
2245
- // generic network quiet: nothing in flight and no new requests issued.
2246
- const networkQuiet =
2247
- snapshot.requestInFlight === 0 && snapshot.requestTotal === lastRequestTotal
2248
- if (visuallyStill) {
2249
- if (visuallyStillSince === 0) visuallyStillSince = clockNow()
2250
- // two equal idle observations prove the interval between them.
2251
- // discarding the first requires a third worker round trip, which
2252
- // can exhaust the budget after a late image on a loaded host.
2253
- if (!maestro && !paintStill && stillPolls.length === 0 && lastIdlePoll) {
2254
- stillPolls.push(lastIdlePoll)
2255
- }
2256
- stillPolls.push({ started: pollStarted, answered: clockNow() })
2257
- // still long enough, counting only polls that began after a started
2258
- // transition drained.
2259
- const stillProven = () => {
2260
- const proving = stillPolls.filter((poll) => transitionEndedAt === null || poll.started >= transitionEndedAt)
2261
- return proving.length >= minimumStablePolls && clockNow() - proving[0].answered >= requiredStillMs
2262
- }
2263
- // settle once the screen has held still long enough AND either the
2264
- // network is genuinely quiet OR it has refused to quiet within the
2265
- // grace (continuous background traffic must not block forever).
2266
- if (
2267
- stillProven() &&
2268
- (maestro || networkQuiet || clockNow() - visuallyStillSince >= networkQuietGraceMs)
2269
- ) {
2270
- if (transitionWait) {
2271
- await transitionWait
2272
- transitionWait = null
2273
- }
2274
- if (stillProven()) return { settled: true, elapsed: clockNow() - start, blockedBy: '' }
2197
+ !snapshot.layoutDirty)
2198
+ // visually settled: no worker motion or layout work, no new layout
2199
+ // commits, a stable mounted node count, no image content loading
2200
+ // (unless motion alone is asked), no webview startup in progress,
2201
+ // layout unchanged since the last poll. both modes wait out finite
2202
+ // worker motion now; strict additionally implies the flags through
2203
+ // strictOk and adds shell motion plus the blocking-stats floor. a
2204
+ // null count or commit reading means the runtime does not report
2205
+ // it, which reads as stable the way a missing stats block does.
2206
+ // equal presented pixels can precede pending worker motion or layout.
2207
+ // after that work drains, iOS's 3 s pixel phase may accept two equal
2208
+ // native TreeNodes while paint-only playback continues. overlap
2209
+ // hierarchy reads so neither the gesture nor screenshot deadline grows.
2210
+ const maestroStill = !snapshot.workerBusy && snapshot.pendingFetches === 0 && snapshot.requestInFlight === 0 && !snapshot.webViewStarting &&
2211
+ !snapshot.animating && !snapshot.shellAnimating && !snapshot.layoutDirty && (
2212
+ !screenChanged || (clockNow() - start >= 3000 &&
2213
+ hierarchyUnchanged(snapshot.nativeHierarchy, lastNativeHierarchy))
2214
+ )
2215
+ const idleSnapshot =
2216
+ strictOk &&
2217
+ !snapshot.animating &&
2218
+ !snapshot.shellAnimating &&
2219
+ !snapshot.layoutDirty &&
2220
+ snapshot.pendingFetches === 0 &&
2221
+ !snapshot.workerBusy &&
2222
+ !snapshot.webViewStarting
2223
+ const visuallyStill = maestro ? maestroStill :
2224
+ idleSnapshot &&
2225
+ (snapshot.appCommits === null || lastAppCommits === null || snapshot.appCommits === lastAppCommits) &&
2226
+ (snapshot.nodeCount === null || lastNodeCount === null || snapshot.nodeCount === lastNodeCount) &&
2227
+ !screenChanged &&
2228
+ snapshot.layout === lastLayout
2229
+ // generic network quiet: nothing in flight and no new requests issued.
2230
+ const networkQuiet =
2231
+ snapshot.requestInFlight === 0 && snapshot.requestTotal === lastRequestTotal
2232
+ if (visuallyStill) {
2233
+ if (visuallyStillSince === 0) visuallyStillSince = clockNow()
2234
+ // two equal idle observations prove the interval between them.
2235
+ // discarding the first requires a third worker round trip, which
2236
+ // can exhaust the budget after a late image on a loaded host.
2237
+ if (!maestro && !screenStill && stillPolls.length === 0 && lastIdlePoll) {
2238
+ stillPolls.push(lastIdlePoll)
2239
+ }
2240
+ stillPolls.push({ started: pollStarted, answered: clockNow() })
2241
+ // still long enough, counting only polls that began after a started
2242
+ // transition drained.
2243
+ const stillProven = () => {
2244
+ const proving = stillPolls.filter((poll) => transitionEndedAt === null || poll.started >= transitionEndedAt)
2245
+ return proving.length >= minimumStablePolls && clockNow() - proving[0].answered >= requiredStillMs
2246
+ }
2247
+ // settle once the screen has held still long enough AND either the
2248
+ // network is genuinely quiet OR it has refused to quiet within the
2249
+ // grace (continuous background traffic must not block forever).
2250
+ if (
2251
+ stillProven() &&
2252
+ (maestro || networkQuiet || clockNow() - visuallyStillSince >= networkQuietGraceMs)
2253
+ ) {
2254
+ if (transitionWait) {
2255
+ await transitionWait
2256
+ transitionWait = null
2275
2257
  }
2276
- } else {
2277
- stillPolls = []
2278
- visuallyStillSince = 0
2258
+ if (stillProven()) return { settled: true, elapsed: clockNow() - start, blockedBy: '' }
2279
2259
  }
2280
- lastIdlePoll = idleSnapshot ? { started: pollStarted, answered: clockNow() } : null
2281
- lastNativeHierarchy = snapshot.nativeHierarchy
2282
- lastLayout = snapshot.layout
2283
- lastNodeRows = snapshot.nodeRows
2284
- lastScreenPixels = snapshot.screenPixels
2285
- lastRequestTotal = snapshot.requestTotal
2286
- lastAppCommits = snapshot.appCommits
2287
- lastNodeCount = snapshot.nodeCount
2288
- // reply latency belongs inside the poll interval; the stillness window
2289
- // above remains measured from completed observations.
2290
- const remainingPollMs = pollMs - (clockNow() - pollStarted)
2291
- if (remainingPollMs > 0) await clockSleep(remainingPollMs)
2292
- }
2293
- if (!report) {
2294
- return { settled: false, elapsed: clockNow() - start, blockedBy: 'no poll fit the budget' }
2295
- }
2296
- const last = report.snapshot
2297
- const blockers = []
2298
- if (!maestro && strict && !last.renderStatsAvailable) blockers.push('render stats unavailable')
2299
- if (!maestro && last.animating) blockers.push('animations still running' + (last.animatingBy ? ' (' + last.animatingBy + ')' : ''))
2300
- if (last.shellAnimating) blockers.push('animations still running (' + last.shellBlockers + ')')
2301
- if (!maestro && last.layoutDirty) blockers.push('layout still dirty')
2302
- if (!maestro && last.appCommits !== null && report.appCommits !== null && last.appCommits !== report.appCommits) blockers.push('layout commits still landing')
2303
- if (!maestro && last.nodeCount !== null && report.nodeCount !== null && last.nodeCount !== report.nodeCount) blockers.push('node count still changing')
2304
- if (last.pendingFetches > 0) blockers.push(last.pendingFetches + ' image fetches pending')
2305
- if (last.workerBusy) blockers.push('a render worker too busy to report')
2306
- if (last.webViewStarting) blockers.push(last.webViewBlocker || 'webView still starting')
2307
- if (!maestro && last.layout !== report.layout) blockers.push('layout still changing')
2308
- if (maestro && !hierarchyUnchanged(last.nativeHierarchy, report.nativeHierarchy)) blockers.push(last.nativeHierarchy === null ? 'native accessibility hierarchy unavailable' : 'native accessibility hierarchy still changing')
2309
- if (paintStill && !last.screenPixels) blockers.push('screen pixels unavailable')
2310
- else if (paintStill && !screenUnchanged(last.screenPixels, report.screenPixels)) blockers.push('screen pixels still changing')
2311
- if (last.requestInFlight > 0) blockers.push(last.requestInFlight + ' requests in flight')
2312
- else if (!maestro && last.requestTotal !== report.requestTotal) blockers.push('new requests issued')
2313
- if (polls < 2) blockers.push('sim too busy to poll twice')
2314
- // the last read is still: motion ended too near the deadline for the
2315
- // stillness window to hold before it.
2316
- if (!blockers.length) blockers.push('motion ended before stillness was proven')
2317
- return {
2318
- settled: false,
2319
- elapsed: clockNow() - start,
2320
- blockedBy:
2321
- blockers.join(', ') + ' over ' + polls + ' polls (layout changed ' + layoutChangedPolls +
2322
- 'x, layoutDirty ' + dirtyPolls + 'x, animating ' + animatingPolls + 'x, webViewStarting ' + webViewStartingPolls + 'x, screen changed ' + screenChangedPolls + 'x)' +
2323
- (lastLayoutChange ? '; last layout change ' + JSON.stringify(lastLayoutChange) : ''),
2324
- }
2325
- } finally {
2326
- unsubscribe?.()
2260
+ } else {
2261
+ stillPolls = []
2262
+ visuallyStillSince = 0
2263
+ }
2264
+ lastIdlePoll = idleSnapshot ? { started: pollStarted, answered: clockNow() } : null
2265
+ lastNativeHierarchy = snapshot.nativeHierarchy
2266
+ lastLayout = snapshot.layout
2267
+ lastNodeRows = snapshot.nodeRows
2268
+ lastRequestTotal = snapshot.requestTotal
2269
+ lastAppCommits = snapshot.appCommits
2270
+ lastNodeCount = snapshot.nodeCount
2271
+ // reply latency belongs inside the poll interval; the stillness window
2272
+ // above remains measured from completed observations.
2273
+ const remainingPollMs = pollMs - (clockNow() - pollStarted)
2274
+ if (remainingPollMs > 0) await clockSleep(remainingPollMs)
2275
+ }
2276
+ if (!report) {
2277
+ return { settled: false, elapsed: clockNow() - start, blockedBy: 'no poll fit the budget' }
2278
+ }
2279
+ const last = report.snapshot
2280
+ const blockers = []
2281
+ if (!maestro && strict && !last.renderStatsAvailable) blockers.push('render stats unavailable')
2282
+ if (!maestro && last.animating) blockers.push('animations still running' + (last.animatingBy ? ' (' + last.animatingBy + ')' : ''))
2283
+ if (last.shellAnimating) blockers.push('animations still running (' + last.shellBlockers + ')')
2284
+ if (!maestro && last.layoutDirty) blockers.push('layout still dirty')
2285
+ if (!maestro && last.appCommits !== null && report.appCommits !== null && last.appCommits !== report.appCommits) blockers.push('layout commits still landing')
2286
+ if (!maestro && last.nodeCount !== null && report.nodeCount !== null && last.nodeCount !== report.nodeCount) blockers.push('node count still changing')
2287
+ if (last.pendingFetches > 0) blockers.push(last.pendingFetches + ' image fetches pending')
2288
+ if (last.motionUnavailable) blockers.push('animation reporting unavailable')
2289
+ if (last.workerBusy && !last.motionUnavailable) blockers.push('a render worker too busy to report')
2290
+ if (last.webViewStarting) blockers.push(last.webViewBlocker || 'webView still starting')
2291
+ if (!maestro && last.layout !== report.layout) blockers.push('layout still changing')
2292
+ if (maestro && !hierarchyUnchanged(last.nativeHierarchy, report.nativeHierarchy)) blockers.push(last.nativeHierarchy === null ? 'native accessibility hierarchy unavailable' : 'native accessibility hierarchy still changing')
2293
+ if (screenStill && last.visibleMotion) blockers.push('visible motion continues (' + last.visibleMotionBy + ')')
2294
+ if (last.requestInFlight > 0) blockers.push(last.requestInFlight + ' requests in flight')
2295
+ else if (!maestro && last.requestTotal !== report.requestTotal) blockers.push('new requests issued')
2296
+ if (polls < 2) blockers.push('sim too busy to poll twice')
2297
+ // the last read is still: motion ended too near the deadline for the
2298
+ // stillness window to hold before it.
2299
+ if (!blockers.length) blockers.push('motion ended before stillness was proven')
2300
+ return {
2301
+ settled: false,
2302
+ elapsed: clockNow() - start,
2303
+ blockedBy:
2304
+ blockers.join(', ') + ' over ' + polls + ' polls (layout changed ' + layoutChangedPolls +
2305
+ 'x, layoutDirty ' + dirtyPolls + 'x, animating ' + animatingPolls + 'x, webViewStarting ' + webViewStartingPolls + 'x, screen changed ' + screenChangedPolls + 'x)' +
2306
+ (lastLayoutChange ? '; last layout change ' + JSON.stringify(lastLayoutChange) : ''),
2327
2307
  }
2328
2308
  })()`
2329
2309
  },