castle-web-cli 0.4.229 → 0.4.231

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 (259) hide show
  1. package/dist/agent-prompts.d.ts +2 -0
  2. package/dist/agent-prompts.js +16 -8
  3. package/dist/agent.d.ts +2 -0
  4. package/dist/agent.js +21 -21
  5. package/dist/api.d.ts +28 -2
  6. package/dist/api.js +74 -16
  7. package/dist/castle-host/host.d.ts +91 -0
  8. package/dist/castle-host/host.js +860 -3
  9. package/dist/castleJson.d.ts +44 -0
  10. package/dist/castleJson.js +131 -0
  11. package/dist/check.js +27 -1
  12. package/dist/contentPack.d.ts +49 -0
  13. package/dist/contentPack.js +273 -0
  14. package/dist/devExperiments.d.ts +21 -0
  15. package/dist/devExperiments.js +139 -0
  16. package/dist/devHub.d.ts +55 -0
  17. package/dist/devHub.js +187 -0
  18. package/dist/devSaveStorage.d.ts +36 -0
  19. package/dist/devSaveStorage.js +469 -0
  20. package/dist/devSessionChild.js +25 -13
  21. package/dist/devSessionServer.d.ts +14 -1
  22. package/dist/devSessionServer.js +237 -46
  23. package/dist/devSessionStorage.d.ts +9 -0
  24. package/dist/devSessionStorage.js +66 -1
  25. package/dist/experimentAssignment.d.ts +15 -0
  26. package/dist/experimentAssignment.js +41 -0
  27. package/dist/importCheckHook.d.ts +40 -0
  28. package/dist/importCheckHook.js +171 -0
  29. package/dist/importRegression.d.ts +15 -0
  30. package/dist/importRegression.js +100 -0
  31. package/dist/importTrust.d.ts +2 -0
  32. package/dist/importTrust.js +27 -0
  33. package/dist/importUpdateHook.d.ts +18 -0
  34. package/dist/importUpdateHook.js +31 -8
  35. package/dist/importUpdateHookRunner.js +19 -7
  36. package/dist/imports.d.ts +16 -0
  37. package/dist/imports.js +141 -31
  38. package/dist/index.js +3 -1
  39. package/dist/init.d.ts +3 -0
  40. package/dist/init.js +126 -9
  41. package/dist/install.js +4 -1
  42. package/dist/localPaths.js +4 -0
  43. package/dist/login.js +2 -2
  44. package/dist/platformDoc.js +3 -8
  45. package/dist/playPagePolicy.js +3 -1
  46. package/dist/remix.js +5 -0
  47. package/dist/routerTaskReport.d.ts +28 -0
  48. package/dist/routerTaskReport.js +56 -0
  49. package/dist/save-deck.d.ts +18 -0
  50. package/dist/save-deck.js +142 -6
  51. package/dist/serve.d.ts +8 -0
  52. package/dist/serve.js +99 -14
  53. package/dist/serverBundle.d.ts +1 -1
  54. package/dist/serverBundle.js +5 -1
  55. package/dist/webSourceSync.d.ts +2 -0
  56. package/dist/webSourceSync.js +2 -0
  57. package/kits/base/CLAUDE.md +2 -3
  58. package/kits/base/castle.json +1 -1
  59. package/kits/base/sdk/README.md +406 -53
  60. package/kits/base/sdk/agent.js +4 -4
  61. package/kits/base/sdk/avatar.d.ts +12 -0
  62. package/kits/base/sdk/avatar.js +23 -0
  63. package/kits/base/sdk/castle.d.ts +9 -0
  64. package/kits/base/sdk/castle.js +5 -0
  65. package/kits/base/sdk/commands.d.ts +223 -0
  66. package/kits/base/sdk/commands.js +16 -0
  67. package/kits/base/sdk/context.d.ts +6 -0
  68. package/kits/base/sdk/experiments.d.ts +15 -0
  69. package/kits/base/sdk/experiments.js +83 -0
  70. package/kits/base/sdk/hub.d.ts +85 -0
  71. package/kits/base/sdk/hub.js +107 -0
  72. package/kits/base/sdk/multiplayer.d.ts +45 -1
  73. package/kits/base/sdk/multiplayer.js +158 -8
  74. package/kits/base/sdk/save.d.ts +197 -0
  75. package/kits/base/sdk/save.js +525 -0
  76. package/kits/base/sdk/saveCoordinator.d.ts +39 -0
  77. package/kits/base/sdk/saveCoordinator.js +252 -0
  78. package/kits/base/sdk/server/hub.d.ts +169 -0
  79. package/kits/base/sdk/server/hub.js +125 -0
  80. package/kits/base/sdk/server/platformHandle.d.ts +42 -1
  81. package/kits/base/sdk/server/storage.d.ts +58 -4
  82. package/kits/base/sdk/server/storage.js +25 -5
  83. package/kits/base/sdk/server/wrapper.d.ts +36 -2
  84. package/kits/base/sdk/server/wrapper.js +92 -11
  85. package/kits/base/sdk/store.d.ts +3 -2
  86. package/kits/base/sdk/store.js +5 -0
  87. package/kits/base/sdk/transport.d.ts +2 -1
  88. package/kits/base/sdk/transport.js +13 -1
  89. package/kits/hub-game/.prettierrc +5 -0
  90. package/kits/hub-game/CLAUDE.md +149 -0
  91. package/kits/hub-game/blueprints/avatar-0.scene +28 -0
  92. package/kits/hub-game/blueprints/avatar-1.scene +28 -0
  93. package/kits/hub-game/blueprints/avatar-2.scene +28 -0
  94. package/kits/hub-game/blueprints/avatar-3.scene +28 -0
  95. package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
  96. package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
  97. package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
  98. package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
  99. package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
  100. package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
  101. package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
  102. package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
  103. package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
  104. package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
  105. package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
  106. package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
  107. package/kits/hub-game/castle.json +96 -0
  108. package/kits/hub-game/code/client/attention.js +133 -0
  109. package/kits/hub-game/code/client/avatar.js +288 -0
  110. package/kits/hub-game/code/client/cabinets.js +90 -0
  111. package/kits/hub-game/code/client/chat.js +135 -0
  112. package/kits/hub-game/code/client/chrome.js +1035 -0
  113. package/kits/hub-game/code/client/doorFrame.js +15 -0
  114. package/kits/hub-game/code/client/firstJoin.js +14 -0
  115. package/kits/hub-game/code/client/grab.js +376 -0
  116. package/kits/hub-game/code/client/hookLayer.js +236 -0
  117. package/kits/hub-game/code/client/idle.js +326 -0
  118. package/kits/hub-game/code/client/keys.js +48 -0
  119. package/kits/hub-game/code/client/pack.js +232 -0
  120. package/kits/hub-game/code/client/packFormat.js +397 -0
  121. package/kits/hub-game/code/client/say.js +127 -0
  122. package/kits/hub-game/code/client/sha256.js +80 -0
  123. package/kits/hub-game/code/client/sound.js +147 -0
  124. package/kits/hub-game/code/client/state.js +143 -0
  125. package/kits/hub-game/code/client/talk.js +233 -0
  126. package/kits/hub-game/code/client/tiers.js +480 -0
  127. package/kits/hub-game/code/client/together.js +440 -0
  128. package/kits/hub-game/code/client/wear.js +149 -0
  129. package/kits/hub-game/code/server/actors.js +627 -0
  130. package/kits/hub-game/code/server/blocks.js +103 -0
  131. package/kits/hub-game/code/server/cabinets.js +309 -0
  132. package/kits/hub-game/code/server/game.js +137 -0
  133. package/kits/hub-game/code/server/grab.js +248 -0
  134. package/kits/hub-game/code/server/history.js +96 -0
  135. package/kits/hub-game/code/server/hub.js +1998 -0
  136. package/kits/hub-game/code/server/idle.js +412 -0
  137. package/kits/hub-game/code/server/index.js +64 -0
  138. package/kits/hub-game/code/server/labels.js +59 -0
  139. package/kits/hub-game/code/server/manifest.js +554 -0
  140. package/kits/hub-game/code/server/npcs.js +733 -0
  141. package/kits/hub-game/code/server/party.js +439 -0
  142. package/kits/hub-game/code/server/place.js +43 -0
  143. package/kits/hub-game/code/server/say.js +83 -0
  144. package/kits/hub-game/code/server/wear.js +142 -0
  145. package/kits/hub-game/code/systems/hub.js +2347 -0
  146. package/kits/hub-game/docs/content-pack.md +151 -0
  147. package/kits/hub-game/docs/contract.md +1209 -0
  148. package/kits/hub-game/docs/style.md +137 -0
  149. package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
  150. package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
  151. package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
  152. package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
  153. package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
  154. package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
  155. package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
  156. package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
  157. package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
  158. package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
  159. package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
  160. package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
  161. package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
  162. package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
  163. package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
  164. package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
  165. package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
  166. package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
  167. package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
  168. package/kits/hub-game/eslint.config.js +20 -0
  169. package/kits/hub-game/fonts.generated.js +9 -0
  170. package/kits/hub-game/index.html +22 -0
  171. package/kits/hub-game/main.jsx +6 -0
  172. package/kits/hub-game/models/avatar-0.pxmodel +21 -0
  173. package/kits/hub-game/models/avatar-1.pxmodel +24 -0
  174. package/kits/hub-game/models/avatar-2.pxmodel +27 -0
  175. package/kits/hub-game/models/avatar-3.pxmodel +22 -0
  176. package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
  177. package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
  178. package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
  179. package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
  180. package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
  181. package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
  182. package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
  183. package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
  184. package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
  185. package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
  186. package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
  187. package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
  188. package/kits/hub-game/package-lock.json +365 -0
  189. package/kits/hub-game/package.json +32 -0
  190. package/kits/hub-game/scenes/main.scene +318 -0
  191. package/kits/hub-game/scripts/check.mjs +339 -0
  192. package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
  193. package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
  194. package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
  195. package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
  196. package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
  197. package/kits/hub-game/scripts/pack.mjs +192 -0
  198. package/kits/hub-game/scripts/test-actors.mjs +666 -0
  199. package/kits/hub-game/scripts/test-attention.mjs +103 -0
  200. package/kits/hub-game/scripts/test-avatar.mjs +472 -0
  201. package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
  202. package/kits/hub-game/scripts/test-blocks.mjs +351 -0
  203. package/kits/hub-game/scripts/test-chat.mjs +98 -0
  204. package/kits/hub-game/scripts/test-classic.mjs +590 -0
  205. package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
  206. package/kits/hub-game/scripts/test-door.mjs +56 -0
  207. package/kits/hub-game/scripts/test-grab-client.mjs +328 -0
  208. package/kits/hub-game/scripts/test-grab.mjs +331 -0
  209. package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
  210. package/kits/hub-game/scripts/test-hub-trip.mjs +1518 -0
  211. package/kits/hub-game/scripts/test-idle.mjs +518 -0
  212. package/kits/hub-game/scripts/test-interest.mjs +413 -0
  213. package/kits/hub-game/scripts/test-keys.mjs +50 -0
  214. package/kits/hub-game/scripts/test-manifest.mjs +270 -0
  215. package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
  216. package/kits/hub-game/scripts/test-npcs.mjs +724 -0
  217. package/kits/hub-game/scripts/test-pack.mjs +424 -0
  218. package/kits/hub-game/scripts/test-party.mjs +369 -0
  219. package/kits/hub-game/scripts/test-say.mjs +149 -0
  220. package/kits/hub-game/scripts/test-tiers.mjs +666 -0
  221. package/kits/hub-game/scripts/test-together.mjs +215 -0
  222. package/kits/hub-game/theme.style +3 -0
  223. package/kits/multiplayer-3d/castle.json +5 -5
  224. package/kits/multiplayer-3d/code/client/avatars.js +101 -1
  225. package/kits/multiplayer-3d/code/server/players.js +4 -1
  226. package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
  227. package/kits/multiplayer-3d/code/server/world.js +20 -7
  228. package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
  229. package/kits/physics-2d/CLAUDE.md +2 -0
  230. package/kits/physics-2d/castle.json +2 -2
  231. package/kits/physics-2d/engine/art.js +13 -0
  232. package/kits/physics-2d/engine/assets.js +4 -2
  233. package/kits/physics-2d/engine/scene.js +117 -5
  234. package/kits/physics-2d/package.json +1 -1
  235. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +254 -0
  236. package/kits/physics-3d/CLAUDE.md +285 -1
  237. package/kits/physics-3d/behaviors/Player.jsx +74 -1
  238. package/kits/physics-3d/castle.json +3 -3
  239. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -5
  240. package/kits/physics-3d/engine3d/actornode.js +253 -0
  241. package/kits/physics-3d/engine3d/artobjects.js +2 -2
  242. package/kits/physics-3d/engine3d/materials.js +29 -1
  243. package/kits/physics-3d/engine3d/nearshadows.js +600 -0
  244. package/kits/physics-3d/engine3d/unchanged.js +153 -0
  245. package/kits/physics-3d/engine3d/world3d.js +527 -5
  246. package/kits/physics-3d/package.json +1 -1
  247. package/kits/physics-3d/scripts/test-camera-follow.mjs +533 -0
  248. package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
  249. package/kits/physics-3d/scripts/test-static-actors.mjs +662 -0
  250. package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
  251. package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
  252. package/kits/physics-3d/systems/physics3d.js +187 -5
  253. package/kits/real-time/castle.json +2 -2
  254. package/kits/real-time/code/client/connection.js +77 -7
  255. package/kits/real-time/code/client/gameHooks.js +63 -3
  256. package/kits/real-time/code/client/messages.js +7 -0
  257. package/kits/real-time/code/server/gameHooks.js +24 -0
  258. package/kits/real-time/code/server/session.js +390 -22
  259. package/package.json +2 -2
