@wildshard/engine 0.1.18 → 0.1.19

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 (293) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/budgets/shard-size-baseline.json +10 -4
  3. package/index.html +6 -4
  4. package/lint/engine-sides.json +14 -0
  5. package/lint/ratchet.json +0 -68
  6. package/lint/ratchet.mjs +1 -4
  7. package/package.json +17 -15
  8. package/scripts/agent-sync.mjs +27 -8
  9. package/scripts/app-build/appCook.ts +8 -2
  10. package/scripts/app-build/catalogue.ts +10 -7
  11. package/scripts/app-build/gen.ts +22 -2
  12. package/scripts/app-build/isolation.d.mts +10 -0
  13. package/scripts/app-build/isolation.mjs +47 -0
  14. package/scripts/app-build/outputProducts.mjs +4 -0
  15. package/scripts/app-build/previousDeploy.d.mts +2 -0
  16. package/scripts/app-build/previousDeploy.mjs +10 -1
  17. package/scripts/app-build/serviceWorker.ts +10 -3
  18. package/scripts/app-build/splitOutput.mjs +4 -2
  19. package/scripts/app-build/standaloneOutput.d.mts +1 -1
  20. package/scripts/app-build/standaloneOutput.mjs +5 -3
  21. package/scripts/app-build/titlePreloads.d.mts +8 -0
  22. package/scripts/app-build/titlePreloads.mjs +69 -0
  23. package/scripts/app-build/worldMapAtlas.ts +10 -6
  24. package/scripts/app-build-pipeline.mjs +31 -3
  25. package/scripts/built-product.mjs +1 -1
  26. package/scripts/cell-mem-bench.mjs +81 -23
  27. package/scripts/check-custom-sections-zero.mjs +1 -1
  28. package/scripts/check-devserver.mjs +2 -0
  29. package/scripts/check-models.mjs +2 -0
  30. package/scripts/check-paths.allow.json +0 -115
  31. package/scripts/check-paths.mjs +2 -2
  32. package/scripts/check-platform-ratchets.mjs +2 -3
  33. package/scripts/chromium-keychain.d.mts +1 -1
  34. package/scripts/ci-static.sh +1 -1
  35. package/scripts/committed-fast-checks.mjs +0 -2
  36. package/scripts/content-sw-proof.mjs +2 -1
  37. package/scripts/cook-worker.mjs +9 -3
  38. package/scripts/cook.mjs +18 -5
  39. package/scripts/docs-inputs-proof.mjs +6 -6
  40. package/scripts/e7-voice-staging-proof.mjs +1 -1
  41. package/scripts/gate-related-tests.mjs +1 -1
  42. package/scripts/git-source-view.mjs +1 -1
  43. package/scripts/goldens/capture.mjs +17 -5
  44. package/scripts/grid-crossing-nightly.mjs +59 -0
  45. package/scripts/grid-crossing-qa.mjs +44 -0
  46. package/scripts/grid-crossing-ratchet.d.mts +6 -0
  47. package/scripts/grid-crossing-ratchet.mjs +52 -0
  48. package/scripts/grid-crossing-report.mjs +122 -0
  49. package/scripts/grid-crossing-stages.mjs +47 -0
  50. package/scripts/grid-crossing-tour.mjs +277 -0
  51. package/scripts/grid-crossing-walk-proof.mjs +124 -17
  52. package/scripts/host-ruler/roots.mjs +2 -2
  53. package/scripts/host-ruler.d.mts +91 -0
  54. package/scripts/host-ruler.mjs +565 -0
  55. package/scripts/live-prepush.py +3 -5
  56. package/scripts/loading-flow/benchmax.mjs +3 -1
  57. package/scripts/look-loop/test_look_loop.py +1 -38
  58. package/scripts/memory-proof.mjs +61 -6
  59. package/scripts/mmo-bots.mjs +8 -2
  60. package/scripts/net-lag-proof.mjs +219 -0
  61. package/scripts/night-market-kit-budget.mjs +2 -2
  62. package/scripts/offline-proof-rules.d.mts +2 -2
  63. package/scripts/offline-proof-rules.mjs +15 -4
  64. package/scripts/offline-proof.mjs +74 -13
  65. package/scripts/{shard-platform-output.mjs → output-reader.mjs} +1 -1
  66. package/scripts/page-release/content.d.mts +9 -1
  67. package/scripts/page-release/content.mjs +131 -17
  68. package/scripts/page-release/flow.mjs +36 -10
  69. package/scripts/page-release/stamp-content.mjs +24 -0
  70. package/scripts/page-release.mjs +28 -6
  71. package/scripts/page-size.mjs +2 -1
  72. package/scripts/pin-packs.ts +1 -1
  73. package/scripts/pins.ts +4 -4
  74. package/scripts/precommit-checks.mjs +1 -7
  75. package/scripts/precommit-jobs.mjs +0 -1
  76. package/scripts/precommit-source.py +1 -9
  77. package/scripts/program-discovery.mjs +1 -1
  78. package/scripts/ring-cook.mjs +2 -1
  79. package/scripts/ring-step.ts +1 -1
  80. package/scripts/script-scenario-metrics.mjs +1 -1
  81. package/scripts/shard-output-content.d.mts +1 -1
  82. package/scripts/shard-output-content.mjs +2 -2
  83. package/scripts/shard-outputs.mjs +1 -1
  84. package/scripts/shard-public.mjs +1 -1
  85. package/scripts/shard-wire-meter.mjs +24 -9
  86. package/scripts/side-parity.mjs +4 -2
  87. package/scripts/standalone-smoke.mjs +8 -3
  88. package/scripts/tier-textures.mjs +22 -4
  89. package/scripts/tile-bake-report.mjs +1 -1
  90. package/scripts/tile-bakes.mjs +1 -1
  91. package/scripts/title-assets.generated.json +2 -0
  92. package/scripts/tsconfig.json +0 -2
  93. package/scripts/vendor/basisu/LICENSE +201 -0
  94. package/scripts/vendor/basisu/basis_encoder.cjs +2 -0
  95. package/scripts/vendor/basisu/basis_encoder.wasm +0 -0
  96. package/scripts/vitest-push-guards.config.ts +1 -1
  97. package/scripts/vps/harden-apply.sh +4 -1
  98. package/scripts/vps/harden-prometheus.sh +176 -0
  99. package/scripts/vps/harden.sh +16 -0
  100. package/scripts/vps/rebuild.sh +18 -0
  101. package/scripts/vps/wildshard-config +6 -2
  102. package/scripts/worker-client-play.mjs +6 -2
  103. package/scripts/worktree-reap.mjs +5 -5
  104. package/src/.oxlintrc.json +3 -182
  105. package/src/client/app/entry.ts +10 -2
  106. package/src/client/engine/boot/bootCache.ts +2 -2
  107. package/src/client/engine/boot/bootTrace.ts +12 -4
  108. package/src/client/engine/boot/browserChunkRecovery.ts +4 -0
  109. package/src/client/engine/boot/clearDownloads.ts +5 -2
  110. package/src/client/engine/boot/contentRead.ts +11 -0
  111. package/src/client/engine/boot/gpuFiles.ts +4 -2
  112. package/src/client/engine/boot/lastEnd.ts +99 -12
  113. package/src/client/engine/boot/texturePack.ts +2 -2
  114. package/src/client/engine/net/netPlayer.ts +19 -2
  115. package/src/client/engine/net/otherPlayers.ts +55 -8
  116. package/src/client/engine/net/predictor.ts +33 -9
  117. package/src/client/engine/net/redial.ts +29 -6
  118. package/src/client/engine/pwa/cacheNames.ts +58 -1
  119. package/src/client/engine/pwa/sw.js +41 -11
  120. package/src/client/engine/render/dataLook.ts +152 -40
  121. package/src/client/engine/render/families/detail.ts +89 -0
  122. package/src/client/engine/render/families/pbr.ts +7 -1
  123. package/src/client/engine/render/look.ts +6 -0
  124. package/src/client/engine/render/lookLight.ts +103 -11
  125. package/src/client/engine/render/lookRender.ts +105 -0
  126. package/src/client/engine/saves/indexed.ts +2 -2
  127. package/src/client/engine/telemetry/browserErrors.ts +24 -3
  128. package/src/client/engine/telemetry/staleBuildReport.ts +22 -1
  129. package/src/client/engine/ui/debugOptions.ts +1 -1
  130. package/src/client/engine/ui/lookLightOption.ts +10 -6
  131. package/src/client/engine/ui/namePrompt.ts +7 -0
  132. package/src/client/game/boot/audio.generated.ts +114 -114
  133. package/src/client/game/boot/bytes.generated.ts +118 -220
  134. package/src/client/game/boot/placedSpawn.ts +35 -0
  135. package/src/client/game/boot/spawnDownload.ts +25 -6
  136. package/src/client/game/boot/versions.generated.ts +7 -5
  137. package/src/client/game/devScene/hook.ts +291 -0
  138. package/src/client/game/grid/cellLoading.ts +12 -2
  139. package/src/client/game/grid/live.ts +112 -16
  140. package/src/client/game/grid/liveSession.ts +33 -2
  141. package/src/client/game/grid/mapAtlas.ts +18 -4
  142. package/src/client/game/grid/minimapBlend.ts +15 -5
  143. package/src/client/game/grid/oneWayIn.ts +5 -1
  144. package/src/client/game/grid/placedCells.ts +114 -12
  145. package/src/client/game/grid/placedContent.ts +85 -0
  146. package/src/client/game/grid/prefetch.ts +9 -1
  147. package/src/client/game/grid/productInputs.ts +3 -1
  148. package/src/client/game/grid/productLeases.ts +4 -1
  149. package/src/client/game/grid/products.ts +8 -4
  150. package/src/client/game/grid/roadLook.ts +24 -15
  151. package/src/client/game/grid/roadLookPlatform.ts +4 -2
  152. package/src/client/game/grid/roadResources.ts +24 -0
  153. package/src/client/game/grid/roadSign.worker.ts +4 -3
  154. package/src/client/game/grid/roadSignPaint.ts +16 -5
  155. package/src/client/game/grid/roadSignPreparation.ts +4 -3
  156. package/src/client/game/grid/roadSignScale.ts +8 -0
  157. package/src/client/game/grid/roadTileCapture.worker.ts +3 -1
  158. package/src/client/game/grid/roadTileCaptureWorker.ts +2 -1
  159. package/src/client/game/grid/roadTileWrite.worker.ts +4 -2
  160. package/src/client/game/grid/roadTileWriter.ts +2 -1
  161. package/src/client/game/grid/screenReports.ts +39 -0
  162. package/src/client/game/grid/session.ts +20 -4
  163. package/src/client/game/grid/softWallLook.ts +25 -8
  164. package/src/client/game/mainMenu.ts +6 -2
  165. package/src/client/game/plugin/context.ts +2 -1
  166. package/src/client/game/plugin/followedMovers.ts +7 -1
  167. package/src/client/game/quest/figures.ts +2 -0
  168. package/src/client/game/session/finish.ts +6 -0
  169. package/src/client/game/shardfile/assetCache.ts +4 -4
  170. package/src/client/game/shardfile/client.ts +4 -1
  171. package/src/client/game/shardfile/clientAssets.ts +9 -5
  172. package/src/client/game/shardfile/clientLibrary.ts +1 -1
  173. package/src/client/game/shardfile/clientWater.ts +51 -9
  174. package/src/client/game/shardfile/clientWorker.ts +19 -7
  175. package/src/client/game/shardfile/look.ts +8 -3
  176. package/src/client/game/shardfile/product.ts +34 -7
  177. package/src/client/game/shardfile/productChecks.ts +2 -2
  178. package/src/client/game/shardfile/productCost.ts +2 -2
  179. package/src/client/game/shardfile/readAsset.ts +2 -2
  180. package/src/client/game/shardfile/reflectingWater.ts +73 -0
  181. package/src/client/game/shardfile/seatGrace.ts +9 -0
  182. package/src/client/game/shardfile/skinPlayback.ts +1 -1
  183. package/src/client/game/systems/npc/figureRows.ts +9 -0
  184. package/src/client/host/online/doctor.ts +2 -0
  185. package/src/client/host/online/linkScreens.ts +30 -4
  186. package/src/client/host/standalone/shell.ts +4 -0
  187. package/src/cook/game/astc6Encode.ts +55 -0
  188. package/src/cook/game/astc6Wasm.ts +176 -0
  189. package/src/cook/game/cookJob.ts +30 -6
  190. package/src/cook/game/cookWorker.ts +38 -11
  191. package/src/cook/game/entryTotals.ts +51 -24
  192. package/src/cook/game/shardCook.ts +35 -7
  193. package/src/cook/game/spawnParts.ts +33 -8
  194. package/src/cook/game/tierTextures.ts +87 -14
  195. package/src/server/engine/ai/bossContenders.ts +27 -3
  196. package/src/server/engine/ai/phases.ts +1 -1
  197. package/src/server/engine/entities/creatureRefill.ts +9 -2
  198. package/src/server/engine/net/ledgerBook.ts +2 -0
  199. package/src/server/engine/net/room.ts +15 -0
  200. package/src/server/engine/sim/respawn.ts +8 -0
  201. package/src/server/game/boss/arenaRoomEntry.ts +5 -1
  202. package/src/server/game/boss/arenaRoomNative.ts +2 -0
  203. package/src/server/game/boss/native.ts +2 -1
  204. package/src/server/game/boss/nativeWake.ts +9 -5
  205. package/src/server/game/boss/openArenaNative.ts +2 -2
  206. package/src/server/game/boss/openArenaRoom.ts +3 -1
  207. package/src/server/game/grid/room.ts +44 -3
  208. package/src/server/game/grid/simulation.ts +23 -0
  209. package/src/server/game/population/mixedRoster.ts +11 -3
  210. package/src/server/game/population/nativeBake.ts +8 -3
  211. package/src/server/game/population/nativeReturns.ts +6 -3
  212. package/src/server/game/population/roster.ts +5 -3
  213. package/src/server/game/quest/eliteDrops.ts +15 -4
  214. package/src/server/game/quest/nativeChapter.ts +1 -1
  215. package/src/server/game/quest/nativeComposition.ts +5 -1
  216. package/src/server/game/riding/nativeTaming.ts +10 -6
  217. package/src/server/game/riding/wildRefill.ts +3 -2
  218. package/src/server/game/shardfile/bossRow.ts +4 -2
  219. package/src/server/game/shardfile/homeKeeper.ts +4 -2
  220. package/src/server/host/bake/headlessWorker.ts +1 -1
  221. package/src/server/host/dedicated/cellHost.ts +98 -16
  222. package/src/server/host/dedicated/cellProtocol.ts +16 -1
  223. package/src/server/host/dedicated/cellWorker.ts +8 -5
  224. package/src/server/host/dedicated/dedicatedRoom.ts +16 -6
  225. package/src/server/host/dedicated/gridCells.ts +15 -6
  226. package/src/server/host/dedicated/loopLag.ts +21 -0
  227. package/src/server/host/dedicated/main.ts +13 -5
  228. package/src/server/host/dedicated/packReader.ts +3 -3
  229. package/src/server/host/dedicated/placementFile.ts +3 -2
  230. package/src/server/host/dedicated/roadRoom.ts +34 -4
  231. package/src/server/host/dedicated/serverMetrics.ts +126 -0
  232. package/src/server/host/dedicated/socketPump.ts +21 -4
  233. package/src/server/host/dedicated/workerTable.ts +15 -4
  234. package/src/server/host/dedicated/world.ts +65 -7
  235. package/src/server/host/headless.ts +1 -1
  236. package/src/server/host/headlessRuntime.ts +1 -1
  237. package/src/server/host/standalone/roadWorld.ts +15 -3
  238. package/src/server/host/standalone/serverHost.ts +4 -1
  239. package/src/server/host/standalone/serverProduct.ts +41 -11
  240. package/src/shared/engine/ai/BossBrain.ts +8 -0
  241. package/src/shared/game/boss/wake.ts +6 -0
  242. package/src/shared/game/devColliders.ts +47 -0
  243. package/src/shared/game/eliteSystem.ts +8 -0
  244. package/src/shared/game/grid/allocator.ts +3 -0
  245. package/src/shared/game/grid/placementRows.ts +5 -2
  246. package/src/shared/game/plugin/bossRecord.ts +3 -2
  247. package/src/shared/game/shardfile/ktx2Targets.ts +23 -3
  248. package/src/shared/game/shardfile/outputDescriptor.ts +9 -5
  249. package/src/shared/game/shardfile/packReads.ts +28 -3
  250. package/src/shared/game/shardfile/serverPack.ts +9 -0
  251. package/src/shared/game/systems/looks/trampleField.ts +2 -0
  252. package/src/shared/host/formatJsonSchema.ts +2 -2
  253. package/src/tsconfig.json +1 -27
  254. package/lint/host-reviews.json +0 -14
  255. package/lint/listed-view-code.json +0 -13
  256. package/lint/platform-pending-users.json +0 -2520
  257. package/lint/platform-pending-users.md +0 -18
  258. package/scripts/cell-mem/metrics-preload.mjs +0 -65
  259. package/scripts/check-closed-components.d.mts +0 -7
  260. package/scripts/check-closed-components.mjs +0 -87
  261. package/scripts/g571-hosts.d.mts +0 -3
  262. package/scripts/g571-hosts.mjs +0 -54
  263. package/scripts/host-ruler/register-migrate.mjs +0 -242
  264. package/scripts/listed-view-code.d.mts +0 -7
  265. package/scripts/listed-view-code.mjs +0 -93
  266. package/scripts/look-loop/fit-lut.py +0 -142
  267. package/scripts/look-loop/palette-delta.py +0 -183
  268. package/scripts/look-loop/regions/driftwood-isle.json +0 -25
  269. package/scripts/look-loop/regions/far-reach.json +0 -225
  270. package/scripts/look-loop/regions/open-plot-night-market.json +0 -855
  271. package/scripts/look-loop/regions/pine-hollow.json +0 -22
  272. package/scripts/look-loop/regions/sunscar-dunes.json +0 -281
  273. package/scripts/platform-chargebacks.d.mts +0 -9
  274. package/scripts/platform-chargebacks.mjs +0 -135
  275. package/scripts/shard-component-spans.d.mts +0 -15
  276. package/scripts/shard-component-spans.mjs +0 -18
  277. package/scripts/shard-components.d.mts +0 -16
  278. package/scripts/shard-components.mjs +0 -363
  279. package/scripts/shard-platform-hosts.d.mts +0 -2
  280. package/scripts/shard-platform-hosts.mjs +0 -93
  281. package/scripts/shard-platform-sections.d.mts +0 -2
  282. package/scripts/shard-platform-sections.mjs +0 -9
  283. package/scripts/shard-platform.d.mts +0 -76
  284. package/scripts/shard-platform.mjs +0 -1072
  285. package/src/.oxfmtrc.json +0 -48
  286. package/src/scripts/ask-new.sh +0 -29
  287. package/src/scripts/asks.mjs +0 -142
  288. package/src/scripts/herdr-prompt.sh +0 -34
  289. package/src/scripts/herdr-question-open.sh +0 -67
  290. package/src/scripts/md-wrap.mjs +0 -229
  291. /package/scripts/{shard-platform-format.d.mts → node-format.d.mts} +0 -0
  292. /package/scripts/{shard-platform-format.mjs → node-format.mjs} +0 -0
  293. /package/scripts/{shard-platform-output.d.mts → output-reader.d.mts} +0 -0
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env python3
2
- """The look loop's Python logic: CIEDE2000 against Sharma, Wu and Dalal's (2005) reference pairs, the sRGB to Lab
3
- conversion, capture-pattern globbing, and targets.py's capture finding and seed-mode prompts. Run by
2
+ """The look loop's Python logic: targets.py's capture finding, seed-mode prompts and job polling. Run by
4
3
  test/look-loop.test.ts; standalone: python3 scripts/look-loop/test_look_loop.py"""
5
4
  import importlib.util
6
5
  import tempfile
@@ -17,47 +16,11 @@ def load(name, file):
17
16
  return mod
18
17
 
19
18
 
20
- try: # palette-delta.py needs numpy and Pillow; hosted CI's Python has neither, so its checks run where they exist
21
- import numpy, PIL # noqa: F401
22
- PD = load('palette_delta', 'palette-delta.py')
23
- except ImportError:
24
- PD = None
25
19
  TG = load('targets', 'targets.py')
26
20
  SCRATCH = HERE.parent.parent / 'tmp' if (HERE.parent.parent / 'tmp').is_dir() else None # the repo's tmp/, not /tmp
27
- NEEDS = unittest.skipUnless(PD, 'numpy and Pillow are not installed')
28
-
29
-
30
- @NEEDS
31
- class DeltaE(unittest.TestCase):
32
- def test_sharma_pairs(self):
33
- pairs = [
34
- ((50.0, 2.6772, -79.7751), (50.0, 0.0, -82.7485), 2.0425),
35
- ((50.0, 0.0, 0.0), (50.0, -1.0, 2.0), 2.3669),
36
- ((50.0, 2.5, 0.0), (73.0, 25.0, -18.0), 27.1492),
37
- ((60.2574, -34.0099, 36.2677), (60.4626, -34.1751, 39.4387), 1.2644),
38
- ]
39
- for a, b, want in pairs:
40
- self.assertAlmostEqual(PD.ciede2000(a, b), want, places=3)
41
- self.assertAlmostEqual(PD.ciede2000(b, a), want, places=3)
42
-
43
- def test_identity_and_lab(self):
44
- self.assertEqual(PD.ciede2000((40, 10, -5), (40, 10, -5)), 0.0)
45
- L, a, b = PD.srgb_to_lab((255, 255, 255))
46
- self.assertAlmostEqual(L, 100, delta=0.05); self.assertAlmostEqual(a, 0, delta=0.05); self.assertAlmostEqual(b, 0, delta=0.05)
47
- L, a, b = PD.srgb_to_lab((255, 0, 0))
48
- self.assertAlmostEqual(L, 53.24, delta=0.1); self.assertAlmostEqual(a, 80.09, delta=0.2); self.assertAlmostEqual(b, 67.20, delta=0.2)
49
21
 
50
22
 
51
23
  class Files(unittest.TestCase):
52
- @NEEDS
53
- def test_frame_path(self):
54
- with tempfile.TemporaryDirectory(dir=SCRATCH) as d:
55
- for name in ['capture-1-fp-front.jpg', 'r2-capture-1-fp-front.jpg']:
56
- (Path(d) / name).write_bytes(b'x')
57
- self.assertEqual(PD.frame_path(f'{d}/capture-{{n}}-*.jpg', 1).name, 'capture-1-fp-front.jpg')
58
- self.assertIsNone(PD.frame_path(f'{d}/capture-{{n}}-*.jpg', 2))
59
- self.assertEqual(PD.frame_path(f'{d}/r2-capture-{{n}}-*.jpg', 1).name, 'r2-capture-1-fp-front.jpg')
60
-
61
24
  def test_captures(self):
62
25
  with tempfile.TemporaryDirectory(dir=SCRATCH) as d:
63
26
  for name in ['capture-1-fp-front.jpg', 'capture-5-top.jpg', 'r2-capture-1-fp-front.jpg', 'mockup-1-fp-front.jpg']:
@@ -6,13 +6,17 @@
6
6
  // device loads, the grid's resident cells and claims, the JS heap (Chromium) and, on Chromium, the renderer and GPU
7
7
  // process footprints. Phone tier, iPhone 17 Pro viewport (402x874, 3x pixel density), headless.
8
8
  // scripts/browser-lane.sh node scripts/memory-proof.mjs --base=<staging or loopback url> [--engine=chromium|webkit]
9
- // [--out=tmp/<lane>/memory-proof] [--label=<name>] [--edge=0] [--budget-mb=<n>]
9
+ // [--out=tmp/<lane>/memory-proof] [--label=<name>] [--edge=0] [--budget-mb=<n>] [--dump]
10
+ // --inspector-buffers=keep: the old launch, whose DevTools Network sessions buffer every response body (~500 MB here).
11
+ // --dump (Chromium, PZ24): a memory-infra dump at every phase, the renderer's footprint by allocator (V8, PartitionAlloc's
12
+ // array buffers, malloc, Oilpan, Skia, GPU shared memory), so what holds the process is read, not guessed.
10
13
  // --budget-mb fails the run (exit 1) when the ledger's GPU+RAM peak passes n MB: the gate a later lane can hold.
11
14
  import { spawnSync } from 'node:child_process';
12
15
  import { mkdirSync, writeFileSync } from 'node:fs';
13
16
  import { join, resolve as absolute } from 'node:path';
14
17
  import { chromium, webkit } from 'playwright';
15
18
  import { KEYCHAIN_ARGS } from './chromium-keychain.mjs';
19
+ import { launchMemoryBrowser } from './chromium-memory-browser.mjs';
16
20
  import { saveFixture } from './debug-settings.mjs';
17
21
  import { pageMemoryAttributionExpression } from './memory-report-snapshot.mjs';
18
22
 
@@ -66,8 +70,14 @@ const PAGE_READ = `(() => {
66
70
 
67
71
  /** @type {Record<string, unknown>} */
68
72
  const result = { lane: 'opus-iosmem', engine: engineName, base, label, at: new Date().toISOString(), phases: [], errors: [] };
69
- const browser = await (engineName === 'webkit' ? webkit : chromium).launch({ headless: true,
70
- args: engineName === 'chromium' ? [...KEYCHAIN_ARGS, '--mute-audio', '--use-angle=metal', '--ignore-gpu-blocklist', '--enable-precise-memory-info'] : [] });
73
+ // PZ24: Chromium through launchMemoryBrowser, so Playwright's Network sessions (the page's and every worker's) keep no
74
+ // response bodies. Before, DevTools' NetworkResourcesData held ~500 MB of the game's fetched bytes in the renderer's
75
+ // buffer partition (memory-infra, after a full GC), a cost a player's phone, with no inspector attached, never has.
76
+ const chromiumArgs = ['--use-angle=metal', '--ignore-gpu-blocklist', '--enable-precise-memory-info', ...args.dump === undefined ? [] : ['--js-flags=--expose-gc']];
77
+ const launched = engineName === 'webkit' ? webkit.launch({ headless: true }).then(browser => ({ browser, close: () => browser.close() }))
78
+ : args['inspector-buffers'] === 'keep' ? chromium.launch({ headless: true, args: [...KEYCHAIN_ARGS, ...chromiumArgs] }).then(browser => ({ browser, close: () => browser.close() }))
79
+ : launchMemoryBrowser(chromiumArgs);
80
+ const { browser, close: closeBrowser } = await launched;
71
81
  let code = 0;
72
82
  try {
73
83
  const context = await browser.newContext({ viewport: { width: 402, height: 874 }, deviceScaleFactor: 3, isMobile: engineName === 'chromium', hasTouch: true,
@@ -82,7 +92,9 @@ try {
82
92
  const pageCdp = engineName === 'chromium' ? await context.newCDPSession(page) : null;
83
93
  const heapProfile = args['heap-profile'] !== undefined && pageCdp !== null;
84
94
  /** Chromium only: the live JS heap after a full collection, so garbage awaiting GC is told apart from what is held. */
85
- const heapAfterGc = async () => { if (pageCdp === null) return null; await pageCdp.send('HeapProfiler.collectGarbage'); return Math.round((await pageCdp.send('Runtime.getHeapUsage')).usedSize / MB); };
95
+ const heapAfterGc = async () => { if (pageCdp === null) return null; await pageCdp.send('HeapProfiler.collectGarbage');
96
+ // --dump: the workers' isolates too (an idle worker may never collect on its own)
97
+ if (args.dump !== undefined) for (const worker of page.workers()) await worker.evaluate('globalThis.gc?.()').catch(() => undefined); return Math.round((await pageCdp.send('Runtime.getHeapUsage')).usedSize / MB); };
86
98
  const footprint = async () => {
87
99
  if (cdp === null) return null;
88
100
  const info = await cdp.send('SystemInfo.getProcessInfo'), pids = info.processInfo.filter(row => row.type === 'renderer' || row.type === 'GPU');
@@ -90,9 +102,42 @@ try {
90
102
  const mb = (/** @type {string} */ type) => Math.round(pids.filter(row => row.type === type).reduce((sum, row) => sum + (sizes[String(row.id)] ?? 0), 0) / MB);
91
103
  return { rendererMB: mb('renderer'), gpuMB: mb('GPU') };
92
104
  };
105
+ /** PZ24: the renderer's memory-infra allocators at this moment (before the GC heapAfterGc runs), in MB. */
106
+ const allocators = async (deterministic = false) => {
107
+ if (cdp === null || args.dump === undefined) return null;
108
+ /** @type {any[]} */ const events = [];
109
+ const onData = (/** @type {any} */ data) => { events.push(...data.value); };
110
+ cdp.on('Tracing.dataCollected', onData);
111
+ let dumped = { success: false };
112
+ try {
113
+ const done = new Promise(resolve => { cdp.once('Tracing.tracingComplete', resolve); });
114
+ await cdp.send('Tracing.start', { traceConfig: { includedCategories: ['disabled-by-default-memory-infra'],
115
+ // no periodic dumps: only the one requested below (Playwright types the config as string pairs)
116
+ memoryDumpConfig: /** @type {Record<string, string>} */ (/** @type {unknown} */ ({ triggers: [] })) }, transferMode: 'ReportEvents' });
117
+ // deterministic: Chrome collects every isolate (page and workers) first, so freed buffers are not counted
118
+ try { dumped = await cdp.send('Tracing.requestMemoryDump', { deterministic, levelOfDetail: 'detailed' }); }
119
+ finally { await cdp.send('Tracing.end'); await done; }
120
+ } finally { cdp.off('Tracing.dataCollected', onData); }
121
+ const info = await cdp.send('SystemInfo.getProcessInfo'), renderers = new Set(info.processInfo.filter(row => row.type === 'renderer').map(row => row.id));
122
+ /** @type {Record<string, number>} */ const sizes = {};
123
+ for (const event of events) {
124
+ if (event.ph !== 'v' || !renderers.has(event.pid)) continue;
125
+ const all = event.args?.dumps?.allocators ?? {};
126
+ for (const [name, node] of Object.entries(all)) {
127
+ const depth = name.split('/').length; if (depth > 3 && !(args.dump === 'buckets' && name.startsWith('partition_alloc/partitions/'))) continue;
128
+ const size = node.attrs?.size?.value; if (size === undefined) continue;
129
+ sizes[name] = (sizes[name] ?? 0) + Number.parseInt(size, 16);
130
+ }
131
+ }
132
+ return { ok: dumped.success, mb: Object.fromEntries(Object.entries(sizes).filter(([, b]) => b >= MB).sort((a, b) => b[1] - a[1]).map(([k, b]) => [k, Math.round(b / MB * 10) / 10])) };
133
+ };
93
134
  const phase = async (/** @type {string} */ name) => {
94
- const row = { phase: name, ...await page.evaluate(PAGE_READ), process: await footprint(), heapAfterGcMB: await heapAfterGc() };
135
+ const dump = await allocators();
136
+ const row = { phase: name, ...await page.evaluate(PAGE_READ), process: await footprint(), dump, heapAfterGcMB: await heapAfterGc() };
137
+ if (dump !== null) console.log(` allocators ${JSON.stringify(Object.fromEntries(Object.entries(dump.mb).filter(([k]) => k.split('/').length === 1)))}`);
95
138
  row.processAfterGc = pageCdp === null ? null : await footprint();
139
+ row.dumpAfterGc = await allocators(true);
140
+ if (row.dumpAfterGc !== null) console.log(` after GC ${JSON.stringify(Object.fromEntries(Object.entries(row.dumpAfterGc.mb).filter(([k]) => k.split('/').length === 1 || /partitions\/[a-z_]+$|v8\/[a-z]+$/u.test(k))))} workers ${page.workers().length}`);
96
141
  /** @type {unknown[]} */ (result.phases).push(row);
97
142
  await page.screenshot({ path: join(out, `${label}-${name}.jpg`), type: 'jpeg', quality: 60 }).catch(() => undefined);
98
143
  const t = row.totalsMB;
@@ -117,6 +162,16 @@ try {
117
162
  await page.getByText('DONE', { exact: true }).click({ timeout: 2000 }).catch(() => undefined);
118
163
  await sleep(10_000);
119
164
  await phase('playing');
165
+ if (args.snapshot !== undefined && pageCdp !== null) {
166
+ // --snapshot: the page's heap at Playing (written beside the json), for a holder the ledger does not name. V8 keeps
167
+ // tracking object moves after it, so the later phases of a --snapshot run read a little high (result.snapshot).
168
+ result.snapshot = true;
169
+ const { createWriteStream } = await import('node:fs'), file = createWriteStream(join(out, `${label}-playing.heapsnapshot`));
170
+ const onChunk = (/** @type {any} */ c) => { file.write(c.chunk); };
171
+ pageCdp.on('HeapProfiler.addHeapSnapshotChunk', onChunk);
172
+ await pageCdp.send('HeapProfiler.takeHeapSnapshot', { reportProgress: false, captureNumericValue: false, exposeInternals: true });
173
+ pageCdp.off('HeapProfiler.addHeapSnapshotChunk', onChunk); await new Promise(resolve => { file.end(resolve); });
174
+ }
120
175
  // 40 s more without moving: a page that keeps growing while the player stands still is the leak, not the walk.
121
176
  /** @type {unknown[]} */ const still = []; result.still = still;
122
177
  for (let i = 0; i < 4; i++) { await sleep(10_000); const at = await page.evaluate(() => ({ heapMB: (() => { const memory = /** @type {any} */ (performance).memory; return memory ? Math.round(memory.usedJSHeapSize / 1048576) : null; })(), loading: /** @type {any} */ (window).__wildshard.shard.grid.state().cells.filter((/** @type {any} */ c) => c.shows === 'loading').length })); still.push({ s: (i + 1) * 10, ...at, process: await footprint() }); console.log(`still +${(i + 1) * 10}s ${JSON.stringify(still.at(-1))}`); }
@@ -152,7 +207,7 @@ try {
152
207
  } catch (error) { code = 1; /** @type {string[]} */ (result.errors).push(String(error).slice(0, 400)); console.log(`FAIL ${String(error).slice(0, 400)}`); }
153
208
  finally {
154
209
  writeFileSync(join(out, `${label}.json`), `${JSON.stringify(result, null, 2)}\n`);
155
- await browser.close();
210
+ await closeBrowser();
156
211
  }
157
212
  console.log(`memory proof ${label}: ${code === 0 ? 'done' : 'FAIL'} → ${join(out, `${label}.json`)}`);
158
213
  process.exit(code);
@@ -6,6 +6,7 @@
6
6
  // node scripts/mmo-bots.mjs replica [--remote wildshard] --server-from <main commit> ... (MP1.2: that commit's server code)
7
7
  // node scripts/mmo-bots.mjs replica --remote wildshard-agent --bots-on-host [--bot-cpus 14-15] ... (MP1.2: bots on the box too)
8
8
  // node scripts/mmo-bots.mjs staging [--bots 2] [--seconds 60] (at most 4: one address)
9
+ // node scripts/mmo-bots.mjs staging --tailnet ... (NET-LAG NL3: the same, over staging's tailnet Serve address, no Cloudflare)
9
10
  // Both read the signed staging release file and check it against the public key setup.sh pins. The bots are built from that
10
11
  // release's own commit (its tree, an offline install, build-server's `--entry`), so their build and wire are the server's.
11
12
  // `replica` runs that release's exact server bundle (downloaded, SHA-256 checked) on loopback, with production's shape: its
@@ -46,7 +47,7 @@ const [mode = '', ...rest] = process.argv.slice(2);
46
47
  const { values } = parseArgs({ args: rest, options: { bots: { type: 'string' }, seconds: { type: 'string' }, seats: { type: 'string', default: '32' }, workers: { type: 'string', default: '4' },
47
48
  cells: { type: 'string', default: 'driftwood-isle' }, database: { type: 'string', default: 'memory:' }, keep: { type: 'boolean', default: false },
48
49
  remote: { type: 'string' }, cpus: { type: 'string', default: '9-13' }, 'server-from': { type: 'string' },
49
- 'bots-on-host': { type: 'boolean', default: false }, 'bot-cpus': { type: 'string', default: '14-15' } } });
50
+ 'bots-on-host': { type: 'boolean', default: false }, 'bot-cpus': { type: 'string', default: '14-15' }, tailnet: { type: 'boolean', default: false } } });
50
51
  const serverFrom = values['server-from'];
51
52
  if (serverFrom !== undefined && (mode !== 'replica' || !/^[0-9a-f]{40}$/u.test(serverFrom))) throw new Error('--server-from is a full commit, for a replica');
52
53
  // These reach the host's shell inside the replica's env line: only slugs and whole numbers.
@@ -152,7 +153,12 @@ process.once('exit', () => { for (const child of [botsChild, room]) if (child !=
152
153
  try {
153
154
  /** @type {{ players: number, p95: number, max: number, drops: number, ticksPerSecond: number, rss: number }[]} */
154
155
  const readings = [];
155
- let url = release.socket.replace(/\/$/u, '');
156
+ // NET-LAG NL3: `staging --tailnet` dials staging's tailnet Serve address (the other door on the staging list) instead of the one
157
+ // the release names, so the same bots measure the wire without Cloudflare
158
+ if (values.tailnet && mode !== 'staging') throw new Error('--tailnet is for staging');
159
+ const tailnetDoor = STAGING_SOCKETS[1];
160
+ if (values.tailnet && tailnetDoor === undefined) throw new Error('No tailnet door on the staging list');
161
+ let url = values.tailnet && tailnetDoor !== undefined ? tailnetDoor : release.socket.replace(/\/$/u, '');
156
162
  if (mode === 'replica') {
157
163
  const tarball = join(work, 'server.tar.gz'), served = join(work, 'server');
158
164
  const bytes = serverBundle !== null ? readFileSync(serverBundle) : Buffer.from(await (await fetch(`${BUNDLES}/${release.bundle.name}`, { signal: AbortSignal.timeout(300_000) })).arrayBuffer());
@@ -0,0 +1,219 @@
1
+ #!/usr/bin/env node
2
+ // NET-LAG NL8 (meta docs/plans/NET-LAG-PLAN.md): "buttery" walking and running, read by numbers. Per engine, layout and deck
3
+ // shard, a headless page enters the shard, walks, sprints and boosts (hoverboard, Shift) for `--seconds` each, and prints the
4
+ // plan's bar per run; any miss exits 1.
5
+ // B1 drawn frames (the renderer's own, so a 30 fps cap reads as 30): none over 2x the frame budget nor over 50 ms, p99 at
6
+ // most 1.25x it. Budget = 1000 / min(display Hz, the tier's cap), read from the drawn rate before moving.
7
+ // B2 own character on foot (walk and sprint): at most 2 corrections a minute, worst render offset at most 0.10 m.
8
+ // B3 others: interpolation delay at most 120 ms from 10 s after entry, and no frame held past the buffer (`interpHeld`, from entry).
9
+ // B4 Driftwood only: the rope bridge crossed with forced 60 ms frames, the feet never under its planks, no fall.
10
+ // J205: staging, preview or a loopback page only, never production; the page's sockets are held to the one door.
11
+ // node scripts/net-lag-proof.mjs [--base=https://staging.wildshard.io] [--socket=wss://rooms-staging.wildshard.io]
12
+ // [--engines=chromium,webkit] [--layouts=desktop,phone] [--shards=driftwood-isle,...] [--seconds=20] [--out=<dir>]
13
+ // [--delay-ms=<one way>] [--rig=<app dist>,<work dir>,<key.json>] [--no-bridge]
14
+ // `--rig` opens engine's loopback room (online-rig.mjs) per shard, with a dist stamped for http://127.0.0.1:18799/release.json;
15
+ // `--delay-ms=90` holds every frame each way in the page for 90 ms: a 180 ms round trip on the loopback rig (NL12).
16
+ import { mkdirSync, writeFileSync } from 'node:fs';
17
+ import { join, resolve as absolute } from 'node:path';
18
+ import { chromium, webkit } from 'playwright';
19
+ import { KEYCHAIN_ARGS } from './chromium-keychain.mjs';
20
+ import { saveFixture } from './debug-settings.mjs';
21
+ import { guardStagingSockets } from './staging-proof-lines.mjs';
22
+
23
+ const arg = (/** @type {string} */ name, /** @type {string} */ fallback) => process.argv.find(value => value.startsWith(`--${name}=`))?.slice(name.length + 3) ?? fallback;
24
+ const DECK = ['driftwood-isle', 'sunscar-dunes', 'nalati-grasslands', 'far-reach', 'pine-hollow', 'nine-dragon-stack'];
25
+ const TITLES = /** @type {Record<string, string>} */ ({ 'pine-hollow': 'PINE HOLLOW', 'nalati-grasslands': 'NALATI GRASSLANDS', 'nine-dragon-stack': 'NINE DRAGON STACK', 'sunscar-dunes': 'SIGNAL DUNES', 'far-reach': 'SKY REACH', 'driftwood-isle': 'DRIFTWOOD ISLE' });
26
+ const rigArg = arg('rig', ''), base = arg('base', rigArg === '' ? 'https://staging.wildshard.io' : '').replace(/\/$/u, '');
27
+ if (rigArg === '' && !/^https:\/\/(staging|preview)\.wildshard\.io$|^http:\/\/127\.0\.0\.1:\d+$/u.test(base)) throw new Error('--base takes staging, preview or a loopback page only: never production (J205)');
28
+ const engines = arg('engines', 'chromium,webkit').split(','), layouts = arg('layouts', 'desktop,phone').split(','), shards = arg('shards', DECK.join(',')).split(',');
29
+ const SECONDS = Number(arg('seconds', '20')), DELAY_MS = Number(arg('delay-ms', '0')), out = absolute(arg('out', 'tmp/net-lag-proof')), bridge = !process.argv.includes('--no-bridge');
30
+ if (!Number.isFinite(SECONDS) || SECONDS < 5 || !Number.isFinite(DELAY_MS) || DELAY_MS < 0) throw new Error('--seconds is at least 5 and --delay-ms at least 0');
31
+ mkdirSync(out, { recursive: true });
32
+ const IPHONE = { viewport: { width: 402, height: 874 }, deviceScaleFactor: 3, hasTouch: true, userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 26_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Mobile/15E148 Safari/604.1' };
33
+ /** Driftwood's way from the pier to the rope bridge (test/fixtures/headless/driftwood-optional-run.ts) and across it (NL5's route). */
34
+ const TO_BRIDGE = [[0, -186.5], [-8, -172], [-17, -161], [-20, -150], [-30, -142], [-30, -130], [-30, -118], [-30, -106], [-30, -104], [-24, -80], [-22, -71.5], [-8, -50], [10.8, -27.8], [15.4, -8.6], [15.6, -7], [13.88, 11.88]];
35
+ const ACROSS = [[15.29, 13.29], [23.99, 21.99], [31.98, 29.98], [34.38, 32.38], [35.8, 33.8]], SPAN = { a: { x: 15.29, z: 13.29 }, b: { x: 34.38, z: 32.38 } };
36
+ /** @param {number} ms */
37
+ const sleep = ms => new Promise(resolve => { setTimeout(resolve, ms); });
38
+
39
+ /** In the page: drawn frames (page frames that rendered), a forced-slow-frame switch, and the socket delay. Self-contained. @param {number} delay */
40
+ function pageProbe(delay) {
41
+ const W = /** @type {any} */ (window), S = W.__netLag = { on: false, drawn: /** @type {number[]} */ ([]), last: 0, slowMs: 0, rendered: false, worst: 0 };
42
+ // a drawn frame is a page frame that rendered at least once (a frame may render offscreen passes too; a capped one renders none)
43
+ // B2's worst render offset, over the window the proof opens (the client's own `worstOffset` runs from entry)
44
+ const frame = (/** @type {number} */ now) => { const offset = W.__wildshard?.world?.player?.renderOffset; if (S.on && offset !== undefined) S.worst = Math.max(S.worst, offset.length()); if (S.rendered) { if (S.on && S.last !== 0) S.drawn.push(now - S.last); S.last = now; S.rendered = false; } requestAnimationFrame(frame); };
45
+ requestAnimationFrame(frame);
46
+ const hook = () => {
47
+ const renderer = W.__wildshard?.world?.game?.renderer;
48
+ if (renderer === undefined || renderer.__netLag === true) return;
49
+ renderer.__netLag = true;
50
+ const render = renderer.render.bind(renderer);
51
+ renderer.render = (/** @type {unknown} */ scene, /** @type {unknown} */ camera) => {
52
+ if (S.slowMs > 0 && !S.rendered) { const until = performance.now() + S.slowMs; while (performance.now() < until) { /* NL5's forced long frame */ } }
53
+ S.rendered = true;
54
+ return render(scene, camera);
55
+ };
56
+ };
57
+ setInterval(hook, 250);
58
+ if (delay > 0) {
59
+ const P = WebSocket.prototype, held = new WeakMap();
60
+ const raw = /** @type {any} */ (P), sendFn = raw.send, addFn = raw.addEventListener, removeFn = raw.removeEventListener;
61
+ P.send = function send(/** @type {any} */ data) { setTimeout(() => { if (this.readyState === 1) sendFn.call(this, data); }, delay); };
62
+ P.addEventListener = function addEventListener(/** @type {string} */ type, /** @type {any} */ listener, /** @type {any} */ options) {
63
+ if (type !== 'message' || typeof listener !== 'function') { addFn.call(this, type, listener, options); return; }
64
+ const late = (/** @type {Event} */ event) => { setTimeout(() => { listener.call(this, event); }, delay); };
65
+ held.set(listener, late);
66
+ addFn.call(this, type, late, options);
67
+ };
68
+ P.removeEventListener = function removeEventListener(/** @type {string} */ type, /** @type {any} */ listener, /** @type {any} */ options) { removeFn.call(this, type, held.get(listener) ?? listener, options); };
69
+ }
70
+ }
71
+
72
+ /** @param {number[]} list @param {number} p */
73
+ const at = (list, p) => { const sorted = [...list].sort((a, b) => a - b); return sorted.length === 0 ? 0 : Number((sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * p))] ?? 0).toFixed(1)); };
74
+
75
+ /** One run: enter `slug` on `engineName` at `layout`, walk, sprint, boost (and the bridge on Driftwood). @param {import('playwright').Browser} browser @param {string} engineName @param {string} layout @param {string} slug @param {string} site @param {string} socket */
76
+ async function runOne(browser, engineName, layout, slug, site, socket) {
77
+ const context = await browser.newContext(layout === 'phone' ? { ...IPHONE, isMobile: engineName === 'chromium' } : { viewport: { width: 1280, height: 800 }, deviceScaleFactor: 1 });
78
+ if (socket !== '') await context.addInitScript(guardStagingSockets, socket);
79
+ await context.addInitScript(pageProbe, DELAY_MS);
80
+ await saveFixture(context, { scope: 'device', key: 'devMode', data: true });
81
+ await saveFixture(context, { scope: 'global', key: 'settings', data: { music: false, sfx: false, volume: 0 }, merge: true });
82
+ const page = await context.newPage(), errors = /** @type {string[]} */ ([]), row = /** @type {Record<string, any>} */ ({ engine: engineName, layout, slug, delayMs: DELAY_MS * 2 });
83
+ page.on('pageerror', error => { errors.push(error.message.slice(0, 200)); });
84
+ const t0 = Date.now();
85
+ /** @type {ReturnType<typeof setInterval> | undefined} */
86
+ let sampler;
87
+ try {
88
+ await page.goto(`${site}/?chunk=${slug}&mute=1&nolock=1&skipintro=1`, { waitUntil: 'load', timeout: 90_000 });
89
+ for (const ends = Date.now() + 120_000; Date.now() < ends;) {
90
+ if (await page.locator('#ws-name-box input').isVisible().catch(() => false)) break;
91
+ const clicked = await page.evaluate(title => {
92
+ const all = [...document.querySelectorAll('body *')], head = all.find(e => e.children.length === 0 && (e.textContent ?? '').trim().toUpperCase() === title);
93
+ for (let up = head?.parentElement; up; up = up.parentElement) {
94
+ const load = [...up.querySelectorAll('*')].find(e => e.children.length === 0 && (e.textContent ?? '').trim().toUpperCase() === 'LOAD');
95
+ if (load !== undefined) { /** @type {HTMLElement} */ (load.closest('button') ?? load).click(); return true; }
96
+ }
97
+ return false;
98
+ }, TITLES[slug] ?? slug.toUpperCase().replaceAll('-', ' ')).catch(() => false);
99
+ if (await page.getByText(/could not load/iu).isVisible().catch(() => false)) throw new Error('the shard could not load');
100
+ await sleep(clicked ? 6000 : 1000);
101
+ }
102
+ await page.locator('#ws-name-box input').fill(`Lag ${engineName[0] ?? 'x'}${Date.now().toString(36).slice(-3)}`);
103
+ await page.locator('#ws-name-box button[type=submit]').click();
104
+ await page.waitForFunction(() => typeof window.__workerClient === 'function' && /** @type {any} */ (window).__wildshard?.world?.player !== undefined, undefined, { timeout: 150_000 });
105
+ await page.evaluate(() => /** @type {any} */ (window).__wildshard?.world?.hud.enterNow());
106
+ await page.waitForFunction(() => (window.__workerClient?.().frames ?? 0) > 30, undefined, { timeout: 90_000 });
107
+ if (await page.evaluate(() => /** @type {any} */ (window).__wildshard?.world?.game.app.clock.paused === true)) await page.getByRole('button', { name: /^resume$/iu }).click().catch(() => undefined);
108
+ row.enterMs = Date.now() - t0;
109
+ const entered = Date.now(), delays = /** @type {{ t: number, delay: number }[]} */ ([]), heldFrom = await page.evaluate(() => window.__workerClient?.().interpHeld ?? 0);
110
+ const report = () => page.evaluate(() => { const w = window.__workerClient?.(); return w === undefined ? null : { corrections: w.corrections, worst: w.worstOffset, delay: w.delayMs, held: w.interpHeld, falls: w.falls, missed: { ...w.missed } }; });
111
+ sampler = setInterval(() => { void report().then(r => { if (r !== null) delays.push({ t: Date.now() - entered, delay: r.delay }); return undefined; }).catch(() => undefined); }, 250);
112
+ await sleep(2000);
113
+ // the budget: the drawn rate standing still, against the display's 60 Hz (headless)
114
+ await page.evaluate(() => { const S = /** @type {any} */ (window).__netLag; S.drawn.length = 0; S.on = true; });
115
+ await sleep(2000);
116
+ const idle = await page.evaluate(() => /** @type {any} */ (window).__netLag.drawn.slice());
117
+ row.budgetMs = at(idle, 0.5) > 25 ? 1000 / 30 : 1000 / 60;
118
+ // B4 first, from the spawn on the pier, where its route starts
119
+ if (bridge && slug === 'driftwood-isle') row.bridge = await crossBridge(page);
120
+ await page.evaluate(() => { /** @type {any} */ (window).__netLag.worst = 0; });
121
+ const before = await report();
122
+ const phase = async (/** @type {string} */ name, /** @type {string[]} */ keys) => {
123
+ await page.evaluate(() => { const S = /** @type {any} */ (window).__netLag; S.drawn.length = 0; });
124
+ const from = await report();
125
+ for (const key of keys) await page.keyboard.down(key);
126
+ for (let left = SECONDS * 1000, turn = 0; left > 0; left -= 1000, turn++) {
127
+ await sleep(1000);
128
+ if (turn % 5 === 2) { const side = turn % 10 === 2 ? 'KeyA' : 'KeyD'; await page.keyboard.down(side); await sleep(300); await page.keyboard.up(side); }
129
+ }
130
+ for (const key of [...keys].reverse()) await page.keyboard.up(key);
131
+ const drawn = await page.evaluate(() => /** @type {any} */ (window).__netLag.drawn.slice()), to = await report();
132
+ // what this phase's corrections disagreed on (position, grounded, board, swim, ride), for the row a miss becomes
133
+ const missed = Object.fromEntries(Object.entries(to?.missed ?? {}).filter(([key]) => key !== 'gap').map(([key, value]) => [key, value - (/** @type {Record<string, number> | undefined} */ (from?.missed)?.[key] ?? 0)]).filter(([, value]) => value !== 0));
134
+ return { name, corrections: (to?.corrections ?? 0) - (from?.corrections ?? 0), missed, frames: drawn.length, p50: at(drawn, 0.5), p99: at(drawn, 0.99), max: at(drawn, 1), over2x: drawn.filter((/** @type {number} */ ms) => ms > 2 * row.budgetMs).length, over50: drawn.filter((/** @type {number} */ ms) => ms > 50).length };
135
+ };
136
+ row.walk = await phase('walk', ['KeyW']);
137
+ row.sprint = await phase('sprint', ['KeyW', 'ShiftLeft']);
138
+ const foot = await report(), footWorst = await page.evaluate(() => /** @type {any} */ (window).__netLag.worst);
139
+ await page.keyboard.press('KeyH'); await sleep(600);
140
+ row.boost = await phase('boost', ['KeyW', 'ShiftLeft']);
141
+ await page.keyboard.press('KeyH'); await sleep(600);
142
+ const after = await report();
143
+ const footMinutes = (2 * SECONDS) / 60, late = delays.filter(sample => sample.t >= 10_000);
144
+ row.b1 = { budgetMs: Number(row.budgetMs.toFixed(1)), over2x: row.walk.over2x + row.sprint.over2x + row.boost.over2x, over50: row.walk.over50 + row.sprint.over50 + row.boost.over50, p99: Math.max(row.walk.p99, row.sprint.p99, row.boost.p99) };
145
+ row.b1.ok = row.b1.over2x === 0 && row.b1.over50 === 0 && row.b1.p99 <= 1.25 * row.budgetMs;
146
+ row.b2 = { perMinute: Number((((foot?.corrections ?? 0) - (before?.corrections ?? 0)) / footMinutes).toFixed(1)), worst: Number(footWorst.toFixed(3)) };
147
+ row.b2.ok = row.b2.perMinute <= 2 && row.b2.worst <= 0.1;
148
+ row.b3 = { delayMaxAfter10s: late.length === 0 ? null : Math.max(...late.map(sample => sample.delay)), held: (after?.held ?? 0) - heldFrom };
149
+ row.b3.ok = row.b3.delayMaxAfter10s !== null && row.b3.delayMaxAfter10s <= 120 && row.b3.held === 0;
150
+ if (row.bridge !== undefined) row.b4 = { ok: row.bridge.reached && row.bridge.under === 0 && row.bridge.falls === 0, ...row.bridge };
151
+ row.ok = row.b1.ok && row.b2.ok && row.b3.ok && (row.b4?.ok ?? true);
152
+ await page.screenshot({ path: join(out, `${engineName}-${layout}-${slug}.png`) }).catch(() => undefined);
153
+ } catch (error) {
154
+ row.error = String(error instanceof Error ? error.message : error).slice(0, 300); row.ok = false;
155
+ await page.screenshot({ path: join(out, `${engineName}-${layout}-${slug}-error.png`) }).catch(() => undefined);
156
+ }
157
+ clearInterval(sampler);
158
+ row.errors = errors.slice(0, 5);
159
+ await context.close();
160
+ return row;
161
+ }
162
+
163
+ /** B4: walk Driftwood's pier to the rope bridge, then cross it with every drawn frame forced to 60 ms. @param {import('playwright').Page} page */
164
+ async function crossBridge(page) {
165
+ const where = () => page.evaluate(() => { const p = /** @type {any} */ (window).__wildshard.world.player.position; return { x: p.x, y: p.y, z: p.z }; });
166
+ const steer = (/** @type {number} */ x, /** @type {number} */ z, /** @type {boolean} */ sprint) => page.evaluate(([toX, toZ, fast]) => { const p = /** @type {any} */ (window).__wildshard.world.player; p.yaw = Math.atan2(-(toX - p.position.x), -(toZ - p.position.z)); p.touchMove.y = 1; p.touchMove.x = 0; p.touchSprint = fast === 1; }, [x, z, sprint ? 1 : 0]);
167
+ const stop = () => page.evaluate(() => { const p = /** @type {any} */ (window).__wildshard.world.player; p.touchMove.y = 0; p.touchSprint = false; });
168
+ let lowest = Infinity, under = 0;
169
+ const go = async (/** @type {number} */ x, /** @type {number} */ z, /** @type {boolean} */ sprint, /** @type {boolean} */ watch) => {
170
+ for (const ends = Date.now() + 20_000; Date.now() < ends;) {
171
+ const p = await where();
172
+ if (watch) {
173
+ const along = ((p.x - SPAN.a.x) * (SPAN.b.x - SPAN.a.x) + (p.z - SPAN.a.z) * (SPAN.b.z - SPAN.a.z)) / ((SPAN.b.x - SPAN.a.x) ** 2 + (SPAN.b.z - SPAN.a.z) ** 2);
174
+ if (along > 0.1 && along < 0.9) { lowest = Math.min(lowest, p.y); if (p.y < 3) under++; } // NL5: the planks stay over 5 m; the gully floor is under 0
175
+ }
176
+ if (Math.hypot(p.x - x, p.z - z) < 0.7) return true;
177
+ await steer(x, z, sprint); await sleep(50);
178
+ }
179
+ return false;
180
+ };
181
+ const fallsBefore = await page.evaluate(() => window.__workerClient?.().falls ?? 0);
182
+ for (const [x = 0, z = 0] of TO_BRIDGE) if (!await go(x, z, true, false)) { await stop(); return { reached: false, at: await where(), under: 0, falls: 0, lowest: null }; }
183
+ await page.evaluate(() => { /** @type {any} */ (window).__netLag.slowMs = 60; });
184
+ let reached = true;
185
+ for (const [index, [x = 0, z = 0]] of ACROSS.entries()) reached = await go(x, z, index % 2 === 1, true) && reached;
186
+ for (const [x = 0, z = 0] of [...ACROSS].reverse().slice(1)) reached = await go(x, z, true, true) && reached;
187
+ await page.evaluate(() => { /** @type {any} */ (window).__netLag.slowMs = 0; });
188
+ await stop();
189
+ const falls = (await page.evaluate(() => window.__workerClient?.().falls ?? 0)) - fallsBefore;
190
+ return { reached, under, falls, lowest: Number.isFinite(lowest) ? Number(lowest.toFixed(2)) : null };
191
+ }
192
+
193
+ const rows = /** @type {Record<string, any>[]} */ ([]);
194
+ for (const engineName of engines) {
195
+ const browser = await (engineName === 'webkit' ? webkit : chromium).launch({ headless: true, args: engineName === 'chromium' ? [...KEYCHAIN_ARGS, '--use-angle=metal', '--ignore-gpu-blocklist', '--autoplay-policy=user-gesture-required'] : [] });
196
+ try {
197
+ for (const slug of shards) {
198
+ /** @type {{ base: string, close: () => Promise<void> }} */
199
+ let site = { base, close: () => Promise.resolve() }, socket = /^https:\/\/(staging|preview)\./u.test(base) ? arg('socket', 'wss://rooms-staging.wildshard.io') : arg('socket', '');
200
+ if (rigArg !== '') {
201
+ const [dist = '', work = '', keyFile = ''] = rigArg.split(','), { openRig, WORLD_PORT } = await import('./online-rig.mjs');
202
+ site = await openRig({ dist: absolute(dist), work: absolute(work, slug), keyFile, pgBin: 'memory:', pgData: '', shard: slug, crossing: false });
203
+ socket = `ws://127.0.0.1:${String(WORLD_PORT)}`;
204
+ }
205
+ try {
206
+ for (const layout of layouts) {
207
+ const row = await runOne(browser, engineName, layout, slug, site.base, socket);
208
+ rows.push(row);
209
+ const { walk: _w, sprint: _s, boost: _b, bridge: _r, ...brief } = row;
210
+ console.log(`${row.ok === true ? 'ok ' : 'MISS'} ${JSON.stringify(brief)}`);
211
+ }
212
+ } finally { await site.close(); }
213
+ }
214
+ } finally { await browser.close(); }
215
+ }
216
+ writeFileSync(join(out, 'net-lag-proof.json'), `${JSON.stringify({ base: rigArg !== '' ? 'loopback rig' : base, delayMs: DELAY_MS * 2, seconds: SECONDS, rows }, null, 1)}\n`);
217
+ const missed = rows.filter(row => row.ok !== true);
218
+ console.log(`net-lag proof: ${String(rows.length - missed.length)}/${String(rows.length)} runs buttery${missed.length === 0 ? '' : `; missed: ${missed.map(row => `${String(row.engine)} ${String(row.layout)} ${String(row.slug)} ${['b1', 'b2', 'b3', 'b4'].filter(key => row[key]?.ok === false).join('+') || 'error'}`).join(', ')}`}`);
219
+ process.exit(missed.length === 0 ? 0 : 1);
@@ -6,10 +6,10 @@ import { resolve } from 'node:path';
6
6
  import { pathToFileURL } from 'node:url';
7
7
  import * as v from 'valibot';
8
8
  import { readBuiltShardfile } from './built-product.mjs';
9
- import { outputFormat } from './shard-platform-format.mjs';
9
+ import { outputFormat } from './node-format.mjs';
10
10
  import { tileBakeCensus } from './tile-bakes.mjs';
11
11
 
12
- // Use the existing format-only Node resolver installed by shard-platform-format, as tile-bakes does.
12
+ // Use the existing format-only Node resolver installed by node-format.mjs, as tile-bakes does.
13
13
  const { TilesSchema } = await import('@wildshard/format/shardSections');
14
14
  const product = 'open-plot-night-market';
15
15
  /** @param {Uint8Array} bytes */
@@ -2,7 +2,7 @@ export interface RequestRow {
2
2
  n: number; t: number; url: string; type: string; origin: 'page' | 'sw'; phase: string; step: string;
3
3
  servedBy: 'service-worker' | 'network' | 'failed' | 'pending'; status: number; fail: string;
4
4
  }
5
- export interface ScreenSample { t: number; phase: string; step: string; card: boolean; title: boolean; player: boolean; failCard: string; text: string }
5
+ export interface ScreenSample { t: number; phase: string; step: string; card: boolean; title: boolean; player: boolean; failCard: string; text: string; inside?: string | null }
6
6
  export interface Failure { shard: string; rule: string; url?: string; detail?: string }
7
7
  export type Outcome = 'play' | 'seat-wait' | 'title' | 'stalled' | 'error' | 'no-resume' | 'outside-world';
8
8
  export const DECK_SHARDS: readonly { slug: string; card: string }[];
@@ -21,6 +21,6 @@ export function textureForm(path: string): { name: string; form: 'img' | 'ktx2'
21
21
  export function judge(run: {
22
22
  shard: string; channel: 'staging' | 'preview'; mode: string; entry: string; rows: readonly RequestRow[];
23
23
  samples: readonly ScreenSample[]; outcome: Outcome; warm?: ReadonlySet<string>; layout?: boolean; walkthrough?: boolean;
24
- requireWorld?: boolean; proofError?: string; leaks?: number; placed?: boolean;
24
+ requireWorld?: boolean; proofError?: string; leaks?: number; placed?: boolean; linked?: boolean;
25
25
  }): Failure[];
26
26
  export function servedCounts(rows: readonly RequestRow[]): Record<string, number>;
@@ -34,7 +34,7 @@ export const CRITICAL_PHASES = Object.freeze(['start', 'download', 'load', 'none
34
34
  * servedBy: 'service-worker' | 'network' | 'failed' | 'pending', status: number, fail: string }} RequestRow */
35
35
  /** One poll of the screen.
36
36
  * @typedef {{ t: number, phase: string, step: string, card: boolean, title: boolean, player: boolean, failCard: string,
37
- * text: string }} ScreenSample */
37
+ * text: string, inside?: string | null }} ScreenSample */
38
38
  /** One reason a run is red.
39
39
  * @typedef {{ shard: string, rule: string, url?: string, detail?: string }} Failure */
40
40
  /** @typedef {'play' | 'seat-wait' | 'title' | 'stalled' | 'error' | 'no-resume' | 'outside-world'} Outcome */
@@ -77,7 +77,7 @@ const failed = row => (row.servedBy === 'failed' && row.fail !== 'net::ERR_ABORT
77
77
  * The red rules of one entry. `warm` is the paths the warm visit read (undefined for the warm visit itself).
78
78
  * @param {{ shard: string, channel: 'staging' | 'preview', mode: string, entry: string, rows: readonly RequestRow[],
79
79
  * samples: readonly ScreenSample[], outcome: Outcome, warm?: ReadonlySet<string>, layout?: boolean, walkthrough?: boolean,
80
- * requireWorld?: boolean, proofError?: string, leaks?: number, placed?: boolean }} run
80
+ * requireWorld?: boolean, proofError?: string, leaks?: number, placed?: boolean, linked?: boolean }} run
81
81
  * @returns {Failure[]}
82
82
  */
83
83
  export function judge(run) {
@@ -114,9 +114,20 @@ export function judge(run) {
114
114
  const proof = run.proofError !== undefined && run.proofError !== '';
115
115
  out.push({ shard, rule: proof ? 'proof-error' : 'load-error-screen', detail: proof ? run.proofError : samples.at(-1)?.text.slice(0, 200) ?? '' });
116
116
  }
117
- if (run.outcome === 'no-resume') out.push({ shard, rule: 'no-resume', detail: 'reopening the page showed the title, not the shard' });
117
+ // OF9: on a world build, reopening the page lands on the title by design (QA 11-12 row 35, Jake: "I expected reload to go back to
118
+ // main menu"; GO1: only a tap enters a world that seats a body), so its resume is the title, and the deck is the way back in.
119
+ // GC26: preview's grid page is a world page too (its deck enters the grid), so a placed shard's resume is the title there as well.
120
+ const titleByDesign = (channel === 'staging' || run.placed === true) && run.outcome === 'no-resume';
121
+ if (run.outcome === 'no-resume' && !titleByDesign) out.push({ shard, rule: 'no-resume', detail: 'reopening the page showed the title, not the shard' });
118
122
  if ((run.leaks ?? 0) > 0) out.push({ shard, rule: 'offline-leak', detail: `${String(run.leaks)} reads reached the server while offline (the URLs are in the run's screens log)` });
119
- if (run.requireWorld === true && run.outcome !== 'play' && !(run.outcome === 'outside-world' && run.placed === false)) out.push({ shard, rule: 'not-in-world', detail: run.outcome });
123
+ if (run.requireWorld === true && run.outcome !== 'play' && !titleByDesign && !(run.outcome === 'outside-world' && run.placed === false)) out.push({ shard, rule: 'not-in-world', detail: run.outcome });
124
+ // GC26 (J311): preview's deck enters a placed shard in its grid cell, so the player ends inside that cell (the grid's `inside`), not
125
+ // on a one-shard page (no grid: `inside` absent) or another cell. A shard with no card (the Open Plots, Pastel Plain, Ink & Cel) is
126
+ // entered by its `?chunk=` link, which opens its one-shard page (GC25/GC27: the deck shows 7 grid cards), so it is judged as that page.
127
+ if (channel === 'preview' && run.placed === true && run.entry === 'deck' && run.linked !== true && run.outcome === 'play') {
128
+ let last; for (const sample of samples) if (sample.player) last = sample;
129
+ if (last !== undefined && last.inside !== shard) out.push({ shard, rule: 'not-in-cell', detail: last.inside === undefined ? 'a one-shard page, not the grid' : `inside ${last.inside ?? 'the road'}` });
130
+ }
120
131
  // OF3: a world build never enters a shard its grid doesn't place (a draft such as Thin Ice): the title's "Not in this world yet"
121
132
  // is the right end there, and wrong for a placed shard or a build with no world (preview opens every shard).
122
133
  if (run.outcome === 'outside-world' && !(channel === 'staging' && run.placed === false))