castle-web-cli 0.4.232 → 0.4.234

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 (587) 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/api.d.ts +11 -0
  8. package/dist/api.js +43 -0
  9. package/dist/bundle.d.ts +64 -0
  10. package/dist/bundle.js +558 -2
  11. package/dist/castle-host/host.d.ts +18 -2
  12. package/dist/castle-host/host.js +844 -39
  13. package/dist/castleJson.d.ts +23 -2
  14. package/dist/castleJson.js +46 -2
  15. package/dist/check.d.ts +3 -1
  16. package/dist/check.js +20 -3
  17. package/dist/chunkLoader.d.ts +3 -0
  18. package/dist/chunkLoader.js +111 -0
  19. package/dist/devParty.d.ts +26 -0
  20. package/dist/devParty.js +231 -0
  21. package/dist/devSaveStorage.js +4 -0
  22. package/dist/devSessionStorage.js +50 -2
  23. package/dist/devSocial.d.ts +24 -0
  24. package/dist/devSocial.js +70 -0
  25. package/dist/ide.d.ts +2 -0
  26. package/dist/ide.js +119 -15
  27. package/dist/importPinMismatch.d.ts +22 -0
  28. package/dist/importPinMismatch.js +77 -0
  29. package/dist/importRegression.js +3 -15
  30. package/dist/imports.d.ts +10 -3
  31. package/dist/imports.js +88 -20
  32. package/dist/index.js +11 -4
  33. package/dist/init.js +1 -1
  34. package/dist/platformDoc.js +22 -0
  35. package/dist/routerFences.d.ts +5 -0
  36. package/dist/routerFences.js +12 -2
  37. package/dist/save-deck.d.ts +25 -1
  38. package/dist/save-deck.js +178 -9
  39. package/dist/serve.js +32 -11
  40. package/dist/shell/assets/{index-D2tWM896.js → index-DulbYIJm.js} +97 -97
  41. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  42. package/dist/shell/index.html +2 -2
  43. package/dist/taskSteer.d.ts +13 -0
  44. package/dist/taskSteer.js +22 -2
  45. package/dist/vitePlugins.d.ts +2 -1
  46. package/dist/vitePlugins.js +13 -0
  47. package/kits/base/castle.json +1 -1
  48. package/kits/base/package-lock.json +1 -1
  49. package/kits/base/sdk/README.md +339 -5
  50. package/kits/base/sdk/avatar.d.ts +6 -2
  51. package/kits/base/sdk/avatar.js +12 -4
  52. package/kits/base/sdk/castle.d.ts +7 -3
  53. package/kits/base/sdk/castle.js +2 -0
  54. package/kits/base/sdk/commands.d.ts +176 -1
  55. package/kits/base/sdk/commands.js +3 -0
  56. package/kits/base/sdk/display.d.ts +3 -0
  57. package/kits/base/sdk/display.js +9 -3
  58. package/kits/base/sdk/hub.d.ts +37 -6
  59. package/kits/base/sdk/hub.js +63 -4
  60. package/kits/base/sdk/multiplayer.d.ts +7 -1
  61. package/kits/base/sdk/multiplayer.js +148 -32
  62. package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
  63. package/kits/base/sdk/party.d.ts +23 -0
  64. package/kits/base/sdk/party.js +91 -0
  65. package/kits/base/sdk/reconnectBudget.d.ts +23 -0
  66. package/kits/base/sdk/reconnectBudget.js +96 -0
  67. package/kits/base/sdk/save.d.ts +38 -1
  68. package/kits/base/sdk/save.js +81 -7
  69. package/kits/base/sdk/server/hub.d.ts +117 -0
  70. package/kits/base/sdk/server/hub.js +119 -2
  71. package/kits/base/sdk/server/platformHandle.d.ts +43 -1
  72. package/kits/base/sdk/server/storage.d.ts +17 -0
  73. package/kits/base/sdk/server/storage.js +65 -3
  74. package/kits/base/sdk/server/wrapper.d.ts +43 -6
  75. package/kits/base/sdk/server/wrapper.js +93 -9
  76. package/kits/base/sdk/social.d.ts +9 -0
  77. package/kits/base/sdk/social.js +5 -0
  78. package/kits/hub-game/CLAUDE.md +451 -13
  79. package/kits/hub-game/README.md +63 -0
  80. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  81. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  82. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  83. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  84. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  85. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  86. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  87. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  88. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  89. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  90. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  91. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  92. package/kits/hub-game/castle.json +5 -5
  93. package/kits/hub-game/code/client/act.js +312 -0
  94. package/kits/hub-game/code/client/actionLayout.js +147 -0
  95. package/kits/hub-game/code/client/actionOverflow.js +556 -0
  96. package/kits/hub-game/code/client/actorBudget.js +47 -0
  97. package/kits/hub-game/code/client/arrivalCamera.js +50 -0
  98. package/kits/hub-game/code/client/askSlot.js +117 -0
  99. package/kits/hub-game/code/client/attention.js +11 -2
  100. package/kits/hub-game/code/client/avatar.js +311 -35
  101. package/kits/hub-game/code/client/avatarCap.js +228 -0
  102. package/kits/hub-game/code/client/avatarColors.js +70 -0
  103. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  104. package/kits/hub-game/code/client/avatarShare.js +253 -0
  105. package/kits/hub-game/code/client/backVisibility.js +13 -0
  106. package/kits/hub-game/code/client/ballot.js +472 -0
  107. package/kits/hub-game/code/client/build.js +38 -0
  108. package/kits/hub-game/code/client/chat.js +41 -5
  109. package/kits/hub-game/code/client/chatModeration.js +5 -0
  110. package/kits/hub-game/code/client/chrome.js +2144 -160
  111. package/kits/hub-game/code/client/companion.js +716 -0
  112. package/kits/hub-game/code/client/companionDress.js +99 -0
  113. package/kits/hub-game/code/client/crowdNames.js +241 -0
  114. package/kits/hub-game/code/client/decor.js +515 -0
  115. package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
  116. package/kits/hub-game/code/client/doorErrors.js +39 -0
  117. package/kits/hub-game/code/client/earned.js +131 -0
  118. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  119. package/kits/hub-game/code/client/fall.js +18 -0
  120. package/kits/hub-game/code/client/farAvatars.js +233 -0
  121. package/kits/hub-game/code/client/firstJoin.js +9 -2
  122. package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
  123. package/kits/hub-game/code/client/frameBatch.js +5 -0
  124. package/kits/hub-game/code/client/grab.js +368 -29
  125. package/kits/hub-game/code/client/hookLayer.js +385 -20
  126. package/kits/hub-game/code/client/hudCopy.js +51 -0
  127. package/kits/hub-game/code/client/hudRate.js +20 -0
  128. package/kits/hub-game/code/client/idle.js +177 -24
  129. package/kits/hub-game/code/client/interestCap.js +81 -0
  130. package/kits/hub-game/code/client/invites.js +231 -0
  131. package/kits/hub-game/code/client/joinError.js +9 -0
  132. package/kits/hub-game/code/client/keys.js +36 -0
  133. package/kits/hub-game/code/client/labelsNear.js +234 -0
  134. package/kits/hub-game/code/client/landscapeLayout.js +17 -0
  135. package/kits/hub-game/code/client/layoutCache.js +264 -0
  136. package/kits/hub-game/code/client/loadTelemetry.js +20 -0
  137. package/kits/hub-game/code/client/loadingCover.js +148 -0
  138. package/kits/hub-game/code/client/loadingEntry.js +8 -0
  139. package/kits/hub-game/code/client/menuIcons.js +34 -0
  140. package/kits/hub-game/code/client/menuRows.js +43 -0
  141. package/kits/hub-game/code/client/modelReady.js +7 -0
  142. package/kits/hub-game/code/client/pack.js +6 -2
  143. package/kits/hub-game/code/client/packFormat.js +3 -3
  144. package/kits/hub-game/code/client/padCueArrival.js +23 -0
  145. package/kits/hub-game/code/client/padCues.js +112 -0
  146. package/kits/hub-game/code/client/padOccupancy.js +88 -0
  147. package/kits/hub-game/code/client/padReadability.js +26 -0
  148. package/kits/hub-game/code/client/padRings.js +69 -0
  149. package/kits/hub-game/code/client/pushVisit.js +14 -0
  150. package/kits/hub-game/code/client/quality.js +205 -0
  151. package/kits/hub-game/code/client/qualityEntry.js +55 -0
  152. package/kits/hub-game/code/client/rehello.js +167 -0
  153. package/kits/hub-game/code/client/safeLayout.js +338 -0
  154. package/kits/hub-game/code/client/safeStyle.js +42 -0
  155. package/kits/hub-game/code/client/say.js +12 -3
  156. package/kits/hub-game/code/client/shot.js +146 -0
  157. package/kits/hub-game/code/client/shotFit.js +56 -0
  158. package/kits/hub-game/code/client/signIn.js +28 -0
  159. package/kits/hub-game/code/client/sound.js +63 -8
  160. package/kits/hub-game/code/client/soundscape.js +1151 -0
  161. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  162. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  163. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  164. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  165. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  166. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  167. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  168. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  169. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  170. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  171. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  172. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  173. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  174. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  175. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  176. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  177. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  178. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  179. package/kits/hub-game/code/client/spin.js +101 -0
  180. package/kits/hub-game/code/client/state.js +162 -1
  181. package/kits/hub-game/code/client/stuck.js +259 -0
  182. package/kits/hub-game/code/client/talk.js +714 -59
  183. package/kits/hub-game/code/client/tiers.js +543 -52
  184. package/kits/hub-game/code/client/toastBand.js +37 -0
  185. package/kits/hub-game/code/client/together.js +39 -2
  186. package/kits/hub-game/code/client/visibility.js +43 -0
  187. package/kits/hub-game/code/client/weakestLookBake.js +92 -0
  188. package/kits/hub-game/code/client/weakestTier.js +295 -0
  189. package/kits/hub-game/code/client/wear.js +461 -170
  190. package/kits/hub-game/code/client/worldLabels.js +241 -0
  191. package/kits/hub-game/code/client/yours.js +200 -0
  192. package/kits/hub-game/code/companionSpec.js +45 -0
  193. package/kits/hub-game/code/npcDisplayText.js +55 -0
  194. package/kits/hub-game/code/privateText.js +7 -0
  195. package/kits/hub-game/code/server/act.js +124 -0
  196. package/kits/hub-game/code/server/actions.js +138 -0
  197. package/kits/hub-game/code/server/actors.js +11 -2
  198. package/kits/hub-game/code/server/analytics.js +83 -0
  199. package/kits/hub-game/code/server/anonymousEntry.js +49 -0
  200. package/kits/hub-game/code/server/arrivalPose.js +36 -0
  201. package/kits/hub-game/code/server/ask.js +155 -0
  202. package/kits/hub-game/code/server/ballot.js +539 -0
  203. package/kits/hub-game/code/server/cells.js +100 -0
  204. package/kits/hub-game/code/server/companion.js +107 -0
  205. package/kits/hub-game/code/server/cues.js +70 -0
  206. package/kits/hub-game/code/server/decor.js +269 -0
  207. package/kits/hub-game/code/server/doorAnalytics.js +52 -0
  208. package/kits/hub-game/code/server/earned.js +478 -0
  209. package/kits/hub-game/code/server/frameBatch.js +183 -0
  210. package/kits/hub-game/code/server/friendBests.js +166 -0
  211. package/kits/hub-game/code/server/friendsAmong.js +272 -0
  212. package/kits/hub-game/code/server/history.js +7 -0
  213. package/kits/hub-game/code/server/hub.js +2510 -95
  214. package/kits/hub-game/code/server/idle.js +60 -12
  215. package/kits/hub-game/code/server/index.js +28 -6
  216. package/kits/hub-game/code/server/invites.js +19 -0
  217. package/kits/hub-game/code/server/labels.js +36 -2
  218. package/kits/hub-game/code/server/loadAbandon.js +106 -0
  219. package/kits/hub-game/code/server/manifest.js +586 -7
  220. package/kits/hub-game/code/server/menu.js +161 -0
  221. package/kits/hub-game/code/server/npcs.js +1025 -113
  222. package/kits/hub-game/code/server/observe.js +408 -0
  223. package/kits/hub-game/code/server/padOccupancy.js +85 -0
  224. package/kits/hub-game/code/server/party.js +2 -2
  225. package/kits/hub-game/code/server/players.js +30 -0
  226. package/kits/hub-game/code/server/resumePose.js +152 -0
  227. package/kits/hub-game/code/server/say.js +1 -1
  228. package/kits/hub-game/code/server/shot.js +110 -0
  229. package/kits/hub-game/code/server/standing.js +123 -0
  230. package/kits/hub-game/code/server/storageLimit.js +187 -0
  231. package/kits/hub-game/code/server/vis.js +175 -0
  232. package/kits/hub-game/code/server/wear.js +12 -0
  233. package/kits/hub-game/code/server/yours.js +59 -0
  234. package/kits/hub-game/code/shared/act.js +35 -0
  235. package/kits/hub-game/code/shared/cues.js +9 -0
  236. package/kits/hub-game/code/shared/danceIdle.js +28 -0
  237. package/kits/hub-game/code/shared/decor.js +41 -0
  238. package/kits/hub-game/code/shared/loadStages.js +12 -0
  239. package/kits/hub-game/code/shared/quality.js +74 -0
  240. package/kits/hub-game/code/shared/say.js +2 -0
  241. package/kits/hub-game/code/shared/shot.js +53 -0
  242. package/kits/hub-game/code/shared/spin.js +57 -0
  243. package/kits/hub-game/code/systems/hub.js +1753 -202
  244. package/kits/hub-game/docs/analytics.md +279 -0
  245. package/kits/hub-game/docs/content-pack.md +1 -1
  246. package/kits/hub-game/docs/contract.md +3475 -77
  247. package/kits/hub-game/docs/home-pieces.md +71 -0
  248. package/kits/hub-game/docs/observed-progress.md +252 -0
  249. package/kits/hub-game/main.jsx +2 -0
  250. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  251. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  252. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  253. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  254. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  255. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  256. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  257. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  258. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  259. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  260. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  261. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  262. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  263. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  264. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  265. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  266. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  267. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  268. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  269. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  270. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  271. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  272. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  273. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  274. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  275. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  276. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  277. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  278. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  279. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  280. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  281. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  282. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  283. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  284. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  285. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  286. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  287. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  288. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  289. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  290. package/kits/hub-game/package-lock.json +10 -1
  291. package/kits/hub-game/package.json +6 -2
  292. package/kits/hub-game/play/player.js +142 -0
  293. package/kits/hub-game/play/registry.js +47 -0
  294. package/kits/hub-game/play.jsx +37 -0
  295. package/kits/hub-game/scripts/check.mjs +117 -16
  296. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  297. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +132 -0
  298. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  299. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +26 -0
  300. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +123 -0
  301. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  302. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  303. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  304. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  305. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  306. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  307. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  308. package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
  309. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  310. package/kits/hub-game/scripts/test-act-client.mjs +186 -0
  311. package/kits/hub-game/scripts/test-act.mjs +171 -0
  312. package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
  313. package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
  314. package/kits/hub-game/scripts/test-actions-client.mjs +853 -0
  315. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  316. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  317. package/kits/hub-game/scripts/test-actors.mjs +38 -23
  318. package/kits/hub-game/scripts/test-analytics.mjs +76 -0
  319. package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
  320. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
  321. package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
  322. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  323. package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
  324. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  325. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  326. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  327. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  328. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  329. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  330. package/kits/hub-game/scripts/test-avatar-wire.mjs +792 -0
  331. package/kits/hub-game/scripts/test-avatar.mjs +584 -7
  332. package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
  333. package/kits/hub-game/scripts/test-ballot.mjs +1008 -0
  334. package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
  335. package/kits/hub-game/scripts/test-build.mjs +49 -0
  336. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  337. package/kits/hub-game/scripts/test-chat.mjs +863 -0
  338. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  339. package/kits/hub-game/scripts/test-companion-chat.mjs +216 -0
  340. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  341. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  342. package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
  343. package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
  344. package/kits/hub-game/scripts/test-decor-client.mjs +344 -0
  345. package/kits/hub-game/scripts/test-decor.mjs +464 -0
  346. package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
  347. package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
  348. package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
  349. package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
  350. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  351. package/kits/hub-game/scripts/test-earned.mjs +1224 -0
  352. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  353. package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
  354. package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
  355. package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
  356. package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
  357. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  358. package/kits/hub-game/scripts/test-grab-orbit.mjs +961 -0
  359. package/kits/hub-game/scripts/test-grab.mjs +7 -0
  360. package/kits/hub-game/scripts/test-hats.mjs +422 -168
  361. package/kits/hub-game/scripts/test-high-only.mjs +170 -0
  362. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  363. package/kits/hub-game/scripts/test-hub-ops.mjs +758 -2
  364. package/kits/hub-game/scripts/test-hub-trip.mjs +1594 -12
  365. package/kits/hub-game/scripts/test-hud-clear.mjs +484 -57
  366. package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
  367. package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
  368. package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
  369. package/kits/hub-game/scripts/test-idle.mjs +427 -1
  370. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  371. package/kits/hub-game/scripts/test-interest-cells.mjs +513 -0
  372. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  373. package/kits/hub-game/scripts/test-interest.mjs +15 -0
  374. package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
  375. package/kits/hub-game/scripts/test-invites.mjs +109 -0
  376. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  377. package/kits/hub-game/scripts/test-labels.mjs +664 -0
  378. package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
  379. package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
  380. package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
  381. package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
  382. package/kits/hub-game/scripts/test-manifest.mjs +472 -0
  383. package/kits/hub-game/scripts/test-menu-client.mjs +585 -0
  384. package/kits/hub-game/scripts/test-menu.mjs +319 -0
  385. package/kits/hub-game/scripts/test-npcs.mjs +2528 -13
  386. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  387. package/kits/hub-game/scripts/test-observed.mjs +745 -0
  388. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  389. package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
  390. package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
  391. package/kits/hub-game/scripts/test-picker.mjs +541 -0
  392. package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
  393. package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
  394. package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
  395. package/kits/hub-game/scripts/test-quality.mjs +385 -0
  396. package/kits/hub-game/scripts/test-rehello.mjs +1733 -0
  397. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  398. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  399. package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
  400. package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
  401. package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
  402. package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
  403. package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
  404. package/kits/hub-game/scripts/test-say.mjs +1 -1
  405. package/kits/hub-game/scripts/test-shot.mjs +901 -0
  406. package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
  407. package/kits/hub-game/scripts/test-soundscape.mjs +5437 -0
  408. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  409. package/kits/hub-game/scripts/test-standing.mjs +449 -0
  410. package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
  411. package/kits/hub-game/scripts/test-stuck.mjs +1904 -0
  412. package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
  413. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  414. package/kits/hub-game/scripts/test-tiers-render.mjs +412 -0
  415. package/kits/hub-game/scripts/test-tiers.mjs +476 -2
  416. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  417. package/kits/hub-game/scripts/test-try-on.mjs +22 -22
  418. package/kits/hub-game/scripts/test-vis.mjs +770 -0
  419. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  420. package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
  421. package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
  422. package/kits/hub-game/scripts/test-yours-chrome.mjs +210 -0
  423. package/kits/hub-game/scripts/test-yours.mjs +403 -0
  424. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  425. package/kits/multiplayer-3d/castle.json +5 -5
  426. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  427. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  428. package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
  429. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  430. package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
  431. package/kits/multiplayer-3d/code/options.js +5 -0
  432. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  433. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  434. package/kits/multiplayer-3d/code/server/world.js +7 -0
  435. package/kits/multiplayer-3d/code/systems/multiplayer.js +443 -34
  436. package/kits/multiplayer-3d/package-lock.json +8 -1
  437. package/kits/multiplayer-3d/package.json +3 -1
  438. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  439. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  440. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  441. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  442. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  443. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  444. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  445. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
  446. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  447. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
  448. package/kits/physics-2d/CLAUDE.md +19 -1
  449. package/kits/physics-2d/castle.json +2 -2
  450. package/kits/physics-2d/engine/frozenActors.js +233 -0
  451. package/kits/physics-2d/engine/scene.js +337 -3
  452. package/kits/physics-2d/engine/skyKey.js +129 -0
  453. package/kits/physics-2d/engine/stillClock.js +106 -0
  454. package/kits/physics-2d/engine/updateBudget.js +21 -0
  455. package/kits/physics-2d/eslint.config.js +1 -1
  456. package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
  457. package/kits/physics-2d/play/behaviors/Camera.js +40 -0
  458. package/kits/physics-2d/play/behaviors/Collider.js +122 -0
  459. package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
  460. package/kits/physics-2d/play/behaviors/Goal.js +46 -0
  461. package/kits/physics-2d/play/behaviors/Joints.js +126 -0
  462. package/kits/physics-2d/play/behaviors/Layout.js +71 -0
  463. package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
  464. package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
  465. package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
  466. package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
  467. package/kits/physics-2d/play/behaviors/Style.js +209 -0
  468. package/kits/physics-2d/play/behaviors/Text.js +85 -0
  469. package/kits/physics-2d/play/behaviors/Video.js +93 -0
  470. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
  471. package/kits/physics-3d/CLAUDE.md +42 -529
  472. package/kits/physics-3d/behaviors/Body.jsx +3 -0
  473. package/kits/physics-3d/behaviors/Model.jsx +3 -0
  474. package/kits/physics-3d/behaviors/Player.jsx +661 -87
  475. package/kits/physics-3d/behaviors/Shape.jsx +3 -0
  476. package/kits/physics-3d/behaviors/Solid.jsx +3 -0
  477. package/kits/physics-3d/behaviors/Transform.jsx +3 -0
  478. package/kits/physics-3d/castle.json +3 -3
  479. package/kits/physics-3d/docs/engine-camera.md +542 -0
  480. package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
  481. package/kits/physics-3d/docs/engine-load.md +149 -0
  482. package/kits/physics-3d/docs/engine-look.md +114 -0
  483. package/kits/physics-3d/docs/engine-shadows.md +372 -0
  484. package/kits/physics-3d/docs/engine-skip-work.md +187 -0
  485. package/kits/physics-3d/docs/engine-sky.md +198 -0
  486. package/kits/physics-3d/docs/engine-static-actors.md +226 -0
  487. package/kits/physics-3d/docs/engine-view.md +37 -0
  488. package/kits/physics-3d/docs/pxmodel-format.md +9 -1
  489. package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
  490. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -277
  491. package/kits/physics-3d/engine3d/actornode.js +87 -0
  492. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  493. package/kits/physics-3d/engine3d/branches.js +3 -13
  494. package/kits/physics-3d/engine3d/cage.js +2 -7
  495. package/kits/physics-3d/engine3d/cageops.js +2 -17
  496. package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
  497. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  498. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  499. package/kits/physics-3d/engine3d/framecap.js +99 -0
  500. package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
  501. package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
  502. package/kits/physics-3d/engine3d/gait.js +126 -0
  503. package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
  504. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  505. package/kits/physics-3d/engine3d/look.js +514 -48
  506. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  507. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  508. package/kits/physics-3d/engine3d/modelFiles.js +3 -17
  509. package/kits/physics-3d/engine3d/modelMath.js +49 -0
  510. package/kits/physics-3d/engine3d/modelready.js +16 -0
  511. package/kits/physics-3d/engine3d/motion.js +39 -10
  512. package/kits/physics-3d/engine3d/nearshadows.js +106 -21
  513. package/kits/physics-3d/engine3d/optimize.js +9 -5
  514. package/kits/physics-3d/engine3d/orbitinput.js +522 -10
  515. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  516. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  517. package/kits/physics-3d/engine3d/partgeometry.js +1 -16
  518. package/kits/physics-3d/engine3d/paths.js +1 -9
  519. package/kits/physics-3d/engine3d/playTimings.js +50 -0
  520. package/kits/physics-3d/engine3d/playerRun.js +372 -0
  521. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  522. package/kits/physics-3d/engine3d/rapier.js +27 -0
  523. package/kits/physics-3d/engine3d/scatter.js +1 -11
  524. package/kits/physics-3d/engine3d/shadowfade.js +890 -0
  525. package/kits/physics-3d/engine3d/sky.js +547 -0
  526. package/kits/physics-3d/engine3d/skylife.js +306 -0
  527. package/kits/physics-3d/engine3d/squarefirst.js +177 -0
  528. package/kits/physics-3d/engine3d/stillshadows.js +399 -0
  529. package/kits/physics-3d/engine3d/sweep.js +1 -25
  530. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  531. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  532. package/kits/physics-3d/engine3d/world3d.js +1253 -76
  533. package/kits/physics-3d/eslint.config.js +2 -1
  534. package/kits/physics-3d/main.jsx +10 -2
  535. package/kits/physics-3d/package-lock.json +7 -0
  536. package/kits/physics-3d/package.json +5 -1
  537. package/kits/physics-3d/play/behaviors/Body.js +31 -0
  538. package/kits/physics-3d/play/behaviors/Door.js +37 -0
  539. package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
  540. package/kits/physics-3d/play/behaviors/Model.js +23 -0
  541. package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
  542. package/kits/physics-3d/play/behaviors/Player.js +1204 -0
  543. package/kits/physics-3d/play/behaviors/Shape.js +47 -0
  544. package/kits/physics-3d/play/behaviors/Solid.js +16 -0
  545. package/kits/physics-3d/play/behaviors/Transform.js +29 -0
  546. package/kits/physics-3d/pnpm-lock.yaml +8 -0
  547. package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
  548. package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
  549. package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
  550. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  551. package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
  552. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2613 -82
  553. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +2 -2
  554. package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
  555. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +438 -0
  556. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  557. package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
  558. package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
  559. package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
  560. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  561. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  562. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  563. package/kits/physics-3d/scripts/test-near-shadows.mjs +5 -2
  564. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +2001 -0
  565. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +582 -0
  566. package/kits/physics-3d/scripts/test-orbit-shot.mjs +657 -0
  567. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  568. package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
  569. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  570. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  571. package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
  572. package/kits/physics-3d/scripts/test-static-actors.mjs +10 -1
  573. package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
  574. package/kits/physics-3d/scripts/test-static-scenery.mjs +2174 -0
  575. package/kits/physics-3d/scripts/test-steady-hover.mjs +7 -2
  576. package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
  577. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  578. package/kits/physics-3d/systems/physics3d.js +419 -9
  579. package/kits/real-time/castle.json +2 -2
  580. package/kits/real-time/code/client/connection.js +33 -10
  581. package/kits/real-time/code/client/gameHooks.js +2 -0
  582. package/kits/real-time/code/client/joinOverlay.js +9 -4
  583. package/kits/real-time/code/server/gameHooks.js +7 -0
  584. package/kits/real-time/code/server/session.js +102 -22
  585. package/kits/real-time/package-lock.json +1 -1
  586. package/package.json +2 -2
  587. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -9,7 +9,7 @@
