castle-web-cli 0.4.232 → 0.4.233

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 (355) hide show
  1. package/dist/agent-failures.d.ts +8 -0
  2. package/dist/agent-failures.js +19 -2
  3. package/dist/agent-prompts.d.ts +1 -1
  4. package/dist/agent-prompts.js +10 -3
  5. package/dist/agent.d.ts +64 -3
  6. package/dist/agent.js +170 -81
  7. package/dist/castle-host/host.d.ts +1 -0
  8. package/dist/castle-host/host.js +51 -3
  9. package/dist/castleJson.d.ts +4 -2
  10. package/dist/castleJson.js +2 -0
  11. package/dist/check.d.ts +3 -1
  12. package/dist/check.js +11 -1
  13. package/dist/devSessionStorage.js +47 -1
  14. package/dist/importPinMismatch.d.ts +22 -0
  15. package/dist/importPinMismatch.js +77 -0
  16. package/dist/importRegression.js +3 -15
  17. package/dist/imports.d.ts +10 -3
  18. package/dist/imports.js +88 -20
  19. package/dist/index.js +5 -4
  20. package/dist/init.js +1 -1
  21. package/dist/platformDoc.js +22 -0
  22. package/dist/routerFences.d.ts +5 -0
  23. package/dist/routerFences.js +12 -2
  24. package/dist/save-deck.d.ts +5 -0
  25. package/dist/save-deck.js +37 -4
  26. package/dist/serve.js +3 -0
  27. package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
  28. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  29. package/dist/shell/index.html +2 -2
  30. package/dist/taskSteer.d.ts +13 -0
  31. package/dist/taskSteer.js +22 -2
  32. package/kits/base/castle.json +1 -1
  33. package/kits/base/package-lock.json +1 -1
  34. package/kits/base/sdk/README.md +79 -2
  35. package/kits/base/sdk/avatar.d.ts +6 -2
  36. package/kits/base/sdk/avatar.js +12 -4
  37. package/kits/base/sdk/castle.d.ts +1 -1
  38. package/kits/base/sdk/commands.d.ts +14 -0
  39. package/kits/base/sdk/hub.d.ts +6 -2
  40. package/kits/base/sdk/hub.js +13 -0
  41. package/kits/base/sdk/multiplayer.js +17 -1
  42. package/kits/base/sdk/save.js +2 -1
  43. package/kits/base/sdk/server/hub.d.ts +87 -0
  44. package/kits/base/sdk/server/hub.js +70 -0
  45. package/kits/base/sdk/server/platformHandle.d.ts +31 -1
  46. package/kits/base/sdk/server/storage.d.ts +13 -0
  47. package/kits/base/sdk/server/storage.js +46 -0
  48. package/kits/base/sdk/server/wrapper.d.ts +36 -5
  49. package/kits/base/sdk/server/wrapper.js +83 -8
  50. package/kits/hub-game/CLAUDE.md +329 -11
  51. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  52. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  53. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  54. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  55. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  56. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  57. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  58. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  59. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  60. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  61. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  62. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  63. package/kits/hub-game/code/client/actorBudget.js +47 -0
  64. package/kits/hub-game/code/client/attention.js +11 -2
  65. package/kits/hub-game/code/client/avatar.js +309 -35
  66. package/kits/hub-game/code/client/avatarCap.js +228 -0
  67. package/kits/hub-game/code/client/avatarColors.js +70 -0
  68. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  69. package/kits/hub-game/code/client/avatarShare.js +251 -0
  70. package/kits/hub-game/code/client/ballot.js +467 -0
  71. package/kits/hub-game/code/client/build.js +22 -0
  72. package/kits/hub-game/code/client/chrome.js +1144 -50
  73. package/kits/hub-game/code/client/companion.js +716 -0
  74. package/kits/hub-game/code/client/companionDress.js +99 -0
  75. package/kits/hub-game/code/client/decor.js +509 -0
  76. package/kits/hub-game/code/client/earned.js +131 -0
  77. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  78. package/kits/hub-game/code/client/grab.js +339 -20
  79. package/kits/hub-game/code/client/hookLayer.js +299 -13
  80. package/kits/hub-game/code/client/idle.js +163 -22
  81. package/kits/hub-game/code/client/interestCap.js +81 -0
  82. package/kits/hub-game/code/client/keys.js +36 -0
  83. package/kits/hub-game/code/client/labelsNear.js +205 -0
  84. package/kits/hub-game/code/client/menuIcons.js +34 -0
  85. package/kits/hub-game/code/client/pack.js +6 -2
  86. package/kits/hub-game/code/client/packFormat.js +3 -3
  87. package/kits/hub-game/code/client/rehello.js +167 -0
  88. package/kits/hub-game/code/client/shot.js +92 -0
  89. package/kits/hub-game/code/client/sound.js +63 -8
  90. package/kits/hub-game/code/client/soundscape.js +1151 -0
  91. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  92. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  93. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  94. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  95. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  96. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  97. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  98. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  99. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  100. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  101. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  102. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  103. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  104. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  105. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  106. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  107. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  108. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  109. package/kits/hub-game/code/client/spin.js +101 -0
  110. package/kits/hub-game/code/client/state.js +109 -1
  111. package/kits/hub-game/code/client/stuck.js +259 -0
  112. package/kits/hub-game/code/client/talk.js +538 -47
  113. package/kits/hub-game/code/client/tiers.js +516 -27
  114. package/kits/hub-game/code/client/toastBand.js +37 -0
  115. package/kits/hub-game/code/client/together.js +32 -0
  116. package/kits/hub-game/code/client/visibility.js +43 -0
  117. package/kits/hub-game/code/client/wear.js +461 -170
  118. package/kits/hub-game/code/client/yours.js +199 -0
  119. package/kits/hub-game/code/companionSpec.js +45 -0
  120. package/kits/hub-game/code/privateText.js +7 -0
  121. package/kits/hub-game/code/server/actions.js +133 -0
  122. package/kits/hub-game/code/server/actors.js +9 -1
  123. package/kits/hub-game/code/server/ask.js +155 -0
  124. package/kits/hub-game/code/server/ballot.js +539 -0
  125. package/kits/hub-game/code/server/cells.js +100 -0
  126. package/kits/hub-game/code/server/companion.js +82 -0
  127. package/kits/hub-game/code/server/cues.js +70 -0
  128. package/kits/hub-game/code/server/decor.js +269 -0
  129. package/kits/hub-game/code/server/earned.js +461 -0
  130. package/kits/hub-game/code/server/friendBests.js +166 -0
  131. package/kits/hub-game/code/server/friendsAmong.js +232 -0
  132. package/kits/hub-game/code/server/history.js +5 -0
  133. package/kits/hub-game/code/server/hub.js +1254 -50
  134. package/kits/hub-game/code/server/idle.js +30 -11
  135. package/kits/hub-game/code/server/index.js +2 -2
  136. package/kits/hub-game/code/server/labels.js +28 -2
  137. package/kits/hub-game/code/server/manifest.js +378 -7
  138. package/kits/hub-game/code/server/menu.js +133 -0
  139. package/kits/hub-game/code/server/npcs.js +830 -80
  140. package/kits/hub-game/code/server/party.js +2 -2
  141. package/kits/hub-game/code/server/players.js +22 -0
  142. package/kits/hub-game/code/server/shot.js +110 -0
  143. package/kits/hub-game/code/server/standing.js +124 -0
  144. package/kits/hub-game/code/server/vis.js +113 -0
  145. package/kits/hub-game/code/server/wear.js +12 -0
  146. package/kits/hub-game/code/server/yours.js +59 -0
  147. package/kits/hub-game/code/shared/cues.js +9 -0
  148. package/kits/hub-game/code/shared/decor.js +41 -0
  149. package/kits/hub-game/code/shared/shot.js +19 -0
  150. package/kits/hub-game/code/shared/spin.js +57 -0
  151. package/kits/hub-game/code/systems/hub.js +845 -95
  152. package/kits/hub-game/docs/content-pack.md +1 -1
  153. package/kits/hub-game/docs/contract.md +2244 -61
  154. package/kits/hub-game/docs/home-pieces.md +64 -0
  155. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  156. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  157. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  158. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  159. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  160. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  161. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  162. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  163. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  164. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  165. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  166. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  167. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  168. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  169. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  170. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  171. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  172. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  173. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  174. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  175. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  176. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  177. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  178. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  179. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  180. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  181. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  182. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  183. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  184. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  185. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  186. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  187. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  188. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  189. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  190. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  191. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  192. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  193. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  194. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  195. package/kits/hub-game/package-lock.json +2 -0
  196. package/kits/hub-game/package.json +2 -1
  197. package/kits/hub-game/scripts/check.mjs +78 -11
  198. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  199. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
  200. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  201. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
  202. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
  203. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  204. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  205. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  206. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  207. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  208. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  209. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  210. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  211. package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
  212. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  213. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  214. package/kits/hub-game/scripts/test-actors.mjs +19 -17
  215. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  216. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  217. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  218. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  219. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  220. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  221. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  222. package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
  223. package/kits/hub-game/scripts/test-avatar.mjs +540 -7
  224. package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
  225. package/kits/hub-game/scripts/test-build.mjs +31 -0
  226. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  227. package/kits/hub-game/scripts/test-chat.mjs +662 -0
  228. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  229. package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
  230. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  231. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  232. package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
  233. package/kits/hub-game/scripts/test-decor.mjs +457 -0
  234. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  235. package/kits/hub-game/scripts/test-earned.mjs +1194 -0
  236. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  237. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  238. package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
  239. package/kits/hub-game/scripts/test-grab.mjs +7 -0
  240. package/kits/hub-game/scripts/test-hats.mjs +422 -168
  241. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  242. package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
  243. package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
  244. package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
  245. package/kits/hub-game/scripts/test-idle.mjs +361 -1
  246. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  247. package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
  248. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  249. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  250. package/kits/hub-game/scripts/test-labels.mjs +596 -0
  251. package/kits/hub-game/scripts/test-manifest.mjs +207 -0
  252. package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
  253. package/kits/hub-game/scripts/test-menu.mjs +296 -0
  254. package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
  255. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  256. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  257. package/kits/hub-game/scripts/test-picker.mjs +314 -0
  258. package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
  259. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  260. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  261. package/kits/hub-game/scripts/test-shot.mjs +756 -0
  262. package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
  263. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  264. package/kits/hub-game/scripts/test-standing.mjs +416 -0
  265. package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
  266. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  267. package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
  268. package/kits/hub-game/scripts/test-tiers.mjs +477 -2
  269. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  270. package/kits/hub-game/scripts/test-try-on.mjs +22 -22
  271. package/kits/hub-game/scripts/test-vis.mjs +343 -0
  272. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  273. package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
  274. package/kits/hub-game/scripts/test-yours.mjs +372 -0
  275. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  276. package/kits/multiplayer-3d/castle.json +5 -5
  277. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  278. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  279. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  280. package/kits/multiplayer-3d/code/options.js +5 -0
  281. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  282. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  283. package/kits/multiplayer-3d/code/server/world.js +7 -0
  284. package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
  285. package/kits/multiplayer-3d/package.json +2 -1
  286. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  287. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  288. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  289. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  290. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  291. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  292. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  293. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  294. package/kits/physics-2d/CLAUDE.md +9 -0
  295. package/kits/physics-2d/castle.json +2 -2
  296. package/kits/physics-2d/engine/scene.js +253 -1
  297. package/kits/physics-2d/engine/skyKey.js +129 -0
  298. package/kits/physics-2d/engine/stillClock.js +106 -0
  299. package/kits/physics-2d/engine/updateBudget.js +21 -0
  300. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
  301. package/kits/physics-3d/CLAUDE.md +1169 -30
  302. package/kits/physics-3d/behaviors/Player.jsx +629 -72
  303. package/kits/physics-3d/castle.json +3 -3
  304. package/kits/physics-3d/docs/pxmodel-format.md +8 -0
  305. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
  306. package/kits/physics-3d/engine3d/actornode.js +86 -0
  307. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  308. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  309. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  310. package/kits/physics-3d/engine3d/framecap.js +96 -0
  311. package/kits/physics-3d/engine3d/gait.js +118 -0
  312. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  313. package/kits/physics-3d/engine3d/look.js +507 -48
  314. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  315. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  316. package/kits/physics-3d/engine3d/motion.js +39 -10
  317. package/kits/physics-3d/engine3d/nearshadows.js +37 -19
  318. package/kits/physics-3d/engine3d/optimize.js +9 -5
  319. package/kits/physics-3d/engine3d/orbitinput.js +487 -9
  320. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  321. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  322. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  323. package/kits/physics-3d/engine3d/shadowfade.js +882 -0
  324. package/kits/physics-3d/engine3d/sky.js +547 -0
  325. package/kits/physics-3d/engine3d/skylife.js +306 -0
  326. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  327. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  328. package/kits/physics-3d/engine3d/world3d.js +796 -69
  329. package/kits/physics-3d/main.jsx +5 -0
  330. package/kits/physics-3d/package.json +1 -1
  331. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  332. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
  333. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  334. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
  335. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  336. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  337. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  338. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  339. package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
  340. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
  341. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
  342. package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
  343. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  344. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  345. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  346. package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
  347. package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
  348. package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
  349. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  350. package/kits/physics-3d/systems/physics3d.js +383 -6
  351. package/kits/real-time/castle.json +2 -2
  352. package/kits/real-time/code/server/gameHooks.js +7 -0
  353. package/kits/real-time/code/server/session.js +97 -19
  354. package/package.json +2 -2
  355. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -0,0 +1,756 @@