@@ -0,0 +1,194 @@
1
+ // A player Castle has barred from the hub (CastleError CAULDRON_HUB_BANNED)
2
+ // is not joined again by multiplayer-3d's join loop: neither after a first
3
+ // join refused that way nor after a connection whose recovery was refused that
4
+ // way. Any other failure is retried as it always was, which is what ordinary
5
+ // decks see. A hub join whose connection closes before the session placed the
6
+ // player reads 'lost'; no other join ever does. Everything multiplayer.js
7
+ // imports but the join loop is stubbed.
8
+ // `npm run check` runs it; it needs nothing installed.
9
+
10
+ import assert from 'node:assert/strict';
11
+ import { register } from 'node:module';
12
+
13
+ const noop = (names) => names.map((name) => `export const ${name} = () => ({ actors: new Map() });`).join(' ');
14
+ const realTime = new URL('../../real-time/code/client/', import.meta.url).href;
15
+ const stubs = {
16
+ '../client/avatars.js': noop(['animate', 'clearAvatars', 'dropMissing', 'enter', 'makeAvatars', 'retire', 'showPlayer', 'showSelf']),
17
+ '../client/poses.js': noop(['applyPose', 'blend', 'flatDistance', 'packMove', 'packPose', 'packVelocity', 'poseOf', 'project', 'quatOf', 'same']) + ' export const REACH = 1;',
18
+ '../client/steer.js': noop(['makeState', 'networkAt', 'place', 'resting', 'steer', 'sweep']) + ' export const LIVE_RADIUS = 1;',
19
+ '@imports/castle.real-time/code/client/connection.js': 'export const connectSession = (...args) => globalThis.__connect(...args);',
20
+ '@imports/castle.real-time/code/client/soloBadge.js': 'export const showSoloBadge = () => {}; export const updateSoloBadge = () => {};',
21
+ '@imports/castle.real-time/code/client/joinOverlay.js': 'export const showJoinOverlay = () => {};',
22
+ '@imports/castle.real-time/code/client/gameHooks.js': 'export const game = {};',
23
+ 'castle-web-sdk': 'export const Multiplayer = { join: async () => globalThis.__connection };',
24
+ };
25
+ register(
26
+ 'data:text/javascript,' +
27
+ encodeURIComponent(`
28
+ const stubs = ${JSON.stringify(stubs)};
29
+ export async function resolve(specifier, context, next) {
30
+ if (specifier in stubs) {
31
+ return { url: 'data:text/javascript,' + encodeURIComponent(stubs[specifier]), shortCircuit: true };
32
+ }
33
+ if (specifier.startsWith('@imports/castle.real-time/code/client/')) {
34
+ return { url: ${JSON.stringify(realTime)} + specifier.split('/').pop(), shortCircuit: true };
35
+ }
36
+ return next(specifier, context);
37
+ }
38
+ // Vite's import.meta.glob finds no deck systems here.
39
+ export async function load(url, context, next) {
40
+ const loaded = await next(url, context);
41
+ if (url.endsWith('/multiplayer-3d/code/systems/multiplayer.js')) {
42
+ const source = String(loaded.source).replaceAll('import.meta.glob(', '((() => ({})))(');
43
+ return { ...loaded, source, shortCircuit: true };
44
+ }
45
+ return loaded;
46
+ }`),
47
+ );
48
+
49
+ let attempts = 0;
50
+ let answer = null;
51
+ globalThis.__connect = async () => {
52
+ attempts += 1;
53
+ return answer();
54
+ };
55
+ const castleError = (code) => Object.assign(new Error(code), { code });
56
+
57
+ const { installSystem } = await import('../../multiplayer-3d/code/systems/multiplayer.js');
58
+ const make = () => {
59
+ let system = null;
60
+ installSystem({ registerSystem: (s) => (system = s), systems: [] });
61
+ return system;
62
+ };
63
+ const scene = { actorWith: () => null, getActors: () => [], persistent: {} };
64
+ const flush = () => new Promise((resolve) => setTimeout(resolve, 0));
65
+ const log = console.log;
66
+ console.log = () => {};
67
+
68
+ let n = 0;
69
+
70
+ // A first join refused as barred: not asked again, no overlay, joinError says so.
71
+ {
72
+ const system = make();
73
+ attempts = 0;
74
+ answer = () => Promise.reject(castleError('CAULDRON_HUB_BANNED'));
75
+ for (let i = 0; i < 5; i += 1) {
76
+ system.afterBehaviors(scene, 0.016);
77
+ await flush();
78
+ }
79
+ assert.equal(attempts, 1);
80
+ assert.equal(system.joinError, 'CAULDRON_HUB_BANNED');
81
+ assert.equal(system.joiningOverlayWanted(), false);
82
+ n += 1;
83
+ }
84
+
85
+ // Any other failure is asked again, as before (an ordinary deck's join).
86
+ {
87
+ const system = make();
88
+ attempts = 0;
89
+ answer = () => Promise.reject(castleError('MULTIPLAYER_UNAVAILABLE'));
90
+ for (let i = 0; i < 5; i += 1) {
91
+ system.afterBehaviors(scene, 0.016);
92
+ await flush();
93
+ }
94
+ assert.ok(attempts > 1);
95
+ assert.equal(system.joinError, null);
96
+ n += 1;
97
+ }
98
+
99
+ // A connection closed because its recovery was refused as barred: not joined again.
100
+ for (const [closeCode, rejoins] of [['CAULDRON_HUB_BANNED', false], ['MULTIPLAYER_CONNECTION_LOST', true], [null, true]]) {
101
+ const system = make();
102
+ attempts = 0;
103
+ let closed = false;
104
+ const net = {
105
+ closed: () => closed,
106
+ closeError: () => (closed ? closeCode : null),
107
+ close() {},
108
+ status: () => ({ solo: false }),
109
+ };
110
+ answer = () => Promise.resolve(net);
111
+ system.afterBehaviors(scene, 0.016);
112
+ await flush();
113
+ assert.equal(system.net, net);
114
+ closed = true;
115
+ system.reset = () => {};
116
+ system.afterBehaviors(scene, 0.016);
117
+ for (let i = 0; i < 3; i += 1) {
118
+ system.afterBehaviors(scene, 0.016);
119
+ await flush();
120
+ }
121
+ assert.equal(attempts > 1, rejoins, `closed on ${closeCode}`);
122
+ assert.equal(system.joinError, rejoins ? null : 'CAULDRON_HUB_BANNED');
123
+ n += 1;
124
+ }
125
+
126
+ // A connection that closes after its join resolved and before the session
127
+ // placed this player: a hub join is lost (not joined again, joinState
128
+ // 'lost'); one closed after placement stays 'joined'. Any other join (public,
129
+ // named) reads 'joined' and is joined again, exactly as before.
130
+ for (const [target, placedFirst, state, rejoins] of [
131
+ [{ mode: 'hub', handoff: { sessionId: 's' } }, false, 'lost', false],
132
+ [{ mode: 'hub', handoff: { sessionId: 's' } }, true, 'joined', false],
133
+ [{ mode: 'public' }, false, 'joined', true],
134
+ [{ mode: 'named', key: 'game' }, false, 'joined', true],
135
+ ]) {
136
+ const system = make();
137
+ system.switchSession(scene, target, { quiet: true });
138
+ system.reset = () => {};
139
+ attempts = 0;
140
+ let closed = false;
141
+ const net = {
142
+ closed: () => closed,
143
+ closeError: () => null,
144
+ close() {},
145
+ status: () => ({ solo: false }),
146
+ };
147
+ answer = () => Promise.resolve(net);
148
+ system.afterBehaviors(scene, 0.016);
149
+ await flush();
150
+ assert.equal(system.joinState(), 'joined');
151
+ system.joined = placedFirst;
152
+ closed = true;
153
+ system.afterBehaviors(scene, 0.016);
154
+ assert.equal(system.joinState(), state, `${target.mode} placed=${placedFirst}`);
155
+ for (let i = 0; i < 3; i += 1) {
156
+ system.afterBehaviors(scene, 0.016);
157
+ await flush();
158
+ }
159
+ assert.equal(attempts > 1, rejoins, `${target.mode} rejoins`);
160
+ assert.equal(system.joinState(), state, `${target.mode} placed=${placedFirst} after`);
161
+ // A new switch starts afresh.
162
+ system.switchSession(scene, { mode: 'public' });
163
+ assert.equal(system.joinState(), 'joining');
164
+ n += 1;
165
+ }
166
+
167
+ // real-time's connection says what a closed connection closed on.
168
+ {
169
+ const { connectSession } = await import('../../real-time/code/client/connection.js');
170
+ const listeners = [];
171
+ globalThis.__connection = {
172
+ state: 'connected',
173
+ playerId: 'p1',
174
+ onMessage() {},
175
+ onRoster() {},
176
+ onStateChange: (callback) => listeners.push(callback),
177
+ leave() {},
178
+ };
179
+ const net = await connectSession({ join: { mode: 'public' } });
180
+ assert.equal(net.closeError(), null);
181
+ globalThis.__connection.state = 'closed';
182
+ for (const listener of listeners) {
183
+ listener('closed', { type: 'error', error: castleError('CAULDRON_HUB_BANNED') });
184
+ }
185
+ assert.equal(net.closeError(), 'CAULDRON_HUB_BANNED');
186
+ for (const listener of listeners) {
187
+ listener('closed', { type: 'bye' });
188
+ }
189
+ assert.equal(net.closeError(), null);
190
+ n += 1;
191
+ }
192
+
193
+ console.log = log;
194
+ console.log(`test-ban-join: ${n} ok`);
@@ -0,0 +1,351 @@
1
+ // Blocks (cauldron-game-server HUB.md "Trust and safety"): two players a block
2
+ // hides from each other are never sent each other's pose rows or avatar
3
+ // (`hubAv`), in either direction, whichever of them listed the other; everyone
4
+ // else sees both. A session whose host says nothing of blocks (no
5
+ // `session.hub.hiddenPair`: the dev serve, an older SDK, a non-hub deck) is
6
+ // sent exactly what it was. `npm run check` runs it; it needs nothing installed.
7
+
8
+ import assert from 'node:assert/strict';
9
+ import { register } from 'node:module';
10
+
11
+ const sceneStub = 'export const readScene = () => globalThis.__blocksActors ?? [];';
12
+ register(
13
+ `data:text/javascript,${encodeURIComponent(`
14
+ export async function resolve(specifier, context, next) {
15
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') {
16
+ return { url: 'data:text/javascript,${encodeURIComponent(sceneStub)}', shortCircuit: true };
17
+ }
18
+ return next(specifier, context);
19
+ }
20
+ `)}`,
21
+ );
22
+ const { layer } = await import('../code/server/hub.js');
23
+ const Blocks = await import('../code/server/blocks.js');
24
+ const { makeSession } = await import('../../real-time/code/server/session.js');
25
+
26
+ const log = console.log;
27
+ console.log = () => {};
28
+
29
+ const world = {
30
+ async createSimulation(scenePath) {
31
+ return { players: new Map(), objects: new Map(), timeMs: 0, scenePath, bodies: new Map() };
32
+ },
33
+ step(sim) {
34
+ sim.timeMs += 33;
35
+ },
36
+ objectPoses: () => [],
37
+ restorePoses: () => 0,
38
+ };
39
+ const players = {
40
+ addPlayer(sim, id) {
41
+ const x = globalThis.__blocksAt?.[id] ?? 0;
42
+ sim.players.set(id, { at: { x, y: 0, z: 0 }, facing: 0, body: { setTranslation() {} } });
43
+ },
44
+ removePlayer(sim, id) {
45
+ sim.players.delete(id);
46
+ },
47
+ setPose() {},
48
+ playerPoses: (sim) => [...sim.players].map(([id, p]) => [id, p.at.x, p.at.y, p.at.z, 0, 0]),
49
+ };
50
+ const ownership = { claim() {}, release() {}, setObjectPoses() {}, sweepOwners() {}, ownerships: () => [] };
51
+ const poses = { PLAYER_GEOMETRY: 4, epsilonAt: () => 0.001 };
52
+
53
+ const castleJson = { server: { maxPlayers: 24 }, hub: { contract: 1, title: 'Town' } };
54
+ const sceneExists = (scene) => scene === 'scenes/main.scene';
55
+ const USERS = { a: '101', b: '102', c: '103', d: '104', e: '105' };
56
+
57
+ // `hidden` maps a player id to the user ids its host-side list names; null is
58
+ // an SDK that predates blocks (no `hiddenPair`).
59
+ async function room(ids, hidden, manifest = castleJson) {
60
+ const hooks = layer(manifest, {}, {}, sceneExists);
61
+ const sent = [];
62
+ const roster = ids.map((playerId) => ({ playerId, userId: USERS[playerId], username: playerId }));
63
+ const hub = {
64
+ place: 'main',
65
+ arrival: () => null,
66
+ readResults: async () => ({ players: {}, boards: {} }),
67
+ updatePad: async () => ({ status: 'gathering', members: [] }),
68
+ reportResult: async () => ({ recorded: false }),
69
+ };
70
+ if (hidden) {
71
+ hub.hiddenPair = (x, y) => {
72
+ const ux = USERS[x];
73
+ const uy = USERS[y];
74
+ return x !== y && Boolean((hidden[x] ?? []).includes(uy) || (hidden[y] ?? []).includes(ux));
75
+ };
76
+ }
77
+ const session = {
78
+ sessionId: 'dev:test',
79
+ players: roster,
80
+ hub,
81
+ send: (to, msg) => sent.push({ to, msg }),
82
+ broadcast: (msg) => sent.push({ to: '*', msg }),
83
+ };
84
+ const server = makeSession({ label: 'test', poses, world, players, ownership, game: hooks });
85
+ for (const player of roster) {
86
+ server.onPlayerJoin(session, player);
87
+ }
88
+ server.onTick(session);
89
+ await new Promise((resolve) => setTimeout(resolve, 10));
90
+ for (const player of roster) {
91
+ hooks.message(session, player, { k: 'hub-hello', avatar: Number(USERS[player.playerId]) % 4 });
92
+ }
93
+ return {
94
+ session,
95
+ sent,
96
+ tick() {
97
+ sent.length = 0;
98
+ server.onTick(session);
99
+ return sent.slice();
100
+ },
101
+ };
102
+ }
103
+
104
+ // Everything each player was sent, by recipient (a broadcast reaches all).
105
+ function received(sent, ids) {
106
+ const out = new Map(ids.map((id) => [id, []]));
107
+ for (const { to, msg } of sent) {
108
+ for (const id of to === '*' ? ids : [to]) {
109
+ out.get(id)?.push(msg);
110
+ }
111
+ }
112
+ return out;
113
+ }
114
+
115
+ // The player ids a client learned of: pose rows (a filtering session numbers
116
+ // them, naming each number in `idm`), `in`, hubAv keys, hub-av keys.
117
+ function learned(msgs) {
118
+ const seen = new Set();
119
+ for (const msg of msgs) {
120
+ for (const [id] of msg.ps ?? []) {
121
+ if (typeof id === 'string') {
122
+ seen.add(id);
123
+ }
124
+ }
125
+ for (const [, id] of msg.idm ?? []) {
126
+ seen.add(id);
127
+ }
128
+ for (const id of msg.in ?? []) {
129
+ seen.add(id);
130
+ }
131
+ for (const id of Object.keys(msg.hubAv ?? {})) {
132
+ seen.add(id);
133
+ }
134
+ }
135
+ return seen;
136
+ }
137
+
138
+ async function play(ids, hidden, ticks = 4, manifest = castleJson) {
139
+ const r = await room(ids, hidden, manifest);
140
+ const all = [];
141
+ all.push(...r.sent);
142
+ for (let i = 0; i < ticks; i += 1) {
143
+ all.push(...r.tick());
144
+ }
145
+ return { r, by: received(all, ids), all };
146
+ }
147
+
148
+ let n = 0;
149
+
150
+ // A blocked B (only a's list names b): neither is sent the other, c sees both.
151
+ for (const hidden of [{ a: [USERS.b] }, { b: [USERS.a] }, { a: [USERS.b], b: [USERS.a] }]) {
152
+ const { by } = await play(['a', 'b', 'c'], hidden);
153
+ const a = learned(by.get('a'));
154
+ const b = learned(by.get('b'));
155
+ const c = learned(by.get('c'));
156
+ assert.ok(!a.has('b'), `a never learns of b (${JSON.stringify(hidden)})`);
157
+ assert.ok(!b.has('a'), `b never learns of a (${JSON.stringify(hidden)})`);
158
+ assert.ok(a.has('c') && b.has('c'), 'both still see c');
159
+ assert.ok(c.has('a') && c.has('b'), 'c sees both');
160
+ // Whatever names a row, a and b never get one beyond their own and c's.
161
+ for (const [me, msgs] of [['a', by.get('a')], ['b', by.get('b')]]) {
162
+ for (const msg of msgs) {
163
+ const names = new Map((msg.idm ?? []).map(([num, id]) => [num, id]));
164
+ for (const [id] of msg.ps ?? []) {
165
+ const who = typeof id === 'string' ? id : names.get(id);
166
+ assert.ok(who === undefined || who === me || who === 'c', `${me} got a row for ${who}`);
167
+ }
168
+ }
169
+ }
170
+ n += 1;
171
+ }
172
+
173
+ // A place that sends each client its nearest 2: b, hidden from a and nearer
174
+ // to it than anyone, takes neither of a's places -- a is sent c and d, the
175
+ // nearest two it may see, and b likewise; e (far) is sent to neither.
176
+ {
177
+ globalThis.__blocksAt = { a: 0, b: 1, c: 2, d: 3, e: 20 };
178
+ const near2 = { ...castleJson, hub: { ...castleJson.hub, nearestPlayers: 2 } };
179
+ const { by } = await play(['a', 'b', 'c', 'd', 'e'], { a: [USERS.b] }, 4, near2);
180
+ globalThis.__blocksAt = undefined;
181
+ const others = (id) => [...learned(by.get(id))].filter((x) => x !== id);
182
+ // hubAv names every visible player whatever its distance; pose rows do not.
183
+ const posed = (id) => {
184
+ const seen = new Set();
185
+ const names = new Map();
186
+ for (const msg of by.get(id)) {
187
+ for (const [num, who] of msg.idm ?? []) {
188
+ names.set(num, who);
189
+ }
190
+ for (const [row] of msg.ps ?? []) {
191
+ seen.add(typeof row === 'string' ? row : names.get(row));
192
+ }
193
+ for (const x of msg.in ?? []) {
194
+ seen.add(x);
195
+ }
196
+ }
197
+ seen.delete(id);
198
+ return [...seen].sort();
199
+ };
200
+ assert.deepEqual(posed('a'), ['c', 'd'], 'a gets its two nearest visible others');
201
+ assert.deepEqual(posed('b'), ['c', 'd'], 'and so does b');
202
+ assert.ok(!others('a').includes('b') && !others('b').includes('a'));
203
+ n += 1;
204
+ }
205
+
206
+ // The everyone-avatars block never names a hidden player; their avatars go
207
+ // only to those who may see them.
208
+ {
209
+ const { by } = await play(['a', 'b', 'c'], { a: [USERS.b] });
210
+ for (const msg of [...by.get('a'), ...by.get('b'), ...by.get('c')]) {
211
+ if (msg.k !== 'hub-av' && msg.hubAv) {
212
+ assert.ok(!('a' in msg.hubAv) && !('b' in msg.hubAv), 'shared hubAv leaves the pair out');
213
+ }
214
+ }
215
+ const mine = (id) => by.get(id).filter((m) => m.k === 'hub-av').at(-1)?.hubAv ?? {};
216
+ assert.deepEqual(Object.keys(mine('c')).sort(), ['a', 'b']);
217
+ assert.ok(!('b' in mine('a')));
218
+ assert.ok(!('a' in mine('b')));
219
+ n += 1;
220
+ }
221
+
222
+ // The interest hook alone: the pair is out of both sets, everyone else in.
223
+ {
224
+ const sim = { players: new Map(['a', 'b', 'c'].map((id) => [id, { at: { x: 0, y: 0, z: 0 } }])) };
225
+ const sees = Blocks.withoutHidden(
226
+ new Map([
227
+ ['a', new Set(['b', 'c'])],
228
+ ['b', new Set(['a', 'c'])],
229
+ ['c', new Set(['a', 'b'])],
230
+ ]),
231
+ Blocks.hiddenPairs({ hub: { hiddenPair: (x, y) => [x, y].sort().join() === 'a,b' } }, [...sim.players.keys()]),
232
+ );
233
+ assert.deepEqual([...sees.get('a')], ['c']);
234
+ assert.deepEqual([...sees.get('b')], ['c']);
235
+ assert.deepEqual([...sees.get('c')], ['a', 'b']);
236
+ assert.equal(Blocks.hiddenPairs({ hub: null }, ['a', 'b']), null, 'no hub: nobody hidden');
237
+ assert.equal(Blocks.hiddenPairs({ hub: { hiddenPair: () => false } }, ['a', 'b']), null);
238
+ n += 1;
239
+ }
240
+
241
+ // No blocks: the same messages as an SDK that knows nothing of blocks -- one
242
+ // broadcast a tick, hubAv with everyone, no hub-av.
243
+ {
244
+ const plain = await play(['a', 'b', 'c'], null);
245
+ const none = await play(['a', 'b', 'c'], {});
246
+ const shape = (all) => all.map(({ to, msg }) => `${to}:${msg.k}:${JSON.stringify(msg.hubAv ?? null)}:${(msg.ps ?? []).length}`);
247
+ assert.deepEqual(shape(none.all), shape(plain.all));
248
+ assert.ok(!none.all.some(({ msg }) => msg.k === 'hub-av'));
249
+ const shared = plain.all.find(({ msg }) => msg.hubAv)?.msg.hubAv;
250
+ assert.deepEqual(Object.keys(shared).sort(), ['a', 'b', 'c']);
251
+ n += 1;
252
+ }
253
+
254
+ // Words: a HUD or label the game writes and an NPC's greeting may name a
255
+ // player. A hidden pair is never sent each other's name in them, whoever
256
+ // arrived first (a WORLD snapshot included); everyone else reads them whole.
257
+ {
258
+ const NAMES = { a: 'alice', b: 'bob', c: 'cy' };
259
+ globalThis.__blocksActors = [
260
+ { id: 'greeter', components: { HubNpc: { name: 'Rowan' }, Transform: { x: 0, y: 1, z: 0 } } },
261
+ { id: 'sign', components: { Transform: { x: 5, y: 1, z: 0 } } },
262
+ ];
263
+ let ctx = null;
264
+ const hooks = layer(castleJson, { ready: (hub) => (ctx = hub) }, {}, sceneExists);
265
+ const hidden = { b: [USERS.a] };
266
+ const sent = [];
267
+ const roster = [];
268
+ const session = {
269
+ sessionId: 'dev:test',
270
+ players: roster,
271
+ hub: {
272
+ place: 'main',
273
+ arrival: () => null,
274
+ readResults: async () => ({ players: {}, boards: {} }),
275
+ updatePad: async () => ({ status: 'gathering', members: [] }),
276
+ reportResult: async () => ({ recorded: false }),
277
+ hiddenPair: (x, y) =>
278
+ x !== y && roster.some((p) => p.playerId === x) && roster.some((p) => p.playerId === y) &&
279
+ Boolean((hidden[x] ?? []).includes(USERS[y]) || (hidden[y] ?? []).includes(USERS[x])),
280
+ },
281
+ send: (to, msg) => sent.push({ to, msg }),
282
+ broadcast: (msg) => sent.push({ to: '*', msg }),
283
+ };
284
+ const bodyWorld = {
285
+ ...world,
286
+ async createSimulation(scenePath) {
287
+ const greeter = { translation: () => ({ x: 0, y: 1, z: 0 }), setNextKinematicTranslation() {}, setNextKinematicRotation() {} };
288
+ return { players: new Map(), objects: new Map(), timeMs: 0, scenePath, bodies: new Map([['greeter', greeter]]) };
289
+ },
290
+ };
291
+ const server = makeSession({ label: 'test', poses, world: bodyWorld, players, ownership, game: hooks });
292
+ const join = async (id) => {
293
+ const player = { playerId: id, userId: USERS[id], username: NAMES[id] };
294
+ roster.push(player);
295
+ server.onPlayerJoin(session, player);
296
+ server.onTick(session);
297
+ await new Promise((resolve) => setTimeout(resolve, 10));
298
+ hooks.message(session, player, { k: 'hub-hello', avatar: 1 });
299
+ server.onTick(session);
300
+ };
301
+ await join('a');
302
+ await join('c');
303
+ // Before b arrives: alice greeted by name, and a results line naming her.
304
+ hooks.message(session, { playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
305
+ ctx.setHud({ title: 'Flag Dash', text: '1. alice 0.5s 2. cy 1.1s' });
306
+ ctx.label('sign', 'alice leads');
307
+ server.onTick(session);
308
+ const before = sent.length;
309
+ await join('b');
310
+ for (let i = 0; i < 3; i += 1) {
311
+ server.onTick(session);
312
+ }
313
+ // And with bob here: a new results line naming alice.
314
+ ctx.setHud({ title: 'Flag Dash', text: '1. alice 0.4s 2. cy 1.1s' });
315
+ for (let i = 0; i < 2; i += 1) {
316
+ server.onTick(session);
317
+ }
318
+ const after = sent.slice(before);
319
+ const by = received(after, ['a', 'b', 'c']);
320
+ const text = (msgs) => JSON.stringify(msgs);
321
+ assert.ok(!text(by.get('b')).includes('alice'), `bob is never sent alice's name: ${text(by.get('b')).slice(0, 400)}`);
322
+ assert.ok(by.get('b').some((m) => m.k === 'w'), 'bob got a WORLD');
323
+ // What alice and cy draw: the shared block with their own over it.
324
+ const view = (id) => {
325
+ let hud = null;
326
+ let hudMe = null;
327
+ let labels = {};
328
+ let labelsMe = {};
329
+ for (const m of sent.filter(({ to }) => to === id || to === '*').map(({ msg }) => msg)) {
330
+ if ('hud' in m && m.k !== 'hub-hud') hud = m.hud;
331
+ if (m.k === 'hub-hud') hudMe = m.hud;
332
+ if (m.labels && m.k !== 'hub-labels') labels = m.labels;
333
+ if (m.k === 'hub-labels') labelsMe = m.labels;
334
+ }
335
+ return { hud: hudMe ?? hud, labels: { ...labels, ...labelsMe } };
336
+ };
337
+ for (const id of ['a', 'c']) {
338
+ const v = view(id);
339
+ assert.equal(v.hud.text, '1. alice 0.4s 2. cy 1.1s', `${id} reads the HUD whole`);
340
+ assert.equal(v.labels.sign.text, 'alice leads');
341
+ assert.match(v.labels.greeter.text, /Hello, alice\./);
342
+ }
343
+ const bob = view('b');
344
+ assert.equal(bob.hud.text, '1. someone 0.4s 2. cy 1.1s');
345
+ assert.equal(bob.labels.sign.text, 'someone leads');
346
+ assert.equal(bob.labels.greeter, undefined, 'the greeting about alice never reaches bob');
347
+ n += 1;
348
+ }
349
+
350
+ console.log = log;
351
+ console.log(`test-blocks: ${n} ok`);
@@ -0,0 +1,98 @@
1
+ // Free-text chat (contract §6, v1.12), the kit's half: it shows only what the
2
+ // host hands it. The first answer sets the cursor and replays nothing; later
3
+ // answers' messages are taken once; a send that ghost accepts is echoed as
4
+ // the player's own; a host without the commands, or one that answers
5
+ // `unavailable`, turns chat off for good. `npm run check` runs it.
6
+
7
+ import assert from 'node:assert/strict';
8
+ import { register } from 'node:module';
9
+
10
+ const sdkStub = 'export const Hub = new Proxy({}, { get: (_, k) => globalThis.__chatHub?.[k], has: (_, k) => k in (globalThis.__chatHub ?? {}) });';
11
+ register(
12
+ `data:text/javascript,${encodeURIComponent(`
13
+ export async function resolve(specifier, context, next) {
14
+ if (specifier === 'castle-web-sdk') {
15
+ return { url: 'data:text/javascript,${encodeURIComponent(sdkStub)}', shortCircuit: true };
16
+ }
17
+ return next(specifier, context);
18
+ }
19
+ `)}`,
20
+ );
21
+ const { makeChat } = await import('../code/client/chat.js');
22
+ const flush = () => new Promise((resolve) => setTimeout(resolve, 0));
23
+ let n = 0;
24
+
25
+ // No commands: off, and nothing is asked.
26
+ {
27
+ globalThis.__chatHub = {};
28
+ const c = makeChat();
29
+ assert.equal(c.available(), false);
30
+ c.frame(true, 1000);
31
+ assert.equal(c.peers, null);
32
+ n += 1;
33
+ }
34
+
35
+ {
36
+ const calls = [];
37
+ let answer = { status: 'ok', canChat: true, peers: ['102'], cursor: 'c1', messages: [{ id: 'old', fromUserId: '102', fromUsername: 'bo', text: 'before you came', at: '' }] };
38
+ let said = { status: 'sent', id: 'm9' };
39
+ globalThis.__chatHub = {
40
+ chat: async (after) => (calls.push(['chat', after]), answer),
41
+ say: async (text) => (calls.push(['say', text]), said),
42
+ reportChat: async (id) => (calls.push(['report', id]), { status: 'ok' }),
43
+ };
44
+ const c = makeChat();
45
+ c.frame(true, 1000);
46
+ await flush();
47
+ assert.deepEqual([c.canChat, c.peers, c.incoming], [true, ['102'], []], 'the first answer replays nothing');
48
+ n += 1;
49
+
50
+ // Not asked again inside the cadence; then from the cursor, and messages land once.
51
+ c.frame(true, 2000);
52
+ answer = { status: 'ok', canChat: true, peers: ['102'], cursor: 'c2', messages: [{ id: 'm1', fromUserId: '102', fromUsername: 'bo', text: 'hi', at: '' }] };
53
+ c.frame(true, 4000);
54
+ await flush();
55
+ assert.deepEqual(calls, [['chat', undefined], ['chat', 'c1']]);
56
+ assert.deepEqual(c.incoming.splice(0), [{ id: 'm1', fromUserId: '102', fromUsername: 'bo', text: 'hi', at: '', mine: false }]);
57
+ n += 1;
58
+
59
+ // A send ghost accepts is echoed as the player's own; one it does not is not.
60
+ let status = null;
61
+ c.send(' hello ', (s) => (status = s));
62
+ await flush();
63
+ assert.deepEqual(calls.at(-1), ['say', 'hello']);
64
+ assert.deepEqual([status, c.incoming.splice(0)], ['sent', [{ id: 'm9', fromUserId: null, fromUsername: null, text: 'hello', mine: true }]]);
65
+ said = { status: 'none', id: null };
66
+ c.send('anyone?', (s) => (status = s));
67
+ await flush();
68
+ assert.deepEqual([status, c.incoming], ['none', []]);
69
+ c.send(' ');
70
+ assert.equal(calls.filter(([k]) => k === 'say').length, 2, 'nothing but spaces is not sent');
71
+ n += 1;
72
+
73
+ let reported = null;
74
+ c.report('m1', (ok) => (reported = ok));
75
+ await flush();
76
+ assert.deepEqual([calls.at(-1), reported], [['report', 'm1'], true]);
77
+ n += 1;
78
+
79
+ // An answer that lands after the session changed is the old session's.
80
+ answer = { status: 'ok', canChat: true, peers: ['102'], cursor: 'c3', messages: [{ id: 'late', fromUserId: '102', fromUsername: 'bo', text: 'late', at: '' }] };
81
+ c.frame(true, 20000);
82
+ c.send('late too');
83
+ c.reset();
84
+ await flush();
85
+ assert.deepEqual([c.peers, c.incoming], [null, []]);
86
+ n += 1;
87
+
88
+ // Another session starts over; a host that cannot say turns chat off.
89
+ c.reset();
90
+ assert.deepEqual([c.peers, c.canChat], [null, false]);
91
+ answer = { status: 'unavailable', canChat: false, peers: null, messages: null, cursor: null };
92
+ c.frame(true, 50000);
93
+ await flush();
94
+ assert.equal(c.available(), false);
95
+ n += 1;
96
+ }
97
+
98
+ console.log(`test-chat: ${n} passed`);