castle-web-cli 0.4.231 → 0.4.233
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-failures.d.ts +8 -0
- package/dist/agent-failures.js +19 -2
- package/dist/agent-prompts.d.ts +1 -1
- package/dist/agent-prompts.js +10 -3
- package/dist/agent.d.ts +64 -3
- package/dist/agent.js +170 -81
- package/dist/castle-host/host.d.ts +1 -0
- package/dist/castle-host/host.js +51 -3
- package/dist/castleJson.d.ts +4 -2
- package/dist/castleJson.js +2 -0
- package/dist/check.d.ts +3 -1
- package/dist/check.js +11 -1
- package/dist/devSessionStorage.js +47 -1
- package/dist/importPinMismatch.d.ts +22 -0
- package/dist/importPinMismatch.js +77 -0
- package/dist/importRegression.js +3 -15
- package/dist/imports.d.ts +10 -3
- package/dist/imports.js +88 -20
- package/dist/index.js +5 -4
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +22 -0
- package/dist/routerFences.d.ts +5 -0
- package/dist/routerFences.js +12 -2
- package/dist/save-deck.d.ts +5 -0
- package/dist/save-deck.js +37 -4
- package/dist/serve.js +3 -0
- package/dist/serverBundle.js +5 -3
- package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
- package/dist/shell/assets/index-MVLfNYd9.css +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/taskSteer.d.ts +13 -0
- package/dist/taskSteer.js +22 -2
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +79 -2
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +1 -1
- package/kits/base/sdk/commands.d.ts +14 -0
- package/kits/base/sdk/hub.d.ts +6 -2
- package/kits/base/sdk/hub.js +13 -0
- package/kits/base/sdk/multiplayer.js +17 -1
- package/kits/base/sdk/save.js +2 -1
- package/kits/base/sdk/server/hub.d.ts +87 -0
- package/kits/base/sdk/server/hub.js +70 -0
- package/kits/base/sdk/server/platformHandle.d.ts +31 -1
- package/kits/base/sdk/server/storage.d.ts +13 -0
- package/kits/base/sdk/server/storage.js +46 -0
- package/kits/base/sdk/server/wrapper.d.ts +36 -5
- package/kits/base/sdk/server/wrapper.js +83 -8
- package/kits/hub-game/CLAUDE.md +352 -12
- package/kits/hub-game/blueprints/avatar-10.scene +28 -0
- package/kits/hub-game/blueprints/avatar-11.scene +28 -0
- package/kits/hub-game/blueprints/avatar-12.scene +28 -0
- package/kits/hub-game/blueprints/avatar-13.scene +28 -0
- package/kits/hub-game/blueprints/avatar-14.scene +28 -0
- package/kits/hub-game/blueprints/avatar-15.scene +28 -0
- package/kits/hub-game/blueprints/avatar-4.scene +28 -0
- package/kits/hub-game/blueprints/avatar-5.scene +28 -0
- package/kits/hub-game/blueprints/avatar-6.scene +28 -0
- package/kits/hub-game/blueprints/avatar-7.scene +28 -0
- package/kits/hub-game/blueprints/avatar-8.scene +28 -0
- package/kits/hub-game/blueprints/avatar-9.scene +28 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +345 -32
- package/kits/hub-game/code/client/avatarCap.js +228 -0
- package/kits/hub-game/code/client/avatarColors.js +70 -0
- package/kits/hub-game/code/client/avatarFaces.js +21 -0
- package/kits/hub-game/code/client/avatarShare.js +251 -0
- package/kits/hub-game/code/client/ballot.js +467 -0
- package/kits/hub-game/code/client/build.js +22 -0
- package/kits/hub-game/code/client/chat.js +12 -0
- package/kits/hub-game/code/client/chrome.js +1334 -50
- package/kits/hub-game/code/client/companion.js +716 -0
- package/kits/hub-game/code/client/companionDress.js +99 -0
- package/kits/hub-game/code/client/decor.js +509 -0
- package/kits/hub-game/code/client/earned.js +131 -0
- package/kits/hub-game/code/client/emoteBubble.js +75 -0
- package/kits/hub-game/code/client/grab.js +363 -20
- package/kits/hub-game/code/client/hats.js +26 -0
- package/kits/hub-game/code/client/hookLayer.js +328 -15
- package/kits/hub-game/code/client/hudClear.js +126 -0
- package/kits/hub-game/code/client/idle.js +163 -22
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +205 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/pack.js +6 -2
- package/kits/hub-game/code/client/packFormat.js +3 -3
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/shot.js +92 -0
- package/kits/hub-game/code/client/sound.js +63 -8
- package/kits/hub-game/code/client/soundscape.js +1151 -0
- package/kits/hub-game/code/client/soundscapeActions.js +99 -0
- package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
- package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
- package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
- package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
- package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
- package/kits/hub-game/code/client/soundscapeCues.js +362 -0
- package/kits/hub-game/code/client/soundscapeMap.js +181 -0
- package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
- package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
- package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
- package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
- package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
- package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
- package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
- package/kits/hub-game/code/client/soundscapeUi.js +211 -0
- package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
- package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
- package/kits/hub-game/code/client/spin.js +101 -0
- package/kits/hub-game/code/client/state.js +131 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +538 -47
- package/kits/hub-game/code/client/tiers.js +541 -27
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +98 -1
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/wear.js +470 -97
- package/kits/hub-game/code/client/yours.js +199 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/actions.js +133 -0
- package/kits/hub-game/code/server/actors.js +14 -1
- package/kits/hub-game/code/server/ask.js +155 -0
- package/kits/hub-game/code/server/ballot.js +539 -0
- package/kits/hub-game/code/server/cells.js +100 -0
- package/kits/hub-game/code/server/companion.js +82 -0
- package/kits/hub-game/code/server/cues.js +70 -0
- package/kits/hub-game/code/server/decor.js +269 -0
- package/kits/hub-game/code/server/earned.js +461 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +232 -0
- package/kits/hub-game/code/server/grab.js +296 -11
- package/kits/hub-game/code/server/history.js +5 -0
- package/kits/hub-game/code/server/hub.js +1317 -52
- package/kits/hub-game/code/server/idle.js +30 -11
- package/kits/hub-game/code/server/index.js +2 -2
- package/kits/hub-game/code/server/labels.js +28 -2
- package/kits/hub-game/code/server/manifest.js +424 -8
- package/kits/hub-game/code/server/menu.js +133 -0
- package/kits/hub-game/code/server/npcs.js +830 -80
- package/kits/hub-game/code/server/party.js +13 -2
- package/kits/hub-game/code/server/players.js +22 -0
- package/kits/hub-game/code/server/say.js +8 -2
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +124 -0
- package/kits/hub-game/code/server/vis.js +113 -0
- package/kits/hub-game/code/server/wear.js +128 -11
- package/kits/hub-game/code/server/yours.js +59 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/shot.js +19 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +1083 -85
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +2440 -61
- package/kits/hub-game/docs/home-pieces.md +64 -0
- package/kits/hub-game/models/avatar-10.pxmodel +28 -0
- package/kits/hub-game/models/avatar-11.pxmodel +28 -0
- package/kits/hub-game/models/avatar-12.pxmodel +27 -0
- package/kits/hub-game/models/avatar-13.pxmodel +24 -0
- package/kits/hub-game/models/avatar-14.pxmodel +29 -0
- package/kits/hub-game/models/avatar-15.pxmodel +24 -0
- package/kits/hub-game/models/avatar-4.pxmodel +29 -0
- package/kits/hub-game/models/avatar-5.pxmodel +27 -0
- package/kits/hub-game/models/avatar-6.pxmodel +26 -0
- package/kits/hub-game/models/avatar-7.pxmodel +25 -0
- package/kits/hub-game/models/avatar-8.pxmodel +24 -0
- package/kits/hub-game/models/avatar-9.pxmodel +30 -0
- package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
- package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
- package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
- package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
- package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
- package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
- package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
- package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
- package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
- package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
- package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
- package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
- package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
- package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
- package/kits/hub-game/models/hats/cap.pxmodel +162 -0
- package/kits/hub-game/models/hats/captain.pxmodel +178 -0
- package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
- package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
- package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
- package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
- package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
- package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
- package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
- package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
- package/kits/hub-game/models/hats/straw.pxmodel +139 -0
- package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
- package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
- package/kits/hub-game/models/hats/witch.pxmodel +147 -0
- package/kits/hub-game/package-lock.json +2 -0
- package/kits/hub-game/package.json +2 -1
- package/kits/hub-game/scripts/check.mjs +78 -11
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
- package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
- package/kits/hub-game/scripts/gen-earned.mjs +285 -0
- package/kits/hub-game/scripts/gen-hats.mjs +827 -0
- package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
- package/kits/hub-game/scripts/test-actions.mjs +298 -0
- package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -17
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask.mjs +269 -0
- package/kits/hub-game/scripts/test-attention.mjs +10 -1
- package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
- package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
- package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
- package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
- package/kits/hub-game/scripts/test-avatar.mjs +540 -7
- package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
- package/kits/hub-game/scripts/test-build.mjs +31 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +694 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
- package/kits/hub-game/scripts/test-companion.mjs +259 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
- package/kits/hub-game/scripts/test-decor.mjs +457 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1194 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +186 -3
- package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
- package/kits/hub-game/scripts/test-grab.mjs +864 -3
- package/kits/hub-game/scripts/test-hats.mjs +483 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +1228 -1
- package/kits/hub-game/scripts/test-hud-clear.mjs +1000 -0
- package/kits/hub-game/scripts/test-idle.mjs +361 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +596 -0
- package/kits/hub-game/scripts/test-manifest.mjs +282 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
- package/kits/hub-game/scripts/test-menu.mjs +296 -0
- package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-party.mjs +22 -1
- package/kits/hub-game/scripts/test-picker.mjs +314 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
- package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
- package/kits/hub-game/scripts/test-say.mjs +59 -2
- package/kits/hub-game/scripts/test-shot.mjs +756 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +416 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
- package/kits/hub-game/scripts/test-tiers.mjs +666 -3
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +940 -0
- package/kits/hub-game/scripts/test-vis.mjs +343 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
- package/kits/hub-game/scripts/test-yours.mjs +372 -0
- package/kits/multiplayer-3d/CLAUDE.md +50 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +7 -0
- package/kits/multiplayer-3d/code/client/gait.js +65 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/options.js +5 -0
- package/kits/multiplayer-3d/code/server/ownership.js +10 -2
- package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
- package/kits/multiplayer-3d/code/server/world.js +7 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
- package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
- package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
- package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
- package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
- package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
- package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/physics-2d/CLAUDE.md +9 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +288 -1
- package/kits/physics-2d/engine/skyKey.js +129 -0
- package/kits/physics-2d/engine/stillClock.js +106 -0
- package/kits/physics-2d/engine/updateBudget.js +21 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +370 -1
- package/kits/physics-3d/CLAUDE.md +1391 -0
- package/kits/physics-3d/behaviors/Player.jsx +921 -3
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +12 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +98 -10
- package/kits/physics-3d/engine3d/actornode.js +86 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/editorWorld.js +6 -0
- package/kits/physics-3d/engine3d/emptynodes.js +232 -0
- package/kits/physics-3d/engine3d/framecap.js +96 -0
- package/kits/physics-3d/engine3d/gait.js +118 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +507 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +37 -19
- package/kits/physics-3d/engine3d/optimize.js +58 -5
- package/kits/physics-3d/engine3d/orbitinput.js +755 -0
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/shadowfade.js +882 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/unchanged.js +11 -0
- package/kits/physics-3d/engine3d/viewrange.js +52 -0
- package/kits/physics-3d/engine3d/world3d.js +870 -87
- package/kits/physics-3d/main.jsx +5 -0
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
- package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +12 -2
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +4588 -0
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-gait.mjs +387 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
- package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
- package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +13 -1
- package/kits/physics-3d/scripts/test-static-passes.mjs +1 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +635 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +474 -12
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +97 -19
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// v1.75 private prompt chrome, submissions, input locks and cleanup.
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { setMaxListeners } from 'node:events';
|
|
4
|
+
import { register } from 'node:module';
|
|
5
|
+
|
|
6
|
+
register(`data:text/javascript,${encodeURIComponent(`
|
|
7
|
+
import { readFile } from 'node:fs/promises';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
export async function resolve(specifier, context, next) {
|
|
10
|
+
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 };
|
|
11
|
+
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 };
|
|
12
|
+
if (specifier === 'castle-web-sdk') return { url: 'data:text/javascript,export {};', shortCircuit: true };
|
|
13
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/client/avatars.js') return { url: 'data:text/javascript,export const dropMissing = () => {};', shortCircuit: true };
|
|
14
|
+
if (specifier.startsWith('@imports/castle.physics-2d/engine/')) return { url: 'data:text/javascript,export const initialMedia = {}; export const playMedia = () => {}; export const stopMedia = () => {};', shortCircuit: true };
|
|
15
|
+
if (specifier === '../client/pack.js') return { url: 'data:text/javascript,export const cachedPacks = () => []; export const loadPack = () => {}; export const matchesOwn = () => false; export const resolveDeckDoor = () => {};', shortCircuit: true };
|
|
16
|
+
return next(specifier, context);
|
|
17
|
+
}
|
|
18
|
+
export async function load(url, context, next) {
|
|
19
|
+
if (url.endsWith('/code/client/hookLayer.js')) {
|
|
20
|
+
const source = await readFile(fileURLToPath(url), 'utf8');
|
|
21
|
+
return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
|
|
22
|
+
}
|
|
23
|
+
return next(url, context);
|
|
24
|
+
}
|
|
25
|
+
`)}`);
|
|
26
|
+
const State = await import('../code/client/state.js');
|
|
27
|
+
const hook = (await import('../code/client/hookLayer.js')).default;
|
|
28
|
+
const { installSystem } = await import('../code/systems/hub.js');
|
|
29
|
+
const { makeChrome } = await import('../code/client/chrome.js');
|
|
30
|
+
const { validPrivateText, REFUSED_TEXT } = await import('../code/privateText.js');
|
|
31
|
+
const { makeTalk } = await import('../code/client/talk.js');
|
|
32
|
+
const Ballot = await import('../code/client/ballot.js');
|
|
33
|
+
function fakeDom(view) {
|
|
34
|
+
const log = [];
|
|
35
|
+
let ids = 0;
|
|
36
|
+
const made = [];
|
|
37
|
+
function node(tag) {
|
|
38
|
+
const id = `${tag}#${(ids += 1)}`;
|
|
39
|
+
const styles = {};
|
|
40
|
+
let text = '';
|
|
41
|
+
const self = {
|
|
42
|
+
id,
|
|
43
|
+
tag,
|
|
44
|
+
children: [],
|
|
45
|
+
parent: null,
|
|
46
|
+
dataset: {},
|
|
47
|
+
attrs: {},
|
|
48
|
+
rect: null,
|
|
49
|
+
size: null,
|
|
50
|
+
style: new Proxy(styles, {
|
|
51
|
+
get: (target, key) => target[key] ?? '',
|
|
52
|
+
set(target, key, value) {
|
|
53
|
+
target[key] = String(value);
|
|
54
|
+
log.push(`${id} style.${String(key)}=${value}`);
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
styles,
|
|
59
|
+
get textContent() {
|
|
60
|
+
return text;
|
|
61
|
+
},
|
|
62
|
+
set textContent(value) {
|
|
63
|
+
text = String(value);
|
|
64
|
+
log.push(`${id} text=${text}`);
|
|
65
|
+
},
|
|
66
|
+
appendChild(child) {
|
|
67
|
+
child.parent = self;
|
|
68
|
+
self.children.push(child);
|
|
69
|
+
log.push(`${id} +${child.id}`);
|
|
70
|
+
return child;
|
|
71
|
+
},
|
|
72
|
+
append(...kids) {
|
|
73
|
+
kids.forEach((kid) => self.appendChild(kid));
|
|
74
|
+
},
|
|
75
|
+
insertBefore(child, before) {
|
|
76
|
+
if (child.parent) {
|
|
77
|
+
child.parent.children = child.parent.children.filter((c) => c !== child);
|
|
78
|
+
}
|
|
79
|
+
child.parent = self;
|
|
80
|
+
const at = self.children.indexOf(before);
|
|
81
|
+
self.children.splice(at < 0 ? self.children.length : at, 0, child);
|
|
82
|
+
return child;
|
|
83
|
+
},
|
|
84
|
+
remove() {
|
|
85
|
+
if (self.parent) {
|
|
86
|
+
self.parent.children = self.parent.children.filter((c) => c !== self);
|
|
87
|
+
log.push(`${id} removed`);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
replaceChildren(...kids) {
|
|
91
|
+
self.children = [];
|
|
92
|
+
log.push(`${id} emptied`);
|
|
93
|
+
kids.forEach((kid) => self.appendChild(kid));
|
|
94
|
+
},
|
|
95
|
+
handlers: {},
|
|
96
|
+
addEventListener(type, fn, options) {
|
|
97
|
+
self.handlers[type] = fn;
|
|
98
|
+
if (options?.signal) {
|
|
99
|
+
setMaxListeners(0, options.signal);
|
|
100
|
+
options.signal.addEventListener('abort', () => { delete self.handlers[type]; }, { once: true });
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
removeEventListener() {},
|
|
104
|
+
setAttribute(key, value) {
|
|
105
|
+
self.attrs[key] = String(value);
|
|
106
|
+
},
|
|
107
|
+
getAttribute: (key) => self.attrs[key] ?? null,
|
|
108
|
+
focus() { document.activeElement = self; },
|
|
109
|
+
blur() { if (document.activeElement === self) document.activeElement = null; },
|
|
110
|
+
// A stand-in layout: 7 px a character and 20 of padding, one 24 px line.
|
|
111
|
+
get offsetWidth() {
|
|
112
|
+
log.push(`${id} read`);
|
|
113
|
+
return (typeof self.size === 'function' ? self.size(self) : self.size)?.w ?? text.length * 7 + 20;
|
|
114
|
+
},
|
|
115
|
+
get offsetHeight() {
|
|
116
|
+
log.push(`${id} read`);
|
|
117
|
+
return (typeof self.size === 'function' ? self.size(self) : self.size)?.h ?? 24;
|
|
118
|
+
},
|
|
119
|
+
get offsetLeft() {
|
|
120
|
+
return parseFloat(styles.left) || 0;
|
|
121
|
+
},
|
|
122
|
+
get clientWidth() {
|
|
123
|
+
return self.client ?? self.offsetWidth;
|
|
124
|
+
},
|
|
125
|
+
get scrollWidth() {
|
|
126
|
+
return self.scroll ?? self.offsetWidth;
|
|
127
|
+
},
|
|
128
|
+
getBoundingClientRect() {
|
|
129
|
+
let r = self.rect ?? { left: 0, right: 0, top: 0, bottom: 0 };
|
|
130
|
+
if (styles.flexDirection === 'column-reverse') {
|
|
131
|
+
const height = self.children.length * 44 + (self.children.length - 1) * 6;
|
|
132
|
+
const bottom = styles.bottom.startsWith('max') ? 132 : parseFloat(styles.bottom);
|
|
133
|
+
r = { left: view.viewW - 162, right: view.viewW - 12, top: view.viewH - bottom - height, bottom: view.viewH - bottom };
|
|
134
|
+
}
|
|
135
|
+
return { ...r, width: r.right - r.left, height: r.bottom - r.top };
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
made.push(self);
|
|
139
|
+
return self;
|
|
140
|
+
}
|
|
141
|
+
const body = node('body');
|
|
142
|
+
globalThis.document = { body, createElement: node, activeElement: null };
|
|
143
|
+
globalThis.window = { innerWidth: view.viewW, innerHeight: view.viewH };
|
|
144
|
+
globalThis.innerWidth = view.viewW;
|
|
145
|
+
return { log, body, made };
|
|
146
|
+
}
|
|
147
|
+
const spec = { id: 'pet-name', title: 'Only you will see this name', max: 16, n: 1 };
|
|
148
|
+
const find = (dom, text) => dom.made.findLast((node) => node.textContent === text);
|
|
149
|
+
const tap = (node) => node.handlers.click?.({ stopPropagation() {} });
|
|
150
|
+
let passed = 0;
|
|
151
|
+
function test(name, fn) { fn(); passed += 1; console.log(`ok: ${name}`); }
|
|
152
|
+
function rig() {
|
|
153
|
+
const dom = fakeDom({ viewW: 360, viewH: 780 }), sent = [], locks = [];
|
|
154
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
155
|
+
const draw = (value = spec) => chrome.setTextAsk(value, (id, n, text) => sent.push({ k: 'hub-answer', id, n, text }), (open) => locks.push(open));
|
|
156
|
+
const input = () => dom.made.findLast((node) => node.tag === 'input' && node.type === 'text');
|
|
157
|
+
const type = (text) => { input().value = text; input().handlers.input(); };
|
|
158
|
+
return { dom, chrome, sent, locks, draw, input, type };
|
|
159
|
+
}
|
|
160
|
+
function noText(r, text) {
|
|
161
|
+
assert(!r.dom.made.some((node) => node.textContent.includes(text) || node.value?.includes(text)));
|
|
162
|
+
assert(!r.dom.log.some((line) => line.includes(text)));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
test('buffer before WORLD, only opted-in place retains prompts, newer versions win', () => {
|
|
166
|
+
State.clear(); assert(!Object.hasOwn(State.hub, 'ask'));
|
|
167
|
+
hook.message({}, { k: 'hub-ask', ...spec }); assert.deepEqual(State.hub.ask, spec);
|
|
168
|
+
hook.state({}, { hubPlace: { id: 'main', ask: true } }); assert.deepEqual(State.hub.ask, spec);
|
|
169
|
+
hook.message({}, { k: 'hub-ask', id: null, n: 2 }); assert.deepEqual(State.hub.ask, { id: null, n: 2 });
|
|
170
|
+
hook.message({}, { k: 'hub-ask', ...spec }); assert.deepEqual(State.hub.ask, { id: null, n: 2 });
|
|
171
|
+
hook.state({}, { hubPlace: { id: 'plain' } }); assert(!Object.hasOwn(State.hub, 'ask'));
|
|
172
|
+
hook.message({}, { k: 'hub-ask', ...spec }); assert(!Object.hasOwn(State.hub, 'ask')); State.clear();
|
|
173
|
+
});
|
|
174
|
+
test('lazy phone card, single field, attributes, code-point limit, viewport above keyboard', () => {
|
|
175
|
+
const r = rig(), count = r.dom.made.length; r.draw(null); assert.equal(r.dom.made.length, count); assert.deepEqual(r.locks, []);
|
|
176
|
+
let resize;
|
|
177
|
+
window.visualViewport = { height: 420, offsetTop: 10, addEventListener(type, fn) { if (type === 'resize') resize = fn; } };
|
|
178
|
+
r.draw(); const input = r.input(), card = input.parent;
|
|
179
|
+
assert.equal(card.style.left, '50%'); assert.equal(card.style.bottom, 'max(374px, calc(env(safe-area-inset-bottom) + 24px))');
|
|
180
|
+
window.visualViewport.height = 350; resize(); assert.equal(card.style.bottom, 'max(444px, calc(env(safe-area-inset-bottom) + 24px))');
|
|
181
|
+
assert.equal(input.maxLength, 32); assert.equal(input.autocomplete, 'off'); assert.equal(input.attrs.autocorrect, 'off'); assert.equal(input.spellcheck, false); assert.equal(input.attrs.autocapitalize, 'words');
|
|
182
|
+
assert.equal(find(r.dom, 'OK').disabled, true); assert.deepEqual(r.locks, [true]); assert.equal(document.activeElement, input);
|
|
183
|
+
r.type('😀'.repeat(17)); assert.equal(input.value, '😀'.repeat(16)); assert.equal(find(r.dom, 'OK').disabled, false);
|
|
184
|
+
r.chrome.dispose(); assert.equal(input.value, ''); assert.deepEqual(r.locks, [true, false]);
|
|
185
|
+
});
|
|
186
|
+
test('OK and Enter send exact answer once, wipe field/remove listeners and never reopen same n', () => {
|
|
187
|
+
for (const enter of [false, true]) {
|
|
188
|
+
const r = rig(); r.draw(); const input = r.input(), old = find(r.dom, 'OK');
|
|
189
|
+
r.type(' Réx '); assert(!r.dom.made.some((node) => node.textContent.includes('Réx')));
|
|
190
|
+
if (enter) input.handlers.keydown({ key: 'Enter', stopPropagation() {}, preventDefault() {} }); else tap(old);
|
|
191
|
+
assert.deepEqual(r.sent, [{ k: 'hub-answer', id: spec.id, n: 1, text: ' Réx ' }]);
|
|
192
|
+
assert.equal(input.value, ''); assert(!r.chrome.textAskOpen()); assert.deepEqual(r.locks, [true, false]); assert.equal(document.activeElement, null);
|
|
193
|
+
noText(r, 'Réx'); tap(old); assert.equal(r.sent.length, 1);
|
|
194
|
+
const count = r.dom.made.length; r.draw(); assert.equal(r.dom.made.length, count); assert(!r.chrome.textAskOpen()); r.chrome.dispose();
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
test('client and server share validation; whitespace, refused characters and oversized raw fields cannot send', () => {
|
|
198
|
+
const r = rig(); r.draw(); const input = r.input(), ok = find(r.dom, 'OK');
|
|
199
|
+
const chars = [...Array.from({ length: 32 }, (_, i) => i), ...Array.from({ length: 33 }, (_, i) => 0x7f + i), 0x061c, 0x200b, 0x200c, 0x200d, 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e, ...Array.from({ length: 10 }, (_, i) => 0x2060 + i), 0xfeff];
|
|
200
|
+
for (const text of ['', ' ', '\u00a0\u2003', ...chars.map((cp) => `R${String.fromCodePoint(cp)}`)]) {
|
|
201
|
+
assert.equal(validPrivateText(text, spec.max), false); r.type(text); assert.equal(ok.disabled, true);
|
|
202
|
+
tap(ok); input.handlers.keydown({ key: 'Enter', stopPropagation() {}, preventDefault() {} });
|
|
203
|
+
assert.deepEqual(r.sent, []); assert(r.chrome.textAskOpen());
|
|
204
|
+
}
|
|
205
|
+
for (const cp of chars) assert(REFUSED_TEXT.test(String.fromCodePoint(cp)));
|
|
206
|
+
r.type('Rex'); assert.equal(ok.disabled, false);
|
|
207
|
+
input.value = 'x'.repeat(1000000); tap(ok); assert.deepEqual(r.sent, [], 'click rechecks even a programmatically changed value');
|
|
208
|
+
r.type('Rex'); tap(ok); assert.equal(r.sent[0].text, 'Rex'); r.chrome.dispose();
|
|
209
|
+
});
|
|
210
|
+
test('phone gesture shield covers the canvas while open and disappears on close', () => {
|
|
211
|
+
const r = rig(); r.draw(); const shield = r.input().parent.parent;
|
|
212
|
+
assert.equal(shield.style.inset, '0'); assert.equal(shield.style.pointerEvents, 'auto'); assert.equal(shield.style.touchAction, 'none');
|
|
213
|
+
for (const type of ['pointerdown', 'pointermove', 'pointerup', 'wheel']) {
|
|
214
|
+
const event = { target: shield, stopped: false, prevented: false, stopPropagation() { this.stopped = true; }, preventDefault() { this.prevented = true; } };
|
|
215
|
+
shield.handlers[type](event); assert(event.stopped); assert(event.prevented);
|
|
216
|
+
}
|
|
217
|
+
tap(find(r.dom, 'Cancel')); assert(!shield.parent.children.includes(shield)); assert.deepEqual(shield.handlers, {}); r.chrome.dispose();
|
|
218
|
+
});
|
|
219
|
+
test('Cancel sends null; null, newer n, travel and disposal wipe field and release lock', () => {
|
|
220
|
+
const r = rig(); r.draw(); r.type('SecretRex'); const input = r.input(); tap(find(r.dom, 'Cancel'));
|
|
221
|
+
assert.deepEqual(r.sent, [{ k: 'hub-answer', id: spec.id, n: 1, text: null }]); noText(r, 'SecretRex'); assert.equal(input.value, '');
|
|
222
|
+
r.draw({ ...spec, n: 2 }); r.type('HiddenName'); const old = r.input();
|
|
223
|
+
r.draw({ ...spec, n: 3 }); assert.equal(old.value, ''); noText(r, 'HiddenName'); assert(r.chrome.textAskOpen());
|
|
224
|
+
r.type('HiddenName'); r.draw({ id: null, n: 4 }); noText(r, 'HiddenName'); assert(!r.chrome.textAskOpen());
|
|
225
|
+
r.draw({ ...spec, n: 3 }); assert(!r.chrome.textAskOpen());
|
|
226
|
+
r.draw({ ...spec, n: 5 }); r.type('HiddenName'); r.chrome.clearTextAsk(); noText(r, 'HiddenName'); assert(!r.chrome.textAskOpen());
|
|
227
|
+
r.draw(); r.type('HiddenName'); r.chrome.dispose(); noText(r, 'HiddenName'); assert.deepEqual(r.locks, [true, false, true, false, true, false, true, false, true, false]);
|
|
228
|
+
});
|
|
229
|
+
test('IME composition stays intact until committed, Enter while composing does not send', () => {
|
|
230
|
+
const r = rig(); r.draw({ ...spec, max: 1 }); const input = r.input();
|
|
231
|
+
input.handlers.compositionstart(); r.type('かな'); assert.equal(input.value, 'かな');
|
|
232
|
+
input.handlers.keydown({ key: 'Enter', isComposing: true, stopPropagation() {}, preventDefault() {} }); assert.deepEqual(r.sent, []);
|
|
233
|
+
input.handlers.compositionend(); assert.equal(input.value, 'か');
|
|
234
|
+
let prevented = false;
|
|
235
|
+
input.handlers.keydown({ key: 'Enter', keyCode: 229, isComposing: false, stopPropagation() {}, preventDefault() { prevented = true; } });
|
|
236
|
+
assert.deepEqual(r.sent, []); assert.equal(prevented, false); assert(r.chrome.textAskOpen());
|
|
237
|
+
input.handlers.keydown({ key: 'Enter', keyCode: 13, isComposing: false, stopPropagation() {}, preventDefault() { prevented = true; } });
|
|
238
|
+
assert(prevented); assert.equal(r.sent[0].text, 'か'); r.chrome.dispose();
|
|
239
|
+
});
|
|
240
|
+
function systemRig() {
|
|
241
|
+
State.clear(); Ballot.forget(); const dom = fakeDom({ viewW: 360, viewH: 780 });
|
|
242
|
+
let system; installSystem({ registerSystem(value) { system = value; } });
|
|
243
|
+
const calls = [], sent = [];
|
|
244
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
245
|
+
system.chrome = new Proxy(chrome, { get(target, name) {
|
|
246
|
+
if (['setTextAsk', 'clearTextAsk'].includes(name)) return (...args) => { calls.push([name, ...args]); return target[name](...args); };
|
|
247
|
+
return target[name];
|
|
248
|
+
} });
|
|
249
|
+
system.talk = { frame() {}, talking: () => false, typing: () => false, talkingWith: () => null };
|
|
250
|
+
system.idle = { frame() {}, draw() {}, labels: () => [] }; system.grab = { frame() {} }; system.sound = { frame() {} }; system.sayHooked = true;
|
|
251
|
+
system.together.frame = () => {};
|
|
252
|
+
for (const method of ['keepResident', 'wearAvatar', 'applyTune', 'watchSession', 'sayHello', 'followPlace', 'holdFall', 'turnSpinners', 'applySpawns', 'applyTints', 'registerInterest', 'applyVisibility', 'applyWear', 'adoptLate', 'runCommands', 'askFriends', 'stepEnd', 'faceArrival', 'measure', 'drawChrome']) system[method] = () => {};
|
|
253
|
+
system.sceneKey = 'main'; let locks = 0;
|
|
254
|
+
const scene = { sceneKey: 'main', currentScenePath: 'scenes/main.scene', multiplayer: { net: { selfId: () => 'p1', send: (msg) => sent.push(msg) } }, actorWith: () => null, persistent: { hubTickets: [], hubAvatar: 0 }, getActors: () => [], moveInput: { active: true, x: 1, y: 1 }, keys: { clear() {} }, cameraControl: 'orbit', lookInput: { lock() { locks += 1; } } };
|
|
255
|
+
return { system, scene, dom, sent, calls, chrome, locks: () => locks, frame: () => system.afterBehaviors(scene, 0.05) };
|
|
256
|
+
}
|
|
257
|
+
test('frame opt-in only and locks released on submit, null, rehello, leave, identity clear and teardown', () => {
|
|
258
|
+
const r = systemRig(); r.frame(); assert.deepEqual(r.calls, []); assert.equal(r.scene.moveInput.active, true); assert.equal(r.locks(), 0);
|
|
259
|
+
hook.state({}, { hubPlace: { id: 'main', ask: true } }); hook.message({}, { k: 'hub-ask', ...spec }); r.frame();
|
|
260
|
+
assert.equal(r.scene.moveInput.active, false); assert(r.locks() > 0); assert.equal(r.scene.moveInput.x, 0); assert(Object.hasOwn(r.system, 'askInput'));
|
|
261
|
+
const input = r.dom.made.findLast((node) => node.tag === 'input' && node.type === 'text'); input.value = 'SecretRex'; input.handlers.input(); tap(find(r.dom, 'OK'));
|
|
262
|
+
assert.equal(r.scene.moveInput.active, true); assert(!Object.hasOwn(r.system, 'askInput')); assert.equal(input.value, ''); assert.equal(r.sent[0].text, 'SecretRex');
|
|
263
|
+
function open(n) { hook.message({}, { k: 'hub-ask', ...spec, n }); r.frame(); assert.equal(r.scene.moveInput.active, false); }
|
|
264
|
+
open(2); hook.message({}, { k: 'hub-ask', id: null, n: 3 }); r.frame(); assert.equal(r.scene.moveInput.active, true);
|
|
265
|
+
open(4); r.system.sendHello(r.scene, r.scene.multiplayer, r.scene.multiplayer.net, 0, { resume: true }); assert.equal(r.scene.moveInput.active, true); assert(!Object.hasOwn(State.hub, 'ask'));
|
|
266
|
+
open(4); State.clear(); assert.equal(r.scene.moveInput.active, true);
|
|
267
|
+
hook.state({}, { hubPlace: { id: 'main', ask: true } }); open(5); hook.state({}, { hubPlace: { id: 'plain' } }); assert.equal(r.scene.moveInput.active, true); r.frame();
|
|
268
|
+
const count = r.calls.length; r.frame(); assert.equal(r.calls.length, count, 'keyless frame has no extra chrome calls');
|
|
269
|
+
hook.state({}, { hubPlace: { id: 'main', ask: true } }); open(6); r.system.reset(); assert.equal(r.scene.moveInput.active, true); assert(!r.chrome.textAskOpen());
|
|
270
|
+
open(7); r.chrome.dispose(); assert.equal(r.scene.moveInput.active, true); assert(!Object.hasOwn(r.system, 'askInput')); State.clear();
|
|
271
|
+
});
|
|
272
|
+
test('input is cleared before the player update, including capped presses, jumps, orbit and captured drags; method restored', () => {
|
|
273
|
+
const add = globalThis.addEventListener, remove = globalThis.removeEventListener, listeners = [];
|
|
274
|
+
globalThis.addEventListener = (type, fn, options) => {
|
|
275
|
+
const entry = { type, fn, options }; listeners.push(entry);
|
|
276
|
+
options?.signal?.addEventListener('abort', () => { const at = listeners.indexOf(entry); if (at >= 0) listeners.splice(at, 1); }, { once: true });
|
|
277
|
+
};
|
|
278
|
+
globalThis.removeEventListener = (type, fn) => { const at = listeners.findIndex((entry) => entry.type === type && entry.fn === fn); if (at >= 0) listeners.splice(at, 1); };
|
|
279
|
+
try {
|
|
280
|
+
for (const inherited of [false, true]) {
|
|
281
|
+
const r = systemRig(), reads = [], player = { runtime: { jumpBuffer: 1 } };
|
|
282
|
+
r.scene.keys = new Set(['KeyW']); r.scene.actorWith = () => player;
|
|
283
|
+
let jump = true, look = { yaw: 1, locked: false }, cancelled = 0;
|
|
284
|
+
r.scene.moveInput.consumeJump = () => { const had = jump; jump = false; return had; };
|
|
285
|
+
r.scene.lookInput = { cancel() { cancelled++; }, lock() { look = { yaw: 0, locked: true }; }, consume() { const had = look; look = { yaw: 0, locked: false }; return had; } };
|
|
286
|
+
const update = function () { reads.push({ keys: [...this.keys], stick: this.moveInput.active, x: this.moveInput.x, jump: this.moveInput.consumeJump(), buffer: player.runtime.jumpBuffer, look: this.lookInput.consume() }); };
|
|
287
|
+
if (inherited) Object.setPrototypeOf(r.scene, { update }); else r.scene.update = update;
|
|
288
|
+
hook.state({}, { hubPlace: { id: 'main', ask: true } }); hook.message({}, { k: 'hub-ask', ...spec }); r.frame();
|
|
289
|
+
assert.notEqual(r.scene.update, update); assert.equal(cancelled, 1);
|
|
290
|
+
// Simulate presses/gesture input lent by a capped frame after the card opened.
|
|
291
|
+
r.scene.keys.add('KeyW'); r.scene.moveInput.active = true; r.scene.moveInput.x = 1; jump = true; player.runtime.jumpBuffer = 1; look = { yaw: 1, locked: false };
|
|
292
|
+
r.scene.update();
|
|
293
|
+
assert.deepEqual(reads, [{ keys: [], stick: false, x: 0, jump: false, buffer: 0, look: { yaw: 0, locked: true } }]);
|
|
294
|
+
for (const type of ['pointerdown', 'pointermove', 'wheel']) {
|
|
295
|
+
const entry = listeners.find((entry) => entry.type === type && entry.options?.capture);
|
|
296
|
+
assert(entry); const event = { target: { tagName: 'CANVAS' }, stopped: false, prevented: false, stopImmediatePropagation() { this.stopped = true; }, preventDefault() { this.prevented = true; } };
|
|
297
|
+
entry.fn(event); assert(event.stopped); assert(event.prevented);
|
|
298
|
+
}
|
|
299
|
+
tap(find(r.dom, 'Cancel')); assert.equal(r.scene.update, update); assert.equal(Object.hasOwn(r.scene, 'update'), !inherited);
|
|
300
|
+
assert(!listeners.some((entry) => entry.options?.capture)); r.chrome.dispose(); State.clear();
|
|
301
|
+
}
|
|
302
|
+
} finally { globalThis.addEventListener = add; globalThis.removeEventListener = remove; }
|
|
303
|
+
});
|
|
304
|
+
test('ballot holds a pending prompt without taking focus; incoming card cancels open prompt once; latest pending version wins', () => {
|
|
305
|
+
const r = systemRig(), focus = document.createElement('button'); focus.focus();
|
|
306
|
+
hook.state({}, { hubPlace: { id: 'main', ask: true, ballot: { lines: [] } } });
|
|
307
|
+
const card = { v: 'v1', mode: 'vote', faces: [], lines: [], who: {}, options: [] };
|
|
308
|
+
r.system.ballot = { frame() {}, dispose() {} };
|
|
309
|
+
hook.message(r.scene, { k: 'hub-ballot-card', card }); hook.message({}, { k: 'hub-ask', ...spec }); r.frame();
|
|
310
|
+
assert(!r.chrome.textAskOpen()); assert.equal(document.activeElement, focus); assert.deepEqual(r.sent, []);
|
|
311
|
+
hook.message({}, { k: 'hub-ask', ...spec, n: 2 }); r.frame(); assert(!r.chrome.textAskOpen()); assert.equal(document.activeElement, focus);
|
|
312
|
+
hook.message(r.scene, { k: 'hub-ballot-card', card: null }); r.frame(); assert(r.chrome.textAskOpen());
|
|
313
|
+
const input = r.dom.made.findLast((node) => node.tag === 'input' && node.type === 'text'); input.value = 'SecretRex'; input.handlers.input();
|
|
314
|
+
hook.message(r.scene, { k: 'hub-ballot-card', card }); r.frame(); r.frame();
|
|
315
|
+
assert.deepEqual(r.sent, [{ k: 'hub-answer', id: spec.id, n: 2, text: null }]); assert.equal(input.value, ''); assert(!r.chrome.textAskOpen());
|
|
316
|
+
hook.message(r.scene, { k: 'hub-ballot-card', card: null }); r.frame(); assert(!r.chrome.textAskOpen(), 'cancelled n stays closed');
|
|
317
|
+
hook.message(r.scene, { k: 'hub-ballot-card', card }); hook.message({}, { k: 'hub-ask', ...spec, n: 3 }); r.frame();
|
|
318
|
+
hook.message({}, { k: 'hub-ask', id: null, n: 4 }); hook.message(r.scene, { k: 'hub-ballot-card', card: null }); r.frame(); assert(!r.chrome.textAskOpen(), 'a close replaces the pending prompt');
|
|
319
|
+
r.chrome.dispose(); State.clear(); Ballot.forget();
|
|
320
|
+
});
|
|
321
|
+
test('v1.76: the message dispatcher queues id-only NPC hooks for the talk controller', () => {
|
|
322
|
+
State.clear();
|
|
323
|
+
const msg = { k: 'hub-npc-hooks', hooks: [{ npc: 'greeter', character: 'greeter' }] };
|
|
324
|
+
hook.message({}, msg);
|
|
325
|
+
assert.deepEqual(State.hub.npcEvents, [msg]);
|
|
326
|
+
State.clear();
|
|
327
|
+
});
|
|
328
|
+
test('NPC conversation holds pending prompt without focus stealing, closes an open prompt as cancel before opening, then latest prompt resumes', () => {
|
|
329
|
+
const r = systemRig(), media = globalThis.matchMedia;
|
|
330
|
+
globalThis.matchMedia = () => ({ matches: true });
|
|
331
|
+
try {
|
|
332
|
+
r.system.talk = makeTalk(r.chrome); r.frame();
|
|
333
|
+
hook.state({}, { hubPlace: { id: 'main', ask: true } });
|
|
334
|
+
hook.message(r.scene, { k: 'hub-npc', npc: 'npc', name: 'NPC', open: true, mind: false }); r.frame();
|
|
335
|
+
const npcInput = document.activeElement; assert(npcInput); assert(r.system.talk.talking());
|
|
336
|
+
hook.message({}, { k: 'hub-ask', ...spec }); r.frame(); assert(!r.chrome.textAskOpen()); assert.equal(document.activeElement, npcInput); assert.deepEqual(r.sent, []);
|
|
337
|
+
hook.message({}, { k: 'hub-ask', ...spec, n: 2 }); r.frame(); assert.equal(document.activeElement, npcInput);
|
|
338
|
+
hook.message(r.scene, { k: 'hub-npc', npc: 'npc', open: false }); r.frame(); assert(r.chrome.textAskOpen());
|
|
339
|
+
const input = document.activeElement; input.value = 'SecretRex'; input.handlers.input();
|
|
340
|
+
hook.message(r.scene, { k: 'hub-npc', npc: 'npc', name: 'NPC', open: true, mind: false }); r.frame();
|
|
341
|
+
assert.equal(document.activeElement, npcInput); assert.equal(input.value, ''); assert(!r.chrome.textAskOpen());
|
|
342
|
+
r.frame(); assert.deepEqual(r.sent, [{ k: 'hub-answer', id: spec.id, n: 2, text: null }]);
|
|
343
|
+
hook.message({}, { k: 'hub-ask', ...spec, n: 3 }); r.frame(); assert.equal(document.activeElement, npcInput);
|
|
344
|
+
hook.message(r.scene, { k: 'hub-npc', npc: 'npc', open: false }); r.frame(); assert(r.chrome.textAskOpen());
|
|
345
|
+
r.chrome.dispose(); State.clear();
|
|
346
|
+
} finally { globalThis.matchMedia = media; }
|
|
347
|
+
});
|
|
348
|
+
test('keyless state/frame/DOM/message trace stays identical with a refused prompt', () => {
|
|
349
|
+
function trace(inject) {
|
|
350
|
+
const r = systemRig(); hook.state({}, { hubPlace: { id: 'plain' } }); const at = r.dom.log.length;
|
|
351
|
+
if (inject) hook.message({}, { k: 'hub-ask', ...spec });
|
|
352
|
+
for (let i = 0; i < 3; i++) r.frame();
|
|
353
|
+
assert(!Object.hasOwn(State.hub, 'ask')); assert(!Object.hasOwn(State.hub, 'askClose')); assert(!Object.hasOwn(r.system, 'askInput')); assert(!Object.hasOwn(r.system, 'askDrawn'));
|
|
354
|
+
const trace = JSON.stringify([r.dom.log.slice(at), r.calls, r.sent]); r.chrome.dispose(); State.clear(); return trace;
|
|
355
|
+
}
|
|
356
|
+
assert.equal(trace(true), trace(false));
|
|
357
|
+
});
|
|
358
|
+
console.log(`${passed} ask client tests passed`);
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// v1.75 private prompts: real hub hooks, exact wire, privacy and eligibility.
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { register } from 'node:module';
|
|
7
|
+
|
|
8
|
+
register(`data:text/javascript,${encodeURIComponent(`
|
|
9
|
+
export async function resolve(specifier, context, next) {
|
|
10
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: 'data:text/javascript,export const readScene = () => globalThis.__hubTestActors;', shortCircuit: true };
|
|
11
|
+
if (context.parentURL?.includes('/kits/base/sdk/') && specifier.startsWith('.') && !specifier.endsWith('.js')) return next(specifier + '.js', context);
|
|
12
|
+
return next(specifier, context);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
`)}`);
|
|
16
|
+
const { layer } = await import('../code/server/hub.js');
|
|
17
|
+
const Manifest = await import('../code/server/manifest.js');
|
|
18
|
+
const check = (await import('./check.mjs')).default;
|
|
19
|
+
const actors = [
|
|
20
|
+
{ id: 'player', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
21
|
+
{ id: 'floor', components: { Transform: { x: 0, y: 0, z: 0 } } },
|
|
22
|
+
];
|
|
23
|
+
const players = [
|
|
24
|
+
{ playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false },
|
|
25
|
+
{ playerId: 'p2', userId: '102', username: 'Bo', isAnonymous: false },
|
|
26
|
+
];
|
|
27
|
+
const json = (keys = {}) => ({ server: { maxPlayers: 8 }, hub: { contract: 1, title: 'House', ...keys } });
|
|
28
|
+
function boot(keys = {}, options = {}) {
|
|
29
|
+
const sent = [], ops = [], arrivals = [];
|
|
30
|
+
let hub;
|
|
31
|
+
const hooks = { ready(ctx) { hub = ctx; }, arrive(ctx, group) { arrivals.push([ctx.owner ?? null, group.map((p) => p.playerId)]); }, answer(ctx, id, askId, text) { ops.push([id, askId, text]); }, ...(options.hooks ?? {}) };
|
|
32
|
+
const bodies = [];
|
|
33
|
+
const engine = {
|
|
34
|
+
createBody(sim, actor, at) {
|
|
35
|
+
const rb = { at: { ...at }, setEnabled() {}, setNextKinematicTranslation(at) { this.at = { ...at }; }, setNextKinematicRotation() {} };
|
|
36
|
+
bodies.push([actor.id, rb]);
|
|
37
|
+
return rb;
|
|
38
|
+
},
|
|
39
|
+
removeActor(sim, id) { sim.bodies.delete(id); sim.objects.delete(id); },
|
|
40
|
+
};
|
|
41
|
+
globalThis.__hubTestActors = structuredClone(actors);
|
|
42
|
+
const server = layer(json(keys), hooks, {}, () => true, () => null, null, engine);
|
|
43
|
+
const session = { sessionId: options.sessionId ?? 'dev', players: [...players], hub: options.platform ?? null, send(id, msg) { sent.push([id, structuredClone(msg)]); }, broadcast(msg) { sent.push(['all', structuredClone(msg)]); } };
|
|
44
|
+
const world = { timeMs: 0, scenePath: 'scenes/main.scene', objects: new Map(), bodies: new Map(), players: new Map(players.map((p) => [p.playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } }])) };
|
|
45
|
+
server.sceneFor(session);
|
|
46
|
+
server.ready(world);
|
|
47
|
+
const say = (id, data) => server.message(session, { playerId: id }, data);
|
|
48
|
+
if (options.hello !== false) {
|
|
49
|
+
for (const id of options.order ?? ['p1', 'p2']) {
|
|
50
|
+
say(id, { k: 'hub-hello', avatar: 0, party: 2 });
|
|
51
|
+
}
|
|
52
|
+
server.place(world);
|
|
53
|
+
}
|
|
54
|
+
const tick = (ms = 50) => { world.timeMs += ms; server.place(world); server.step(world, []); };
|
|
55
|
+
return { server, session, world, hub, sent, ops, say, tick, bodies, arrivals, hooks };
|
|
56
|
+
}
|
|
57
|
+
const Ask = await import('../code/server/ask.js');
|
|
58
|
+
const spec = { id: 'pet-name', title: 'Only you will see this name', max: 16 };
|
|
59
|
+
const wire = (r) => r.sent.filter(([, msg]) => msg.k === 'hub-ask');
|
|
60
|
+
const offer = (r, playerId = 'p1') => wire(r).findLast(([id]) => id === playerId)?.[1];
|
|
61
|
+
const answer = (r, text = 'Rex', playerId = 'p1', prompt = offer(r, playerId)) => r.say(playerId, { k: 'hub-answer', id: prompt?.id, n: prompt?.n, text });
|
|
62
|
+
let passed = 0;
|
|
63
|
+
async function test(name, fn) { await fn(); passed += 1; console.log(`ok: ${name}`); }
|
|
64
|
+
|
|
65
|
+
await test('manifest: main and named places accept only true or an absent key', async () => {
|
|
66
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hub-ask-'));
|
|
67
|
+
try {
|
|
68
|
+
fs.mkdirSync(path.join(dir, 'scenes'));
|
|
69
|
+
fs.writeFileSync(path.join(dir, 'scenes/main.scene'), JSON.stringify({ actors }));
|
|
70
|
+
for (const named of [false, true]) {
|
|
71
|
+
for (const value of [true, false, null, 0, 1, '', 'true', [], {}, undefined]) {
|
|
72
|
+
const keys = named ? { places: { porch: { title: 'Porch', scene: 'scenes/main.scene', ask: value } } } : { ask: value };
|
|
73
|
+
const read = Manifest.readManifest(json(keys));
|
|
74
|
+
assert.equal(read.errors.some((e) => e.includes('.ask')), value !== true);
|
|
75
|
+
fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify({ ...json(keys), server: { main: 'code/server/index.js', maxPlayers: 8 } }));
|
|
76
|
+
const published = await check({ deckDir: dir, self: true });
|
|
77
|
+
assert.equal(published.errors.some((e) => e.includes('.ask')), value !== true && value !== undefined);
|
|
78
|
+
if (value === true) assert.equal(read.manifest.places[named ? 'porch' : 'main'].ask, true);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const plain = Manifest.readManifest(json()).manifest.places.main;
|
|
82
|
+
assert(!Object.hasOwn(plain, 'ask')); assert(!Object.hasOwn(Manifest.publicPlace('main', plain), 'ask'));
|
|
83
|
+
} finally { fs.rmSync(dir, { recursive: true }); }
|
|
84
|
+
});
|
|
85
|
+
await test('atomic validation, own keys, copied single reads and Unicode code points', () => {
|
|
86
|
+
const r = boot({ ask: true });
|
|
87
|
+
r.hub.ask('p1', spec); r.tick(250); const before = offer(r);
|
|
88
|
+
const invalid = [undefined, false, [], 'x', {}, { ...spec, id: 'A' }, { ...spec, id: 'pet-name\n' }, { ...spec, id: 'a'.repeat(25) }, { ...spec, title: '' }, { ...spec, title: ' ' }, { ...spec, title: '😀'.repeat(33) }, ...[0, 33, 1.5, '16', NaN, Infinity].map((max) => ({ ...spec, max })), { ...spec, extra: 1 }, { ...spec, [Symbol('extra')]: 1 }, Object.create(spec), new Date()];
|
|
89
|
+
invalid.push(Object.defineProperty({ ...spec }, 'hidden', { value: 1 }));
|
|
90
|
+
for (const cp of [...Array.from({ length: 32 }, (_, i) => i), ...Array.from({ length: 33 }, (_, i) => 0x7f + i), 0x061c, 0x200b, 0x200c, 0x200d, 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e, ...Array.from({ length: 10 }, (_, i) => 0x2060 + i), 0xfeff]) invalid.push({ ...spec, title: `a${String.fromCodePoint(cp)}b` });
|
|
91
|
+
for (const bad of invalid) assert.throws(() => r.hub.ask('p1', bad), TypeError);
|
|
92
|
+
assert.throws(() => r.hub.ask(null, spec), TypeError); r.tick(250); assert.deepEqual(offer(r), before);
|
|
93
|
+
const reads = { id: 0, title: 0, max: 0 }, getters = {};
|
|
94
|
+
for (const key of Object.keys(reads)) Object.defineProperty(getters, key, { get() { reads[key] += 1; return reads[key] === 1 ? spec[key] : null; } });
|
|
95
|
+
r.hub.ask('p2', getters); r.tick(250); assert.deepEqual(reads, { id: 1, title: 1, max: 1 });
|
|
96
|
+
const copy = { ...spec, title: '😀'.repeat(32), max: 32 };
|
|
97
|
+
r.hub.ask('p1', copy); copy.title = 'mutated'; r.tick(250); assert.equal(offer(r).title, '😀'.repeat(32));
|
|
98
|
+
assert.equal(r.hub.ask('p1', Object.assign(Object.create(null), { ...spec, title: '😀'.repeat(32), max: 32 })), true);
|
|
99
|
+
assert.equal(r.hub.ask('unknown', spec), false);
|
|
100
|
+
assert.throws(() => r.hub.ask('unknown', {}), TypeError);
|
|
101
|
+
});
|
|
102
|
+
await test('not-arrived, disconnected and place-only API; arrive may already ask', () => {
|
|
103
|
+
const r = boot({ ask: true }, { hello: false });
|
|
104
|
+
assert.equal(r.hub.ask('p1', spec), false); answer(r); assert.deepEqual(r.ops, []);
|
|
105
|
+
let ok; boot({ ask: true }, { hooks: { arrive(ctx, group) { ok = ctx.ask(group[0].playerId, spec); } } }); assert.equal(ok, true);
|
|
106
|
+
const named = boot({ ask: true, places: { porch: { title: 'Porch', scene: 'scenes/porch.scene' } } });
|
|
107
|
+
const captured = named.hub.ask; named.session.place = 'porch'; named.server.sceneFor(named.session);
|
|
108
|
+
assert.equal(named.hub.ask, undefined); assert.throws(() => captured('p1', spec), TypeError);
|
|
109
|
+
r.session.players = []; assert.equal(r.hub.ask('p1', spec), false);
|
|
110
|
+
});
|
|
111
|
+
await test('coalesced private offers, same-spec suppression, session versions and safe overflow', () => {
|
|
112
|
+
const r = boot({ ask: true }); r.sent.length = 0;
|
|
113
|
+
for (let i = 0; i < 10000; i++) r.hub.ask('p1', { ...spec, title: String(i) });
|
|
114
|
+
assert.deepEqual(wire(r), []); r.tick(250);
|
|
115
|
+
assert.deepEqual(wire(r), [['p1', { k: 'hub-ask', ...spec, title: '9999', n: 10000 }]]);
|
|
116
|
+
r.hub.ask('p1', { ...spec, title: '9999' }); r.tick(250); assert.equal(wire(r).length, 1);
|
|
117
|
+
const old = offer(r);
|
|
118
|
+
r.hub.ask('p1', spec); r.hub.ask('p1', { ...spec, title: '9999' }); r.tick(250); assert.equal(wire(r).length, 2, 'equal content with advanced n is delivered');
|
|
119
|
+
assert.equal(offer(r).n, 10002); answer(r, 'Rex', 'p1', old); assert.deepEqual(r.ops, [], 'changed-back prompt still invalidates old answer');
|
|
120
|
+
r.say('p1', { k: 'hub-hello', resume: true }); assert.equal(offer(r).n, 10002);
|
|
121
|
+
r.hub.ask('p2', spec); r.tick(250); assert.equal(offer(r, 'p2').n, 10003);
|
|
122
|
+
const times = []; const send = r.session.send;
|
|
123
|
+
r.session.send = (id, msg) => { if (msg.k === 'hub-ask') times.push(r.world.timeMs); send(id, msg); };
|
|
124
|
+
for (let i = 0; i < 100; i++) { r.hub.ask('p1', { ...spec, title: String(i) }); r.tick(10); }
|
|
125
|
+
assert.equal(times.length, 4); assert(times.slice(1).every((at, i) => at - times[i] >= 250));
|
|
126
|
+
const h = { place: { ask: true }, session: { players: [{ playerId: 'p' }] }, sim: { players: new Map([['p', {}]]) }, players: new Map([['p', { arrived: true }]]), askSeq: Number.MAX_SAFE_INTEGER };
|
|
127
|
+
assert.throws(() => Ask.set(h, 'p', spec), TypeError); assert(!Object.hasOwn(h, 'askMe'));
|
|
128
|
+
});
|
|
129
|
+
await test('accept once, exact unnormalised text, consume before hook and coalesce close; no text in wire/state', () => {
|
|
130
|
+
let consumed;
|
|
131
|
+
const r = boot({ ask: true }, { hooks: { answer(ctx, id, promptId, text) { r.ops.push([id, promptId, text]); answer(r, text); consumed = r.ops.length === 1; } } });
|
|
132
|
+
r.hub.ask('p1', spec); r.tick(250); const prompt = offer(r), text = ' Réx ';
|
|
133
|
+
answer(r, text); answer(r, text, 'p1', prompt);
|
|
134
|
+
assert(consumed); assert.deepEqual(r.ops, [['p1', spec.id, text]]);
|
|
135
|
+
assert.deepEqual(offer(r), prompt, 'close waits for ordinary delivery budget');
|
|
136
|
+
r.tick(250); assert.deepEqual(offer(r), { k: 'hub-ask', id: null, n: prompt.n + 1 });
|
|
137
|
+
assert(!JSON.stringify([r.sent, r.server.join(), r.server.delta()]).includes(text));
|
|
138
|
+
r.tick(500); r.hub.ask('p1', spec); r.tick(250); answer(r, null);
|
|
139
|
+
assert.deepEqual(r.ops.at(-1), ['p1', spec.id, null]);
|
|
140
|
+
});
|
|
141
|
+
await test('accepted answer closes share the four/s tick delivery budget', () => {
|
|
142
|
+
const r = boot({ ask: true }); r.sent.length = 0;
|
|
143
|
+
for (let i = 0; i < 4; i++) {
|
|
144
|
+
r.hub.ask('p1', spec); r.tick(250); const count = wire(r).length;
|
|
145
|
+
answer(r); assert.equal(wire(r).length, count, 'no immediate over-budget close');
|
|
146
|
+
r.tick(249); assert.equal(wire(r).length, count);
|
|
147
|
+
r.tick(1); assert.equal(wire(r).length, count + 1); assert.equal(offer(r).id, null);
|
|
148
|
+
}
|
|
149
|
+
assert.equal(r.ops.length, 4);
|
|
150
|
+
});
|
|
151
|
+
await test('unsent, changed, closed and another player answers are dropped', () => {
|
|
152
|
+
const r = boot({ ask: true }); r.hub.ask('p1', spec);
|
|
153
|
+
answer(r, 'Rex', 'p1', { id: spec.id, n: 1 }); assert.deepEqual(r.ops, []);
|
|
154
|
+
r.tick(250); const old = offer(r); answer(r, 'Rex', 'p2', old); assert.deepEqual(r.ops, []);
|
|
155
|
+
r.hub.ask('p1', { ...spec, title: 'New title' });
|
|
156
|
+
answer(r, 'Rex', 'p1', old); answer(r, 'Rex', 'p1', { ...old, n: old.n + 1 }); assert.deepEqual(r.ops, []);
|
|
157
|
+
r.tick(2000); r.tick(250); answer(r); assert.equal(r.ops.length, 1);
|
|
158
|
+
r.tick(2000); r.hub.ask('p1', spec); r.tick(250); const closing = offer(r); r.hub.ask('p1', null); answer(r, 'Rex', 'p1', closing); assert.equal(r.ops.length, 1);
|
|
159
|
+
});
|
|
160
|
+
await test('refused text on the current prompt consumes as cancel, never passes text or echoes it', () => {
|
|
161
|
+
const r = boot({ ask: true });
|
|
162
|
+
const bad = ['', ' ', 'x'.repeat(65), 'x'.repeat(17), '😀'.repeat(17), 'R\nex', 'R\u061cex', 'R\u200bex', 'R\u200cex', 'R\u200dex', 'R\u202eex', 'R\u2068ex', 'R\ufeffex', 7, {}, []];
|
|
163
|
+
for (const text of bad) {
|
|
164
|
+
r.hub.ask('p1', spec); r.tick(500); const prompt = offer(r), before = r.ops.length;
|
|
165
|
+
answer(r, text); assert.deepEqual(r.ops.at(-1), ['p1', spec.id, null]); assert.equal(r.ops.length, before + 1);
|
|
166
|
+
answer(r, 'Duplicate', 'p1', prompt); assert.equal(r.ops.length, before + 1);
|
|
167
|
+
r.tick(250); assert.deepEqual(offer(r), { k: 'hub-ask', id: null, n: prompt.n + 1 });
|
|
168
|
+
}
|
|
169
|
+
assert(r.ops.every(([, , text]) => text === null));
|
|
170
|
+
assert(!JSON.stringify([r.sent, r.server.join(), r.server.delta()]).includes('R\u061cex'));
|
|
171
|
+
});
|
|
172
|
+
await test('malformed and stale envelopes drop, spend tokens and leave the prompt unchanged', () => {
|
|
173
|
+
const r = boot({ ask: true }); r.hub.ask('p1', spec); r.tick(250);
|
|
174
|
+
for (const n of [undefined, null, true, '1', 1.5, NaN, Infinity, Number.MAX_SAFE_INTEGER + 1]) { r.tick(500); answer(r, 'Rex', 'p1', { ...offer(r), n }); }
|
|
175
|
+
r.tick(2000);
|
|
176
|
+
for (const extra of [{ extra: 1 }, { [Symbol('extra')]: 1 }]) r.say('p1', { k: 'hub-answer', id: spec.id, n: offer(r).n, text: 'Rex', ...extra });
|
|
177
|
+
r.say('p1', { k: 'hub-answer', id: spec.id, n: offer(r).n });
|
|
178
|
+
answer(r, 'x'.repeat(1000000), 'p1', { ...offer(r), n: -1 });
|
|
179
|
+
answer(r); assert.deepEqual(r.ops, [], 'four invalid attempts exhaust burst');
|
|
180
|
+
r.tick(499); answer(r); assert.deepEqual(r.ops, []); r.tick(1); answer(r); assert.equal(r.ops.length, 1);
|
|
181
|
+
const h = { place: { ask: true }, session: { players: [{ playerId: 'p' }], send() {} }, sim: { timeMs: 0, players: new Map([['p', {}]]) }, players: new Map([['p', { arrived: true }]]), ctx: {}, hooks: {} };
|
|
182
|
+
Ask.set(h, 'p', spec); Ask.prune(h); Ask.message(h, 'p', { k: 'hub-answer', id: spec.id, n: 1, text: 'SecretRex' });
|
|
183
|
+
assert(!JSON.stringify(h).includes('SecretRex')); assert(!JSON.stringify([...h.askMe.values()]).includes('SecretRex'));
|
|
184
|
+
});
|
|
185
|
+
await test('answer/cancel then immediate reopening of the same spec delivers its new version', () => {
|
|
186
|
+
for (const text of ['Rex', null]) {
|
|
187
|
+
const r = boot({ ask: true }, { hooks: { answer(ctx, playerId, promptId, text) { r.ops.push([playerId, promptId, text]); ctx.ask(playerId, spec); } } });
|
|
188
|
+
r.hub.ask('p1', spec); r.tick(250); const old = offer(r), count = wire(r).length;
|
|
189
|
+
answer(r, text); assert.equal(wire(r).length, count); r.tick(250);
|
|
190
|
+
assert.deepEqual(offer(r), { k: 'hub-ask', ...spec, n: old.n + 2 });
|
|
191
|
+
answer(r, 'Old', 'p1', old); assert.equal(r.ops.length, 1);
|
|
192
|
+
answer(r, 'Fresh'); assert.equal(r.ops.length, 2); assert.equal(r.ops.at(-1)[2], 'Fresh');
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
await test('throwing getters/Proxies are silent, contained and spend budget; wide envelopes reject before key arrays or fields', () => {
|
|
196
|
+
const calls = [], h = { place: { ask: true }, session: { players: [{ playerId: 'p' }], send() {} }, sim: { timeMs: 0, players: new Map([['p', {}]]) }, players: new Map([['p', { arrived: true }]]), ctx: {}, hooks: { answer(...args) { calls.push(args); } } };
|
|
197
|
+
Ask.set(h, 'p', spec); Ask.prune(h);
|
|
198
|
+
const wire = { k: 'hub-answer', id: spec.id, n: 1, text: 'SecretRex' }, warn = console.warn, warnings = [];
|
|
199
|
+
console.warn = (...args) => warnings.push(args);
|
|
200
|
+
try {
|
|
201
|
+
const invalid = ['k', 'id', 'n', 'text'].map((key) => Object.defineProperty({ ...wire }, key, { get() { throw new Error('SecretRex'); } }));
|
|
202
|
+
invalid.push(new Proxy(wire, { getPrototypeOf() { throw new Error('SecretRex'); } }), new Proxy(wire, { ownKeys() { throw new Error('SecretRex'); } }), new Proxy(wire, { getOwnPropertyDescriptor() { throw new Error('SecretRex'); } }));
|
|
203
|
+
const revoked = Proxy.revocable(wire, {}); revoked.revoke(); invalid.push(revoked.proxy);
|
|
204
|
+
for (const msg of invalid) { h.sim.timeMs += 500; assert.doesNotThrow(() => Ask.message(h, 'p', msg)); }
|
|
205
|
+
assert.deepEqual(calls, []); assert.deepEqual(warnings, []); assert.equal(h.askMe.get('p').spec.id, spec.id);
|
|
206
|
+
h.sim.timeMs += 2000;
|
|
207
|
+
for (let i = 0; i < 4; i++) Ask.message(h, 'p', invalid[0]); Ask.message(h, 'p', wire); assert.deepEqual(calls, []);
|
|
208
|
+
h.sim.timeMs += 500;
|
|
209
|
+
let reads = 0;
|
|
210
|
+
const wide = { ...wire }; Object.defineProperty(wide, 'k', { enumerable: true, get() { reads++; return 'hub-answer'; } });
|
|
211
|
+
for (let i = 0; i < 10000; i++) wide[`extra${i}`] = true;
|
|
212
|
+
const ownKeys = Reflect.ownKeys; let reflected = false;
|
|
213
|
+
Reflect.ownKeys = (value) => { if (value === wide) reflected = true; return ownKeys(value); };
|
|
214
|
+
try { Ask.message(h, 'p', wide); } finally { Reflect.ownKeys = ownKeys; }
|
|
215
|
+
assert.equal(reads, 0); assert.equal(reflected, false);
|
|
216
|
+
h.sim.timeMs += 500;
|
|
217
|
+
const nonplain = Object.assign(Object.create({ inherited: true }), wire);
|
|
218
|
+
const hostile = new Proxy(nonplain, { ownKeys() { throw new Error('should not enumerate'); } });
|
|
219
|
+
assert.doesNotThrow(() => Ask.message(h, 'p', hostile)); assert.deepEqual(calls, []);
|
|
220
|
+
h.sim.timeMs += 500; Ask.message(h, 'p', wire); assert.equal(calls[0][3], 'SecretRex');
|
|
221
|
+
} finally { console.warn = warn; }
|
|
222
|
+
});
|
|
223
|
+
await test('flooding budget is per player and refills two/s, malformed attempts included', () => {
|
|
224
|
+
const r = boot({ ask: true }); r.hub.ask('p1', spec); r.hub.ask('p2', spec); r.tick(250);
|
|
225
|
+
for (let i = 0; i < 100; i++) r.say('p1', { k: 'hub-answer' });
|
|
226
|
+
answer(r); assert.deepEqual(r.ops, []); answer(r, 'Bo', 'p2'); assert.deepEqual(r.ops, [['p2', spec.id, 'Bo']]);
|
|
227
|
+
r.tick(500); answer(r); assert.equal(r.ops.length, 2);
|
|
228
|
+
});
|
|
229
|
+
await test('throw and rejection contained and logged once without text or error details', async () => {
|
|
230
|
+
const warnings = [], warn = console.warn, secret = 'SecretRex'; console.warn = (...args) => warnings.push(args.join(' '));
|
|
231
|
+
try {
|
|
232
|
+
let calls = 0;
|
|
233
|
+
const r = boot({ ask: true }, { hooks: { answer() { calls += 1; if (calls === 1) throw new Error(secret); return Promise.reject(new Error(secret)); } } });
|
|
234
|
+
for (let i = 0; i < 2; i++) { r.hub.ask('p1', spec); r.tick(500); answer(r, secret); r.tick(250); }
|
|
235
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
236
|
+
assert.equal(calls, 2); assert.deepEqual(warnings, ['[hub] answer hook failed']); assert(!JSON.stringify(r.sent).includes(secret));
|
|
237
|
+
} finally { console.warn = warn; }
|
|
238
|
+
});
|
|
239
|
+
await test('fresh hello replay once, null replay, forget on leave, never reuse session versions', () => {
|
|
240
|
+
const r = boot({ ask: true }); r.hub.ask('p1', spec); r.tick(250); const old = offer(r).n;
|
|
241
|
+
r.sent.length = 0; r.say('p1', { k: 'hub-hello', resume: true }); r.tick(250);
|
|
242
|
+
assert.deepEqual(wire(r), [['p1', { k: 'hub-ask', ...spec, n: old }]]);
|
|
243
|
+
r.sent.length = 0; r.say('p1', { k: 'hub-hello', again: true }); assert.deepEqual(wire(r), []);
|
|
244
|
+
r.hub.ask('p1', null); r.say('p1', { k: 'hub-hello', resume: true }); r.tick(250); assert.deepEqual(offer(r), { k: 'hub-ask', id: null, n: old + 1 });
|
|
245
|
+
r.hub.ask('p1', spec); r.tick(250); const n = offer(r).n, body = r.world.players.get('p1');
|
|
246
|
+
r.session.players = [players[1]]; r.world.players.delete('p1'); r.tick(); assert.equal(r.hub.ask('p1', spec), false);
|
|
247
|
+
r.session.players.push(players[0]); r.world.players.set('p1', body); r.sent.length = 0;
|
|
248
|
+
r.say('p1', { k: 'hub-hello', resume: true }); r.tick(); assert.deepEqual(offer(r), { k: 'hub-ask', id: null, n: 0 });
|
|
249
|
+
r.hub.ask('p1', spec); r.tick(250); assert.equal(offer(r).n, n + 1); answer(r, 'Rex', 'p1', { id: spec.id, n }); assert.deepEqual(r.ops, []);
|
|
250
|
+
});
|
|
251
|
+
await test('absent key: no API, hook lookup, private state, snapshot/delta key or extra wire; traces identical', () => {
|
|
252
|
+
function trace(inject) {
|
|
253
|
+
const r = boot(); Object.defineProperty(r.hooks, 'answer', { get() { throw new Error('keyless hook lookup'); } });
|
|
254
|
+
assert.equal(r.hub.ask, undefined); assert(!Object.hasOwn(r.hub, 'ask'));
|
|
255
|
+
const snapshots = [JSON.stringify(r.server.join())], deltas = [];
|
|
256
|
+
for (let i = 0; i < 4; i++) {
|
|
257
|
+
if (inject) r.say('p1', { k: 'hub-answer', id: spec.id, n: 1, text: 'PrivateRex' });
|
|
258
|
+
r.tick(250); snapshots.push(JSON.stringify(r.server.join())); deltas.push(JSON.stringify(r.server.delta()));
|
|
259
|
+
}
|
|
260
|
+
assert.deepEqual(wire(r), []); assert.deepEqual(r.ops, []);
|
|
261
|
+
assert(!JSON.stringify([r.sent, snapshots, deltas]).includes('PrivateRex'));
|
|
262
|
+
assert(snapshots.every((s) => !s.includes('"ask"'))); assert(deltas.every((s) => !s?.includes('"ask"')));
|
|
263
|
+
return JSON.stringify([r.sent, snapshots, deltas]);
|
|
264
|
+
}
|
|
265
|
+
assert.equal(trace(true), trace(false));
|
|
266
|
+
const h = { place: {}, session: { players: [{ playerId: 'p' }] }, sim: { players: new Map([['p', {}]]) } }, keys = Reflect.ownKeys(h);
|
|
267
|
+
Ask.message(h, 'p', { k: 'hub-answer', text: 'Rex' }); assert.deepEqual(Reflect.ownKeys(h), keys);
|
|
268
|
+
});
|
|
269
|
+
console.log(`${passed} ask tests passed`);
|