9
9
  import assert from 'node:assert/strict';
10
10
  import { register } from 'node:module';
11
11
 
12
- const sdkStub = 'export const Hub = globalThis.__tripHub;';
12
+ const sdkStub = 'export const Hub = globalThis.__tripHub; export const User = { getCurrent: async () => { globalThis.__yoursUserReads = (globalThis.__yoursUserReads ?? 0) + 1; return globalThis.__tripUser ? globalThis.__tripUser() : { userId: \"101\", isAnonymous: false }; } };';
13
13
  const packStub = `
14
14
  export const loadPack = (...args) => globalThis.__tripLoadPack(...args);
15
15
  export const cachedPacks = () => [];
@@ -21,7 +21,13 @@ const mediaStub = 'export const initialMedia = {}; export const playMedia = () =
21
21
  register(
22
22
  'data:text/javascript,' +
23
23
  encodeURIComponent(`
24
+ import { readFile } from 'node:fs/promises';
25
+ import { fileURLToPath } from 'node:url';
24
26
  export async function resolve(specifier, context, next) {
27
+ 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 };
28
+ 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 };
29
+ if (specifier === '@imports/castle.real-time/code/client/messages.js') return { url: ${JSON.stringify(new URL('../../real-time/code/client/messages.js', import.meta.url).href)}, shortCircuit: true };
30
+ if (specifier === '@imports/castle.multiplayer-3d/code/client/avatars.js') return { url: 'data:text/javascript,export const dropMissing = () => {};', shortCircuit: true };
25
31
  if (specifier === 'castle-web-sdk') {
26
32
  return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(sdkStub))}, shortCircuit: true };
27
33
  }
@@ -32,14 +38,21 @@ register(
32
38
  return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(packStub))}, shortCircuit: true };
33
39
  }
34
40
  return next(specifier, context);