1
+ // Private orbit shots (contract v1.61), server delivery and real client hooks.
2
+ import assert from 'node:assert/strict';
3
+ import { register } from 'node:module';
4
+
5
+ const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
6
+ const avatarsStub = 'export function dropMissing() {}';
7
+ register(
8
+ `data:text/javascript,${encodeURIComponent(`
9
+ import { readFile } from 'node:fs/promises';
10
+ import { fileURLToPath } from 'node:url';
11
+ const stubs = {
12
+ '@imports/castle.multiplayer-3d/code/server/sceneBodies.js': 'data:text/javascript,${encodeURIComponent(sceneStub)}',
13
+ '@imports/castle.multiplayer-3d/code/client/avatars.js': 'data:text/javascript,${encodeURIComponent(avatarsStub)}',
14
+ 'castle-web-sdk': ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)},
15
+ };
16
+ export async function resolve(specifier, context, next) {
17
+ if (['pxmodel', 'optimize', 'look', 'lookbake'].some((m) => specifier === '@imports/castle.physics-3d/engine3d/' + m)) return { url: ${JSON.stringify(new URL('./fixtures/engine-models-stub.mjs', import.meta.url).href)}, shortCircuit: true };
18
+ if (specifier === '@imports/castle.physics-3d/engine3d/orbitlens.js') return { url: ${JSON.stringify(new URL('../../physics-3d/engine3d/orbitlens.js', import.meta.url).href)}, shortCircuit: true };
19
+ if (stubs[specifier]) {
20
+ return { url: stubs[specifier], shortCircuit: true };
21
+ }
22
+ return next(specifier, context);
23
+ }
24
+ // The hook layer reads the deck's castle.json through the bundler.
25
+ export async function load(url, context, next) {
26
+ if (url.endsWith('/code/client/hookLayer.js')) {
27
+ const source = await readFile(fileURLToPath(url), 'utf8');
28
+ return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
29
+ }
30
+ return next(url, context);
31
+ }
32
+ `)}`,
33
+ );
34
+
35
+ const { layer } = await import('../code/server/hub.js');
36
+ const hook = (await import('../code/client/hookLayer.js')).default;
37
+ const State = await import('../code/client/state.js');
38
+ const { shot, joinedAfresh, forgetPlayer, stopHolding } = await import('../code/server/shot.js');
39
+ const ShotClient = await import('../code/client/shot.js');
40
+ const clearShot = () => ShotClient.clearShot();
41
+ const pose = () => ({ look: { x: 1, y: 2, z: 3 }, distance: 8, pitch: 30, yaw: 45 });
42
+ const sent = [];
43
+ let clientTime = 0;
44
+ const warnings = [];
45
+ const warn = console.warn;
46
+ const log = console.log;
47
+ console.warn = (...args) => warnings.push(args.join(' '));
48
+ console.log = () => {};
49
+ let n = 0;
50
+ function test(name, fn) {
51
+ try {
52
+ State.clear();
53
+ clientTime = 0;
54
+ warnings.length = 0;
55
+ fn();
56
+ n += 1;
57
+ } catch (err) {
58
+ console.warn = warn;
59
+ console.log = log;
60
+ console.error(`FAIL ${name}`);
61
+ throw err;
62
+ } finally {
63
+ clearShot();
64
+ }
65
+ }
66
+ function serverState() {
67
+ sent.length = 0;
68
+ return {
69
+ warned: new Set(),
70
+ players: new Map(['p1', 'p2'].map((id) => [id, { arrived: true, ended: false }])),
71
+ sim: { timeMs: 0, players: new Map([['p1', {}], ['p2', {}]]) },
72
+ session: { players: [{ playerId: 'p1' }, { playerId: 'p2' }], send: (id, msg) => sent.push([id, msg]) },
73
+ };
74
+ }
75
+
76
+ test('private delivery, plain copied pose, no broadcast, pitch capped', () => {
77
+ const h = serverState();
78
+ const value = { ...pose(), pitch: 100, extra: 'discard', look: { ...pose().look, extra: 99 } };
79
+ assert.equal(shot(h, 'p1', value), true);
80
+ assert.deepEqual(sent, [['p1', { k: 'hub-shot', shot: { ...pose(), pitch: 89 } }]]);
81
+ assert.notEqual(sent[0][1].shot, value);
82
+ assert.notEqual(sent[0][1].shot.look, value.look);
83
+ value.look.x = 100;
84
+ assert.equal(sent[0][1].shot.look.x, 1);
85
+ assert.equal(shot(h, 'p2', { ...pose(), pitch: -100 }), true);
86
+ assert.equal(sent[1][1].shot.pitch, -89);
87
+ });
88
+
89
+ test('null and every invalid finite field clear, invalid values warn only once', () => {
90
+ const bad = [undefined, {}, [], false, { ...pose(), look: null }, { ...pose(), distance: 0 }, { ...pose(), distance: -1 }];
91
+ for (const value of [NaN, Infinity, -Infinity, '1']) {
92
+ for (const field of ['distance', 'pitch', 'yaw']) {
93
+ bad.push({ ...pose(), [field]: value });
94
+ }
95
+ for (const field of ['x', 'y', 'z']) {
96
+ bad.push({ ...pose(), look: { ...pose().look, [field]: value } });
97
+ }
98
+ }
99
+ bad.push(Object.defineProperty({}, 'look', { get() { throw Error('bad getter'); } }));
100
+ const h = serverState();
101
+ for (const value of bad) {
102
+ assert.equal(shot(h, 'p1', pose()), true);
103
+ assert.equal(shot(h, 'p1', value), true);
104
+ assert.deepEqual(sent.at(-1), ['p1', { k: 'hub-shot', shot: null }]);
105
+ h.sim.timeMs += 1000;
106
+ }
107
+ assert.equal(warnings.filter((s) => s.includes('invalid shot; clearing')).length, 1);
108
+ assert.equal(shot(h, 'p1', pose()), true);
109
+ assert.equal(shot(h, 'p1', null), true);
110
+ });
111
+
112
+ test('unknown, unarrived, ended, disconnected and unsendable players refuse once', () => {
113
+ for (const change of [
114
+ (h) => h.players.delete('p1'),
115
+ (h) => { h.players.get('p1').arrived = false; },
116
+ (h) => { h.players.get('p1').ended = true; },
117
+ (h) => h.sim.players.delete('p1'),
118
+ (h) => { h.session.players = [{ playerId: 'p2' }]; },
119
+ (h) => { delete h.session.send; },
120
+ ]) {
121
+ const h = serverState();
122
+ change(h);
123
+ const before = warnings.length;
124
+ assert.equal(shot(h, 'p1', pose()), false);
125
+ assert.equal(shot(h, 'p1', null), false);
126
+ assert.equal(warnings.length, before + 1);
127
+ assert.equal(sent.length, 0);
128
+ assert.equal(Object.hasOwn(h, 'shotBudgets'), false);
129
+ }
130
+ const h = serverState();
131
+ for (const id of [null, {}, 1, 'missing']) {
132
+ assert.equal(shot(h, id, pose()), false);
133
+ }
134
+ });
135
+
136
+ test('equal values spend nothing; bounded repeat, per-player refill, clear despite exhausted budget', () => {
137
+ const h = serverState();
138
+ assert.equal(shot(h, 'p1', pose()), true);
139
+ for (let i = 0; i < 20; i += 1) {
140
+ assert.equal(shot(h, 'p1', pose()), false);
141
+ }
142
+ assert.equal(sent.length, 1);
143
+ assert.equal(h.shotBudgets.get('p1').tokens, 3);
144
+ assert.equal(warnings.length, 1);
145
+ for (let yaw = 1; yaw <= 3; yaw += 1) {
146
+ assert.equal(shot(h, 'p1', { ...pose(), yaw }), true);
147
+ }
148
+ assert.equal(shot(h, 'p1', { ...pose(), yaw: 4 }), false);
149
+ assert.equal(shot(h, 'p2', pose()), true);
150
+ assert.equal(shot(h, 'p1', null), true);
151
+ assert.equal(shot(h, 'p1', null), false);
152
+ h.sim.timeMs = 250;
153
+ assert.equal(shot(h, 'p1', pose()), true);
154
+ h.sim.timeMs = 1249;
155
+ assert.equal(shot(h, 'p1', pose()), false);
156
+ h.sim.timeMs = 1250;
157
+ assert.equal(shot(h, 'p1', pose()), true);
158
+ });
159
+
160
+ test('fresh join renews a held pose privately without deleting or spending its budget', () => {
161
+ const h = serverState();
162
+ joinedAfresh(h, 'p1');
163
+ assert.equal(Object.hasOwn(h, 'shotBudgets'), false);
164
+ assert.equal(Object.hasOwn(h, 'renewShots'), false);
165
+ assert.equal(sent.length, 0);
166
+ assert.equal(shot(h, 'p1', pose()), true);
167
+ assert.equal(shot(h, 'p2', pose()), true);
168
+ const otherBudget = h.shotBudgets.get('p2');
169
+ const budget = h.shotBudgets.get('p1');
170
+ sent.length = 0;
171
+ joinedAfresh(h, 'p1');
172
+ assert.deepEqual(sent, [['p1', { k: 'hub-shot', shot: pose(), lease: true }]]);
173
+ assert.equal(h.shotBudgets.get('p1'), budget);
174
+ assert.equal(budget.tokens, 3);
175
+ assert.equal(h.shotBudgets.get('p2'), otherBudget);
176
+ forgetPlayer(h, 'p1');
177
+ assert.equal(sent.length, 1, 'departure sends nothing to the gone player');
178
+ assert.equal(h.shotBudgets.has('p1'), false);
179
+ forgetPlayer(h, 'p2');
180
+ assert.equal(sent.length, 1, 'departure sends nothing to the gone player');
181
+ assert.equal(h.shotBudgets.has('p2'), false);
182
+ assert.equal(Object.hasOwn(h, 'renewShots'), false);
183
+ });
184
+
185
+ test('fresh join sends nothing after null or an unsuccessful shot send', () => {
186
+ const h = serverState();
187
+ assert.equal(shot(h, 'p1', null), true);
188
+ sent.length = 0;
189
+ joinedAfresh(h, 'p1');
190
+ assert.equal(sent.length, 0);
191
+ h.session.send = () => { throw Error('send failed'); };
192
+ assert.equal(shot(h, 'p1', pose()), false);
193
+ assert.equal(h.shotBudgets.get('p1').key, 'null', 'a failed send retains the last accepted clear');
194
+ h.session.send = (id, msg) => sent.push([id, msg]);
195
+ joinedAfresh(h, 'p1');
196
+ assert.equal(sent.length, 0);
197
+ assert.equal(Object.hasOwn(h, 'renewShots'), false);
198
+ });
199
+
200
+ test('held poses renew every 2 s of sim time, without roster iteration, budget cost or catch-up bursts', () => {
201
+ const h = serverState();
202
+ for (let yaw = 0; yaw < 4; yaw += 1) {
203
+ assert.equal(shot(h, 'p1', { ...pose(), yaw }), true);
204
+ }
205
+ const budget = h.shotBudgets.get('p1');
206
+ assert.equal(budget.tokens, 0);
207
+ h.session.players = new Proxy([], { get() { throw Error('renewal read the roster'); } });
208
+ h.players[Symbol.iterator] = h.sim.players[Symbol.iterator] = () => { throw Error('renewal iterated players'); };
209
+ sent.length = 0;
210
+ h.sim.timeMs = 1999;
211
+ h.renewShots();
212
+ assert.equal(sent.length, 0);
213
+ for (const now of [2000, 4000, 60000]) {
214
+ h.sim.timeMs = now;
215
+ h.renewShots();
216
+ assert.deepEqual(sent.at(-1), ['p1', { k: 'hub-shot', shot: { ...pose(), yaw: 3 }, lease: true }]);
217
+ assert.equal(budget.tokens, 0);
218
+ assert.equal(budget.sentAt, 0);
219
+ const count = sent.length;
220
+ h.renewShots();
221
+ assert.equal(sent.length, count, 'one renewal per interval, including after a stall');
222
+ }
223
+ assert.equal(sent.length, 3);
224
+ });
225
+
226
+ test('clear stops only that player renewing; last clear and forget remove the renewal callback', () => {
227
+ const h = serverState();
228
+ shot(h, 'p1', pose());
229
+ shot(h, 'p2', pose());
230
+ sent.length = 0;
231
+ assert.equal(shot(h, 'p1', null), true);
232
+ assert.equal(shot(h, 'p1', null), false);
233
+ assert.deepEqual(sent, [['p1', { k: 'hub-shot', shot: null }]]);
234
+ h.sim.timeMs = 2000;
235
+ h.renewShots();
236
+ assert.deepEqual(sent.at(-1), ['p2', { k: 'hub-shot', shot: pose(), lease: true }]);
237
+ assert.equal(shot(h, 'p2', null), true);
238
+ assert.equal(Object.hasOwn(h, 'renewShots'), false);
239
+ const count = sent.length;
240
+ h.sim.timeMs = 6000;
241
+ h.renewShots?.();
242
+ joinedAfresh(h, 'p1');
243
+ joinedAfresh(h, 'p2');
244
+ assert.equal(sent.length, count);
245
+ shot(h, 'p1', pose());
246
+ forgetPlayer(h, 'p1');
247
+ assert.equal(Object.hasOwn(h, 'renewShots'), false);
248
+ });
249
+
250
+ test('unused server has no shot state, renewal callback or renewal messages', () => {
251
+ const h = serverState();
252
+ const keys = Object.keys(h);
253
+ for (let i = 0; i < 20; i += 1) {
254
+ h.sim.timeMs = i * 2000;
255
+ h.renewShots?.();
256
+ joinedAfresh(h, 'p1');
257
+ forgetPlayer(h, 'missing');
258
+ }
259
+ assert.deepEqual(Object.keys(h), keys);
260
+ assert.equal(sent.length, 0);
261
+ });
262
+
263
+ function bootServer(hooks = {}, { sessionId = 'test', actors = [], manifest = {} } = {}) {
264
+ const delivered = [];
265
+ const players = [{ playerId: 'p1' }, { playerId: 'p2' }];
266
+ const session = { sessionId, players, send: (id, msg) => delivered.push([id, msg]), broadcast() {} };
267
+ const world = { timeMs: 0, scenePath: 'scenes/main.scene', bodies: new Map(), players: new Map(players.map((p) => [p.playerId,
268
+ { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } }])) };
269
+ let hub;
270
+ globalThis.__hubTestActors = actors;
271
+ const server = layer({ server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Town', ...manifest } }, { ...hooks, ready(ctx) { hub = ctx; } }, {}, () => true);
272
+ server.sceneFor(session);
273
+ server.ready(world);
274
+ const hello = (extra = {}) => server.message(session, players[0], { k: 'hub-hello', avatar: 0, ...extra });
275
+ hello();
276
+ server.place(world);
277
+ return { delivered, players, session, world, hub, server, hello };
278
+ }
279
+
280
+ test('layer exposes shot; no snapshot/delta fields; fresh hello renews and departure forgets', () => {
281
+ const { delivered, players, session, world, hub, server, hello } = bootServer();
282
+ assert.equal(hub.shot('p1', pose()), true);
283
+ assert.equal(hub.shot('p1', pose()), false);
284
+ assert.deepEqual(delivered.filter(([, msg]) => msg.k === 'hub-shot'), [['p1', { k: 'hub-shot', shot: pose() }]]);
285
+ assert.ok(!JSON.stringify(server.join()).includes('hub-shot'));
286
+ assert.ok(!JSON.stringify(server.delta()).includes('hub-shot'));
287
+ delivered.length = 0;
288
+ hello();
289
+ assert.deepEqual(delivered.filter(([, msg]) => msg.k === 'hub-shot'), [['p1', { k: 'hub-shot', shot: pose(), lease: true }]]);
290
+ assert.equal(hub.shot('p1', pose()), false, 'fresh hello preserves the explicit-call budget');
291
+ delivered.length = 0;
292
+ session.players = [];
293
+ world.players.clear();
294
+ server.place(world);
295
+ session.players = players;
296
+ world.players.set('p1', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
297
+ hello();
298
+ server.place(world);
299
+ assert.equal(delivered.some(([, msg]) => msg.k === 'hub-shot'), false, 'forget and a later hello send no clear to a gone player');
300
+ assert.equal(hub.shot('p1', pose()), true);
301
+ });
302
+
303
+ test('production server step renews held shots and sends none when unused or cleared', () => {
304
+ const r = bootServer();
305
+ for (const now of [2000, 4000, 6000]) {
306
+ r.world.timeMs = now;
307
+ r.server.step(r.world);
308
+ }
309
+ assert.equal(r.delivered.some(([, msg]) => msg.k === 'hub-shot'), false);
310
+ assert.equal(r.hub.shot('p1', pose()), true);
311
+ r.delivered.length = 0;
312
+ r.world.timeMs = 7999;
313
+ r.server.step(r.world);
314
+ assert.equal(r.delivered.some(([, msg]) => msg.k === 'hub-shot'), false);
315
+ r.world.timeMs = 8000;
316
+ r.server.step(r.world);
317
+ assert.deepEqual(r.delivered.filter(([, msg]) => msg.k === 'hub-shot'), [['p1', { k: 'hub-shot', shot: pose(), lease: true }]]);
318
+ r.hub.shot('p1', null);
319
+ r.delivered.length = 0;
320
+ r.world.timeMs = 16000;
321
+ r.server.step(r.world);
322
+ assert.equal(r.delivered.some(([, msg]) => msg.k === 'hub-shot'), false);
323
+ });
324
+
325
+ test('fresh hello when no shot was sent sends no shot messages; avatar hello retains the budget', () => {
326
+ const { delivered, hub, hello } = bootServer();
327
+ delivered.length = 0;
328
+ hello();
329
+ hello();
330
+ assert.equal(delivered.some(([, msg]) => msg.k === 'hub-shot'), false);
331
+ assert.equal(hub.shot('p1', pose()), true);
332
+ delivered.length = 0;
333
+ hello({ again: true, avatar: 1 });
334
+ assert.equal(delivered.some(([, msg]) => msg.k === 'hub-shot'), false);
335
+ assert.equal(hub.shot('p1', pose()), false, 'avatar changes keep equal-shot suppression');
336
+ });
337
+
338
+ test('stopping a holder preserves its budget and only renews other holders', () => {
339
+ const h = serverState();
340
+ stopHolding(h, 'missing');
341
+ assert.equal(Object.hasOwn(h, 'shotBudgets'), false);
342
+ shot(h, 'p1', pose());
343
+ shot(h, 'p2', pose());
344
+ const budget = h.shotBudgets.get('p1');
345
+ const before = { tokens: budget.tokens, key: budget.key, sentAt: budget.sentAt };
346
+ stopHolding(h, 'p1');
347
+ assert.equal(h.shotBudgets.get('p1'), budget);
348
+ assert.deepEqual({ tokens: budget.tokens, key: budget.key, sentAt: budget.sentAt }, before);
349
+ assert.equal(Object.hasOwn(budget, 'pose'), false);
350
+ assert.equal(Object.hasOwn(budget, 'renewAt'), false);
351
+ sent.length = 0;
352
+ h.sim.timeMs = 2000;
353
+ joinedAfresh(h, 'p1');
354
+ h.renewShots();
355
+ assert.deepEqual(sent, [['p2', { k: 'hub-shot', shot: pose(), lease: true }]]);
356
+ stopHolding(h, 'p2');
357
+ assert.equal(Object.hasOwn(h, 'renewShots'), false);
358
+ });
359
+
360
+ test('successful hub.go stops renewals only for the departing player, without sending a clear', () => {
361
+ const r = bootServer({}, {
362
+ sessionId: 'dev',
363
+ actors: [{ id: 'door-race', components: { HubDoor: { id: 'race', to: 'race' }, Transform: {} } }],
364
+ manifest: { places: { race: { title: 'Race', scene: 'scenes/race.scene' } } },
365
+ });
366
+ r.server.message(r.session, r.players[1], { k: 'hub-hello', avatar: 0 });
367
+ r.server.place(r.world);
368
+ assert.equal(r.hub.shot('p1', pose()), true);
369
+ assert.equal(r.hub.shot('p2', pose()), true);
370
+ assert.equal(r.hub.go('missing', ['p1']), null);
371
+ r.delivered.length = 0;
372
+ assert.match(r.hub.go('race', ['p1']), /^hub\.race\./);
373
+ assert.deepEqual(r.delivered.filter(([, msg]) => msg.k === 'hub-shot'), []);
374
+ assert.deepEqual(r.delivered.filter(([, msg]) => msg.k === 'hub-go').map(([id]) => id), ['p1']);
375
+ r.hello();
376
+ r.world.timeMs = 2000;
377
+ r.server.step(r.world);
378
+ assert.deepEqual(r.delivered.filter(([, msg]) => msg.k === 'hub-shot'), [['p2', { k: 'hub-shot', shot: pose(), lease: true }]]);
379
+ });
380
+
381
+ test('hub.end drops the held pose so a later fresh hello cannot renew it', () => {
382
+ const r = bootServer();
383
+ r.hub.shot('p1', pose());
384
+ r.delivered.length = 0;
385
+ r.hub.end(['p1']);
386
+ assert.deepEqual(r.delivered.filter(([, msg]) => msg.k === 'hub-shot'), []);
387
+ assert.equal(r.delivered.some(([id, msg]) => id === 'p1' && msg.k === 'hub-end'), true);
388
+ r.hello();
389
+ r.world.timeMs = 2000;
390
+ r.server.step(r.world);
391
+ assert.deepEqual(r.delivered.filter(([, msg]) => msg.k === 'hub-shot'), []);
392
+ });
393
+
394
+ // Deterministic active-only connection watcher; no real browser/timers needed.
395
+ const realSet = globalThis.setInterval;
396
+ const realClear = globalThis.clearInterval;
397
+ const nowDescriptor = Object.getOwnPropertyDescriptor(performance, 'now');
398
+ Object.defineProperty(performance, 'now', { configurable: true, value: () => clientTime });
399
+ const timers = new Map();
400
+ let nextTimer = 0;
401
+ globalThis.setInterval = (fn, ms) => { assert.equal(ms, 100); timers.set(++nextTimer, fn); return nextTimer; };
402
+ globalThis.clearInterval = (id) => timers.delete(id);
403
+ function scene() {
404
+ return { cameraControl: 'orbit', currentScenePath: 'scenes/main.scene', sceneKey: 'main', multiplayer: { generation: 1, net: { status: () => ({ state: 'connected' }), closed: () => false } } };
405
+ }
406
+ const receive = (s, value = pose(), extra = {}) => hook.message(s, { k: 'hub-shot', shot: value, ...extra });
407
+ const watch = () => { for (const fn of [...timers.values()]) { fn(); } };
408
+
409
+ test('a lease without a received shot is ignored, with no pose or watcher', () => {
410
+ const s = scene();
411
+ receive(s, pose(), { lease: true });
412
+ assert.equal(s.orbitShot, undefined);
413
+ assert.equal(timers.size, 0);
414
+ });
415
+
416
+ test('a lease cannot change the held pose or renew a different pose', () => {
417
+ const s = scene();
418
+ receive(s);
419
+ const held = s.orbitShot;
420
+ clientTime = 2000;
421
+ receive(s, { ...pose(), yaw: 90 }, { lease: true });
422
+ assert.equal(s.orbitShot, held);
423
+ clientTime = 5001;
424
+ watch();
425
+ assert.equal(s.orbitShot, undefined);
426
+ receive(s, { ...pose(), yaw: 90 }, { lease: true });
427
+ assert.equal(s.orbitShot, undefined);
428
+ receive(s, pose(), { lease: true });
429
+ assert.deepEqual(s.orbitShot, pose(), 'an equal pose can resume after lease expiry');
430
+ });
431
+
432
+ for (const tickFirst of [false, true]) {
433
+ test('deck-owned orbitShot survives lease renewal before and after the ownership watcher', () => {
434
+ const s = scene();
435
+ receive(s);
436
+ const deckShot = pose();
437
+ s.orbitShot = deckShot;
438
+ if (tickFirst) {
439
+ watch();
440
+ }
441
+ receive(s, pose(), { lease: true });
442
+ assert.equal(s.orbitShot, deckShot);
443
+ assert.equal(timers.size, 0);
444
+ delete s.orbitShot;
445
+ receive(s, pose(), { lease: true });
446
+ assert.equal(s.orbitShot, undefined, 'the declined pose stays declined after the deck shot ends');
447
+ receive(s);
448
+ assert.deepEqual(s.orbitShot, pose(), 'a fresh explicit call can apply again');
449
+ });
450
+ }
451
+
452
+ test('equal renewals and fresh pose messages refresh the 5 s lease without replacing the shot or watcher', () => {
453
+ const s = scene();
454
+ receive(s);
455
+ const held = s.orbitShot;
456
+ const timer = [...timers.keys()][0];
457
+ for (const now of [2000, 4000, 6000]) {
458
+ clientTime = now;
459
+ receive(s, pose(), { lease: true });
460
+ watch();
461
+ assert.equal(s.orbitShot, held);
462
+ assert.deepEqual([...timers.keys()], [timer]);
463
+ }
464
+ clientTime = 8000;
465
+ receive(s);
466
+ assert.equal(s.orbitShot, held);
467
+ clientTime = 13000;
468
+ watch();
469
+ assert.equal(s.orbitShot, held, 'valid through the 5 s boundary');
470
+ clientTime = 13001;
471
+ watch();
472
+ assert.equal(s.orbitShot, undefined);
473
+ assert.equal(timers.size, 0);
474
+ });
475
+
476
+ test('restarted-server reconnect expires an old shot on the first delayed watcher callback', () => {
477
+ const oldServer = bootServer();
478
+ const s = scene();
479
+ hook.state(s, { ...oldServer.server.join(), k: 'w' }, null);
480
+ oldServer.hub.shot('p1', pose());
481
+ hook.message(s, oldServer.delivered.find(([, msg]) => msg.k === 'hub-shot')[1]);
482
+ const net = s.multiplayer.net;
483
+ const generation = s.multiplayer.generation;
484
+ const deferredWatcher = [...timers.values()][0];
485
+ // The background tab missed the disconnect. A restarted process has no
486
+ // held pose to renew, even though connectSession retains both identities.
487
+ const restarted = bootServer();
488
+ restarted.hello();
489
+ restarted.server.step(restarted.world);
490
+ assert.equal(restarted.delivered.some(([, msg]) => msg.k === 'hub-shot'), false);
491
+ hook.state(s, { ...restarted.server.join(), k: 'w' }, null);
492
+ assert.equal(s.multiplayer.net, net);
493
+ assert.equal(s.multiplayer.generation, generation);
494
+ clientTime = 5001;
495
+ deferredWatcher();
496
+ assert.equal(s.orbitShot, undefined);
497
+ assert.equal(timers.size, 0);
498
+ // A much later first callback, rather than ticking a counter, also expires.
499
+ receive(s);
500
+ const delayedAgain = [...timers.values()][0];
501
+ clientTime = 60000;
502
+ delayedAgain();
503
+ assert.equal(s.orbitShot, undefined);
504
+ assert.equal(timers.size, 0);
505
+ });
506
+
507
+ test('same-server reconnect regains its held pose through an immediate hello renewal', () => {
508
+ const r = bootServer();
509
+ const s = scene();
510
+ let status = 'connected';
511
+ s.multiplayer.net.status = () => ({ state: status });
512
+ r.hub.shot('p1', pose());
513
+ hook.message(s, r.delivered.find(([, msg]) => msg.k === 'hub-shot')[1]);
514
+ status = 'reconnecting';
515
+ watch();
516
+ assert.equal(s.orbitShot, undefined);
517
+ status = 'connected';
518
+ r.delivered.length = 0;
519
+ clientTime = 3000;
520
+ r.hello();
521
+ const messages = r.delivered.filter(([, msg]) => msg.k === 'hub-shot');
522
+ assert.deepEqual(messages, [['p1', { k: 'hub-shot', shot: pose(), lease: true }]]);
523
+ hook.message(s, messages[0][1]);
524
+ assert.deepEqual(s.orbitShot, pose());
525
+ const held = s.orbitShot;
526
+ hook.state(s, { ...r.server.join(), k: 'w' }, null);
527
+ watch();
528
+ assert.equal(s.orbitShot, held);
529
+ });
530
+
531
+ test('late fresh hello after a changed fresh shot renews that shot without clearing or restarting it', () => {
532
+ const r = bootServer();
533
+ const s = scene();
534
+ r.hub.shot('p1', pose());
535
+ const freshPose = { ...pose(), yaw: 90 };
536
+ r.hub.shot('p1', freshPose);
537
+ const freshMessage = r.delivered.filter(([, msg]) => msg.k === 'hub-shot').at(-1)[1];
538
+ hook.message(s, freshMessage);
539
+ const held = s.orbitShot;
540
+ r.delivered.length = 0;
541
+ r.hello();
542
+ const messages = r.delivered.filter(([, msg]) => msg.k === 'hub-shot');
543
+ assert.deepEqual(messages, [['p1', { k: 'hub-shot', shot: freshPose, lease: true }]]);
544
+ hook.message(s, messages[0][1]);
545
+ assert.equal(s.orbitShot, held);
546
+ assert.equal(timers.size, 1);
547
+ });
548
+
549
+ test('client copies valid pose, replaces mid-hold, clears null and invalid without leaking watcher', () => {
550
+ const s = scene();
551
+ const value = pose();
552
+ receive(s, value);
553
+ assert.deepEqual(s.orbitShot, value);
554
+ assert.notEqual(s.orbitShot, value);
555
+ assert.notEqual(s.orbitShot.look, value.look);
556
+ value.look.x = 999;
557
+ assert.equal(s.orbitShot.look.x, 1);
558
+ assert.equal(timers.size, 1);
559
+ const before = s.orbitShot;
560
+ receive(s, { ...pose(), yaw: 90 });
561
+ assert.notEqual(s.orbitShot, before);
562
+ assert.equal(s.orbitShot.yaw, 90);
563
+ assert.equal(timers.size, 1);
564
+ receive(s, null);
565
+ assert.equal(Object.hasOwn(s, 'orbitShot'), false);
566
+ assert.equal(Object.hasOwn(State.hub, 'shot'), false);
567
+ assert.equal(timers.size, 0);
568
+ receive(s);
569
+ receive(s, { ...pose(), pitch: Infinity });
570
+ assert.equal(s.orbitShot, undefined);
571
+ assert.equal(timers.size, 0);
572
+ });
573
+
574
+ test('without orbit key: no pose read, state, storage, watcher or later replay', () => {
575
+ const s = scene();
576
+ delete s.cameraControl;
577
+ const deckShot = pose();
578
+ s.orbitShot = deckShot;
579
+ receive(s, Object.defineProperty({}, 'look', { get() { throw Error('must not read'); } }));
580
+ receive(s, null);
581
+ assert.equal(s.orbitShot, deckShot);
582
+ assert.equal(Object.hasOwn(State.hub, 'shot'), false);
583
+ assert.equal(timers.size, 0);
584
+ s.cameraControl = 'orbit';
585
+ hook.state(s, { hubPlace: { id: 'main' } }, null);
586
+ watch();
587
+ assert.equal(s.orbitShot, deckShot);
588
+ });
589
+
590
+ for (const clear of [
591
+ () => clearShot(),
592
+ (s) => receive(s, null),
593
+ () => State.clear(),
594
+ (s) => hook.reset(s),
595
+ (s) => hook.dispose(s),
596
+ (s) => hook.message(s, { k: 'hub-go' }),
597
+ (s) => { s.multiplayer.net.status = () => ({ state: 'reconnecting' }); watch(); },
598
+ () => { clientTime = 5001; watch(); },
599
+ ]) {
600
+ test('cleanup preserves a deck-assigned shot, including an equal replacement', () => {
601
+ const s = scene();
602
+ receive(s);
603
+ const deckShot = pose();
604
+ s.orbitShot = deckShot;
605
+ clear(s);
606
+ assert.equal(s.orbitShot, deckShot);
607
+ assert.equal(timers.size, 0);
608
+ });
609
+ }
610
+
611
+ for (const k of ['hub-go', 'hub-end']) {
612
+ test(`${k} clears before the command is queued`, () => {
613
+ const s = scene();
614
+ receive(s);
615
+ hook.message(s, { k });
616
+ assert.equal(s.orbitShot, undefined);
617
+ assert.equal(timers.size, 0);
618
+ receive(s, pose(), { lease: true });
619
+ assert.equal(s.orbitShot, undefined, 'renewal cannot undo the command clear');
620
+ receive(s);
621
+ assert.deepEqual(s.orbitShot, pose());
622
+ });
623
+ }
624
+ for (const clear of [() => State.clear(), (s) => hook.reset(s), (s) => hook.dispose(s)]) {
625
+ test('leave, same-scene load and runtime disposal clear owned shots', () => {
626
+ const s = scene();
627
+ receive(s);
628
+ clear(s);
629
+ assert.equal(s.orbitShot, undefined);
630
+ assert.equal(timers.size, 0);
631
+ receive(s, pose(), { lease: true });
632
+ assert.equal(s.orbitShot, undefined, 'renewal cannot undo the lifecycle clear');
633
+ receive(s);
634
+ assert.deepEqual(s.orbitShot, pose());
635
+ });
636
+ }
637
+
638
+ for (const decline of [(s) => receive(s, null), () => State.clear(), (s) => { s.sceneKey = 'new'; }, (s) => { s.currentScenePath = 'scenes/new.scene'; }, (s) => { s.orbitShot = pose(); }]) {
639
+ test('lifecycle clears and ownership changes also decline an already disconnected shot', () => {
640
+ const s = scene();
641
+ let status = 'connected';
642
+ s.multiplayer.net.status = () => ({ state: status });
643
+ receive(s);
644
+ status = 'reconnecting';
645
+ watch();
646
+ assert.equal(s.orbitShot, undefined);
647
+ decline(s);
648
+ const before = s.orbitShot;
649
+ status = 'connected';
650
+ receive(s, pose(), { lease: true });
651
+ assert.equal(s.orbitShot, before);
652
+ assert.equal(timers.size, 0);
653
+ });
654
+ }
655
+ for (const update of [
656
+ (s) => { s.multiplayer.net.status = () => ({ state: 'reconnecting' }); },
657
+ (s) => { s.multiplayer.net.closed = () => true; },
658
+ (s) => { s.multiplayer.net = null; },
659
+ (s) => { s.multiplayer.net = { status: () => ({ state: 'connected' }) }; },
660
+ (s) => { s.multiplayer.generation += 1; },
661
+ (s) => { s.currentScenePath = 'scenes/other.scene'; },
662
+ (s) => { s.sceneKey = 'other-content'; },
663
+ ]) {
664
+ test('disconnect/reconnect, session replacement or scene change clears and cancels watcher', () => {
665
+ const s = scene();
666
+ receive(s);
667
+ update(s);
668
+ watch();
669
+ assert.equal(s.orbitShot, undefined);
670
+ assert.equal(timers.size, 0);
671
+ assert.equal(Object.hasOwn(State.hub, 'shot'), false);
672
+ });
673
+ }
674
+ for (const field of ['currentScenePath', 'sceneKey']) {
675
+ test('a renewal cannot undo a scene change, even before the watcher runs or after returning', () => {
676
+ const s = scene();
677
+ receive(s);
678
+ const old = s[field];
679
+ s[field] = 'new-scene';
680
+ receive(s, pose(), { lease: true });
681
+ assert.equal(s.orbitShot, undefined);
682
+ assert.equal(timers.size, 0);
683
+ s[field] = old;
684
+ receive(s, pose(), { lease: true });
685
+ assert.equal(s.orbitShot, undefined);
686
+ receive(s);
687
+ assert.deepEqual(s.orbitShot, pose());
688
+ });
689
+ }
690
+ test('same-net reconnect: a fresh place shot before WORLD survives the hello renewal and snapshot', () => {
691
+ let resend = false;
692
+ const freshPose = { ...pose(), yaw: 90 };
693
+ const r = bootServer({ step(hub) { if (resend) { assert.equal(hub.shot('p1', freshPose), true); } } });
694
+ const s = scene();
695
+ const net = s.multiplayer.net;
696
+ const generation = s.multiplayer.generation;
697
+ let status = 'connected';
698
+ net.status = () => ({ state: status });
699
+ hook.state(s, { ...r.server.join(), k: 'w' }, null);
700
+ assert.equal(r.hub.shot('p1', pose()), true);
701
+ const oldMessage = r.delivered.find(([, msg]) => msg.k === 'hub-shot')[1];
702
+ hook.message(s, oldMessage);
703
+ const old = s.orbitShot;
704
+ r.delivered.length = 0;
705
+ // A fast connectSession reconnect keeps both identities, and completes
706
+ // before the watcher ticks. The server renews rather than clearing.
707
+ status = 'reconnecting';
708
+ status = 'connected';
709
+ r.hello();
710
+ resend = true;
711
+ r.server.step(r.world);
712
+ const messages = r.delivered.filter(([, msg]) => msg.k === 'hub-shot');
713
+ assert.deepEqual(messages, [
714
+ ['p1', { k: 'hub-shot', shot: pose(), lease: true }],
715
+ ['p1', { k: 'hub-shot', shot: freshPose }],
716
+ ]);
717
+ hook.message(s, messages[0][1]);
718
+ assert.equal(s.orbitShot, old);
719
+ assert.equal(timers.size, 1);
720
+ hook.message(s, messages[1][1]);
721
+ const fresh = s.orbitShot;
722
+ assert.notEqual(fresh, old);
723
+ assert.deepEqual(fresh, freshPose);
724
+ // session.js sends WORLD only after the place/step hooks have run.
725
+ hook.state(s, { ...r.server.join(), k: 'w' }, null);
726
+ watch();
727
+ assert.equal(s.multiplayer.net, net);
728
+ assert.equal(s.multiplayer.generation, generation);
729
+ assert.equal(s.orbitShot, fresh);
730
+ assert.equal(timers.size, 1);
731
+ });
732
+
733
+ test('unused clients allocate no shot state, timers or storage and never inspect scene poses', () => {
734
+ const keys = Object.keys(State.hub);
735
+ const s = Object.defineProperty({}, 'orbitShot', { get() { throw Error('unused pose read'); } });
736
+ hook.message(s, { k: 'unrelated' });
737
+ hook.state(s, { hubPlace: { id: 'main' } }, null);
738
+ hook.state(s, { t: 20 }, null);
739
+ hook.reset(s);
740
+ State.clear();
741
+ assert.deepEqual(Object.keys(State.hub), keys);
742
+ assert.equal(timers.size, 0);
743
+ const h = serverState();
744
+ assert.equal(Object.hasOwn(h, 'shotBudgets'), false);
745
+ });
746
+
747
+ globalThis.setInterval = realSet;
748
+ globalThis.clearInterval = realClear;
749
+ if (nowDescriptor) {
750
+ Object.defineProperty(performance, 'now', nowDescriptor);
751
+ } else {
752
+ delete performance.now;
753
+ }
754
+ console.warn = warn;
755
+ console.log = log;
756
+ console.log(`hub shots: ${n} tests passed`);