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