castle-web-cli 0.4.237 β†’ 0.4.238

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 (216) hide show
  1. package/dist/bundle.d.ts +24 -0
  2. package/dist/bundle.js +447 -4
  3. package/dist/bundleLatin1.d.ts +6 -0
  4. package/dist/bundleLatin1.js +333 -0
  5. package/dist/castle-host/host.d.ts +10 -1
  6. package/dist/castle-host/host.js +78 -9
  7. package/dist/castleJson.d.ts +2 -0
  8. package/dist/castleJson.js +1 -0
  9. package/dist/deckExports.d.ts +35 -0
  10. package/dist/deckExports.js +365 -0
  11. package/dist/importCheckHook.d.ts +1 -0
  12. package/dist/importCheckHook.js +1 -1
  13. package/dist/index.js +5 -0
  14. package/dist/init.js +2 -1
  15. package/dist/save-deck.js +4 -0
  16. package/kits/base/castle.json +1 -1
  17. package/kits/base/sdk/README.md +47 -0
  18. package/kits/base/sdk/castle.d.ts +3 -1
  19. package/kits/base/sdk/castle.js +1 -0
  20. package/kits/base/sdk/commands.d.ts +25 -1
  21. package/kits/base/sdk/commands.js +29 -1
  22. package/kits/base/sdk/hub.d.ts +17 -0
  23. package/kits/base/sdk/hub.js +33 -9
  24. package/kits/base/sdk/localCache.d.ts +27 -0
  25. package/kits/base/sdk/localCache.js +115 -0
  26. package/kits/base/sdk/localCacheStore.d.ts +15 -0
  27. package/kits/base/sdk/localCacheStore.js +358 -0
  28. package/kits/base/sdk/transport.d.ts +1 -0
  29. package/kits/base/sdk/transport.js +4 -5
  30. package/kits/hub-game/CLAUDE.md +22 -2
  31. package/kits/hub-game/castle.json +4 -1
  32. package/kits/hub-game/code/client/act.js +66 -91
  33. package/kits/hub-game/code/client/actCore.js +134 -0
  34. package/kits/hub-game/code/client/car.js +35 -0
  35. package/kits/hub-game/code/client/chrome.js +207 -381
  36. package/kits/hub-game/code/client/crowdNames.js +2 -2
  37. package/kits/hub-game/code/client/emoteWheel.js +109 -0
  38. package/kits/hub-game/code/client/hats.js +2 -0
  39. package/kits/hub-game/code/client/hookLayer.js +99 -48
  40. package/kits/hub-game/code/client/hostGo.js +77 -0
  41. package/kits/hub-game/code/client/hubControls.js +125 -0
  42. package/kits/hub-game/code/client/hubEntry.js +187 -0
  43. package/kits/hub-game/code/client/hudSurface.js +148 -0
  44. package/kits/hub-game/code/client/hudTree.js +96 -0
  45. package/kits/hub-game/code/client/idle.js +59 -13
  46. package/kits/hub-game/code/client/invites.js +13 -4
  47. package/kits/hub-game/code/client/menuIcons.js +8 -0
  48. package/kits/hub-game/code/client/noTrips.js +38 -0
  49. package/kits/hub-game/code/client/qualityEntry.js +6 -1
  50. package/kits/hub-game/code/client/rehello.js +3 -1
  51. package/kits/hub-game/code/client/riders.js +26 -0
  52. package/kits/hub-game/code/client/role.js +79 -0
  53. package/kits/hub-game/code/client/safeLayout.js +32 -3
  54. package/kits/hub-game/code/client/sound.js +10 -3
  55. package/kits/hub-game/code/client/soundscape.js +2 -2
  56. package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
  57. package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
  58. package/kits/hub-game/code/client/soundscapeCues.js +2 -1
  59. package/kits/hub-game/code/client/state.js +19 -0
  60. package/kits/hub-game/code/client/stuck.js +2 -1
  61. package/kits/hub-game/code/client/talkSurface.js +178 -0
  62. package/kits/hub-game/code/client/talkTree.js +238 -0
  63. package/kits/hub-game/code/client/tiers.js +8 -5
  64. package/kits/hub-game/code/client/uiDom.js +600 -0
  65. package/kits/hub-game/code/client/uiTree.js +359 -0
  66. package/kits/hub-game/code/client/vehicle.js +154 -0
  67. package/kits/hub-game/code/client/wear.js +27 -5
  68. package/kits/hub-game/code/client/worldLabels.js +3 -2
  69. package/kits/hub-game/code/client/yours.js +10 -3
  70. package/kits/hub-game/code/server/actors.js +4 -3
  71. package/kits/hub-game/code/server/analytics.js +56 -6
  72. package/kits/hub-game/code/server/decor.js +56 -16
  73. package/kits/hub-game/code/server/hub.js +258 -46
  74. package/kits/hub-game/code/server/idle.js +118 -5
  75. package/kits/hub-game/code/server/manifest.js +46 -4
  76. package/kits/hub-game/code/server/npcs.js +4 -2
  77. package/kits/hub-game/code/server/players.js +3 -0
  78. package/kits/hub-game/code/server/role.js +142 -0
  79. package/kits/hub-game/code/server/standing.js +6 -4
  80. package/kits/hub-game/code/server/vehicle.js +126 -0
  81. package/kits/hub-game/code/shared/car.js +52 -0
  82. package/kits/hub-game/code/shared/deckFlags.js +34 -0
  83. package/kits/hub-game/code/shared/deviceClass.js +39 -0
  84. package/kits/hub-game/code/shared/expression.js +9 -0
  85. package/kits/hub-game/code/systems/hub.js +272 -84
  86. package/kits/hub-game/docs/analytics.md +11 -2
  87. package/kits/hub-game/docs/contract.md +352 -14
  88. package/kits/hub-game/docs/vehicle-preset.md +132 -0
  89. package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
  90. package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
  91. package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
  92. package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
  93. package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
  94. package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
  95. package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
  96. package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
  97. package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
  98. package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
  99. package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
  100. package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
  101. package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
  102. package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
  103. package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
  104. package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
  105. package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
  106. package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
  107. package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
  108. package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
  109. package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
  110. package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
  111. package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
  112. package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
  113. package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
  114. package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
  115. package/kits/hub-game/package-lock.json +1 -1
  116. package/kits/hub-game/package.json +1 -1
  117. package/kits/hub-game/scripts/check.mjs +7 -4
  118. package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
  119. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
  120. package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
  121. package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
  122. package/kits/hub-game/scripts/gen-hats.mjs +46 -2
  123. package/kits/hub-game/scripts/gen-role.mjs +80 -0
  124. package/kits/hub-game/scripts/test-act-core.mjs +167 -0
  125. package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
  126. package/kits/hub-game/scripts/test-actors.mjs +48 -0
  127. package/kits/hub-game/scripts/test-analytics.mjs +99 -5
  128. package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
  129. package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
  130. package/kits/hub-game/scripts/test-ballot.mjs +2 -0
  131. package/kits/hub-game/scripts/test-car.mjs +43 -0
  132. package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
  133. package/kits/hub-game/scripts/test-decor.mjs +77 -0
  134. package/kits/hub-game/scripts/test-device-class.mjs +83 -0
  135. package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
  136. package/kits/hub-game/scripts/test-hats.mjs +5 -4
  137. package/kits/hub-game/scripts/test-host-go.mjs +265 -0
  138. package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
  139. package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
  140. package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
  141. package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
  142. package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
  143. package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
  144. package/kits/hub-game/scripts/test-idle.mjs +347 -1
  145. package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
  146. package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
  147. package/kits/hub-game/scripts/test-manifest.mjs +30 -0
  148. package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
  149. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  150. package/kits/hub-game/scripts/test-quality.mjs +13 -0
  151. package/kits/hub-game/scripts/test-rehello.mjs +258 -3
  152. package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
  153. package/kits/hub-game/scripts/test-resync.mjs +183 -0
  154. package/kits/hub-game/scripts/test-role-client.mjs +421 -0
  155. package/kits/hub-game/scripts/test-role.mjs +350 -0
  156. package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
  157. package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
  158. package/kits/hub-game/scripts/test-standing.mjs +15 -1
  159. package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
  160. package/kits/hub-game/scripts/test-tiers.mjs +13 -0
  161. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
  162. package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
  163. package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
  164. package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
  165. package/kits/hub-game/scripts/test-yours.mjs +33 -0
  166. package/kits/hub-game/tools/hubScene/export.mjs +613 -0
  167. package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
  168. package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
  169. package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
  170. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
  171. package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
  172. package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
  173. package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
  174. package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
  175. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
  176. package/kits/multiplayer-3d/castle.json +4 -4
  177. package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
  178. package/kits/multiplayer-3d/code/client/steer.js +3 -1
  179. package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
  180. package/kits/multiplayer-3d/package-lock.json +1 -1
  181. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
  182. package/kits/physics-3d/CLAUDE.md +1 -1
  183. package/kits/physics-3d/behaviors/Player.jsx +37 -27
  184. package/kits/physics-3d/castle.json +2 -2
  185. package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
  186. package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
  187. package/kits/physics-3d/engine3d/playerRun.js +6 -1
  188. package/kits/physics-3d/engine3d/pxmodel.js +6 -1
  189. package/kits/physics-3d/engine3d/world3d.js +6 -3
  190. package/kits/physics-3d/package.json +1 -1
  191. package/kits/physics-3d/play/behaviors/Player.js +40 -28
  192. package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
  193. package/kits/physics-3d/systems/physics3d.js +5 -2
  194. package/kits/real-time/castle.json +2 -2
  195. package/kits/real-time/code/client/messages.js +5 -0
  196. package/kits/real-time/code/server/session.js +28 -1
  197. package/kits/real-time/package-lock.json +1 -1
  198. package/package.json +5 -4
  199. package/vendor/three/LICENSE +21 -0
  200. package/vendor/three/build/three.core.js +58773 -0
  201. package/vendor/three/build/three.module.js +18251 -0
  202. package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
  203. package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
  204. package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
  205. package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  206. package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  207. package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
  208. package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  209. package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
  210. package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  211. package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
  212. package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  213. package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  214. package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  215. package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  216. package/vendor/three/package.json +134 -0