41
+ }
42
+ export async function load(url, context, next) {
43
+ if (url.endsWith('/code/client/hookLayer.js')) {
44
+ const source = await readFile(fileURLToPath(url), 'utf8');
45
+ return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
46
+ }
47
+ return next(url, context);
35
48
  }`),
36
49
  );
37
50
 
38
51
  const calls = [];
39
52
  const answers = {};
40
53
  globalThis.__tripHub = {
41
- go: async (doorId) => {
42
- calls.push(['go', doorId]);
54
+ go: async (doorId, ...options) => {
55
+ calls.push(['go', doorId, ...options]);
43
56
  if (answers.goError) {
44
57
  throw Object.assign(new Error('refused'), { code: answers.goError });
45
58
  }
@@ -90,6 +103,11 @@ globalThis.__tripLoadPack = async (sha, url) => {
90
103
 
91
104
  const { installSystem, BANNED_TEXT } = await import('../code/systems/hub.js');
92
105
  const HubState = await import('../code/client/state.js');
106
+ const HookLayer = (await import('../code/client/hookLayer.js')).default;
107
+ const { packPlayer } = await import('../../multiplayer-3d/code/client/poses.js');
108
+ const ShotClient = await import('../code/client/shot.js');
109
+ const { receiveShot } = ShotClient;
110
+ const clearShot = () => ShotClient.clearShot();
93
111
  const { makeTogether } = await import('../code/client/together.js');
94
112
 
95
113
  const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
@@ -141,6 +159,288 @@ async function test(name, fn) {
141
159
  n += 1;
142
160
  }
143
161
 
162
+ await test('v1.125 same-id replay stays one invitation; a new identity receives a new occurrence', async () => {
163
+ const { system, scene } = setup();
164
+ const seen = cueChrome(system);
165
+ system.talk.reset = () => {};
166
+ const local = { id: 'me', components: { Transform: { x: 0, z: 0 } } };
167
+ system.scene = scene;
168
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
169
+ HookLayer.message(scene, { k: 'hub-party', members: null, away: 0, invite: { from: 'p2', username: 'bo' } });
170
+ system.drawChrome(scene, local, 0);
171
+ assert.equal(seen.ask?.kind, 'invite');
172
+ system.drawChrome(scene, local, 12_000);
173
+ assert.equal(seen.ask, null, 'the displayed invitation expires');
174
+ const first = HubState.hub.inviteOccurrence;
175
+ HookLayer.message(scene, { k: 'hub-party', members: null, away: 0, invite: { from: 'p2', username: 'bo' } });
176
+ system.drawChrome(scene, local, 30_000);
177
+ assert.equal(seen.ask, null, 'an indistinguishable same-id replay remains the expired observable offer');
178
+ assert.equal(HubState.hub.inviteOccurrence.n, first.n);
179
+
180
+ system.newIdentity();
181
+ assert.equal(HubState.hub.inviteOccurrence, null, 'the old identity cannot retain a server invitation');
182
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
183
+ HookLayer.message(scene, { k: 'hub-party', members: null, away: 0, invite: { from: 'p2', username: 'bo' } });
184
+ system.drawChrome(scene, local, 31_000);
185
+ assert.equal(seen.ask?.kind, 'invite', 'a later invitation to the new identity is a new offer');
186
+ assert.ok(HubState.hub.inviteOccurrence.n > first.n);
187
+ HubState.clear();
188
+ });
189
+
190
+ await test('v1.125 receipt-boundary clear then same-sender invite is a later occurrence before render', async () => {
191
+ const { system, scene } = setup();
192
+ try {
193
+ HubState.clear();
194
+ HookLayer.message(scene, { k: 'hub-party', invite: { from: 'p2', username: 'bo' } });
195
+ const first = system.ask();
196
+ HookLayer.message(scene, { k: 'hub-party', invite: null });
197
+ HookLayer.message(scene, { k: 'hub-party', invite: { from: 'p2', username: 'bo' } });
198
+ const later = system.ask();
199
+ assert.notEqual(later.key, first.key, 'the clear is observed even when neither packet rendered');
200
+ HookLayer.message(scene, { k: 'hub-party', invite: { from: 'p2', username: 'bo' } });
201
+ assert.equal(system.ask().key, later.key, 'indistinguishable same-sender packets remain one observable offer');
202
+ } finally {
203
+ HubState.clear();
204
+ }
205
+ });
206
+
207
+ await test('a returned ask placement latches only after hub-arrived and an own clamp or later WORLD', () => {
208
+ const scene = { files: {} };
209
+ const system = { net: { selfId: () => 'me' } };
210
+ const playerRow = (id, clamped) => JSON.parse(JSON.stringify([
211
+ id,
212
+ ...packPlayer({ x: 0.9, y: 0, z: -1.4 }, 0, clamped),
213
+ ]));
214
+ HubState.clear();
215
+ HookLayer.state(scene, { k: 'w', ps: [playerRow('me', false)] }, system);
216
+ assert.equal(HubState.hub.arrivalPlaced, false, 'the session\'s initial WORLD is not an arrival placement');
217
+ HookLayer.message(scene, { k: 'hub-arrived', facing: 0 });
218
+ HookLayer.state(scene, { ps: [playerRow('other', true), playerRow('me', false)] }, system);
219
+ assert.equal(HubState.hub.arrivalPlaced, false, 'another player and an ordinary own row do not place this client');
220
+ const clamped = playerRow('me', true);
221
+ assert.equal(clamped[5], 1, 'the production wire packer serialises a clamp as numeric 1');
222
+ HookLayer.state(scene, { ps: [clamped] }, system);
223
+ assert.equal(HubState.hub.arrivalPlaced, true, 'the post-arrived numeric wire clamp is authoritative');
224
+
225
+ HubState.clear();
226
+ HookLayer.message(scene, { k: 'hub-arrived', facing: 0 });
227
+ HookLayer.state(scene, { k: 'w', ps: [playerRow('me', false)] }, system);
228
+ assert.equal(HubState.hub.arrivalPlaced, true, 'a later WORLD after hub-arrived is authoritative on reconnect');
229
+ HubState.clear();
230
+ });
231
+
232
+ await test('v1.125 new identity preserves an expired Your games occurrence', async () => {
233
+ const { system, scene } = setup();
234
+ system.scene = scene;
235
+ const before = { key: 'yours:before', slotKey: 'yours:4:return:1', kind: 'yours' };
236
+ const redrawn = { key: 'yours:after', slotKey: before.slotKey, kind: 'yours' };
237
+ system.askSlot.display(before, { x: 0, z: 0 }, new Set(), 0);
238
+ system.askSlot.frame({ x: 0, z: 0 }, new Set(), 12_000);
239
+ system.newIdentity();
240
+ assert.equal(system.askSlot.display(redrawn, { x: 0, z: 0 }, new Set(), 30_000), null);
241
+ HubState.clear();
242
+ });
243
+
244
+ await test('v1.125 a stale card tap sends nothing after another ask takes the slot', async () => {
245
+ const { system, scene } = setup();
246
+ const sent = [];
247
+ scene.multiplayer.net = { send: (msg) => sent.push(msg) };
248
+ scene.actorWith = () => ({ components: { Transform: { x: 0, z: 0 } } });
249
+ system.talk = { talking: () => false };
250
+ HubState.hub.place = { title: 'Town', result: null };
251
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }];
252
+ HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
253
+ system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: performance.now() + 20_000 };
254
+ const stale = system.ask();
255
+ system.askSlot.display(stale, { x: 0, z: 0 }, new Set(), performance.now());
256
+ HubState.hub.party.proposal = { id: 9, door: 'race', by: 'p3', username: 'dee', asked: true };
257
+ system.answer(scene, stale, true, true);
258
+ assert.deepEqual(sent, [], 'the old play action cannot jump after a proposal replaces it');
259
+ HubState.clear();
260
+ });
261
+
262
+ await test('v1.125 higher-priority chrome delays first display without pausing a shown lease', async () => {
263
+ try {
264
+ HubState.clear();
265
+ const { system, scene } = setup();
266
+ const seen = cueChrome(system);
267
+ const sent = [];
268
+ scene.multiplayer.net = { send: (msg) => sent.push(msg), others: () => new Map(), selfId: () => 'me' };
269
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
270
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }];
271
+ const local = { id: 'me', components: { Transform: { x: 0, z: 0 } } };
272
+ system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: 60_000 };
273
+
274
+ for (const field of ['askInput', 'menuInput', 'actionInput']) {
275
+ system[field] = {};
276
+ system.drawChrome(scene, local, 1_000);
277
+ assert.equal(seen.ask, null, `${field} shields the shared ask`);
278
+ delete system[field];
279
+ }
280
+ system.decor = { opened: () => true };
281
+ system.drawChrome(scene, local, 8_000);
282
+ assert.equal(seen.ask, null, 'decorating shields the shared ask');
283
+ system.decor = { opened: () => false };
284
+ system.drawChrome(scene, local, 9_000);
285
+ assert.equal(seen.ask?.kind, 'play', 'lease starts when chrome can first display the card');
286
+
287
+ system.actionInput = {};
288
+ system.drawChrome(scene, local, 20_999);
289
+ assert.equal(seen.ask, null, 'shown card is covered while the action shield is open');
290
+ delete system.actionInput;
291
+ system.drawChrome(scene, local, 21_000);
292
+ assert.equal(seen.ask, null, 'covering a shown card does not pause its 12-second lease');
293
+ assert.deepEqual(sent, [], 'passive expiry emits no decline or other wire message');
294
+ } finally {
295
+ HubState.clear();
296
+ }
297
+ });
298
+
299
+ await test('v1.125 a hidden or suspended page starts no lease before the card can display', async () => {
300
+ try {
301
+ HubState.clear();
302
+ const { system, scene } = setup();
303
+ const seen = cueChrome(system);
304
+ let showable = false;
305
+ system.chrome.askShowable = () => showable;
306
+ scene.multiplayer.net = { send() {}, others: () => new Map(), selfId: () => 'me' };
307
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
308
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }];
309
+ const local = { id: 'me', components: { Transform: { x: 0, z: 0 } } };
310
+ system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: 60_000 };
311
+ system.drawChrome(scene, local, 0);
312
+ assert.equal(seen.ask, null, 'nothing is drawn on a hidden page');
313
+ assert.equal(system.askSlot.known(system.ask(0)), false, 'a hidden frame starts no lease');
314
+ showable = true;
315
+ system.drawChrome(scene, local, 12_000);
316
+ assert.equal(seen.ask?.kind, 'play', 'foregrounding at 12 s shows the unseen offer');
317
+ system.drawChrome(scene, local, 23_999);
318
+ assert.equal(seen.ask?.kind, 'play', 'its lease starts at that first actual display');
319
+ showable = false;
320
+ system.drawChrome(scene, local, 24_000);
321
+ showable = true;
322
+ system.drawChrome(scene, local, 24_001);
323
+ assert.equal(seen.ask, null, 'a hidden page still ages a lease that was already shown');
324
+ } finally {
325
+ HubState.clear();
326
+ }
327
+ });
328
+
329
+ await test('v1.125 a tap on a redrawn Your games presentation keeps the live lease', async () => {
330
+ const oldYours = HubState.deck.yourGames;
331
+ const savedPerformance = globalThis.performance;
332
+ try {
333
+ HubState.clear();
334
+ HubState.deck.yourGames = true;
335
+ let now = 1_000;
336
+ globalThis.performance = { now: () => now };
337
+ const { system, scene } = setup();
338
+ scene.multiplayer.net = { send() {} };
339
+ scene.actorWith = () => ({ components: { Transform: { x: 0, z: 0 } } });
340
+ system.talk = { talking: () => false };
341
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
342
+ const drawn = { key: 'yours:s1:house::', slotKey: 's1', kind: 'yours', door: 'house', yes: 'Go', no: 'Not now' };
343
+ let card = drawn;
344
+ let dismissed = 0;
345
+ system.yours = { ask: () => card, dismiss() { dismissed += 1; } };
346
+ system.askSlot.display(drawn, { x: 0, z: 0 }, new Set(), now);
347
+ card = { ...drawn, key: 'yours:s1:house:house:' };
348
+ now = 2_000;
349
+ system.answer(scene, drawn, false, true);
350
+ assert.equal(dismissed, 0, 'a stale presentation is not acted on');
351
+ assert.equal(system.askSlot.expired(drawn), false, 'and does not consume the lease');
352
+ system.answer(scene, card, false, true);
353
+ assert.equal(dismissed, 1, 'a tap on the current presentation still answers the offer');
354
+ assert.equal(system.askSlot.expired(card), true);
355
+ } finally {
356
+ globalThis.performance = savedPerformance;
357
+ HubState.deck.yourGames = oldYours;
358
+ HubState.clear();
359
+ }
360
+ });
361
+
362
+ await test('v1.125 an ask-card heart honours the lease', async () => {
363
+ const oldYours = HubState.deck.yourGames;
364
+ const savedPerformance = globalThis.performance;
365
+ try {
366
+ HubState.clear();
367
+ HubState.deck.yourGames = true;
368
+ let now = 1_000;
369
+ globalThis.performance = { now: () => now };
370
+ const { system, scene } = setup();
371
+ scene.actorWith = () => ({ components: { Transform: { x: 0, z: 0 } } });
372
+ system.talk = { talking: () => false };
373
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
374
+ const card = { key: 'yours:s1:house::', slotKey: 's1', kind: 'yours', door: 'house', heart: false, yes: 'Go', no: 'Not now' };
375
+ const toggled = [];
376
+ system.yours = { ask: () => card, dismiss() {}, toggle: (door) => toggled.push(door) };
377
+ system.askSlot.display(card, { x: 0, z: 0 }, new Set(), now);
378
+ now = 12_999;
379
+ system.heartAsk(scene, card, 'house');
380
+ assert.deepEqual(toggled, ['house'], 'a heart inside the lease toggles');
381
+ assert.equal(system.askSlot.expired(card), false, 'a heart does not consume the card');
382
+ system.heartAsk(scene, card, 'other');
383
+ assert.deepEqual(toggled, ['house'], 'only the door the card names');
384
+ now = 13_000;
385
+ system.heartAsk(scene, card, 'house');
386
+ assert.deepEqual(toggled, ['house'], 'a heart at the expiry boundary changes nothing');
387
+ } finally {
388
+ globalThis.performance = savedPerformance;
389
+ HubState.deck.yourGames = oldYours;
390
+ HubState.clear();
391
+ }
392
+ });
393
+
394
+ await test('v1.125 play, follow and Play again deadlines are pending-only after first display', async () => {
395
+ const oldCues = HubState.deck.cues;
396
+ const oldYours = HubState.deck.yourGames;
397
+ const savedPerformance = globalThis.performance;
398
+ try {
399
+ HubState.deck.cues = true;
400
+ HubState.deck.yourGames = false;
401
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
402
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }];
403
+ for (const kind of ['play', 'follow', 'again']) {
404
+ const { system } = setup();
405
+ if (kind === 'again') {
406
+ system.againAsk = { door: 'race', until: 20_000 };
407
+ } else {
408
+ system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: 20_000, ...(kind === 'follow' ? { went: true } : {}) };
409
+ }
410
+ const card = system.ask(15_000);
411
+ assert.equal(card.kind, kind === 'again' ? 'again' : 'play');
412
+ system.askSlot.display(card, { x: 0, z: 0 }, new Set(), 15_000);
413
+ assert.equal(system.ask(26_999)?.key, card.key, `${kind} survives its producer deadline`);
414
+ assert.equal(system.askSlot.accepts(card, { x: 0, z: 0 }, new Set(), 26_999), true, `${kind} remains actionable for the full lease`);
415
+ assert.equal(system.askSlot.accepts(card, { x: 0, z: 0 }, new Set(), 27_000), false, `${kind} expires at first display plus 12 seconds`);
416
+ system.retireExpiredAsk(system.ask(27_000));
417
+ assert.equal(kind === 'again' ? system.againAsk : system.playAsk, null, `${kind} source retires without resurrection`);
418
+ }
419
+ const { system } = setup();
420
+ system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: 20_000 };
421
+ assert.equal(system.ask(20_000), null, 'an undisplayed pending offer still ends at its producer deadline');
422
+
423
+ let now = 26_999;
424
+ globalThis.performance = { now: () => now };
425
+ const active = setup();
426
+ const sent = [];
427
+ active.scene.multiplayer.net = { send: (msg) => sent.push(msg) };
428
+ active.scene.actorWith = () => ({ components: { Transform: { x: 0, z: 0 } } });
429
+ active.system.talk = { talking: () => false };
430
+ active.system.jumpSentAt = -Infinity;
431
+ active.system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: 20_000 };
432
+ const actionable = active.system.ask(15_000);
433
+ active.system.askSlot.display(actionable, { x: 0, z: 0 }, new Set(), 15_000);
434
+ active.system.answer(active.scene, actionable, true, true);
435
+ assert.deepEqual(sent, [{ k: 'hub-door-jump', door: 'race' }], 'the action still works after the producer deadline and before lease expiry');
436
+ } finally {
437
+ globalThis.performance = savedPerformance;
438
+ HubState.deck.cues = oldCues;
439
+ HubState.deck.yourGames = oldYours;
440
+ HubState.clear();
441
+ }
442
+ });
443
+
144
444
  await test('a fired pad is Hub.go, then the pack the handoff names, then a hub join', async () => {
145
445
  const { system, scene } = setup();
146
446
  answers.go = handoff();
@@ -470,6 +770,45 @@ await test('a place behind a door whose server is replaced under a player: left
470
770
  assert.equal(r.system.toast.text, 'The game ended');
471
771
  assert.deepEqual(r.switched, []);
472
772
 
773
+ // A game that ended while the player was away, seen as they come back: the
774
+ // multiplayer kit's cover is up over the place as it was, so the way back
775
+ // starts under the trip's cover, fully down in that same frame, rather than
776
+ // playing the door beat over the old scene.
777
+ for (const place of [{ title: 'Foot Race', result: {} }, { title: 'Pebble Cove' }]) {
778
+ const { system, scene } = setup();
779
+ const covers = [];
780
+ system.chrome.setCover = (...args) => covers.push(args[0]);
781
+ scene.multiplayer = { ...mpStub(scene), net: null, returning: () => true };
782
+ scene.multiplayer.target = { mode: 'hub', handoff: { sessionId: 'cove-1' } };
783
+ scene.persistent.hubDepth = 1;
784
+ scene.persistent.hubTickets = [{ scene: 'scenes/main.scene', title: 'Town', door: 'cove', hub: true, join: { mode: 'public' } }];
785
+ HubState.hub.place = place;
786
+ answers.back = handoff();
787
+ system.lastNet = closedNet();
788
+ system.watchSession(scene, scene.multiplayer);
789
+ assert.ok(system.trip, `${place.title}: on its way back`);
790
+ system.stepTrip(scene, scene.multiplayer, null, performance.now());
791
+ assert.equal(covers[0], 1, `${place.title}: the first cover drawn is fully down`);
792
+ await flush();
793
+ }
794
+ // Not returning: the beat plays, and the cover comes down over it.
795
+ {
796
+ const { system, scene } = setup();
797
+ const covers = [];
798
+ system.chrome.setCover = (...args) => covers.push(args[0]);
799
+ scene.multiplayer = { ...mpStub(scene), net: null, returning: () => false };
800
+ scene.multiplayer.target = { mode: 'hub', handoff: { sessionId: 'cove-1' } };
801
+ scene.persistent.hubDepth = 1;
802
+ scene.persistent.hubTickets = [{ scene: 'scenes/main.scene', title: 'Town', door: 'cove', hub: true, join: { mode: 'public' } }];
803
+ HubState.hub.place = { title: 'Foot Race', result: {} };
804
+ answers.back = handoff();
805
+ system.lastNet = closedNet();
806
+ system.watchSession(scene, scene.multiplayer);
807
+ system.stepTrip(scene, scene.multiplayer, null, performance.now());
808
+ assert.equal(covers[0], 0, 'the beat starts uncovered');
809
+ await flush();
810
+ }
811
+
473
812
  // Barred from the hub: nothing is asked.
474
813
  r = run({ error: 'CAULDRON_HUB_BANNED' });
475
814
  await flush();
@@ -513,6 +852,46 @@ await test("a game's end waits out a pending join, settles once it resolves else
513
852
  assert.notEqual(system.pendingEnd, null);
514
853
  });
515
854
 
855
+ await test("a game's end that meets a player coming back from away leaves at once, under the cover", async () => {
856
+ for (const returning of [true, false]) {
857
+ const { system, scene } = setup();
858
+ const backs = [];
859
+ system.back = (_scene, opts) => backs.push(opts ?? {});
860
+ Object.assign(scene.multiplayer, { joinState: () => 'joined', net: null, placed: () => false, returning: () => returning, target: { mode: 'named', key: 'game' } });
861
+ HubState.hub.commands.push({ k: 'hub-end', why: 'end' });
862
+ system.runCommands(scene, 1000);
863
+ system.stepEnd(scene, scene.multiplayer, 1000);
864
+ if (returning) {
865
+ assert.deepEqual(backs, [{ covered: true }], 'no end pause, and no beat over the old place');
866
+ } else {
867
+ assert.deepEqual(backs, [], 'the end pause first');
868
+ system.stepEnd(scene, scene.multiplayer, system.pendingEnd);
869
+ assert.deepEqual(backs, [{ covered: false }]);
870
+ }
871
+ }
872
+ });
873
+
874
+ await test('a returning game with no ticket (a fresh instance, or a town root) also leaves under the cover', async () => {
875
+ for (const place of [{ id: 'race', title: 'Foot Race', result: {} }, { id: 'main', title: 'Town' }]) {
876
+ const { system, scene } = setup();
877
+ const covers = [];
878
+ system.chrome.setCover = (...args) => covers.push(args[0]);
879
+ scene.multiplayer = { ...mpStub(scene), net: null, joinState: () => 'joined', returning: () => true };
880
+ scene.multiplayer.target = { mode: 'named', key: 'game' };
881
+ scene.persistent.hubTickets = [];
882
+ HubState.hub.place = place;
883
+ HubState.hub.commands.push({ k: 'hub-end', why: 'end' });
884
+ const now = performance.now();
885
+ system.runCommands(scene, now);
886
+ system.stepEnd(scene, scene.multiplayer, now);
887
+ assert.ok(system.trip, `${place.title}: on its way`);
888
+ system.stepTrip(scene, scene.multiplayer, null, performance.now());
889
+ assert.equal(covers[0], 1, `${place.title}: the first cover drawn is fully down`);
890
+ await flush();
891
+ }
892
+ HubState.hub.place = null;
893
+ });
894
+
516
895
  await test('with no ticket in a place joined by a hub trip, Hub.back leads wherever ghost says', async () => {
517
896
  const { system, scene } = setup();
518
897
  scene.multiplayer.target = { mode: 'hub', handoff: handoff() };
@@ -548,7 +927,7 @@ function mpStub(scene, state = 'joining') {
548
927
  // Through the opening, to the moment the trip switches sessions.
549
928
  async function toSwitch(system, scene, mp) {
550
929
  await flush();
551
- system.trip.startedAt -= 10000;
930
+ system.trip.startedAt = -10000;
552
931
  system.stepTrip(scene, mp, null, 0);
553
932
  }
554
933
 
@@ -1023,13 +1402,112 @@ await test('a failed door at the root of the trail rejoins the join the runtime
1023
1402
  assert.deepEqual(calls.map((c) => c[0]), ['go', 'loadPack']);
1024
1403
  });
1025
1404
 
1026
- await test('Back at the root of the trail is not Hub.back', async () => {
1027
- const { system, scene } = setup();
1028
- scene.multiplayer.target = { mode: 'hub', handoff: handoff({ nonce: 'spent' }) };
1029
- scene.persistent.hubDepth = 0;
1030
- system.back(scene);
1031
- assert.equal(system.trip.target.join.mode, 'named');
1032
- assert.deepEqual(calls, []);
1405
+ await test('Back at a town root without a ticket rejoins the root join, or public when unset', async () => {
1406
+ const place = HubState.hub.place;
1407
+ const quiet = console.warn;
1408
+ try {
1409
+ for (const town of [{ id: 'main', title: 'Town' }, null]) {
1410
+ for (const root of [{ mode: 'public', destination: { routeId: 'town', slot: 'main' } }, undefined]) {
1411
+ const { system, scene } = setup();
1412
+ HubState.hub.place = town;
1413
+ scene.multiplayer.target = { mode: 'hub', handoff: handoff({ nonce: 'spent' }) };
1414
+ scene.persistent.hubDepth = 0;
1415
+ scene.persistent.hubRootJoin = root;
1416
+ const warnings = [];
1417
+ console.warn = (...args) => warnings.push(args);
1418
+ system.back(scene, { lost: 1 });
1419
+ assert.deepEqual(system.trip.target.join, root ?? { mode: 'public' });
1420
+ if (root) assert.equal(system.trip.target.join, root);
1421
+ assert.notEqual(system.trip.target.join.mode, 'named');
1422
+ assert.equal(system.trip.target.scene, system.scenePath);
1423
+ assert.equal(system.trip.target.title, town?.title ?? '');
1424
+ assert.equal(system.trip.target.exitDoor, null);
1425
+ assert.deepEqual(system.trip.target.arrive, { door: null, party: 1, returning: false });
1426
+ assert.equal(system.trip.target.lost, 1);
1427
+ assert.match(warnings[0][0], /town root without a ticket/);
1428
+ assert.match(warnings[0][1], /HubSystem.back/);
1429
+ assert.deepEqual(calls, []);
1430
+ }
1431
+ }
1432
+ } finally {
1433
+ HubState.hub.place = place;
1434
+ console.warn = quiet;
1435
+ }
1436
+ });
1437
+
1438
+ await test('Back at a game root without a ticket still starts a fresh named round', async () => {
1439
+ const place = HubState.hub.place;
1440
+ try {
1441
+ for (const prefix of ['', 'deck:race/']) {
1442
+ const { system, scene } = setup();
1443
+ HubState.hub.place = { id: 'race', title: 'Race', result: {} };
1444
+ scene.content = { sessionKeyPrefix: prefix };
1445
+ scene.persistent.hubDepth = 0;
1446
+ scene.persistent.hubRootJoin = { mode: 'public' };
1447
+ system.back(scene);
1448
+ assert.equal(system.trip.target.join.mode, 'named');
1449
+ assert.ok(system.trip.target.join.key.startsWith(`${prefix}hub.race.`));
1450
+ assert.match(system.trip.target.join.key.slice(`${prefix}hub.race.`.length), /^[a-z0-9]+$/);
1451
+ assert.deepEqual(calls, []);
1452
+ }
1453
+ } finally {
1454
+ HubState.hub.place = place;
1455
+ }
1456
+ });
1457
+
1458
+ await test('Back at a town root settles an ended town visit, so the end does not send the player Back again', async () => {
1459
+ const place = HubState.hub.place;
1460
+ const quiet = console.warn;
1461
+ try {
1462
+ console.warn = () => {};
1463
+ const { system, scene } = setup();
1464
+ HubState.hub.place = { id: 'main', title: 'Town' };
1465
+ scene.multiplayer.target = { mode: 'public' };
1466
+ scene.persistent.hubDepth = 0;
1467
+ system.pendingEnd = 1;
1468
+ system.endSession = 'public:';
1469
+ system.back(scene);
1470
+ assert.deepEqual(system.trip.target.join, { mode: 'public' });
1471
+ assert.equal(system.pendingEnd, null);
1472
+ assert.equal(system.endSession, null);
1473
+ } finally {
1474
+ HubState.hub.place = place;
1475
+ console.warn = quiet;
1476
+ }
1477
+ });
1478
+
1479
+ await test('Back at a game root whose place a close cleared is still a fresh named round', async () => {
1480
+ const place = HubState.hub.place;
1481
+ try {
1482
+ const { system, scene } = setup();
1483
+ HubState.hub.place = null;
1484
+ system.knownPlace = { id: 'race', title: 'Race', result: {} };
1485
+ scene.multiplayer.target = { mode: 'public' };
1486
+ scene.persistent.hubDepth = 0;
1487
+ scene.persistent.hubRootJoin = { mode: 'public' };
1488
+ system.back(scene);
1489
+ assert.equal(system.trip.target.join.mode, 'named');
1490
+ assert.deepEqual(calls, []);
1491
+ } finally {
1492
+ HubState.hub.place = place;
1493
+ }
1494
+ });
1495
+
1496
+ await test('Back at a town root joined by a named key (a dev place) keeps the fresh named place', async () => {
1497
+ const place = HubState.hub.place;
1498
+ try {
1499
+ const { system, scene } = setup();
1500
+ HubState.hub.place = { id: 'main', title: 'Town' };
1501
+ scene.multiplayer.target = { mode: 'named', key: 'hub.main.original' };
1502
+ scene.persistent.hubDepth = 0;
1503
+ scene.persistent.hubRootJoin = { mode: 'public' };
1504
+ system.back(scene);
1505
+ assert.equal(system.trip.target.join.mode, 'named');
1506
+ assert.match(system.trip.target.join.key, /^hub\.main\.[a-z0-9]+$/);
1507
+ assert.deepEqual(calls, []);
1508
+ } finally {
1509
+ HubState.hub.place = place;
1510
+ }
1033
1511
  });
1034
1512
 
1035
1513
  await test('the root join is remembered at the first hub trip only', async () => {
@@ -1171,6 +1649,79 @@ await test('friends: asked from a place that is not a game; here and empty rows
1171
1649
  }
1172
1650
  });
1173
1651
 
1652
+ await test('friends wanted asks at once, after 20 s, then every 90 s, never a trip or keyless game', async () => {
1653
+ const { system, scene } = setup();
1654
+ const mp = { joinState: () => 'joined' };
1655
+ HubState.hub.place = { id: 'main', title: 'Game', result: { outcomes: ['win'] } };
1656
+ HubState.hub.friendsWanted = false;
1657
+ try {
1658
+ system.askFriends(scene, mp, 0);
1659
+ await flush();
1660
+ assert.deepEqual(calls, [], 'keyless game sends nothing');
1661
+ answers.friends = { status: 'ok', friends: [] };
1662
+ HubState.hub.friendsWanted = true;
1663
+ system.askFriends(scene, mp, 1);
1664
+ await flush();
1665
+ assert.deepEqual(calls, [['friends']], 'first idle tick on receipt');
1666
+ system.askFriends(scene, mp, 20000);
1667
+ await flush();
1668
+ assert.equal(calls.length, 1);
1669
+ system.trip = {};
1670
+ system.askFriends(scene, mp, 20001);
1671
+ await flush();
1672
+ assert.equal(calls.length, 1, 'trip sends nothing');
1673
+ system.trip = null;
1674
+ system.askFriends(scene, { joinState: () => 'joining' }, 20001);
1675
+ await flush();
1676
+ assert.equal(calls.length, 1, 'not yet joined');
1677
+ system.askFriends(scene, mp, 20001);
1678
+ await flush();
1679
+ assert.equal(calls.length, 2, 'warm-up ask after heartbeat roster');
1680
+ system.askFriends(scene, mp, 40001);
1681
+ system.askFriends(scene, mp, 110000);
1682
+ await flush();
1683
+ assert.equal(calls.length, 2, 'warm-up does not repeat');
1684
+ answers.friendsError = 'TIMEOUT';
1685
+ system.askFriends(scene, mp, 110001);
1686
+ await flush();
1687
+ assert.equal(system.friendsOff, false);
1688
+ answers.friendsError = 'UNKNOWN_COMMAND';
1689
+ system.askFriends(scene, mp, 200001);
1690
+ await flush();
1691
+ assert.equal(system.friendsOff, true);
1692
+ system.askFriends(scene, mp, 290001);
1693
+ await flush();
1694
+ assert.equal(calls.length, 4, 'unknown command stops all asks');
1695
+ } finally {
1696
+ HubState.hub.place = null;
1697
+ HubState.hub.friendsWanted = false;
1698
+ }
1699
+ });
1700
+
1701
+ await test('a failed first friends ask still warms up after 20 s', async () => {
1702
+ const { system, scene } = setup();
1703
+ const mp = { joinState: () => 'joined' };
1704
+ HubState.hub.place = { id: 'main', result: {} };
1705
+ HubState.hub.friendsWanted = true;
1706
+ try {
1707
+ answers.friendsError = 'TIMEOUT';
1708
+ system.askFriends(scene, mp, 0);
1709
+ await flush();
1710
+ assert.equal(system.friendsOff, false);
1711
+ answers.friendsError = null;
1712
+ answers.friends = { status: 'ok', friends: [] };
1713
+ system.askFriends(scene, mp, 19999);
1714
+ await flush();
1715
+ assert.equal(calls.length, 1);
1716
+ system.askFriends(scene, mp, 20000);
1717
+ await flush();
1718
+ assert.equal(calls.length, 2);
1719
+ } finally {
1720
+ HubState.hub.place = null;
1721
+ HubState.hub.friendsWanted = false;
1722
+ }
1723
+ });
1724
+
1174
1725
  await test('a door refused because the player is barred from the hub says so, and is not asked again', async () => {
1175
1726
  const { system, scene } = setup();
1176
1727
  answers.goError = 'CAULDRON_HUB_BANNED';
@@ -1335,6 +1886,143 @@ await test('People: a game lists who may be reported, only where the host runs t
1335
1886
  HubState.hub.whereAt = {};
1336
1887
  });
1337
1888
 
1889
+ await test('People: Join on a friend at home in their House goes through the House door with the owner; other friends keep the door jump', async () => {
1890
+ const { system, scene } = setup();
1891
+ const sent = [];
1892
+ scene.multiplayer.net = { others: () => new Map(), userId: () => null, send: (msg) => sent.push(msg) };
1893
+ HubState.hub.place = { title: 'Town', result: null };
1894
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }, { id: 'home-1', title: 'Your House' }];
1895
+ const friends = [
1896
+ { userId: '13', username: 'fay', here: false, door: 'home-1', home: true, ownerUserId: '13' },
1897
+ { userId: '11', username: 'dee', here: false, door: 'race' },
1898
+ // A host that predates owners: no home, so the pad, as before.
1899
+ { userId: '14', username: 'gus', here: false, door: 'home-1' },
1900
+ { userId: '15', username: 'hal', here: false, door: 'home-1', home: true, ownerUserId: 'not an id' },
1901
+ ];
1902
+ system.friendsAll = friends;
1903
+ const rows = system.people(scene, false);
1904
+ assert.deepEqual(
1905
+ rows.map((row) => [row.username, row.where, row.actions.map((a) => a.id).join(), row.door, row.owner ?? null]),
1906
+ [
1907
+ ['fay', "inside fay's House", 'door', 'home-1', '13'],
1908
+ ['dee', 'inside Foot Race', 'door', 'race', null],
1909
+ ['gus', 'inside Your House', 'door', 'home-1', null],
1910
+ ['hal', 'inside Your House', 'door', 'home-1', null],
1911
+ ],
1912
+ );
1913
+
1914
+ // Join asks the place, which ends the visit here as any door's trip does
1915
+ // and sends this player through with the owner (`hub-go` carrying it).
1916
+ system.join(scene, rows[0], 'door');
1917
+ assert.deepEqual(sent, [{ k: 'hub-house-visit', door: 'home-1', owner: '13' }], 'no walk to the pad');
1918
+ assert.equal(system.toast.text, "Going to fay's House");
1919
+ assert.equal(system.trip ?? null, null, 'nothing travels until the place says so');
1920
+ answers.go = handoff();
1921
+ system.goHub(scene, { k: 'hub-go', door: 'home-1', key: null, place: null, scene: null, title: 'Your House', party: 1, owner: '13' });
1922
+ await flush();
1923
+ assert.deepEqual(calls[0], ['go', 'home-1', { ownerUserId: '13' }], 'Hub.go names the owner');
1924
+ assert.equal(system.trip.target.retryOwner, '13', 'a retried acquisition keeps the owner');
1925
+ sent.length = 0;
1926
+
1927
+ // Not at home: the door jump, and Hub.go is never asked from here.
1928
+ const plain = setup();
1929
+ plain.scene.multiplayer.net = { others: () => new Map(), userId: () => null, send: (msg) => sent.push(msg) };
1930
+ plain.system.friendsAll = friends;
1931
+ const again = plain.system.people(plain.scene, false);
1932
+ plain.system.join(plain.scene, again[1], 'door');
1933
+ plain.system.jumpSentAt = -Infinity;
1934
+ plain.system.join(plain.scene, again[2], 'door');
1935
+ await flush();
1936
+ assert.deepEqual(sent, [{ k: 'hub-door-jump', door: 'race' }, { k: 'hub-door-jump', door: 'home-1' }]);
1937
+ assert.equal(calls.some(([c]) => c === 'go'), false);
1938
+ assert.equal(plain.system.trip ?? null, null);
1939
+ HubState.hub.place = null;
1940
+ HubState.hub.doors = [];
1941
+ });
1942
+
1943
+ await test('a door trip without an owner calls Hub.go with the door alone', async () => {
1944
+ const { system, scene } = setup();
1945
+ answers.go = handoff();
1946
+ system.goHub(scene, { door: 'home-1', key: null, title: 'Your House' });
1947
+ await flush();
1948
+ assert.deepEqual(calls[0], ['go', 'home-1']);
1949
+ assert.equal(system.trip.target.retryOwner, null);
1950
+ });
1951
+
1952
+ await test('v1.122 play cards: friends/party far, strangers near, bounded across doors', async () => {
1953
+ const { system } = setup();
1954
+ const oldPolicy = HubState.deck.playCards;
1955
+ const oldParty = HubState.hub.party;
1956
+ const oldDoors = HubState.hub.doors;
1957
+ const at = { p2: { x: 12, z: 0 }, p3: { x: 11, z: 0 } };
1958
+ const local = { components: { Transform: { x: 0, z: 0 } } };
1959
+ const scene = {
1960
+ multiplayer: {
1961
+ net: { userId: (id) => ({ p2: '102', p3: '103' })[id] },
1962
+ players: { get: (id) => at[id] ? { samples: [{ pose: [at[id].x, 1, at[id].z, 0] }] } : null },
1963
+ avatars: { actors: new Map([['p2', 'p2'], ['p3', 'p3']]) },
1964
+ },
1965
+ getActor: (id) => at[id] ? { components: { Transform: at[id] } } : null,
1966
+ };
1967
+ const offer = (id, door, now) => system.offerPlay(scene, local, now, id, id, door);
1968
+ try {
1969
+ HubState.deck.playCards = true;
1970
+ HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
1971
+ HubState.hub.doors = [{ id: 'race', title: 'Race' }, { id: 'tiles', title: 'Tiles' }];
1972
+ offer('p2', 'race', 1000);
1973
+ assert.equal(system.playAsk.from, 'p2', '12 m stranger included');
1974
+ const first = system.playAsk;
1975
+ offer('p3', 'tiles', 2000);
1976
+ assert.equal(system.playAsk, first, 'another stranger cannot replace the live card');
1977
+ offer('p2', 'tiles', 3000);
1978
+ assert.equal(system.playAsk, first, 'cycling doors cannot extend the card');
1979
+ system.playAsk = null; // Not now.
1980
+ offer('p2', 'tiles', 22000);
1981
+ assert.equal(system.playAsk, null, 'cooldown applies across doors after dismissal');
1982
+ offer('p2', 'tiles', 60999);
1983
+ assert.equal(system.playAsk, null);
1984
+ offer('p2', 'tiles', 61000);
1985
+ assert.equal(system.playAsk.door, 'tiles', '60 s permits another card');
1986
+ offer('p3', 'race', 81000);
1987
+ assert.equal(system.playAsk.from, 'p3', 'expiry frees the stranger slot');
1988
+ system.playAsk = null;
1989
+ // The rendered pose deliberately disagrees with the network position.
1990
+ scene.getActor = () => ({ components: { Transform: { x: 11.98, z: 0 } } });
1991
+ at.p2.x = 12.2;
1992
+ offer('p2', 'race', 150000);
1993
+ assert.equal(system.playAsk, null, 'far stranger refused');
1994
+ scene.getActor = () => ({ components: { Transform: { x: 12.2, z: 0 } } });
1995
+ at.p2.x = 11.98;
1996
+ offer('p2', 'race', 150001);
1997
+ assert.equal(system.playAsk.from, 'p2', 'near network pose wins over far rendered pose');
1998
+ system.playAsk = null;
1999
+ delete at.p2;
2000
+ offer('p2', 'race', 250001);
2001
+ assert.equal(system.playAsk, null, 'missing pose refused');
2002
+ at.p2 = { x: 500, z: 0 };
2003
+ system.friendsAll = [{ userId: 102, here: true }];
2004
+ offer('p2', 'race', 250002);
2005
+ assert.equal(system.playAsk.from, 'p2', 'mutual friend far included');
2006
+ assert.equal(system.playAsk.stranger, false);
2007
+ system.playAsk = null;
2008
+ system.friendsAll = [];
2009
+ HubState.hub.party.members = ['p2'];
2010
+ offer('p2', 'tiles', 250003);
2011
+ assert.equal(system.playAsk.from, 'p2', 'party member far included');
2012
+ system.playAsk = null;
2013
+ HubState.hub.party.members = null;
2014
+ HubState.deck.playCards = false;
2015
+ offer('p2', 'race', 350000);
2016
+ assert.deepEqual(system.playAsk, { from: 'p2', name: 'p2', door: 'race', until: 370000 }, 'keyless card shape and far policy unchanged');
2017
+ offer('p2', 'tiles', 350001);
2018
+ assert.equal(system.playAsk.door, 'tiles', 'keyless cooldown remains per door');
2019
+ } finally {
2020
+ HubState.deck.playCards = oldPolicy;
2021
+ HubState.hub.party = oldParty;
2022
+ HubState.hub.doors = oldDoors;
2023
+ }
2024
+ });
2025
+
1338
2026
  await test('a sent chat line says whom it reached', async () => {
1339
2027
  const { system } = setup();
1340
2028
  let status = 'sent';
@@ -1522,7 +2210,7 @@ function cueChrome(system) {
1522
2210
  const seen = { toast: '', say: null, ask: null };
1523
2211
  system.chrome = {
1524
2212
  showBack() {}, showPicker() {}, setFriends() {}, setDoors() {}, setPeople() {}, setHud() {}, setLabels() {}, setRibbon() {},
1525
- setToast(text) { seen.toast = text; },
2213
+ setToast(text, options) { seen.toast = text; seen.toastOptions = options; },
1526
2214
  setSay(say) { seen.say = say; },
1527
2215
  setAsk(ask) { seen.ask = ask; },
1528
2216
  };
@@ -1923,6 +2611,54 @@ await test('cues: the chat field says who reads it or why it is off, and chat pe
1923
2611
  }
1924
2612
  });
1925
2613
 
2614
+ // A guest (their own account is anonymous) is over 13 like any other player:
2615
+ // their chat field reads exactly what a signed-in player's does, on or off,
2616
+ // cues or not, in a town or behind a door, and in a place that names guests.
2617
+ await test('a guest\'s chat field reads what a signed-in player\'s does: no sign-in hint', async () => {
2618
+ const why = 'Typed chat is for friends who follow each other. Emotes work with everyone.';
2619
+ const off = "Chat isn't available on this account";
2620
+ try {
2621
+ for (const cues of [true, false]) {
2622
+ const today = cues ? { input: false, note: why, placeholder: 'Friends only', label: why } : { input: false, note: off };
2623
+ const on = { input: true, note: 'Chat reaches amy', ...(cues ? { placeholder: 'To your follows…', label: 'Message · only players you follow each other with' } : {}) };
2624
+ for (const anonymousEntry of [false, true]) {
2625
+ for (const user of [{ userId: '101', isAnonymous: true }, { userId: '101', isAnonymous: false }]) {
2626
+ const what = `cues ${cues}, anonymousEntry ${anonymousEntry}, anonymous ${user.isAnonymous}`;
2627
+ const { system, scene } = setup();
2628
+ HubState.deck.cues = cues;
2629
+ HubState.hub.place = { title: 'Town', result: null, ...(anonymousEntry ? { anonymousEntry: true } : {}) };
2630
+ if (anonymousEntry && user.isAnonymous) {HubState.hub.guests = new Set(['me']);}
2631
+ const seen = cueChrome(system);
2632
+ townNet(scene, new Map([['p2', 'bo'], ['p4', 'amy']]), { me: '101', p2: '102', p4: '104' });
2633
+ const chat = { canChat: false, peers: [], incoming: [], available: () => true, frame() {}, soon() {} };
2634
+ system.chat = chat;
2635
+ globalThis.__tripUser = () => user;
2636
+ system.drawChrome(scene, null, 1000);
2637
+ await flush();
2638
+ system.drawChrome(scene, null, 1100);
2639
+ assert.deepEqual(seen.say.chat, today, `${what}: off`);
2640
+ chat.canChat = true;
2641
+ chat.peers = ['104'];
2642
+ system.drawChrome(scene, null, 1200);
2643
+ assert.deepEqual(seen.say.chat, on, `${what}: on`);
2644
+ chat.canChat = false;
2645
+ chat.peers = [];
2646
+ // Behind a door: the game's chat is left as the host answers it.
2647
+ HubState.hub.place = { title: 'Foot Race', result: { outcomes: ['win'] } };
2648
+ system.drawChrome(scene, null, 1300);
2649
+ assert.deepEqual(seen.say.chat, { input: false, note: off }, `${what}: behind a door`);
2650
+ delete HubState.hub.guests;
2651
+ resetTown();
2652
+ }
2653
+ }
2654
+ }
2655
+ } finally {
2656
+ delete globalThis.__tripUser;
2657
+ delete HubState.hub.guests;
2658
+ resetTown();
2659
+ }
2660
+ });
2661
+
1926
2662
  // A phrase id the kit does not have.
1927
2663
  const GONE = 'join';
1928
2664
  await test('Doors > Go sends what it always did, cues or not: a jump alone, a proposal to a party here, a jump to a solo door; an unknown phrase heard is nothing', async () => {
@@ -2026,6 +2762,852 @@ await test('cues: a party that gains a member says so; not the party a session i
2026
2762
  }
2027
2763
  });
2028
2764
 
2765
+ await test('v1.52: Back, hub-end then Back, local doors and Hub.go capture the leaving line; cabinets do not', async () => {
2766
+ try {
2767
+ for (const way of ['back', 'end', 'door', 'hub', 'classic']) {
2768
+ HubState.clear();
2769
+ HubState.hub.place = { id: 'main', title: 'Town' };
2770
+ HubState.hub.leaving = 'Your lantern is waiting';
2771
+ const { system, scene } = setup();
2772
+ if (way === 'back') system.back(scene);
2773
+ if (way === 'end') {
2774
+ HubState.hub.commands.push({ k: 'hub-end', why: 'end' });
2775
+ system.runCommands(scene, 1000);
2776
+ system.stepEnd(scene, { joinState: () => 'joined' }, 2200);
2777
+ }
2778
+ if (way === 'door') system.go(scene, { door: 'race', key: 'hub.race', title: 'Foot Race' });
2779
+ if (way === 'hub') {
2780
+ answers.go = handoff();
2781
+ system.goHub(scene, { door: 'race', title: 'Foot Race' });
2782
+ await flush();
2783
+ }
2784
+ if (way === 'classic') system.startTrip(scene, { classic: true, title: 'Cabinet' });
2785
+ assert.equal(system.trip.leaving, way === 'classic' ? null : 'Your lantern is waiting', way);
2786
+ const captured = system.trip.leaving;
2787
+ HubState.clear();
2788
+ assert.equal(system.trip.leaving, captured, 'captured across Hub.clear');
2789
+ }
2790
+ } finally { HubState.clear(); }
2791
+ });
2792
+
2793
+ await test('v1.52: a fast trip shows the line as soon as the cover lifts, expires at 2800 ms, and never waits', async () => {
2794
+ const saved = globalThis.performance;
2795
+ let now = 1000;
2796
+ globalThis.performance = { now: () => now };
2797
+ try {
2798
+ HubState.clear();
2799
+ HubState.hub.leaving = 'Next time, the well';
2800
+ const { system, scene } = setup();
2801
+ const seen = cueChrome(system);
2802
+ const covers = [];
2803
+ system.chrome.setCover = (...args) => covers.push(args);
2804
+ system.startTrip(scene, { scene: 'scenes/next.scene', title: 'Next', join: { mode: 'public' } });
2805
+ const trip = system.trip;
2806
+ const mp = mpStub(scene, 'joined');
2807
+ mp.placed = () => true;
2808
+ system.stepTrip(scene, mp, null, 1650);
2809
+ assert.equal(trip.phase, 'loading');
2810
+ assert.deepEqual(covers.at(-1), [1, 'Next', 'Next time, the well']);
2811
+ assert.equal(HubState.hub.leaving, null, 'switch clears the old place line');
2812
+ scene.currentScenePath = scene.requestedScene;
2813
+ scene.requestedScene = null;
2814
+ HubState.hub.arrivedFacing = 0;
2815
+ system.stepTrip(scene, mp, null, 1651);
2816
+ assert.equal(trip.phase, 'revealing');
2817
+ now = 2071; // 60% of reveal: cover lifted, trip still moving.
2818
+ system.stepTrip(scene, mp, null, now);
2819
+ system.drawChrome(scene, null, now);
2820
+ assert.equal(seen.toast, 'Next time, the well');
2821
+ assert.deepEqual(seen.toastOptions, { wrap: true });
2822
+ assert.equal(system.trip, trip);
2823
+ now = 2351;
2824
+ system.stepTrip(scene, mp, null, now);
2825
+ assert.equal(system.trip, null, 'finished on the ordinary 700 ms reveal deadline');
2826
+ system.drawChrome(scene, null, 3799);
2827
+ assert.equal(seen.toast, 'Next time, the well');
2828
+ system.drawChrome(scene, null, 3800);
2829
+ assert.equal(seen.toast, '');
2830
+ assert.equal(seen.toastOptions, undefined, 'ordinary toasts keep the original call');
2831
+ } finally { globalThis.performance = saved; HubState.clear(); }
2832
+ });
2833
+
2834
+ await test('v1.52: return result and leaving line share one bounded toast; result survives the line deadline', async () => {
2835
+ const saved = globalThis.performance;
2836
+ globalThis.performance = { now: () => 2000 };
2837
+ try {
2838
+ HubState.clear();
2839
+ const { system, scene } = setup();
2840
+ const seen = cueChrome(system);
2841
+ system.chrome.setCover = () => {};
2842
+ scene.persistent.hubResult = { title: 'Foot Race', outcome: 'win' };
2843
+ const trip = { n: 1, startedAt: 1000, leaving: 'Your lantern is waiting', leavingUntil: 3800,
2844
+ target: { scene: 'scenes/main.scene', arrive: { returning: true } },
2845
+ marks: { covered: 1650, arrived: 1700, firstFrame: 1800, revealed: 2000 } };
2846
+ system.finishTrip(scene, trip);
2847
+ system.drawChrome(scene, null, 2000);
2848
+ assert.match(seen.toast, /^Back from Foot Race.* · Your lantern is waiting$/);
2849
+ const resultToast = system.toast;
2850
+ system.drawChrome(scene, null, 3799);
2851
+ assert.match(seen.toast, / · Your lantern is waiting$/);
2852
+ system.drawChrome(scene, null, 3800);
2853
+ assert.equal(system.toast, resultToast);
2854
+ assert.match(seen.toast, /^Back from Foot Race/);
2855
+ assert.doesNotMatch(seen.toast, /Your lantern/);
2856
+ scene.persistent.hubResult.title = 'X'.repeat(300);
2857
+ trip.leaving = 'y'.repeat(120);
2858
+ system.showLeaving(scene, trip, 2000);
2859
+ assert.ok(system.leavingToast.text.length <= 203);
2860
+ } finally { globalThis.performance = saved; HubState.clear(); }
2861
+ });
2862
+
2863
+ await test('v1.52: newer action feedback supersedes leaving, across reveal frames and the arrival result', async () => {
2864
+ const saved = globalThis.performance;
2865
+ let now = 2000;
2866
+ globalThis.performance = { now: () => now };
2867
+ try {
2868
+ for (const returning of [false, true]) {
2869
+ HubState.clear();
2870
+ const { system, scene } = setup();
2871
+ const seen = cueChrome(system);
2872
+ system.chrome.setCover = () => {};
2873
+ scene.persistent.hubResult = { title: 'Foot Race', outcome: 'win' };
2874
+ const trip = { n: 1, startedAt: 1000, leaving: 'Your lantern is waiting', leavingUntil: 3800,
2875
+ target: { scene: 'scenes/main.scene', arrive: { returning } },
2876
+ marks: { covered: 1650, arrived: 1700, firstFrame: 1800, revealed: 2200 } };
2877
+ system.toast = { text: 'Older feedback', until: 6000 };
2878
+ system.showLeaving(scene, trip, now);
2879
+ system.drawChrome(scene, null, now);
2880
+ assert.match(seen.toast, /Your lantern is waiting$/);
2881
+ // Real People-list action after the leaving toast starts.
2882
+ scene.multiplayer.net = { send() {} };
2883
+ now = 2100;
2884
+ system.join(scene, { playerId: 'ada', username: 'Ada' }, 'invite');
2885
+ const feedback = system.toast;
2886
+ system.drawChrome(scene, null, now);
2887
+ assert.equal(seen.toast, 'Invited Ada to your party');
2888
+ assert.equal(seen.toastOptions, undefined);
2889
+ now = 2200;
2890
+ system.showLeaving(scene, trip, now);
2891
+ system.finishTrip(scene, trip);
2892
+ system.drawChrome(scene, null, now);
2893
+ assert.equal(system.toast, feedback, 'arrival result does not overwrite newer feedback');
2894
+ assert.equal(seen.toast, 'Invited Ada to your party');
2895
+ // Expired newer feedback must not uncover the old leaving line again.
2896
+ feedback.until = 2300;
2897
+ system.drawChrome(scene, null, 2400);
2898
+ assert.equal(seen.toast, '');
2899
+ now = 2000;
2900
+ }
2901
+ } finally { globalThis.performance = saved; HubState.clear(); }
2902
+ });
2903
+
2904
+ await test('v1.52: replacement trips retain the first line and deadline after Hub.clear', async () => {
2905
+ const saved = globalThis.performance;
2906
+ let now = 1000;
2907
+ globalThis.performance = { now: () => now };
2908
+ try {
2909
+ for (const way of ['back', 'door', 'door-nested', 'jump', 'jump-nested', 'lost', 'mount']) {
2910
+ now = 1000;
2911
+ HubState.clear();
2912
+ HubState.hub.leaving = 'Next time, the well';
2913
+ const { system, scene } = setup();
2914
+ const mp = mpStub(scene);
2915
+ answers.go = handoff();
2916
+ answers.jump = handoff();
2917
+ answers.back = handoff();
2918
+ if (['back', 'door-nested', 'jump-nested'].includes(way)) {
2919
+ scene.persistent.hubDepth = 1;
2920
+ scene.persistent.hubTickets.push({ hub: true, scene: 'scenes/main.scene', title: 'Town', join: { mode: 'public' } });
2921
+ scene.multiplayer.target = { mode: 'hub', handoff: handoff({ nonce: 'spent' }) };
2922
+ }
2923
+ if (way === 'back') system.back(scene);
2924
+ else if (way.startsWith('jump')) system.jump(scene, { userId: 'ada', username: 'Ada' });
2925
+ else system.goHub(scene, { door: 'race', title: 'Foot Race' });
2926
+ await flush();
2927
+ const first = system.trip;
2928
+ assert.equal(first.leavingUntil, first.startedAt + 2800);
2929
+ system.stepTrip(scene, mp, null, 1650);
2930
+ assert.equal(first.phase, 'committing', way);
2931
+ assert.equal(HubState.hub.leaving, null);
2932
+ now = 1800;
2933
+ if (way === 'lost' || way === 'mount') {
2934
+ mp.state = 'joined';
2935
+ system.stepTrip(scene, mp, null, now);
2936
+ assert.equal(first.phase, 'loading');
2937
+ if (way === 'lost') mp.state = 'lost';
2938
+ else scene.mountError = new Error('could not mount');
2939
+ now = 1900;
2940
+ } else {
2941
+ mp.state = 'failed';
2942
+ }
2943
+ system.stepTrip(scene, mp, null, now);
2944
+ await flush();
2945
+ const replacement = system.trip;
2946
+ assert.notEqual(replacement, first, way);
2947
+ assert.equal(replacement.leaving, 'Next time, the well', way);
2948
+ assert.equal(replacement.leavingUntil, 3800, `${way}: deadline never restarts`);
2949
+ const covers = [];
2950
+ system.chrome.setCover = (...args) => covers.push(args);
2951
+ system.setTripCover(1, replacement);
2952
+ assert.equal(covers.at(-1)[2], first.leaving);
2953
+ system.showLeaving(scene, replacement, 3799);
2954
+ assert.equal(system.leavingToast.text, first.leaving);
2955
+ system.leavingToast = null;
2956
+ system.showLeaving(scene, replacement, 3800);
2957
+ assert.equal(system.leavingToast, null, `${way}: no toast beyond the original deadline`);
2958
+ }
2959
+ } finally { globalThis.performance = saved; HubState.clear(); }
2960
+ });
2961
+
2962
+ await test('v1.52: end-triggered Back retries after exhausted join attempts retain the original deadline', async () => {
2963
+ const saved = globalThis.performance;
2964
+ let now = 1000;
2965
+ globalThis.performance = { now: () => now };
2966
+ try {
2967
+ HubState.clear();
2968
+ HubState.hub.leaving = 'Next time, the well';
2969
+ const { system, scene } = setup();
2970
+ scene.persistent.hubDepth = 1;
2971
+ scene.persistent.hubTickets.push({ hub: true, scene: 'scenes/main.scene', title: 'Town', join: { mode: 'public' } });
2972
+ answers.back = handoff();
2973
+ HubState.hub.commands.push({ k: 'hub-end' });
2974
+ system.runCommands(scene, 0);
2975
+ system.back(scene);
2976
+ const first = system.trip;
2977
+ HubState.clear();
2978
+ now = 1800;
2979
+ system.uncommitted(scene, first, now);
2980
+ const retry = system.trip;
2981
+ assert.equal(retry.leaving, first.leaving);
2982
+ assert.equal(retry.leavingUntil, 3800);
2983
+ now = 2000;
2984
+ system.uncommitted(scene, retry, now);
2985
+ assert.equal(system.trip, null, 'ordinary retry exhausted');
2986
+ now = 3900;
2987
+ system.stepEnd(scene, { joinState: () => 'failed' }, now);
2988
+ assert.equal(system.trip.leaving, first.leaving);
2989
+ assert.equal(system.trip.leavingUntil, 3800, 'end retry cannot extend the toast');
2990
+ system.showLeaving(scene, system.trip, now);
2991
+ assert.equal(system.leavingToast, null);
2992
+ await flush();
2993
+ scene.multiplayer.target = { mode: 'named', key: 'another-visit' };
2994
+ system.settleEnd(scene);
2995
+ assert.equal(system.endLeaving, null);
2996
+ } finally { globalThis.performance = saved; HubState.clear(); }
2997
+ });
2998
+
2999
+ await test('v1.52: a slow trip keeps its cover line and creates no expired arrival toast; no-line trips keep the old cover arguments', async () => {
3000
+ try {
3001
+ HubState.clear();
3002
+ const { system, scene } = setup();
3003
+ const covers = [];
3004
+ system.chrome.setCover = (...args) => covers.push(args);
3005
+ system.startTrip(scene, { title: 'Town' });
3006
+ system.setTripCover(1, system.trip);
3007
+ assert.deepEqual(covers.at(-1), [1, 'Town']);
3008
+ const trip = system.trip;
3009
+ trip.leaving = 'The well is waiting';
3010
+ system.setTripCover(1, trip);
3011
+ assert.deepEqual(covers.at(-1), [1, 'Town', 'The well is waiting']);
3012
+ system.showLeaving(scene, trip, trip.leavingUntil + 1);
3013
+ assert.equal(system.leavingToast, null);
3014
+ trip.shut = 'full';
3015
+ system.setTripCover(1, trip);
3016
+ assert.deepEqual(covers.at(-1), [1, 'Town']);
3017
+ system.showLeaving(scene, trip, trip.startedAt + 1);
3018
+ assert.equal(system.leavingToast, null, 'a door that stayed shut has no arrival line');
3019
+ } finally { HubState.clear(); }
3020
+ });
3021
+
3022
+ await test('v1.52: hubLeaving is a bounded localhost fixture, ignored by hosted pages and classic cabinets', async () => {
3023
+ const saved = globalThis.location;
3024
+ try {
3025
+ HubState.clear();
3026
+ for (const hostname of ['localhost', '127.0.0.1', 'castle.xyz']) {
3027
+ globalThis.location = { hostname, search: '?hubLeaving=%20' + 'x'.repeat(140) + '%20' };
3028
+ const { system, scene } = setup();
3029
+ system.startTrip(scene, { title: 'Town' });
3030
+ assert.equal(system.trip.leaving, hostname === 'castle.xyz' ? null : 'x'.repeat(120));
3031
+ system.trip = null;
3032
+ system.startTrip(scene, { title: 'Cabinet', classic: true });
3033
+ assert.equal(system.trip.leaving, null);
3034
+ }
3035
+ } finally { globalThis.location = saved; HubState.clear(); }
3036
+ });
3037
+
3038
+ await test('yourGames v1.54: keyless sends nothing; offers obey party, solo, invitation, game and trip rules', async () => {
3039
+ try {
3040
+ const { system, scene } = setup();
3041
+ const seen = cueChrome(system);
3042
+ system.chrome.setCover = () => {};
3043
+ const sent = townNet(scene, new Map([['p2', 'bo']]), { p2: '102' });
3044
+ HubState.hub.place = { title: 'Town', result: null };
3045
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }, { id: 'solo', title: 'Sprint', solo: true }];
3046
+ HubState.hub.yours = { rows: [{ door: 'race', title: 'Foot Race', line: 'Best 10 s · today', hearted: true }], hearts: ['race'] };
3047
+ let heartReads = 0;
3048
+ globalThis.__tripHub.hearts = async () => { heartReads++; return { status: 'ok', hearts: ['race'] }; };
3049
+ HubState.deck.yourGames = false;
3050
+ const before = globalThis.__yoursUserReads ?? 0;
3051
+ system.drawChrome(scene, null, performance.now());
3052
+ await flush();
3053
+ assert.equal(system.yours, undefined);
3054
+ assert.equal(heartReads, 0);
3055
+ assert.equal(globalThis.__yoursUserReads ?? 0, before, 'keyless reads no account');
3056
+ assert.equal(seen.ask, null);
3057
+ HubState.deck.yourGames = true;
3058
+ HubState.deck.cues = true;
3059
+ system.drawChrome(scene, null, performance.now());
3060
+ await flush();
3061
+ system.drawChrome(scene, null, performance.now());
3062
+ assert.equal(heartReads, 1);
3063
+ assert.deepEqual([seen.ask.kind, seen.ask.text, seen.ask.line, seen.ask.yes], ['yours', '♥ Foot Race', 'Best 10 s · today', 'Go']);
3064
+ system.answer(scene, seen.ask, false);
3065
+ system.drawChrome(scene, null, performance.now());
3066
+ assert.equal(seen.ask, null, 'dismissed once');
3067
+ const back = (door) => {
3068
+ const at = performance.now();
3069
+ system.finishTrip(scene, { n: 1, startedAt: at, marks: { covered: at, arrived: at, firstFrame: at, revealed: at }, target: { arrive: { door, returning: true } } });
3070
+ };
3071
+ HubState.hub.arrivalPlaced = true;
3072
+ back('race');
3073
+ HubState.hub.party.members = ['p2'];
3074
+ system.drawChrome(scene, null, performance.now());
3075
+ assert.equal(seen.ask.yes, 'Go together');
3076
+ assert.equal(seen.ask.heart, true);
3077
+ system.answer(scene, seen.ask, true);
3078
+ assert.deepEqual(sent.splice(0), [{ k: 'hub-party', op: 'go', door: 'race' }]);
3079
+ scene.persistent.hubResult = { title: 'Sprint', score: 14, unit: 's' };
3080
+ back('solo');
3081
+ system.drawChrome(scene, null, performance.now());
3082
+ assert.deepEqual([seen.ask.door, seen.ask.yes, system.againAsk], ['solo', 'Go', null]);
3083
+ assert.equal(seen.ask.line, 'Last 14 s · today', 'return outside the top five still has a personal line');
3084
+ HubState.hub.party.invite = { from: 'p2', username: 'bo' };
3085
+ system.drawChrome(scene, null, performance.now());
3086
+ assert.equal(seen.ask.kind, 'invite');
3087
+ HubState.hub.party.invite = null;
3088
+ HubState.hub.party.proposal = { asked: false, door: 'race' };
3089
+ system.drawChrome(scene, null, performance.now());
3090
+ assert.equal(seen.ask, null, 'no offer over any proposal');
3091
+ HubState.hub.party.proposal = null;
3092
+ HubState.hub.place.result = {};
3093
+ system.drawChrome(scene, null, performance.now());
3094
+ assert.equal(seen.ask, null, 'never in a game');
3095
+ HubState.hub.place.result = null;
3096
+ system.trip = { phase: 'open' };
3097
+ system.drawChrome(scene, null, performance.now());
3098
+ assert.equal(seen.ask, null, 'never during a trip');
3099
+ assert.equal(heartReads, 1);
3100
+ } finally {
3101
+ HubState.deck.yourGames = false;
3102
+ HubState.hub.yours = null;
3103
+ delete globalThis.__tripHub.hearts;
3104
+ delete globalThis.__yoursUserReads;
3105
+ resetTown();
3106
+ }
3107
+ });
3108
+
3109
+ await test('a returned Your games card starts at the authoritative town pose and keeps that lease through reconnect', async () => {
3110
+ const oldYours = HubState.deck.yourGames;
3111
+ try {
3112
+ HubState.clear();
3113
+ HubState.deck.yourGames = true;
3114
+ const { system, scene } = setup();
3115
+ const seen = cueChrome(system);
3116
+ system.talk.reset = () => {};
3117
+ system.chrome.setCover = () => {};
3118
+ system.scene = scene;
3119
+ townNet(scene, new Map(), {});
3120
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
3121
+ HubState.hub.doors = [{ id: 'house', title: 'Your house' }];
3122
+ HubState.hub.yours = { rows: [{ door: 'house', title: 'Your house', line: '', hearted: false }], hearts: [] };
3123
+ globalThis.__tripHub.hearts = async () => ({ status: 'ok', hearts: [] });
3124
+ const local = { id: 'me', components: { Transform: { x: 1.1, z: 9 } } };
3125
+
3126
+ system.drawChrome(scene, local, 0);
3127
+ await flush();
3128
+ system.drawChrome(scene, local, 1);
3129
+ system.answer(scene, seen.ask, false);
3130
+ system.drawChrome(scene, local, 2);
3131
+ assert.equal(seen.ask, null, 'the ordinary arrival card is out of the way');
3132
+
3133
+ const at = performance.now();
3134
+ system.finishTrip(scene, { n: 1, startedAt: at, timedOut: false, marks: { covered: at, arrived: at, firstFrame: at, revealed: at }, target: { arrive: { door: 'house', returning: true } } });
3135
+ system.drawChrome(scene, local, 700);
3136
+ assert.equal(seen.ask, null, 'the return offer has no card or lease at the scene spawn');
3137
+ HubState.hub.arrivalPlaced = true;
3138
+ const readBeforeDisplay = system.ask(700);
3139
+ assert.equal(readBeforeDisplay?.requiresArrivalPlacement, true, 'the returned occurrence carries its placement requirement');
3140
+ assert.equal(system.askSlot.known(readBeforeDisplay), false, 'reading a ready ask does not count as its first display');
3141
+
3142
+ system.newIdentity();
3143
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
3144
+ HubState.hub.doors = [{ id: 'house', title: 'Your house' }];
3145
+ HubState.hub.yours = { rows: [{ door: 'house', title: 'Your house', line: '', hearted: false }], hearts: [] };
3146
+ assert.equal(HubState.hub.arrivalPlaced, false);
3147
+ system.drawChrome(scene, local, 750);
3148
+ assert.equal(seen.ask, null, 'a session clear still withholds an occurrence that was read but never displayed');
3149
+ assert.equal(system.askSlot.known(readBeforeDisplay), false);
3150
+
3151
+ HookLayer.message(scene, { k: 'hub-arrived', facing: 0 });
3152
+ HookLayer.state(scene, { ps: [['me', ...packPlayer({ x: 0.9, y: 0, z: -1.4 }, 0, true)]] }, { net: scene.multiplayer.net });
3153
+ Object.assign(local.components.Transform, { x: 0.9, z: -1.4 });
3154
+ system.drawChrome(scene, local, 800);
3155
+ assert.equal(seen.ask?.kind, 'yours', 'the next hub frame displays at the applied town pose');
3156
+ const shown = seen.ask;
3157
+
3158
+ system.newIdentity();
3159
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
3160
+ HubState.hub.doors = [{ id: 'house', title: 'Your house' }];
3161
+ HubState.hub.yours = { rows: [{ door: 'house', title: 'Your house', line: '', hearted: false }], hearts: [] };
3162
+ assert.equal(HubState.hub.arrivalPlaced, false);
3163
+ system.drawChrome(scene, local, 12_799);
3164
+ assert.equal(seen.ask?.slotKey, shown.slotKey, 'a known lease remains visible through reconnect without a new placement receipt');
3165
+ system.drawChrome(scene, local, 12_800);
3166
+ assert.equal(seen.ask, null, 'reconnect does not restart the original twelve-second deadline');
3167
+
3168
+ HookLayer.message(scene, { k: 'hub-arrived', facing: 0 });
3169
+ HookLayer.state(scene, { ps: [['me', ...packPlayer({ x: 0.9, y: 0, z: -1.4 }, 0, true)]] }, { net: scene.multiplayer.net });
3170
+ const again = performance.now();
3171
+ system.finishTrip(scene, { n: 2, startedAt: again, timedOut: false, marks: { covered: again, arrived: again, firstFrame: again, revealed: again }, target: { arrive: { door: 'house', returning: true } } });
3172
+ system.drawChrome(scene, local, 13_000);
3173
+ assert.notEqual(seen.ask?.slotKey, shown.slotKey, 'a later return is a distinct occurrence');
3174
+ local.components.Transform.x += 3;
3175
+ system.drawChrome(scene, local, 13_000);
3176
+ assert.equal(seen.ask, null, 'three metres from its actual display pose expires the card');
3177
+ } finally {
3178
+ HubState.deck.yourGames = oldYours;
3179
+ delete globalThis.__tripHub.hearts;
3180
+ HubState.clear();
3181
+ }
3182
+ });
3183
+
3184
+ await test('a timed-out or lost return waits for a later authoritative placement', () => {
3185
+ const oldYours = HubState.deck.yourGames;
3186
+ try {
3187
+ HubState.clear();
3188
+ HubState.deck.yourGames = true;
3189
+ for (const fallback of [{ timedOut: true }, { lost: 'join closed' }]) {
3190
+ HubState.clear();
3191
+ const { system, scene } = setup();
3192
+ const label = Object.keys(fallback)[0];
3193
+ const card = { key: `yours:return:${label}`, slotKey: `yours:return:${label}`, kind: 'yours', requiresArrivalPlacement: true };
3194
+ system.yours = { returned() {}, ask: () => card };
3195
+ const at = performance.now();
3196
+ system.finishTrip(scene, { n: 1, startedAt: at, ...fallback, marks: { covered: at, revealed: at }, target: { arrive: { door: 'house', returning: true } } });
3197
+ assert.equal(system.ask(), null, `${label} return remains withheld at the unplaced spawn`);
3198
+ assert.equal(system.askSlot.known(card), false);
3199
+
3200
+ HookLayer.message(scene, { k: 'hub-arrived', facing: 0 });
3201
+ const packed = JSON.parse(JSON.stringify(['me', ...packPlayer({ x: 0.9, y: 0, z: -1.4 }, 0, true)]));
3202
+ assert.equal(packed[5], 1, 'the late placement uses the production numeric clamp flag');
3203
+ HookLayer.state(scene, { ps: [packed] }, { net: { selfId: () => 'me' } });
3204
+ assert.equal(system.ask(), card, `${label} return becomes eligible after authoritative placement`);
3205
+ }
3206
+ } finally {
3207
+ HubState.deck.yourGames = oldYours;
3208
+ HubState.clear();
3209
+ }
3210
+ });
3211
+
3212
+ // v1.61: exercise the production lifecycle methods, including direct door
3213
+ // travel that starts without a hub-go message.
3214
+ for (const [name, leave] of [
3215
+ ['door trip', (system, scene) => system.startTrip(scene, { scene: 'scenes/next.scene' })],
3216
+ ['leaving the session', (system, scene) => {
3217
+ scene.multiplayer.switchSession = () => {};
3218
+ system.leaveSession(scene, scene.multiplayer);
3219
+ }],
3220
+ ['same-scene load', (system, scene) => system.reset(scene)],
3221
+ ['entering another scene', (system, scene) => system.enterScene(scene)],
3222
+ ['disconnect', (system, scene) => {
3223
+ system.lastNet = { closed: () => true };
3224
+ scene.multiplayer.net = null;
3225
+ system.watchSession(scene, scene.multiplayer);
3226
+ }],
3227
+ ['runtime disposal', (system) => { system.chrome = null; system.dispose(); }],
3228
+ ]) {
3229
+ for (const deckOwns of [false, true]) {
3230
+ await test(`v1.61: ${name} clears only a hub-owned shot (deck owns: ${deckOwns})`, () => {
3231
+ HubState.clear();
3232
+ const { system, scene } = setup();
3233
+ scene.cameraControl = 'orbit';
3234
+ const pose = { look: { x: 1, y: 2, z: 3 }, distance: 8, pitch: 30, yaw: 45 };
3235
+ try {
3236
+ receiveShot(scene, pose);
3237
+ if (deckOwns) { scene.orbitShot = pose; }
3238
+ leave(system, scene);
3239
+ assert.equal(scene.orbitShot, deckOwns ? pose : undefined);
3240
+ assert.equal(Object.hasOwn(HubState.hub, 'shot'), false);
3241
+ } finally {
3242
+ clearShot();
3243
+ }
3244
+ });
3245
+ }
3246
+ }
3247
+
3248
+ // A connection the session let go and took back (a phone's app switch): the
3249
+ // real-time server sends a WORLD snapshot each time it gives a connection a
3250
+ // body, and the client's hub system greets again when a second one is drained.
3251
+ function fakeNet(selfId = 'p1') {
3252
+ const net = {
3253
+ sent: [],
3254
+ inbox: [],
3255
+ id: selfId,
3256
+ send(msg) {
3257
+ net.sent.push(msg);
3258
+ },
3259
+ selfId: () => net.id,
3260
+ drain() {
3261
+ const out = net.inbox;
3262
+ net.inbox = [];
3263
+ return out;
3264
+ },
3265
+ };
3266
+ return net;
3267
+ }
3268
+
3269
+ await test('every place: a connection the session took back on the same net says a fresh hello once; steady state sends none', async () => {
3270
+ for (const place of [{}, { decor: { grid: { x: 0, z: 0, w: 1, d: 1, cell: 1 } } }]) {
3271
+ const { system, scene } = setup();
3272
+ HubState.hub.place = place;
3273
+ scene.persistent.hubArriving = { door: 'race', party: 3, returning: true, near: '42' };
3274
+ scene.persistent.hubResult = { title: 'Race', outcome: 'win' };
3275
+ const net = fakeNet();
3276
+ const mp = { net, joined: false };
3277
+ const hellos = () => net.sent.filter((m) => m.k === 'hub-hello');
3278
+ system.sayHello(scene, mp);
3279
+ assert.equal(hellos().length, 1);
3280
+ assert.equal(hellos()[0].party, 3);
3281
+ // The join's own snapshot, then ordinary traffic: no hello again.
3282
+ net.inbox.push({ k: 'w' }, { k: 's' });
3283
+ net.drain();
3284
+ mp.joined = true;
3285
+ for (let i = 0; i < 20; i += 1) {
3286
+ net.inbox.push({ k: 's' }, { k: 'hub-hud' });
3287
+ net.drain();
3288
+ system.sayHello(scene, mp);
3289
+ }
3290
+ assert.equal(hellos().length, 1, 'steady state: no extra hello');
3291
+ // The drop: the session let the player go, the SDK resumed this net, and
3292
+ // the session gave it a body again (a WORLD, queued while frames stopped).
3293
+ const kept = { startNear: system.startNear, say: system.say, together: system.together };
3294
+ net.inbox.push({ k: 'w' });
3295
+ net.drain();
3296
+ system.sayHello(scene, mp);
3297
+ system.sayHello(scene, mp);
3298
+ assert.equal(hellos().length, 2, 'one fresh hello');
3299
+ const again = hellos()[1];
3300
+ assert.equal(again.resume, true);
3301
+ assert.equal(again.again, undefined, 'fresh: the place re-sends what it had sent');
3302
+ assert.equal(again.party, 1, 'from a party of one');
3303
+ assert.equal(again.carry, null, 'carrying nothing back twice');
3304
+ assert.equal(again.near, undefined);
3305
+ assert.equal(again.from, 'race');
3306
+ assert.equal(system.startNear, kept.startNear, 'session state kept');
3307
+ assert.equal(system.say, kept.say);
3308
+ // A second drop greets once more.
3309
+ net.inbox.push({ k: 'w' });
3310
+ net.drain();
3311
+ system.sayHello(scene, mp);
3312
+ assert.equal(hellos().length, 3);
3313
+ HubState.hub.place = null;
3314
+ delete scene.persistent.hubArriving;
3315
+ delete scene.persistent.hubResult;
3316
+ await flush();
3317
+ }
3318
+ });
3319
+
3320
+ await test('a resumed net under a new player id greets afresh; a new net still greets as before', async () => {
3321
+ const { system, scene } = setup();
3322
+ const net = fakeNet('p1');
3323
+ const mp = { net, joined: true };
3324
+ system.sayHello(scene, mp);
3325
+ net.id = 'p9';
3326
+ system.sayHello(scene, mp);
3327
+ const hellos = net.sent.filter((m) => m.k === 'hub-hello');
3328
+ assert.equal(hellos.length, 2);
3329
+ assert.equal(hellos[1].resume, true);
3330
+ system.sayHello(scene, mp);
3331
+ assert.equal(net.sent.filter((m) => m.k === 'hub-hello').length, 2, 'once');
3332
+ const other = fakeNet('p2');
3333
+ system.sayHello(scene, { net: other, joined: false });
3334
+ assert.equal(other.sent.length, 1);
3335
+ assert.equal(other.sent[0].resume, undefined, 'a new net is an ordinary hello');
3336
+ await flush();
3337
+ });
3338
+
3339
+ await test('a new player id on the same net clears the old session\'s private state before the new session\'s packets apply', async () => {
3340
+ // The private packets as the hook layer applies them (client/hookLayer.js).
3341
+ const apply = (msg) => {
3342
+ if (msg.k === 'hub-hud') HubState.hub.hudMe = msg.hud ?? null;
3343
+ if (msg.k === 'hub-tune') HubState.hub.tune = msg.tune;
3344
+ if (msg.k === 'hub-decor') HubState.hub.decor = { button: msg.button, spec: msg.spec, grid: msg.grid };
3345
+ if (msg.k === 'hub-leaving') HubState.hub.leaving = msg.text;
3346
+ if (msg.k === 'hub-ballot-card') BallotClient.gate(HubState.hub.place, net, msg.card);
3347
+ };
3348
+ const BallotClient = await import('../code/client/ballot.js');
3349
+ const { system, scene } = setup();
3350
+ system.scene = scene;
3351
+ const net = fakeNet('pA');
3352
+ const mp = { net, joined: true };
3353
+ scene.multiplayer = { ...scene.multiplayer, net };
3354
+ system.sayHello(scene, mp);
3355
+ // Session A sends this player its own HUD, tune, decor, leaving line,
3356
+ // labels, marks, a held spot, and a choice card.
3357
+ HubState.hub.place = { ballot: true };
3358
+ for (const msg of [
3359
+ { k: 'hub-hud', hud: { title: 'A only' } },
3360
+ { k: 'hub-tune', tune: { speed: 2 } },
3361
+ { k: 'hub-decor', button: 'Decorate', spec: {}, grid: null },
3362
+ { k: 'hub-leaving', text: 'A leaving' },
3363
+ { k: 'hub-ballot-card', card: { v: 'a-1', mode: 'talk', faces: [] } },
3364
+ ]) {
3365
+ apply(msg);
3366
+ }
3367
+ BallotClient.settle(HubState.hub.place);
3368
+ HubState.hub.labelsMe = { x: 'A label' };
3369
+ HubState.hub.marks = { x: 1 };
3370
+ HubState.hub.held.set?.('pA', true);
3371
+ HubState.hub.held.add?.('pA');
3372
+ assert.equal(HubState.hub.hudMe.title, 'A only');
3373
+ assert.ok(BallotClient.cardFor(net), 'the card is held under A');
3374
+ // The SDK re-acquires: same net, new player id; session B has no private
3375
+ // overrides, and its first packet is an ordinary one.
3376
+ net.id = 'pB';
3377
+ net.inbox.push({ k: 'hub-say-x' });
3378
+ const got = net.drain();
3379
+ assert.equal(got.length, 1, 'the packets still go to the caller');
3380
+ assert.equal(HubState.hub.hudMe, null, 'HUD cleared at the boundary');
3381
+ assert.equal(HubState.hub.tune, null, 'tune cleared');
3382
+ assert.equal(HubState.hub.decor, undefined, 'decor cleared');
3383
+ assert.equal(HubState.hub.leaving, null, 'leaving line cleared');
3384
+ assert.deepEqual(HubState.hub.labelsMe, {});
3385
+ assert.deepEqual(HubState.hub.marks, {});
3386
+ assert.equal(HubState.hub.held.size, 0);
3387
+ assert.equal(HubState.hub.place, null);
3388
+ assert.equal(BallotClient.cardFor(net), null, 'the card goes');
3389
+ assert.equal(system.startNear, null, 'a recovery starts beside nobody');
3390
+ // B's own packets then apply normally, and are not cleared again.
3391
+ apply({ k: 'hub-hud', hud: { title: 'B' } });
3392
+ apply({ k: 'hub-tune', tune: { speed: 0.5 } });
3393
+ system.sayHello(scene, mp);
3394
+ net.drain();
3395
+ system.sayHello(scene, mp);
3396
+ assert.equal(HubState.hub.hudMe.title, 'B');
3397
+ assert.equal(HubState.hub.tune.speed, 0.5);
3398
+ const hellos = net.sent.filter((m) => m.k === 'hub-hello');
3399
+ assert.equal(hellos.length, 2, 'one fresh hello for B');
3400
+ assert.equal(hellos[1].resume, true);
3401
+ // The id seen first by sayHello (before any drain) resets too, once.
3402
+ net.id = 'pC';
3403
+ HubState.hub.hudMe = { title: 'B stale' };
3404
+ system.sayHello(scene, mp);
3405
+ assert.equal(HubState.hub.hudMe, null);
3406
+ apply({ k: 'hub-hud', hud: { title: 'C' } });
3407
+ net.drain();
3408
+ assert.equal(HubState.hub.hudMe.title, 'C', 'not reset twice');
3409
+ assert.equal(net.sent.filter((m) => m.k === 'hub-hello').length, 3);
3410
+ HubState.clear();
3411
+ await flush();
3412
+ });
3413
+
3414
+ await test('a game (a place with result) keeps the old way: no client re-hello after a drop', async () => {
3415
+ const { system, scene } = setup();
3416
+ HubState.hub.place = { result: { score: null } };
3417
+ const net = fakeNet();
3418
+ const mp = { net, joined: true };
3419
+ system.sayHello(scene, mp);
3420
+ net.inbox.push({ k: 'w' });
3421
+ net.drain();
3422
+ system.sayHello(scene, mp);
3423
+ system.sayHello(scene, mp);
3424
+ assert.equal(net.sent.filter((m) => m.k === 'hub-hello').length, 1);
3425
+ HubState.hub.place = null;
3426
+ await flush();
3427
+ });
3428
+
3429
+ await test('a game back under a new player id says one fresh, ordinary hello (a party of one, nothing carried)', async () => {
3430
+ const { system, scene } = setup();
3431
+ system.scene = scene;
3432
+ HubState.hub.place = { result: { score: null } };
3433
+ scene.persistent.hubArriving = { door: 'dash', party: 3, returning: true, near: '42' };
3434
+ scene.persistent.hubResult = { title: 'Race', outcome: 'win' };
3435
+ const net = fakeNet('pA');
3436
+ const mp = { net, joined: true };
3437
+ system.sayHello(scene, mp);
3438
+ // A fresh session: the identity reset clears the place until its WORLD.
3439
+ net.id = 'pB';
3440
+ net.drain();
3441
+ assert.equal(HubState.hub.place, null);
3442
+ system.sayHello(scene, mp);
3443
+ system.sayHello(scene, mp);
3444
+ const hellos = net.sent.filter((m) => m.k === 'hub-hello');
3445
+ assert.equal(hellos.length, 2, 'one fresh hello');
3446
+ assert.equal(hellos[1].resume, undefined, 'not a resume');
3447
+ assert.equal(hellos[1].again, undefined, 'a fresh client');
3448
+ assert.equal(hellos[1].party, 1);
3449
+ assert.equal(hellos[1].carry, null);
3450
+ assert.equal(hellos[1].near, undefined);
3451
+ // The new session's WORLD names the game; a drop after it under the same id
3452
+ // keeps the old way.
3453
+ HubState.hub.place = { result: { score: null } };
3454
+ net.inbox.push({ k: 'w' });
3455
+ net.drain();
3456
+ system.sayHello(scene, mp);
3457
+ assert.equal(net.sent.filter((m) => m.k === 'hub-hello').length, 2);
3458
+ HubState.hub.place = null;
3459
+ delete scene.persistent.hubArriving;
3460
+ delete scene.persistent.hubResult;
3461
+ await flush();
3462
+ });
3463
+
3464
+ await test('packets queued under the old player id are dropped at the identity boundary; the new session\'s private packets before its WORLD apply', async () => {
3465
+ const Rehello = await import('../code/client/rehello.js');
3466
+ const BallotClient = await import('../code/client/ballot.js');
3467
+ const { system, scene } = setup();
3468
+ system.scene = scene;
3469
+ const net = fakeNet('pA');
3470
+ const mp = { net, joined: true };
3471
+ system.sayHello(scene, mp);
3472
+ // As the hook layer applies them (client/hookLayer.js).
3473
+ const apply = (msg) => {
3474
+ if (msg.k === 'hub-hud') HubState.hub.hudMe = msg.hud ?? null;
3475
+ if (msg.k === 'hub-tune') HubState.hub.tune = msg.tune;
3476
+ if (msg.k === 'hub-ballot-card') BallotClient.gate(HubState.hub.place, net, msg.card);
3477
+ };
3478
+ // Each message is tagged as it arrives (the hook layer's `arrive`).
3479
+ const arrive = (msg) => {
3480
+ Rehello.tag(msg, net);
3481
+ net.inbox.push(msg);
3482
+ };
3483
+ // Session A's private packets arrive while the page is hidden (no drain).
3484
+ arrive({ k: 'hub-hud', hud: { title: 'A' } });
3485
+ arrive({ k: 'hub-tune', tune: { speed: 2 } });
3486
+ arrive({ k: 'hub-ballot-card', card: { v: 'a-1', mode: 'talk', faces: [] } });
3487
+ // The SDK re-acquires under B; B's private HUD comes ahead of its WORLD.
3488
+ net.id = 'pB';
3489
+ arrive({ k: 'hub-hud', hud: { title: 'B' } });
3490
+ net.inbox.push({ k: 'w', hubPlace: {} });
3491
+ const got = net.drain();
3492
+ assert.deepEqual(got.map((m) => m.k), ['hub-hud', 'w'], 'A\'s packets dropped, B\'s kept in order');
3493
+ assert.equal(got[0].hud.title, 'B');
3494
+ for (const msg of got) apply(msg);
3495
+ assert.equal(HubState.hub.hudMe.title, 'B', 'B\'s HUD applied');
3496
+ assert.equal(HubState.hub.tune, null, 'A\'s tune not re-applied');
3497
+ assert.equal(BallotClient.cardFor(net), null, 'A\'s card not re-applied');
3498
+ // Untagged messages (arrived before a net, or snapshots) are kept.
3499
+ net.inbox.push({ k: 'hub-hud', hud: { title: 'untagged' } });
3500
+ assert.equal(net.drain().length, 1);
3501
+ HubState.clear();
3502
+ await flush();
3503
+ });
3504
+
2029
3505
  console.warn = warn;
2030
3506
  console.log = log;
3507
+
3508
+ await test('scene invite rail: town, House, game; opt-out and stale picks remain dormant', async () => {
3509
+ for (const result of [null, {}]) {
3510
+ const { system, scene } = setup();
3511
+ cueChrome(system);
3512
+ townNet(scene, new Map(), {});
3513
+ system.scene = scene;
3514
+ scene.data = { engine: {} };
3515
+ HubState.hub.place = { title: result ? 'Door' : 'House or town', result, invite: true };
3516
+ let draw, opens = [];
3517
+ system.chrome.showPicker = (...args) => { draw = args; };
3518
+ system.invites = { canInvite: () => true, open: (share) => opens.push(share) };
3519
+ for (const marker of [undefined, false, 'true', true]) {
3520
+ scene.data.engine.hubInviteRail = marker;
3521
+ system.drawChrome(scene, null, performance.now());
3522
+ assert.equal(draw[3] !== undefined, marker === true && !result);
3523
+ assert.equal(draw[0], !result);
3524
+ }
3525
+ if (result) {assert.deepEqual(opens, []); HubState.clear(); continue;}
3526
+ draw[3].onPick();
3527
+ assert.deepEqual(opens, [true]);
3528
+ const stale = draw[3].onPick;
3529
+ // A guest is over 13 like anyone else: the host's canInvite answer decides.
3530
+ HubState.hub.guests = new Set(['me']);
3531
+ system.drawChrome(scene, null, performance.now());
3532
+ assert.notEqual(draw[3], undefined, 'a guest the host can invite sees the invite entry');
3533
+ draw[3].onPick();
3534
+ assert.deepEqual(opens, [true, true], 'a guest the host can invite can open it');
3535
+ opens.pop();
3536
+ delete HubState.hub.guests;
3537
+ system.invites.canInvite = () => false;
3538
+ system.drawChrome(scene, null, performance.now());
3539
+ assert.equal(draw[3], undefined, 'unresolved identity has no invite entry');
3540
+ stale();
3541
+ system.invites.canInvite = () => true;
3542
+ system.trip = { phase: 'open' }; stale(); system.trip = null;
3543
+ const net = scene.multiplayer.net;
3544
+ scene.multiplayer.net = {}; stale(); scene.multiplayer.net = net;
3545
+ const place = HubState.hub.place;
3546
+ HubState.hub.place = { ...place }; stale(); HubState.hub.place = place;
3547
+ scene.data.engine.hubInviteRail = false; stale();
3548
+ assert.deepEqual(opens, [true]);
3549
+ scene.data.engine.hubInviteRail = true;
3550
+ HubState.hub.place = { ...place, invite: false };
3551
+ system.drawChrome(scene, null, performance.now());
3552
+ assert.equal(draw[3], undefined, 'marker cannot invent authored invite capability');
3553
+ HubState.clear();
3554
+ }
3555
+ });
3556
+
2031
3557
  console.log(`hub trips: ${n} tests passed`);
3558
+
3559
+ await test('early proxy not_running retries the same door once with a fresh acquisition under cover', async () => {
3560
+ const { system, scene } = setup(); const mp = mpStub(scene);
3561
+ answers.go = handoff(); system.goHub(scene, { door: 'race', title: 'Foot Race' });
3562
+ await toSwitch(system, scene, mp);
3563
+ const trip = system.trip; trip.target.acquiredAt = 0;
3564
+ mp.state = 'failed'; mp.joinFailure = { code: 'MULTIPLAYER_CONNECTION_FAILED', closeCode: 4404 };
3565
+ system.stepTrip(scene, mp, null, 1500);
3566
+ assert.equal(trip.phase, 'retrying-door');
3567
+ system.stepTrip(scene, mp, null, 3999);
3568
+ assert.equal(calls.filter(c => c[0] === 'go').length, 1);
3569
+ answers.go = handoff({ nonce: 'fresh' });
3570
+ system.stepTrip(scene, mp, null, 4000); await flush();
3571
+ system.stepTrip(scene, mp, null, 4001);
3572
+ assert.equal(trip.phase, 'committing');
3573
+ assert.equal(mp.switched.at(-1).handoff.nonce, 'fresh');
3574
+ assert.equal(scene.persistent.hubTickets.length, 1);
3575
+ assert.equal(scene.persistent.hubDepth ?? 0, 0);
3576
+ assert.equal(scene.requestedScene, undefined);
3577
+ assert.deepEqual(calls.map(c => c[0]), ['go', 'loadPack', 'cancel', 'go', 'loadPack']);
3578
+ mp.state = 'joined'; system.stepTrip(scene, mp, null, 4002);
3579
+ assert.equal(scene.persistent.hubDepth, 1);
3580
+ });
3581
+ for (const [code, age, retried] of [[4401, 1000, false], [1013, 1000, false], [4404, 5001, false], [4404, 1000, true]]) {
3582
+ await test(`door retry limit: close ${code}, age ${age}, already retried ${retried}`, async () => {
3583
+ const { system, scene } = setup(); const mp = mpStub(scene);
3584
+ answers.go = handoff(); system.goHub(scene, { door: 'race' }); await toSwitch(system, scene, mp);
3585
+ system.trip.target.acquiredAt = 0; system.trip.doorRetried = retried;
3586
+ mp.state = 'failed'; mp.joinFailure = { code: 'MULTIPLAYER_CONNECTION_FAILED', closeCode: code };
3587
+ system.stepTrip(scene, mp, null, age);
3588
+ assert.notEqual(system.trip?.phase, 'retrying-door');
3589
+ assert.equal(calls.filter(c => c[0] === 'go').length, 1);
3590
+ });
3591
+ }
3592
+ console.log(`hub trips with retry: ${n} tests passed`);
3593
+
3594
+ for (const failure of ['refused', 'pack', 'timeout']) {
3595
+ await test(`failed door reacquisition recovers the closed source session: ${failure}`, async () => {
3596
+ const { system, scene } = setup(); const mp = mpStub(scene);
3597
+ answers.go = handoff(); system.goHub(scene, { door: 'race' }); await toSwitch(system, scene, mp);
3598
+ system.trip.target.acquiredAt = 0;
3599
+ mp.state = 'failed'; mp.joinFailure = { code: 'MULTIPLAYER_CONNECTION_FAILED', closeCode: 4404 };
3600
+ system.stepTrip(scene, mp, null, 1000);
3601
+ if (failure === 'refused') answers.go = { status: 'full' };
3602
+ if (failure === 'pack') answers.loadPackError = true;
3603
+ system.stepTrip(scene, mp, null, 3500); await flush();
3604
+ if (failure === 'timeout') { system.trip.target.pending.done = false; }
3605
+ system.stepTrip(scene, mp, null, failure === 'timeout' ? 100000 : 3501);
3606
+ assert.equal(system.trip.target.join.mode, 'public');
3607
+ assert.equal(system.trip.target.scene, 'scenes/main.scene');
3608
+ assert.equal(scene.requestedScene, undefined);
3609
+ assert.equal(scene.persistent.hubTickets.length, 0);
3610
+ assert.equal(scene.persistent.hubDepth ?? 0, 0);
3611
+ });
3612
+ }
3613
+ console.log(`hub trips with retry failures: ${n} tests passed`);