@@ -84,6 +84,7 @@ function boot(options = {}) {
84
84
  ['p2', body()],
85
85
  ]),
86
86
  bodies: new Map(options.bodies ?? []),
87
+ ...(options.shape ? { template: { shape: options.shape } } : {}),
87
88
  objects: new Map(),
88
89
  scenePath: 'scenes/main.scene',
89
90
  };
@@ -99,7 +100,7 @@ function boot(options = {}) {
99
100
  h.place(world);
100
101
  Date.now = realNow;
101
102
  }
102
- for (const p of world.players.values()) {
103
+ for (const p of options.keepArrival ? [] : world.players.values()) {
103
104
  p.at = { x: 0, y: 1, z: 0 };
104
105
  }
105
106
  const say = (playerId, data) => h.message(session, { playerId }, data);
@@ -399,6 +400,313 @@ test('emotes: a place with seats only ignores them', () => {
399
400
  assert.equal('hubEmotes' in h.join(), false);
400
401
  });
401
402
 
403
+
404
+ // --- v1.158 expression ---------------------------------------------------------
405
+ const ROLE = { id: 'doctor', emoji: '🩺', label: 'Checkup', motion: 'bow', ms: 3500 };
406
+ const expressionIdle = { emotes: true, expression: { roleEmotes: [ROLE] } };
407
+ function groundBoot(options = {}) {
408
+ // These fixtures hold the body at y=0.85, with its feet on the floor.
409
+ const run = boot({ idle: expressionIdle, shape: { kind: 'capsule', radius: 0.35, height: 1.7 }, ...options });
410
+ for (const body of run.world.players.values()) { body.at = { x: 10, y: 0.85, z: 10 }; }
411
+ run.tick(50); run.tick(250);
412
+ return run;
413
+ }
414
+
415
+ test('v1.158: new kit ids are expression-only, with bounded durations and model motions', () => {
416
+ for (const [id, ms] of Object.entries({ sleep: 4000, eat: 3000, cry: 3000, laugh: 2400, point: 2000 })) {
417
+ const plain = boot();
418
+ plain.say('p1', { k: 'hub-emote', id });
419
+ assert.equal(plain.hub.emote('p1', id), false);
420
+ assert.deepEqual(plain.h.join().hubEmotes, {});
421
+ const r = boot({ idle: expressionIdle });
422
+ r.say('p1', { k: 'hub-emote', id });
423
+ assert.deepEqual(r.h.join().hubEmotes.p1, { id, at: 0, until: ms });
424
+ assert.equal(r.hub.emote('p2', id), true);
425
+ for (const u of [0, 1]) {
426
+ assert.ok(Object.values(ClientIdle.emotePose(id, u, ms * u / 1000)).every((v) => Math.abs(v) < 1e-9));
427
+ }
428
+ assert.ok(Object.values(ClientIdle.emotePose(id, 0.4, ms * 0.4 / 1000)).some((v) => Math.abs(v) > 0.01));
429
+ }
430
+ });
431
+
432
+ test('v1.158: role grants are private, changed-only, visit-scoped and required only for client requests', () => {
433
+ const r = boot({ idle: expressionIdle });
434
+ assert.deepEqual(r.h.join().hubPlace.idle.expression.roleEmotes, [ROLE]);
435
+ assert.equal(r.sent.some(([, data]) => data.k === 'hub-emotes-for'), false);
436
+ r.say('p1', { k: 'hub-emote', id: ROLE.id });
437
+ assert.deepEqual(r.h.join().hubEmotes, {});
438
+ const from = r.sent.length, warns = warned.length;
439
+ assert.equal(r.hub.emotesFor('p1', ['missing', ROLE.id, ROLE.id]), true);
440
+ assert.deepEqual(r.sent.slice(from), [['p1', { k: 'hub-emotes-for', ids: [ROLE.id] }]]);
441
+ assert.equal(warned.length, warns + 1);
442
+ r.hub.emotesFor('p1', ['missing', ROLE.id]);
443
+ assert.equal(warned.length, warns + 1);
444
+ assert.equal(r.sent.length, from + 1);
445
+ r.say('p2', { k: 'hub-emote', id: ROLE.id });
446
+ assert.deepEqual(r.h.join().hubEmotes, {});
447
+ r.say('p1', { k: 'hub-emote', id: ROLE.id });
448
+ assert.deepEqual(r.h.join().hubEmotes.p1, { id: ROLE.id, at: 0, until: ROLE.ms });
449
+ assert.equal(r.hub.emote('p2', ROLE.id), true, 'place API bypasses grants');
450
+ assert.equal(r.hub.emote('p2', 'unknown'), false);
451
+ r.hub.emotesFor('p1', null);
452
+ assert.deepEqual(r.sent.at(-1), ['p1', { k: 'hub-emotes-for', ids: [] }]);
453
+ r.hub.emotesFor('p1', null);
454
+ assert.equal(r.sent.length, from + 2);
455
+ r.world.timeMs = 4000;
456
+ r.say('p1', { k: 'hub-emote', id: ROLE.id });
457
+ assert.deepEqual(r.h.join().hubEmotes, {});
458
+ assert.equal(r.hub.emotesFor('missing', [ROLE.id]), false);
459
+ assert.equal(r.hub.emotesFor('p1', {}), false);
460
+ r.hub.emotesFor('p1', [ROLE.id]);
461
+ const body = r.world.players.get('p1');
462
+ r.world.players.delete('p1'); r.session.players.splice(0, 1); r.tick();
463
+ r.world.players.set('p1', body); r.session.players.push({ playerId: 'p1', username: 'ada' });
464
+ r.say('p1', { k: 'hub-hello', avatar: 0, party: 2 }); r.tick();
465
+ r.say('p1', { k: 'hub-emote', id: ROLE.id });
466
+ assert.equal(r.h.join().hubEmotes.p1, undefined, 'leaving clears the grant');
467
+ });
468
+
469
+ test('v1.158: a fresh or resumed hello replays the player\'s role grants', () => {
470
+ const r = boot({ idle: expressionIdle });
471
+ const sends = () => r.sent.filter(([, data]) => data.k === 'hub-emotes-for');
472
+ r.say('p1', { k: 'hub-hello', avatar: 0, party: 2 });
473
+ assert.equal(sends().length, 0, 'nothing granted, nothing replayed');
474
+ r.hub.emotesFor('p1', [ROLE.id]);
475
+ r.say('p1', { k: 'hub-hello', avatar: 0, party: 2 });
476
+ assert.deepEqual(sends().slice(-2), [['p1', { k: 'hub-emotes-for', ids: [ROLE.id] }], ['p1', { k: 'hub-emotes-for', ids: [ROLE.id] }]]);
477
+ r.hub.emotesFor('p1', null);
478
+ const before = sends().length;
479
+ r.say('p1', { k: 'hub-hello', avatar: 0, party: 2 });
480
+ assert.equal(sends().length, before, 'an empty list stays quiet on a fresh hello');
481
+ r.say('p1', { k: 'hub-hello', avatar: 0, party: 2, resume: true });
482
+ assert.deepEqual(sends().at(-1), ['p1', { k: 'hub-emotes-for', ids: [] }], 'a resume hello resends a clear it may have missed');
483
+ r.say('p1', { k: 'hub-hello', avatar: 1, again: true });
484
+ assert.equal(sends().length, before + 1, 'an avatar change replays nothing');
485
+ const plain = boot();
486
+ plain.say('p1', { k: 'hub-hello', avatar: 0, party: 2, resume: true });
487
+ assert.equal(plain.sent.some(([, data]) => data.k === 'hub-emotes-for'), false);
488
+ });
489
+
490
+ test('v1.158: ground sit holds the accepted pose without seats, and stands through the existing paths', () => {
491
+ const calls = [];
492
+ const r = groundBoot({ hooks: { sit: (hub, ...args) => calls.push(args) } });
493
+ const body = r.world.players.get('p1'); body.facing = 1.2;
494
+ r.say('p1', { k: 'hub-sit-here' });
495
+ assert.deepEqual(calls, [['p1', null]]);
496
+ assert.equal(r.hub.seat('p1'), 'ground');
497
+ assert.deepEqual(r.h.join().hubSeated, { p1: 'ground' });
498
+ assert.deepEqual(r.h.join().held, ['p1']);
499
+ assert.deepEqual(body.at, { x: 10, y: 0.85, z: 10 });
500
+ r.say('p2', { k: 'hub-sit-here' });
501
+ assert.equal(r.hub.seat('p2'), 'ground', 'ground has no occupancy limit');
502
+ body.at.x = 11; r.tick();
503
+ assert.equal(body.at.x, 10);
504
+ assert.equal(body.facing, 1.2);
505
+ r.say('p1', { k: 'hub-stand' });
506
+ assert.equal(r.hub.seat('p1'), null);
507
+ r.tick(); r.tick(1000); r.say('p1', { k: 'hub-sit-here' });
508
+ r.hub.hold('p1'); r.tick(); assert.equal(r.hub.seat('p1'), null);
509
+ r.hub.release('p1'); r.tick(); r.tick(1000); r.say('p1', { k: 'hub-sit-here' });
510
+ r.hub.release('p1'); assert.equal(r.hub.seat('p1'), null);
511
+ r.tick(); r.tick(1000); r.say('p1', { k: 'hub-sit-here' });
512
+ r.say('p1', { k: 'hub-door-jump', door: 'a' }); assert.equal(r.hub.seat('p1'), null);
513
+ r.world.players.delete('p2'); r.session.players = r.session.players.filter((p) => p.playerId !== 'p2'); r.tick();
514
+ assert.equal(r.hub.seat('p2'), null);
515
+ });
516
+
517
+ test('v1.158: sit-here refuses unsupported, moving, held, absent, vetoed or carrying players and shares the sit budget', () => {
518
+ for (const alter of [
519
+ (r) => { r.world.players.get('p1').at.y = 5; },
520
+ (r) => { r.world.players.get('p1').at.y += 0.16; },
521
+ (r) => { r.world.players.get('p1').at.x += 1; },
522
+ (r) => { r.hub.hold('p1'); },
523
+ (r) => { r.world.players.delete('p1'); },
524
+ ]) {
525
+ const r = groundBoot(); alter(r); r.say('p1', { k: 'hub-sit-here' });
526
+ assert.equal(r.hub.seat('p1'), null);
527
+ }
528
+ for (const sit of [() => false, () => { throw new Error('veto'); }, (hub) => hub.hold('p1')]) {
529
+ const r = groundBoot({ hooks: { sit } }); r.say('p1', { k: 'hub-sit-here' }); assert.equal(r.hub.seat('p1'), null);
530
+ }
531
+ const r = groundBoot();
532
+ r.say('p1', { k: 'hub-sit-here' }); r.say('p1', { k: 'hub-stand' });
533
+ r.tick(0); r.tick(250);
534
+ r.say('p1', { k: 'hub-sit-here' }); r.say('p1', { k: 'hub-stand' });
535
+ assert.equal(r.hub.seat('p1'), 'ground'); r.tick(1000); r.say('p1', { k: 'hub-stand' });
536
+ assert.equal(r.hub.seat('p1'), null);
537
+ // Exercise the checks using the actual server helpers with a carried object.
538
+ const state = { place: { idle: expressionIdle }, sim: { timeMs: 500, players: new Map([['p', { at: { x: 10, y: 0.85, z: 10 }, facing: 0 }]]) },
539
+ players: new Map([['p', { arrived: true }]]), held: new Map(), seated: new Map(), sitBudget: new Map(), grabs: new Map([['p', 'crate']]),
540
+ expressionStill: new Map([['p', { since: 0, pose: { x: 10, y: 0.85, z: 10 } }]]), actors: [], hooks: {} };
541
+ const place = () => { throw new Error('must not place'); };
542
+ Idle.sitHereMessage(state, place, 'p'); assert.equal(Idle.seat(state, 'p'), null);
543
+ state.grabs.clear(); state.players.get('p').arrived = false;
544
+ Idle.sitHereMessage(state, place, 'p'); assert.equal(Idle.seat(state, 'p'), null);
545
+ state.players.get('p').arrived = true; state.noGround = true;
546
+ Idle.sitHereMessage(state, place, 'p'); assert.equal(Idle.seat(state, 'p'), null);
547
+ });
548
+
549
+ test('v1.158: stillness tolerates vertical jitter but resets after walking, including between ticks', () => {
550
+ const jitter = groundBoot();
551
+ jitter.world.players.get('p1').at.x += 1; jitter.tick(0);
552
+ for (let i = 0; i < 8; i += 1) {
553
+ jitter.world.players.get('p1').at.y = 0.85 + (i % 2 ? -0.03 : 0.03);
554
+ jitter.tick(50);
555
+ }
556
+ jitter.say('p1', { k: 'hub-sit-here' });
557
+ assert.equal(jitter.hub.seat('p1'), 'ground');
558
+ for (const sampleMove of [true, false]) {
559
+ const walking = groundBoot();
560
+ walking.world.players.get('p1').at.x += 0.5;
561
+ if (sampleMove) { walking.tick(50); walking.tick(100); }
562
+ walking.say('p1', { k: 'hub-sit-here' });
563
+ assert.equal(walking.hub.seat('p1'), null, 'a recent 0.5 m walk resets the anchor');
564
+ walking.tick(250);
565
+ walking.say('p1', { k: 'hub-sit-here' });
566
+ assert.equal(walking.hub.seat('p1'), 'ground', 'sitting works after the new anchor is still for 250 ms');
567
+ }
568
+ const airborne = groundBoot();
569
+ airborne.world.players.get('p1').at.y = 0.85 + 0.3;
570
+ airborne.tick(50); airborne.tick(200);
571
+ airborne.say('p1', { k: 'hub-sit-here' });
572
+ assert.equal(airborne.hub.seat('p1'), null, 'feet 0.3 m above ground are unsupported');
573
+ });
574
+
575
+ test('v1.158: a plain still body needs 250 ms and 0.04 m per tick creep never qualifies', () => {
576
+ for (const ms of [249, 250]) {
577
+ const r = groundBoot();
578
+ r.world.players.get('p1').at.x += 1; r.tick(0); r.tick(ms);
579
+ r.say('p1', { k: 'hub-sit-here' });
580
+ assert.equal(r.hub.seat('p1'), ms === 250 ? 'ground' : null);
581
+ }
582
+ const r = groundBoot();
583
+ for (let i = 0; i < 12; i += 1) {
584
+ r.world.players.get('p1').at.x += 0.04; r.tick(50);
585
+ if (i === 2 || i === 5 || i === 11) {
586
+ r.say('p1', { k: 'hub-sit-here' });
587
+ assert.equal(r.hub.seat('p1'), null, '0.8 m/s walking cannot age into stillness');
588
+ }
589
+ }
590
+ });
591
+
592
+ test('v1.158: rising from 0.85 to 0.94 resets a rested anchor', () => {
593
+ const r = groundBoot();
594
+ r.world.players.get('p1').at.y = 0.94;
595
+ r.say('p1', { k: 'hub-sit-here' });
596
+ assert.equal(r.hub.seat('p1'), null);
597
+ });
598
+
599
+ test('v1.158: a rested body caught rising sits on the floor, and a first walking step never sits', () => {
600
+ // The default 1.4 m capsule rests at 0.76 (0.7 + 0.06 over the ground).
601
+ const r = boot({ idle: expressionIdle });
602
+ const body = r.world.players.get('p1');
603
+ body.at = { x: 10, y: 0.76, z: 10 };
604
+ r.tick(50); r.tick(500);
605
+ body.at.y = 0.81; r.tick(50);
606
+ r.say('p1', { k: 'hub-sit-here' });
607
+ assert.equal(r.hub.seat('p1'), 'ground');
608
+ assert.ok(Math.abs(body.at.y - 0.76) < 1e-9, 'held at standing height on the floor, not 5 cm up');
609
+ const w = boot({ idle: expressionIdle });
610
+ const walker = w.world.players.get('p1');
611
+ walker.at = { x: 10, y: 0.76, z: 10 };
612
+ w.tick(50); w.tick(500);
613
+ walker.at.x += 0.04; w.tick(50);
614
+ w.say('p1', { k: 'hub-sit-here' });
615
+ assert.equal(w.hub.seat('p1'), null, 'a 0.04 m step in the last tick is walking');
616
+ w.tick(50);
617
+ w.say('p1', { k: 'hub-sit-here' });
618
+ assert.equal(w.hub.seat('p1'), 'ground', 'stopped again after one small step, the player may sit');
619
+ const m = boot({ idle: expressionIdle });
620
+ const mover = m.world.players.get('p1');
621
+ mover.at = { x: 10, y: 0.76, z: 10 };
622
+ m.tick(50); m.tick(500);
623
+ mover.at.x += 0.04;
624
+ m.say('p1', { k: 'hub-sit-here' });
625
+ assert.equal(m.hub.seat('p1'), null, 'a move reported between ticks counts as this tick\'s step');
626
+ });
627
+
628
+ test('v1.158: implicit and solid floors require feet within -0.15..0.12 m', () => {
629
+ for (const solid of [false, true]) {
630
+ for (const [gap, accepted] of [[-0.151, false], [-0.149, true], [0.119, true], [0.121, false], [0.24, false]]) {
631
+ const r = groundBoot();
632
+ r.world.players.get('p1').at = { x: solid ? 1 : 10, y: 0.85 + (solid ? 0.5 : 0) + gap, z: solid ? 0 : 10 };
633
+ r.tick(0); r.tick(250);
634
+ r.say('p1', { k: 'hub-sit-here' });
635
+ assert.equal(r.hub.seat('p1'), accepted ? 'ground' : null, `${solid ? 'solid' : 'implicit'} floor gap ${gap}`);
636
+ }
637
+ }
638
+ });
639
+
640
+ test('v1.158: standing from a seat or ground, including release, needs fresh stillness', () => {
641
+ for (const mode of ['ground', 'seat', 'release']) {
642
+ const r = groundBoot({ idle: { ...expressionIdle, seats: true } });
643
+ if (mode === 'seat') {
644
+ r.world.players.get('p1').at = { x: 1, y: 1.35, z: 0 };
645
+ r.say('p1', { k: 'hub-sit', seat: 'bench-a' });
646
+ } else { r.say('p1', { k: 'hub-sit-here' }); }
647
+ assert.equal(r.hub.seat('p1'), mode === 'seat' ? 'bench-a' : 'ground');
648
+ // Even a long seated rest must not count toward the next sit.
649
+ r.tick(400); r.tick(400);
650
+ if (mode === 'release') { r.hub.release('p1'); }
651
+ else { r.say('p1', { k: 'hub-stand' }); }
652
+ r.say('p1', { k: 'hub-sit-here' });
653
+ assert.equal(r.hub.seat('p1'), null, `${mode}: immediate re-sit refused`);
654
+ r.tick(0); r.tick(250);
655
+ r.say('p1', { k: 'hub-sit-here' });
656
+ assert.equal(r.hub.seat('p1'), 'ground', `${mode}: fresh 250 ms rest accepted`);
657
+ }
658
+ });
659
+
660
+ test('v1.158: bodies placed by kit arrival on implicit ground pass floor support with the standing bounds', () => {
661
+ const actors = globalThis.__hubTestActors;
662
+ globalThis.__hubTestActors = actors.map((actor) => actor.id === 'spawn' ? { ...actor, components: { ...actor.components, Transform: { x: 10, y: 1, z: 10 } } } : actor);
663
+ try {
664
+ for (const shape of [undefined, { kind: 'capsule', radius: 0.35, height: 1.8 }]) {
665
+ const r = boot({ idle: expressionIdle, keepArrival: true, shape });
666
+ const at = { ...r.world.players.get('p1').at };
667
+ const halfHeight = (shape?.height ?? 1.4) / 2;
668
+ assert.ok(Math.abs(at.y - (halfHeight + 0.06)) < 1e-9, 'kit arrival lowered the body onto implicit ground');
669
+ r.tick(50); r.tick(250);
670
+ r.say('p1', { k: 'hub-sit-here' });
671
+ assert.equal(r.hub.seat('p1'), 'ground');
672
+ assert.deepEqual(r.world.players.get('p1').at, at, 'sitting keeps the kit arrival pose');
673
+ }
674
+ } finally { globalThis.__hubTestActors = actors; }
675
+ });
676
+
677
+ test('v1.158: absent expression preserves exact place info, tick fields and private traffic', () => {
678
+ const quiet = boot(), busy = boot({ idle: { emotes: true, seats: true, sounds: SOUNDS, expression: undefined } });
679
+ const snapshot = JSON.stringify(quiet.h.join());
680
+ assert.equal(JSON.stringify(busy.h.join()), snapshot);
681
+ assert.deepEqual(quiet.h.join().hubPlace.idle, { emotes: true, seats: true, sounds: SOUNDS });
682
+ assert.equal(JSON.stringify(quiet.h.join().hubPlace), '{"contract":1,"id":"main","title":"Town","scene":"scenes/main.scene","controller":"walk","maxDurationSec":null,"idle":{"emotes":true,"seats":true,"sounds":["sounds/juke.mp3","sounds/ding.wav"]},"result":null,"fallY":-20}');
683
+ assert.deepEqual(Object.keys(quiet.h.join()), ['hubPlace', 'hubAv', 'hud', 'hidden', 'held', 'labels', 'tints', 'marks', 'hubDoors', 'spawned', 'spawnTemplates', 'hubEmotes', 'hubSeated', 'hubSounds']);
684
+ assert.deepEqual({ ...Idle.fields({ place: { idle: { emotes: true, seats: true, sounds: SOUNDS } }, sim: { timeMs: 0 }, emotes: new Map(), seated: new Map(), loops: new Map() }) }, { hubEmotes: {}, hubSeated: {}, hubSounds: {} });
685
+ assert.equal(quiet.hub.emotesFor, undefined);
686
+ const fields = JSON.stringify(quiet.h.delta());
687
+ for (const id of ['sleep', 'eat', 'cry', 'laugh', 'point', ROLE.id]) {
688
+ busy.say('p1', { k: 'hub-emote', id }); assert.equal(busy.hub.emote('p1', id), false);
689
+ }
690
+ busy.say('p1', { k: 'hub-sit-here' });
691
+ assert.equal(JSON.stringify(busy.h.delta()), fields);
692
+ assert.equal(JSON.stringify(busy.h.join()), snapshot);
693
+ for (let i = 0; i < 3; i += 1) {
694
+ quiet.tick(); busy.tick(); assert.equal(JSON.stringify(busy.h.delta()), JSON.stringify(quiet.h.delta()));
695
+ }
696
+ assert.deepEqual(busy.sent, quiet.sent);
697
+ const messages = [];
698
+ const legacy = boot({ hooks: { message: (_hub, _player, data) => messages.push(data) } });
699
+ legacy.say('p1', { k: 'hub-sit-here' });
700
+ assert.deepEqual(messages, [{ k: 'hub-sit-here' }]);
701
+ });
702
+
703
+ test('v1.158: sit-anywhere uses fixed authored support and refuses moving support', () => {
704
+ for (const [at, expected] of [[{ x: 1, y: 1.35, z: 0 }, 'ground'], [{ x: 0, y: 1.35, z: -1 }, null]]) {
705
+ const r = groundBoot(); r.world.players.get('p1').at = at; r.tick(50); r.tick(250);
706
+ r.say('p1', { k: 'hub-sit-here' }); assert.equal(r.hub.seat('p1'), expected);
707
+ }
708
+ });
709
+
402
710
  // --- seats --------------------------------------------------------------------
403
711
 
404
712
  test('sitting near a free seat holds the player on it, facing its way, until they stand', () => {
@@ -631,6 +939,23 @@ test('v1.47: joins and deltas stay unchanged until an NPC reacts, then latch its
631
939
  }
632
940
  });
633
941
 
942
+ test('v1.158: NPC replies reuse original motions and keep the new request id for the hook', () => {
943
+ const actors = globalThis.__hubTestActors;
944
+ try {
945
+ for (const [id, answer] of Object.entries({ sleep: 'wave', eat: 'wave', cry: 'wave', laugh: 'cheer', point: 'wave', constructor: null })) {
946
+ globalThis.__hubTestActors = [...actors, { id: 'greeter', components: { HubNpc: {}, Transform: { x: 0, y: 1, z: 1 }, Body: { type: 'kinematic' } } }];
947
+ const body = { translation: () => ({ x: 0, y: 1, z: 1 }), setNextKinematicRotation() {}, setNextKinematicTranslation() {} };
948
+ const heard = [];
949
+ const r = boot({ idle: { emotes: true, expression: { roleEmotes: [{ ...ROLE, id: 'constructor' }] } }, bodies: [['greeter', body]], hooks: { npcReact: (_hub, _npc, _player, request) => { heard.push(request.emote); return { line: null, emote: id }; } } });
950
+ assert.equal(r.hub.emote('p1', id), true);
951
+ if (answer) {
952
+ assert.equal(r.h.join().hubNpcEmotes.greeter.id, answer, 'new ids cannot become NPC answer ids');
953
+ assert.deepEqual(heard, [id]);
954
+ } else { assert.equal(r.h.join().hubNpcEmotes, undefined); }
955
+ }
956
+ } finally { globalThis.__hubTestActors = actors; }
957
+ });
958
+
634
959
  test('every emote starts and ends at rest, and moves between', () => {
635
960
  for (const [id] of ClientIdle.EMOTES) {
636
961
  const seconds = Idle.EMOTES[id] / 1000;
@@ -694,6 +1019,27 @@ test('v1.47: NPC and player emotes draw the same motion and emoji, then restore
694
1019
  }
695
1020
  });
696
1021
 
1022
+ test('v1.158: remote role emoji/motion resolve without grants; ground uses the seat pose', () => {
1023
+ clearClient();
1024
+ const rig = new Group(); rig.position.y = 2;
1025
+ const actor = { id: 'remote', components: { Transform: { x: 3, y: 0.85, z: 10 } } };
1026
+ const scene = { multiplayer: { net: { selfId: () => 'self' }, avatars: { actors: new Map([['guest', 'remote']]) } },
1027
+ getActor: () => actor, three: { nodes: new Map([['remote', { node: { children: [rig] } }]]) } };
1028
+ const idle = ClientIdle.makeIdle({});
1029
+ try {
1030
+ clientHub.place = { idle: expressionIdle }; clientHub.lastT = 1000; clientHub.lastTAt = performance.now();
1031
+ clientHub.emotes = { guest: { id: ROLE.id, at: 0, until: ROLE.ms } };
1032
+ idle.draw(scene, null);
1033
+ assert.ok(rig.rotation.x > 0.5);
1034
+ assert.deepEqual(clientHub.roleEmotes, []);
1035
+ assert.equal(idle.labels(scene, null, null, null, (_cam, x, y) => ({ x, y }))[0].text, ROLE.emoji);
1036
+ clientHub.emotes = {}; clientHub.seated = { guest: 'ground' }; idle.draw(scene, null);
1037
+ assert.equal(rig.position.y, 2 - ClientIdle.SEAT_DROP_M); assert.equal(rig.rotation.x, -0.1);
1038
+ clientHub.seated = {}; idle.draw(scene, null);
1039
+ assert.equal(rig.position.y, 2); assert.equal(rig.rotation.x, 0);
1040
+ } finally { idle.dispose(); clearClient(); }
1041
+ });
1042
+
697
1043
  const { BoxGeometry, Mesh, MeshBasicMaterial } = await import('three');
698
1044
  test('an emote is placed on the drawn head first, and nothing that is not finite reaches the chrome', () => {
699
1045
  const now = performance.now();
@@ -492,7 +492,14 @@ async function legacy(on = false, table = cells) {
492
492
  all.push(...q.tick());
493
493
  q.ctx.label('sign', null);
494
494
  all.push(...q.tick());
495
- return all;
495
+ // A WORLD's resync offer (`rs`, the real-time kit's `resync`) came later and
496
+ // is the hub's in every place; the rest of the traffic stays pinned.
497
+ return all.map(({ to, msg }) => {
498
+ if (msg.k !== 'w') {return { to, msg };}
499
+ assert.equal(msg.rs, 1);
500
+ const { rs, ...rest } = msg;
501
+ return { to, msg: rest };
502
+ });
496
503
  }
497
504
  const goldenFile = new URL('./fixtures/interest-legacy.json', import.meta.url);
498
505
  const legacyMessages = await legacy();
@@ -263,6 +263,46 @@ for (const [label, hostUser, expected] of [['guest named by the host', '2387022'
263
263
  assert.equal(named.canInvite(identityNet, guest), expected, label);
264
264
  named.dispose();
265
265
  }
266
+ // Without the Character rail nothing calls canInvite: a Town action's share
267
+ // still matches the host's account against the socket frame() follows.
268
+ for (const [label, hostUser, follow, expected] of [['rail off, same account', '2387022', true, 1], ['rail off, another account', '102', true, 0], ['rail off, no socket yet', '2387022', false, 0]]) {
269
+ let minted = 0;
270
+ const railOff = makeInvites({ canInvite: async () => ({ status: 'ok', canInvite: true, userId: hostUser }), inviteArrival: async () => ({ status: 'none' }),
271
+ invite: async () => { minted++; return { status: 'ok', url: 'https://castle.xyz/i/abc' }; } }, () => {}, () => {});
272
+ if (follow) {railOff.frame(identityNet); await flush();}
273
+ const panelsBefore = elements.filter((e) => e.tag === 'section' && !e.removed).length;
274
+ railOff.open(true); await flush(); await flush();
275
+ assert.equal(minted, expected, label);
276
+ if (!expected) {assert.equal(elements.filter((e) => e.tag === 'section' && !e.removed).length, panelsBefore, `${label}: a stale account stays silent`);}
277
+ if (expected) {assert.ok(activePanel().children.some((e) => e.textContent === 'Invite up to five friends. This link lasts 24 hours.'), `${label}: share panel`);}
278
+ railOff.dispose();
279
+ }
280
+ {
281
+ let minted = 0, closed = false;
282
+ const asked = deferred(), closing = { selfId: () => 'me', userId: () => '2387022', closed: () => closed };
283
+ const railOff = makeInvites({ canInvite: () => asked.promise, inviteArrival: async () => ({ status: 'none' }),
284
+ invite: async () => { minted++; return { status: 'ok', url: 'https://castle.xyz/i/abc' }; } }, () => {}, () => {});
285
+ railOff.frame(closing); await flush();
286
+ railOff.open(true); await flush();
287
+ closed = true; asked.resolve({ status: 'ok', canInvite: true, userId: '2387022' }); await flush(); await flush();
288
+ assert.equal(minted, 0, 'rail off: a socket closed while asking never mints');
289
+ railOff.dispose();
290
+ }
291
+ // A recovery behind the same socket can change its player or account while
292
+ // the host is asked: the share is cancelled, rail on or off.
293
+ for (const [label, change, rail] of [['rail-off account', (n) => { n.user = '102'; }, false], ['rail-off player', (n) => { n.self = 'other'; }, false], ['rail-on account', (n) => { n.user = '102'; }, true]]) {
294
+ let minted = 0;
295
+ const asked = deferred(), net = { self: 'me', user: '2387022', selfId() { return this.self; }, userId() { return this.user; } };
296
+ let hostCalls = 0;
297
+ const shared = makeInvites({ canInvite: () => (++hostCalls === (rail ? 2 : 1) ? asked.promise : Promise.resolve({ status: 'ok', canInvite: true, userId: '2387022' })), inviteArrival: async () => ({ status: 'none' }),
298
+ invite: async () => { minted++; return { status: 'ok', url: 'https://castle.xyz/i/abc' }; } }, () => {}, () => {});
299
+ shared.frame(net); await flush();
300
+ if (rail) {shared.canInvite(net, { getCurrent: async () => ({ userId: '2387022' }) }); await flush();}
301
+ shared.open(true); await flush();
302
+ change(net); asked.resolve({ status: 'ok', canInvite: true, userId: '2387022' }); await flush(); await flush();
303
+ assert.equal(minted, 0, `share: ${label} change while asking never mints`);
304
+ shared.dispose();
305
+ }
266
306
  {
267
307
  const refused = makeInvites({ canInvite: async () => ({ status: 'ok', canInvite: false, userId: '2387022' }) }, () => {}, () => {});
268
308
  refused.canInvite(identityNet, { getCurrent: async () => null }); await flush();
@@ -327,7 +367,8 @@ identity.dispose();
327
367
  const panelsBefore = elements.filter((e) => e.tag === 'section').length;
328
368
  revoked.open(true); await flush();
329
369
  assert.equal(minted, 0, 'a share asks the host first and makes no link once the gate closed');
330
- assert.equal(elements.filter((e) => e.tag === 'section').length, panelsBefore, 'a refused share opens no panel');
370
+ assert.equal(elements.filter((e) => e.tag === 'section').length, panelsBefore + 1, 'a refused share opens one panel');
371
+ assert.ok(activePanel().children.some((e) => e.textContent === 'Sharing is unavailable here.'), 'a refused share says sharing is unavailable');
331
372
  assert.equal(revoked.canInvite(identityNet, signedIn), false, 'a refused share hides the rail at once');
332
373
  allow = true; clock = 30000; revoked.canInvite(identityNet, signedIn); await flush();
333
374
  assert.equal(revoked.canInvite(identityNet, signedIn), true, 'the rail returns when the host allows again');
@@ -22,6 +22,36 @@ function test(name, fn) {
22
22
  n += 1;
23
23
  }
24
24
 
25
+
26
+ test('v1.158 expression: strict place opt-in, role bounds and public definitions', () => {
27
+ const role = { id: 'doctor', emoji: '🩺', label: 'Checkup', motion: 'bow', ms: 3000 };
28
+ const parse = (expression, emotes = true) => readManifest(base({ idle: { emotes, expression } }), has);
29
+ for (const expression of [true, {}, { roleEmotes: [] }, { roleEmotes: [role] }]) {
30
+ const result = parse(expression);
31
+ assert.deepEqual(result.errors, []);
32
+ assert.deepEqual(publicPlace('main', result.manifest.places.main).idle.expression, { roleEmotes: expression.roleEmotes ?? [] });
33
+ }
34
+ for (const expression of [false, null, 1, [], 'yes', { extra: true }, { roleEmotes: null }, { roleEmotes: {} },
35
+ { roleEmotes: Array.from({ length: 13 }, (_, i) => ({ ...role, id: `role-${i}` })) }, { roleEmotes: [role, role] },
36
+ ...[null, {}, { ...role, extra: 1 }, ...['wave', 'dance', 'cheer', 'bow', 'spin', 'sleep', 'eat', 'cry', 'laugh', 'point', '1bad', 'Bad', 'a'.repeat(25), ''].map((id) => ({ ...role, id })),
37
+ ...['', 'x', '😴😴', 'πŸ‘©β€πŸ‘©β€πŸ‘§β€πŸ‘¦', null].map((emoji) => ({ ...role, emoji })),
38
+ ...['', ' ', 'x'.repeat(17), null, 2].map((label) => ({ ...role, label })),
39
+ ...['sit', 'unknown', null].map((motion) => ({ ...role, motion })),
40
+ ...[999, 6001, NaN, Infinity, '2000', null].map((ms) => ({ ...role, ms }))].map((item) => ({ roleEmotes: [item] }))]) {
41
+ assert.ok(parse(expression).errors.some((e) => e.includes('expression')), JSON.stringify(expression));
42
+ }
43
+ assert.match(parse(true, false).errors.join(), /requires idle.emotes/);
44
+ for (const emoji of ['πŸ‘‹', '❀️', 'πŸ‘πŸ½', 'πŸ‡ΊπŸ‡Έ', '1️⃣', 'πŸ‘©β€βš•οΈ']) {
45
+ assert.deepEqual(parse({ roleEmotes: [{ ...role, emoji }] }).errors, [], emoji);
46
+ }
47
+ const twelve = Array.from({ length: 12 }, (_, i) => ({ ...role, id: `role-${i}`, ms: i % 2 ? 1000 : 6000 }));
48
+ assert.deepEqual(parse({ roleEmotes: twelve }).errors, []);
49
+ const places = readManifest(base({ idle: { emotes: true }, places: { clinic: { title: 'Clinic', scene: 'scenes/race.scene', idle: { emotes: true, expression: { roleEmotes: [role] } } } } }), has);
50
+ assert.deepEqual(places.errors, []);
51
+ assert.equal('expression' in publicPlace('main', places.manifest.places.main).idle, false);
52
+ assert.deepEqual(publicPlace('clinic', places.manifest.places.clinic).idle.expression.roleEmotes, [role]);
53
+ });
54
+
25
55
  test('push capability is explicit and survives the public place boundary', () => {
26
56
  const absent = readManifest(base(), has);
27
57
  assert(!Object.hasOwn(publicPlace('main', absent.manifest.places.main), 'push'));
@@ -0,0 +1,42 @@
1
+ // `client/noTrips.js`: only a host that refuses `Hub.doors` as an unknown
2
+ // command (an app from before hub commands) has no door trips.
3
+ // `npm run check` runs it; it needs nothing installed.
4
+
5
+ import assert from 'node:assert/strict';
6
+ import { hostHasNoTrips, makeNoTrips } from '../code/client/noTrips.js';
7
+
8
+ const refusing = (code) => ({ Hub: { doors: async () => { throw Object.assign(new Error(code), { code }); } } });
9
+
10
+ assert.equal(await hostHasNoTrips(refusing('UNKNOWN_COMMAND')), true, 'released iOS 1.151');
11
+ assert.equal(await hostHasNoTrips({ Hub: { doors: async () => ({ status: 'ok', doors: [] }) } }), false);
12
+ assert.equal(await hostHasNoTrips({ Hub: { doors: async () => ({ status: 'unavailable', doors: null }) } }), false, 'the dev serve');
13
+ for (const code of ['CASTLE_HOST_UNAVAILABLE', 'TIMEOUT', 'CASTLE_HOST_ERROR']) {
14
+ assert.equal(await hostHasNoTrips(refusing(code)), false, code);
15
+ }
16
+ assert.equal(await hostHasNoTrips({}), false);
17
+ assert.equal(await hostHasNoTrips(null), false);
18
+ console.log('no trips: ok');
19
+
20
+ // After a hello: only the app asks, once a page, and tells only a current connection.
21
+ const conn = () => { const sent = []; let closed = false; return { sent, send: (m) => sent.push(m), closed: () => closed, close() { closed = true; } }; };
22
+ let asks = 0;
23
+ const old = { Hub: { doors: async () => { asks++; throw Object.assign(new Error('x'), { code: 'UNKNOWN_COMMAND' }); } } };
24
+ const web = makeNoTrips(old, { CastleEmbed: { host: 'web' } });
25
+ const a = conn();
26
+ assert.equal(web.afterHello(a, () => true), null);
27
+ assert.equal(asks, 0, 'a web page asks nothing');
28
+ const app = makeNoTrips(old, { CastleEmbed: { host: 'mobile' } });
29
+ const b = conn(), c = conn(), d = conn();
30
+ await app.afterHello(b, () => true);
31
+ assert.deepEqual(b.sent, [{ k: 'hub-no-trips' }]);
32
+ await app.afterHello(c, () => false);
33
+ assert.deepEqual(c.sent, [], 'a connection since replaced is told nothing');
34
+ d.close();
35
+ await app.afterHello(d, () => true);
36
+ assert.deepEqual(d.sent, []);
37
+ assert.equal(asks, 1, 'asked once a page');
38
+ const fresh = makeNoTrips({ Hub: { doors: async () => ({ status: 'ok', doors: [] }) } }, { CastleEmbed: { host: 'mobile' } });
39
+ const e = conn();
40
+ await fresh.afterHello(e, () => true);
41
+ assert.deepEqual(e.sent, [], 'an app with door trips sends nothing');
42
+ console.log('no trips after hello: ok');
@@ -420,7 +420,7 @@ const hubSource = readFileSync(new URL('../code/systems/hub.js', import.meta.url
420
420
  const node = { style: {}, getBoundingClientRect: () => ({ left: 0, right: 100, top, bottom: top + 24, width: 100, height: 24 }) };
421
421
  geometry.register(node); geometry.beginFrame(); top = 80;
422
422
  const context = {
423
- applyVisibility() {}, applyWear() {},
423
+ applyVisibility() {}, applyWear() {}, applyCars() {},
424
424
  fadeNames() {assert.equal(geometry.rect(node).top, 20, 'late crowd geometry uses the read-phase sample');},
425
425
  endLayoutFrame() {geometry.endFrame();},
426
426
  };
@@ -125,6 +125,19 @@ await test('tier before load: manual beats history, history beats GPU/memory; ju
125
125
  }
126
126
  });
127
127
 
128
+ await test('early quality selection honors the low-memory scene profile before a world exists', () => {
129
+ for (const [lowMemory, expected] of [[true, 'low'], [false, 'high']]) {
130
+ enable();
131
+ const undo = adapt('auto', { make: (options) => makeTiers({ ...options, storage: null, deviceMemory: 8 }) });
132
+ try {
133
+ const scene = new SceneRuntime({ ...authored, engine: { lowMemory } }, [], {}, {}, 'scenes/main.scene');
134
+ assert.equal(qualityFor(scene).tiers.current(), expected);
135
+ assert.equal(scene.actors.has('decor'), !lowMemory);
136
+ if (lowMemory) assert.equal(qualityFor(scene).tiers.reason(), 'memory');
137
+ } finally { undo(); }
138
+ }
139
+ });
140
+
128
141
  await test('skip builds no decor actors/nodes on Low; High/hide build all; protects gameplay and authored files', () => {
129
142
  for (const [mode, decor] of [['low', 'skip'], ['high', 'skip'], ['low', 'hide']]) {
130
143
  enable({ decor }); const serialized = JSON.stringify(authored); const undo = adapt(mode);