castle-web-cli 0.4.237 → 0.4.239
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/bundle.d.ts +24 -0
- package/dist/bundle.js +447 -4
- package/dist/bundleLatin1.d.ts +6 -0
- package/dist/bundleLatin1.js +333 -0
- package/dist/castle-host/host.d.ts +10 -1
- package/dist/castle-host/host.js +133 -9
- package/dist/castleJson.d.ts +2 -0
- package/dist/castleJson.js +1 -0
- package/dist/deckExports.d.ts +35 -0
- package/dist/deckExports.js +365 -0
- package/dist/importCheckHook.d.ts +1 -0
- package/dist/importCheckHook.js +1 -1
- package/dist/index.js +21 -0
- package/dist/init.js +2 -1
- package/dist/multiplayerDoc.d.ts +1 -1
- package/dist/multiplayerDoc.js +9 -0
- package/dist/platformDoc.js +2 -1
- package/dist/playPagePolicy.d.ts +1 -0
- package/dist/playPagePolicy.js +8 -3
- package/dist/roomLogs.d.ts +39 -0
- package/dist/roomLogs.js +166 -0
- package/dist/save-deck.js +4 -0
- package/kits/base/CLAUDE.md +1 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +113 -2
- package/kits/base/sdk/castle.d.ts +6 -2
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +56 -1
- package/kits/base/sdk/commands.js +29 -1
- package/kits/base/sdk/hub.d.ts +17 -0
- package/kits/base/sdk/hub.js +33 -9
- package/kits/base/sdk/localCache.d.ts +27 -0
- package/kits/base/sdk/localCache.js +115 -0
- package/kits/base/sdk/localCacheStore.d.ts +15 -0
- package/kits/base/sdk/localCacheStore.js +358 -0
- package/kits/base/sdk/multiplayer.js +30 -0
- package/kits/base/sdk/rooms.d.ts +11 -0
- package/kits/base/sdk/rooms.js +22 -0
- package/kits/base/sdk/store.d.ts +8 -2
- package/kits/base/sdk/store.js +5 -1
- package/kits/base/sdk/transport.d.ts +1 -0
- package/kits/base/sdk/transport.js +4 -5
- package/kits/hub-game/CLAUDE.md +22 -2
- package/kits/hub-game/castle.json +8 -5
- package/kits/hub-game/code/client/act.js +66 -91
- package/kits/hub-game/code/client/actCore.js +134 -0
- package/kits/hub-game/code/client/car.js +35 -0
- package/kits/hub-game/code/client/chrome.js +208 -381
- package/kits/hub-game/code/client/crowdNames.js +2 -2
- package/kits/hub-game/code/client/emoteWheel.js +109 -0
- package/kits/hub-game/code/client/hats.js +2 -0
- package/kits/hub-game/code/client/hookLayer.js +99 -48
- package/kits/hub-game/code/client/hostGo.js +77 -0
- package/kits/hub-game/code/client/hubControls.js +125 -0
- package/kits/hub-game/code/client/hubEntry.js +187 -0
- package/kits/hub-game/code/client/hudSurface.js +148 -0
- package/kits/hub-game/code/client/hudTree.js +96 -0
- package/kits/hub-game/code/client/idle.js +59 -13
- package/kits/hub-game/code/client/invites.js +13 -4
- package/kits/hub-game/code/client/menuIcons.js +8 -0
- package/kits/hub-game/code/client/menuRows.js +8 -2
- package/kits/hub-game/code/client/noTrips.js +38 -0
- package/kits/hub-game/code/client/qualityEntry.js +6 -1
- package/kits/hub-game/code/client/rehello.js +3 -1
- package/kits/hub-game/code/client/riders.js +26 -0
- package/kits/hub-game/code/client/role.js +79 -0
- package/kits/hub-game/code/client/safeLayout.js +32 -3
- package/kits/hub-game/code/client/sound.js +10 -3
- package/kits/hub-game/code/client/soundscape.js +2 -2
- package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
- package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
- package/kits/hub-game/code/client/soundscapeCues.js +2 -1
- package/kits/hub-game/code/client/state.js +19 -0
- package/kits/hub-game/code/client/stuck.js +2 -1
- package/kits/hub-game/code/client/talkSurface.js +178 -0
- package/kits/hub-game/code/client/talkTree.js +238 -0
- package/kits/hub-game/code/client/tiers.js +8 -5
- package/kits/hub-game/code/client/uiDom.js +600 -0
- package/kits/hub-game/code/client/uiTree.js +359 -0
- package/kits/hub-game/code/client/vehicle.js +156 -0
- package/kits/hub-game/code/client/wear.js +27 -5
- package/kits/hub-game/code/client/worldLabels.js +13 -3
- package/kits/hub-game/code/client/yours.js +10 -3
- package/kits/hub-game/code/server/actors.js +4 -3
- package/kits/hub-game/code/server/analytics.js +61 -18
- package/kits/hub-game/code/server/decor.js +56 -16
- package/kits/hub-game/code/server/doorAnalytics.js +2 -5
- package/kits/hub-game/code/server/hub.js +261 -46
- package/kits/hub-game/code/server/idle.js +118 -5
- package/kits/hub-game/code/server/loadAbandon.js +2 -5
- package/kits/hub-game/code/server/manifest.js +46 -4
- package/kits/hub-game/code/server/npcs.js +4 -2
- package/kits/hub-game/code/server/players.js +3 -0
- package/kits/hub-game/code/server/role.js +142 -0
- package/kits/hub-game/code/server/standing.js +6 -4
- package/kits/hub-game/code/server/trackQueue.js +29 -0
- package/kits/hub-game/code/server/vehicle.js +126 -0
- package/kits/hub-game/code/shared/car.js +52 -0
- package/kits/hub-game/code/shared/deckFlags.js +34 -0
- package/kits/hub-game/code/shared/deviceClass.js +39 -0
- package/kits/hub-game/code/shared/expression.js +9 -0
- package/kits/hub-game/code/systems/hub.js +281 -86
- package/kits/hub-game/docs/analytics.md +15 -3
- package/kits/hub-game/docs/contract.md +352 -14
- package/kits/hub-game/docs/vehicle-preset.md +132 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
- package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
- package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
- package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
- package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
- package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
- package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
- package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
- package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
- package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
- package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
- package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
- package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
- package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
- package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
- package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
- package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
- package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
- package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
- package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
- package/kits/hub-game/package-lock.json +1 -1
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/check.mjs +7 -4
- package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
- package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
- package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
- package/kits/hub-game/scripts/gen-hats.mjs +46 -2
- package/kits/hub-game/scripts/gen-role.mjs +80 -0
- package/kits/hub-game/scripts/test-act-core.mjs +167 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
- package/kits/hub-game/scripts/test-actors.mjs +48 -0
- package/kits/hub-game/scripts/test-analytics.mjs +100 -6
- package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
- package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
- package/kits/hub-game/scripts/test-ballot.mjs +2 -0
- package/kits/hub-game/scripts/test-car.mjs +43 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
- package/kits/hub-game/scripts/test-decor.mjs +77 -0
- package/kits/hub-game/scripts/test-device-class.mjs +83 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
- package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
- package/kits/hub-game/scripts/test-hats.mjs +5 -4
- package/kits/hub-game/scripts/test-host-go.mjs +265 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
- package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +103 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +20 -1
- package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
- package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
- package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
- package/kits/hub-game/scripts/test-idle.mjs +347 -1
- package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
- package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
- package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
- package/kits/hub-game/scripts/test-manifest.mjs +30 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +1 -1
- package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-quality.mjs +13 -0
- package/kits/hub-game/scripts/test-rehello.mjs +258 -3
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
- package/kits/hub-game/scripts/test-resync.mjs +196 -0
- package/kits/hub-game/scripts/test-role-client.mjs +427 -0
- package/kits/hub-game/scripts/test-role.mjs +350 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
- package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
- package/kits/hub-game/scripts/test-standing.mjs +15 -1
- package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
- package/kits/hub-game/scripts/test-tiers.mjs +13 -0
- package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
- package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +168 -0
- package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
- package/kits/hub-game/scripts/test-world-labels.mjs +40 -0
- package/kits/hub-game/scripts/test-yours.mjs +33 -0
- package/kits/hub-game/tools/hubScene/export.mjs +613 -0
- package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
- package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
- package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +810 -0
- package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
- package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
- package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
- package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +301 -0
- package/kits/multiplayer-3d/castle.json +4 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
- package/kits/multiplayer-3d/code/client/steer.js +3 -1
- package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
- package/kits/physics-3d/CLAUDE.md +1 -1
- package/kits/physics-3d/behaviors/Player.jsx +37 -27
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
- package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
- package/kits/physics-3d/engine3d/playerRun.js +6 -1
- package/kits/physics-3d/engine3d/pxmodel.js +6 -1
- package/kits/physics-3d/engine3d/world3d.js +6 -3
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/play/behaviors/Player.js +40 -28
- package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/messages.js +5 -0
- package/kits/real-time/code/server/session.js +28 -1
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +5 -4
- package/vendor/three/LICENSE +21 -0
- package/vendor/three/build/three.core.js +58773 -0
- package/vendor/three/build/three.module.js +18251 -0
- package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
- package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
- package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
- package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
- package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
- package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
- package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
- package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
- package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
- package/vendor/three/package.json +134 -0
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
// upload.mjs without the network: key computation, manifest URL rewriting, the skip-existing
|
|
2
|
+
// logic against a fake S3, the aws CLI adapter against a fake spawn, and deck resolution.
|
|
3
|
+
// node --test kits/hub-game/tools/hubScene/test/upload.test.mjs
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import test from 'node:test';
|
|
9
|
+
import {
|
|
10
|
+
CACHE_CONTROL, KIT_VERSION_MAX_LENGTH, allowlistEntry, importFaults, readUnder, isKitVersion, parseKitVersions, resolveKitVersion, runDecks, assetKey, awsCliS3, checkOut, checkPrefix, checksumHex, dryRunS3, findExportDecks, joinKey, kitVersionOf, localKitPin, manifestKey,
|
|
11
|
+
DEFAULTS, parseArgs, planManifest, publicUrl, readDeckList, readExportDeck, resolveDecks, sha256, uploadAll,
|
|
12
|
+
} from '../upload.mjs';
|
|
13
|
+
|
|
14
|
+
const glb = Buffer.concat([Buffer.from('glTF'), Buffer.alloc(16, 1)]);
|
|
15
|
+
const png = Buffer.from('\x89PNG fake image bytes');
|
|
16
|
+
const H_GLB = sha256(glb);
|
|
17
|
+
const H_PNG = sha256(png);
|
|
18
|
+
const shared = { [`${H_GLB}.glb`]: glb, [`${H_PNG}.png`]: png };
|
|
19
|
+
const readShared = (name) => {
|
|
20
|
+
if (!shared[name]) throw new Error(`no ${name}`);
|
|
21
|
+
return shared[name];
|
|
22
|
+
};
|
|
23
|
+
const manifest = () => ({
|
|
24
|
+
format: 'castle.hubScene', version: 1, hubId: 'deckAbc123', title: 'Test',
|
|
25
|
+
source: { deckId: 'deckAbc123', pins: { 'castle.hub-game': '0.4.232' }, kits: { 'castle.hub-game': { publishedVersion: '0.4.240', package: '1.99.0' } } },
|
|
26
|
+
assets: {
|
|
27
|
+
scene: { type: 'glb', uri: `../shared/${H_GLB}.glb`, sha256: H_GLB, bytes: glb.length, shared: true },
|
|
28
|
+
// A second id naming the same bytes: one upload.
|
|
29
|
+
bench: { type: 'glb', uri: `../shared/${H_GLB}.glb`, sha256: H_GLB, bytes: glb.length, shared: true },
|
|
30
|
+
sky: { type: 'png', uri: `../shared/${H_PNG}.png`, sha256: H_PNG, bytes: png.length, shared: true },
|
|
31
|
+
},
|
|
32
|
+
layers: [{ id: 'world', asset: 'scene', role: 'scene' }],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('keys and urls', () => {
|
|
36
|
+
assert.equal(joinKey('', 'nativehub/assets', 'x.glb'), 'nativehub/assets/x.glb');
|
|
37
|
+
assert.equal(joinKey('stage/v2', 'nativehub/assets', 'x.glb'), 'stage/v2/nativehub/assets/x.glb');
|
|
38
|
+
assert.equal(assetKey('', H_GLB, 'glb'), `nativehub/assets/${H_GLB}.glb`);
|
|
39
|
+
assert.equal(assetKey('pre', H_PNG, 'png'), `pre/nativehub/assets/${H_PNG}.png`);
|
|
40
|
+
assert.equal(manifestKey('', H_GLB), `nativehub/manifests/${H_GLB}.json`);
|
|
41
|
+
assert.throws(() => assetKey('', 'abc', 'glb'), /sha256/);
|
|
42
|
+
assert.throws(() => assetKey('', H_GLB, 'json'), /asset type/);
|
|
43
|
+
assert.throws(() => assetKey('', H_GLB, 'exe'), /asset type/);
|
|
44
|
+
assert.equal(publicUrl('https://hosted.castle.games/', 'nativehub/a'), 'https://hosted.castle.games/nativehub/a');
|
|
45
|
+
assert.throws(() => publicUrl('http://hosted.castle.games', 'k'), /https/);
|
|
46
|
+
assert.throws(() => publicUrl('https://h.example/?q=1', 'k'), /plain https/);
|
|
47
|
+
assert.equal(publicUrl('https://h.example/base/', 'a b/c#d'), 'https://h.example/base/a%20b/c%23d', 'segments encoded');
|
|
48
|
+
assert.throws(() => publicUrl('https://h.example', 'a/../b'), /not a key/);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('v1.7 embedded wear models get CDN URIs and share asset uploads', () => {
|
|
52
|
+
const m = manifest();
|
|
53
|
+
m.assets['role/top-vest'] = { ...m.assets.scene };
|
|
54
|
+
m.wearModels = { 'role/top-vest': { ...m.assets.scene } };
|
|
55
|
+
const plan = planManifest(m, { readShared });
|
|
56
|
+
const uri = publicUrl(DEFAULTS.baseUrl, assetKey(DEFAULTS.prefix, H_GLB, 'glb'));
|
|
57
|
+
assert.equal(plan.manifest.wearModels['role/top-vest'].uri, uri);
|
|
58
|
+
assert.equal(plan.manifest.assets['role/top-vest'].uri, uri);
|
|
59
|
+
assert.equal(plan.uploads.filter((u) => u.kind === 'asset').length, 2);
|
|
60
|
+
assert.equal(m.wearModels['role/top-vest'].uri, `../shared/${H_GLB}.glb`, 'source unchanged');
|
|
61
|
+
m.wearModels['role/top-vest'] = m.assets['role/top-vest'];
|
|
62
|
+
assert.equal(planManifest(m, { readShared }).manifest.wearModels['role/top-vest'].uri, uri, 'also handles shared record identity before JSON serialization');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('prefixes are a safe charset only', () => {
|
|
66
|
+
for (const ok of ['', 'staging', 'a/b_c-1', 'x0/y9']) assert.equal(checkPrefix(ok), ok);
|
|
67
|
+
for (const bad of ['test#1', '/lead', 'trail/', 'a//b', '..', 'a/../b', 'a/./b', 'Upper', 'sp ace', 'a?b', 'a%2fb', 'é', null]) {
|
|
68
|
+
assert.throws(() => checkPrefix(bad), /--prefix/, `refuses ${JSON.stringify(bad)}`);
|
|
69
|
+
assert.throws(() => assetKey(bad, H_GLB, 'glb'), /--prefix/);
|
|
70
|
+
assert.throws(() => manifestKey(bad, H_GLB), /--prefix/);
|
|
71
|
+
}
|
|
72
|
+
assert.throws(() => parseArgs(['--prefix', 'test#1', 'abc']), /--prefix/);
|
|
73
|
+
assert.throws(() => planManifest(manifest(), { readShared, prefix: 'a/../b' }), /--prefix/);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('checksums: full-object SHA-256 base64 to hex, anything else null', () => {
|
|
77
|
+
const b64 = Buffer.from(H_GLB, 'hex').toString('base64');
|
|
78
|
+
assert.equal(checksumHex(b64, 'FULL_OBJECT'), H_GLB);
|
|
79
|
+
assert.equal(checksumHex(b64, undefined), H_GLB);
|
|
80
|
+
assert.equal(checksumHex(`${b64}-3`, 'COMPOSITE'), null, 'a multipart composite is not the object hash');
|
|
81
|
+
assert.equal(checksumHex(b64, 'COMPOSITE'), null);
|
|
82
|
+
assert.equal(checksumHex(undefined), null);
|
|
83
|
+
assert.equal(checksumHex('bm90IDMyIGJ5dGVz'), null, 'not 32 bytes');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('planManifest rewrites asset uris and hashes the final bytes', () => {
|
|
87
|
+
const original = manifest();
|
|
88
|
+
const plan = planManifest(original, { readShared });
|
|
89
|
+
assert.equal(original.assets.scene.uri, `../shared/${H_GLB}.glb`, 'the input manifest is not changed');
|
|
90
|
+
assert.equal(plan.manifest.assets.scene.uri, `https://hosted.castle.games/content-packs/nativehub/assets/${H_GLB}.glb`);
|
|
91
|
+
assert.equal(plan.manifest.assets.bench.uri, plan.manifest.assets.scene.uri);
|
|
92
|
+
assert.equal(plan.manifest.assets.sky.uri, `https://hosted.castle.games/content-packs/nativehub/assets/${H_PNG}.png`);
|
|
93
|
+
assert.equal(plan.manifest.assets.sky.sha256, H_PNG, 'sha256 and bytes stay');
|
|
94
|
+
assert.deepEqual(JSON.parse(plan.manifestBytes.toString('utf8')), plan.manifest);
|
|
95
|
+
assert.equal(plan.manifestBytes.toString('utf8'), JSON.stringify(plan.manifest), 'compact JSON, as export.mjs writes');
|
|
96
|
+
assert.equal(plan.manifestSha256, sha256(plan.manifestBytes), 'the sha256 is of the final bytes');
|
|
97
|
+
assert.equal(plan.manifestKey, `content-packs/nativehub/manifests/${plan.manifestSha256}.json`);
|
|
98
|
+
assert.equal(plan.manifestUrl, `https://hosted.castle.games/content-packs/nativehub/manifests/${plan.manifestSha256}.json`);
|
|
99
|
+
assert.deepEqual(plan.uploads.map((u) => u.kind), ['asset', 'asset', 'manifest'], 'deduped assets, manifest last');
|
|
100
|
+
assert.deepEqual(plan.uploads.map((u) => u.contentType), ['model/gltf-binary', 'image/png', 'application/json']);
|
|
101
|
+
assert.equal(planManifest(manifest(), { readShared }).manifestSha256, plan.manifestSha256, 'deterministic');
|
|
102
|
+
const stamped = (at) => { const m = manifest(); m.source.exportedAt = at; return m; };
|
|
103
|
+
const early = planManifest(stamped('2026-01-01T00:00:00.000Z'), { readShared });
|
|
104
|
+
assert.equal(early.manifestSha256, planManifest(stamped('2026-02-02T00:00:00.000Z'), { readShared }).manifestSha256, 'the export time is not in the key');
|
|
105
|
+
assert.equal(early.manifest.source.exportedAt, undefined);
|
|
106
|
+
assert.equal(early.manifest.source.deckId, 'deckAbc123', 'the rest of source stays');
|
|
107
|
+
const prefixed = planManifest(manifest(), { readShared, prefix: 'staging', baseUrl: 'https://cdn.example' });
|
|
108
|
+
assert.equal(prefixed.manifest.assets.scene.uri, `https://cdn.example/staging/nativehub/assets/${H_GLB}.glb`);
|
|
109
|
+
assert.notEqual(prefixed.manifestSha256, plan.manifestSha256, 'other urls, other bytes, other key');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('planManifest uploads v1.6 sound assets with their audio content types', () => {
|
|
113
|
+
const sounds = { mp3: 'audio/mpeg', ogg: 'audio/ogg', wav: 'audio/wav', m4a: 'audio/mp4' };
|
|
114
|
+
const m = manifest();
|
|
115
|
+
const bytes = {};
|
|
116
|
+
m.audio = {};
|
|
117
|
+
for (const [i, ext] of Object.keys(sounds).entries()) {
|
|
118
|
+
const buf = Buffer.from(`fake ${ext} sound`);
|
|
119
|
+
const h = sha256(buf);
|
|
120
|
+
bytes[`${h}.${ext}`] = buf;
|
|
121
|
+
m.assets[`audio-${i}`] = { type: ext, uri: `../shared/${h}.${ext}`, sha256: h, bytes: buf.length, shared: true };
|
|
122
|
+
m.audio[`sounds/a.${ext}`] = `audio-${i}`;
|
|
123
|
+
}
|
|
124
|
+
const plan = planManifest(m, { readShared: (name) => bytes[name] ?? readShared(name) });
|
|
125
|
+
for (const [i, ext] of Object.keys(sounds).entries()) {
|
|
126
|
+
const a = plan.manifest.assets[`audio-${i}`];
|
|
127
|
+
assert.equal(a.uri, `https://hosted.castle.games/content-packs/nativehub/assets/${a.sha256}.${ext}`);
|
|
128
|
+
assert.ok(plan.uploads.some((u) => u.key.endsWith(`${a.sha256}.${ext}`) && u.contentType === sounds[ext]), ext);
|
|
129
|
+
}
|
|
130
|
+
assert.deepEqual(plan.manifest.audio, m.audio, 'the audio map names asset ids, unchanged');
|
|
131
|
+
assert.throws(() => assetKey('p', H_GLB, 'flac'), /not an asset type/);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('planManifest refuses assets that do not hold what they claim', () => {
|
|
135
|
+
const badHash = manifest();
|
|
136
|
+
badHash.assets.sky.sha256 = H_GLB;
|
|
137
|
+
assert.throws(() => planManifest(badHash, { readShared }), /uri/);
|
|
138
|
+
const wrongBytes = { ...shared, [`${H_PNG}.png`]: Buffer.from('other') };
|
|
139
|
+
assert.throws(() => planManifest(manifest(), { readShared: (n) => wrongBytes[n] }), /does not hold its sha256/);
|
|
140
|
+
const badSize = manifest();
|
|
141
|
+
badSize.assets.sky.bytes = 1;
|
|
142
|
+
assert.throws(() => planManifest(badSize, { readShared }), /bytes/);
|
|
143
|
+
const foreign = manifest();
|
|
144
|
+
foreign.assets.sky.uri = 'https://elsewhere/x.png';
|
|
145
|
+
assert.throws(() => planManifest(foreign, { readShared }), /not \.\.\/shared/);
|
|
146
|
+
assert.throws(() => planManifest({ format: 'other' }, { readShared }), /castle.hubScene/);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('allowlist entry shape and kitVersion', () => {
|
|
150
|
+
const plan = planManifest(manifest(), { readShared });
|
|
151
|
+
const entry = allowlistEntry('deckAbc123', plan, kitVersionOf(manifest()));
|
|
152
|
+
assert.deepEqual(Object.keys(entry), ['deckId', 'manifestUrl', 'manifestSha256', 'kitVersion', 'source']);
|
|
153
|
+
assert.deepEqual(entry.source, { exporter: null, access: null, url: null }, 'provenance fields the manifest lacks are null');
|
|
154
|
+
assert.equal(entry.kitVersion, '0.4.232', 'the pinned hub-game version');
|
|
155
|
+
const unpinned = manifest();
|
|
156
|
+
delete unpinned.source.pins;
|
|
157
|
+
assert.equal(kitVersionOf(unpinned), '0.4.240', 'else the shipped kit version');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const fakeS3 = (existing = {}) => {
|
|
161
|
+
const calls = [];
|
|
162
|
+
const store = new Map(Object.entries(existing));
|
|
163
|
+
return {
|
|
164
|
+
calls, store,
|
|
165
|
+
async head(key) {
|
|
166
|
+
calls.push(['head', key]);
|
|
167
|
+
if (!store.has(key)) return { exists: false };
|
|
168
|
+
const v = store.get(key);
|
|
169
|
+
// A stored entry is bytes (checksum of them) or { body, sha256 } to fake another checksum.
|
|
170
|
+
return Buffer.isBuffer(v) ? { exists: true, bytes: v.length, sha256: sha256(v) } : { exists: true, bytes: v.body.length, sha256: v.sha256 };
|
|
171
|
+
},
|
|
172
|
+
async put(key, body, opts) {
|
|
173
|
+
calls.push(['put', key, opts]);
|
|
174
|
+
store.set(key, body);
|
|
175
|
+
return { raced: false };
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
test('uploadAll heads first, skips what exists, puts the manifest last', async () => {
|
|
181
|
+
const plan = planManifest(manifest(), { readShared });
|
|
182
|
+
const [glbUp, pngUp, mUp] = plan.uploads;
|
|
183
|
+
const s3 = fakeS3({ [glbUp.key]: glb });
|
|
184
|
+
const results = await uploadAll(plan.uploads, s3);
|
|
185
|
+
assert.deepEqual(results.map((r) => r.action), ['skipped', 'uploaded', 'uploaded']);
|
|
186
|
+
assert.deepEqual(s3.calls.map((c) => `${c[0]} ${c[1]}`), [`head ${glbUp.key}`, `head ${pngUp.key}`, `put ${pngUp.key}`, `head ${mUp.key}`, `put ${mUp.key}`]);
|
|
187
|
+
const put = s3.calls.find((c) => c[0] === 'put' && c[1] === mUp.key)[2];
|
|
188
|
+
assert.deepEqual(put, { contentType: 'application/json', cacheControl: CACHE_CONTROL, sha256: plan.manifestSha256 });
|
|
189
|
+
assert.equal(CACHE_CONTROL, 'public, max-age=31536000, immutable');
|
|
190
|
+
assert.ok(s3.store.get(mUp.key).equals(plan.manifestBytes));
|
|
191
|
+
// Run again: everything is there, nothing is put.
|
|
192
|
+
const again = fakeS3(Object.fromEntries(s3.store));
|
|
193
|
+
assert.deepEqual((await uploadAll(plan.uploads, again)).map((r) => r.action), ['skipped', 'skipped', 'skipped']);
|
|
194
|
+
assert.ok(again.calls.every((c) => c[0] === 'head'));
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('uploadAll never overwrites or trusts a key holding other bytes, and stops before the manifest', async () => {
|
|
198
|
+
const plan = planManifest(manifest(), { readShared });
|
|
199
|
+
const s3 = fakeS3({ [plan.uploads[1].key]: Buffer.from('short') });
|
|
200
|
+
await assert.rejects(uploadAll(plan.uploads, s3), /not overwriting/);
|
|
201
|
+
assert.ok(!s3.calls.some((c) => c[0] === 'put' && c[1] === plan.manifestKey), 'manifest not put');
|
|
202
|
+
// Same length, other bytes: only the checksum tells.
|
|
203
|
+
const same = Buffer.alloc(png.length, 7);
|
|
204
|
+
const swapped = fakeS3({ [plan.uploads[1].key]: same });
|
|
205
|
+
await assert.rejects(uploadAll(plan.uploads, swapped), new RegExp(`SHA-256 ${sha256(same)}, ours is ${H_PNG}`));
|
|
206
|
+
assert.ok(!swapped.calls.some((c) => c[0] === 'put' && c[1] !== plan.uploads[0].key), 'only the missing glb before it was put; never the png or the manifest');
|
|
207
|
+
// No stored checksum: fail closed.
|
|
208
|
+
const bare = fakeS3({ [plan.uploads[0].key]: { body: glb, sha256: null } });
|
|
209
|
+
await assert.rejects(uploadAll(plan.uploads, bare), /no SHA-256 checksum/);
|
|
210
|
+
assert.ok(!bare.calls.some((c) => c[0] === 'put'));
|
|
211
|
+
// The manifest key too.
|
|
212
|
+
const store = Object.fromEntries(plan.uploads.slice(0, 2).map((u) => [u.key, u.body]));
|
|
213
|
+
const badManifest = fakeS3({ ...store, [plan.manifestKey]: { body: plan.manifestBytes, sha256: 'f'.repeat(64) } });
|
|
214
|
+
await assert.rejects(uploadAll(plan.uploads, badManifest), /nativehub\/manifests\/.*SHA-256 f{64}/);
|
|
215
|
+
assert.ok(!s3.calls.some((c) => c[0] === 'put' && c[1] === plan.manifestKey), 'manifest not put');
|
|
216
|
+
const failing = { ...fakeS3(), async put(key) { throw new Error(`boom ${key}`); } };
|
|
217
|
+
await assert.rejects(uploadAll(plan.uploads, failing), /boom/);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// An S3 where another writer puts `theirs` (key -> bytes or {body, sha256}) between our HEAD and put.
|
|
221
|
+
const racingS3 = (theirs) => {
|
|
222
|
+
const seen = new Set();
|
|
223
|
+
const store = fakeS3();
|
|
224
|
+
return {
|
|
225
|
+
calls: store.calls,
|
|
226
|
+
async head(key) {
|
|
227
|
+
if (seen.has(key) && key in theirs) { store.store.set(key, theirs[key]); }
|
|
228
|
+
seen.add(key);
|
|
229
|
+
return store.head(key);
|
|
230
|
+
},
|
|
231
|
+
async put(key, body, opts) {
|
|
232
|
+
store.calls.push(['put', key, opts]);
|
|
233
|
+
if (key in theirs) return { raced: true };
|
|
234
|
+
store.store.set(key, body);
|
|
235
|
+
return { raced: false };
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
test('a race lost to another writer (412) is verified by checksum before it counts', async () => {
|
|
241
|
+
const plan = planManifest(manifest(), { readShared });
|
|
242
|
+
const all = Object.fromEntries(plan.uploads.map((u) => [u.key, u.body]));
|
|
243
|
+
const won = racingS3(all);
|
|
244
|
+
assert.deepEqual((await uploadAll(plan.uploads, won)).map((r) => r.action), ['skipped', 'skipped', 'skipped']);
|
|
245
|
+
assert.equal(won.calls.filter((c) => c[0] === 'head').length, 6, 'a HEAD before and after each lost race');
|
|
246
|
+
const other = racingS3({ [plan.uploads[0].key]: Buffer.from(glb).fill(3, 4) });
|
|
247
|
+
await assert.rejects(uploadAll(plan.uploads, other), /SHA-256 .* ours is/);
|
|
248
|
+
assert.ok(!other.calls.some((c) => c[0] === 'put' && c[1] !== plan.uploads[0].key), 'stopped at the first asset');
|
|
249
|
+
const bare = racingS3({ [plan.manifestKey]: { body: plan.manifestBytes, sha256: null } });
|
|
250
|
+
await assert.rejects(uploadAll(plan.uploads, bare), /manifests\/.*no SHA-256 checksum/);
|
|
251
|
+
const vanished = { async head() { return { exists: false }; }, async put() { return { raced: true }; } };
|
|
252
|
+
await assert.rejects(uploadAll(plan.uploads, vanished), /412.*HEAD finds nothing/);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('dry run never puts', async () => {
|
|
256
|
+
const s3 = dryRunS3();
|
|
257
|
+
assert.deepEqual(await s3.head('k'), { exists: false, unchecked: true });
|
|
258
|
+
await assert.rejects(s3.put('k', Buffer.alloc(1), {}), /dry run/);
|
|
259
|
+
const real = fakeS3({ k: Buffer.alloc(3) });
|
|
260
|
+
assert.equal((await dryRunS3(real).head('k')).exists, true, '--head reads through');
|
|
261
|
+
await assert.rejects(dryRunS3(real).put('k'), /dry run/);
|
|
262
|
+
assert.ok(real.calls.every((c) => c[0] === 'head'));
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('awsCliS3 builds aws s3api calls and reads their answers', async () => {
|
|
266
|
+
const calls = [];
|
|
267
|
+
const answers = [];
|
|
268
|
+
const run = (cmd, args) => {
|
|
269
|
+
calls.push([cmd, ...args]);
|
|
270
|
+
return answers.shift();
|
|
271
|
+
};
|
|
272
|
+
const s3 = awsCliS3({ bucket: 'castle-hosted-games', profile: 'ra', run });
|
|
273
|
+
const b64 = Buffer.from(H_GLB, 'hex').toString('base64');
|
|
274
|
+
answers.push({ status: 0, stdout: JSON.stringify({ ContentLength: 42, ChecksumSHA256: b64, ChecksumType: 'FULL_OBJECT' }), stderr: '' });
|
|
275
|
+
assert.deepEqual(await s3.head('nativehub/assets/a.glb'), { exists: true, bytes: 42, sha256: H_GLB });
|
|
276
|
+
answers.push({ status: 0, stdout: '{"ContentLength": 42}', stderr: '' });
|
|
277
|
+
assert.deepEqual(await s3.head('nativehub/assets/a.glb'), { exists: true, bytes: 42, sha256: null }, 'no checksum stored');
|
|
278
|
+
assert.deepEqual(calls[0], ['aws', 's3api', 'head-object', '--key', 'nativehub/assets/a.glb', '--checksum-mode', 'ENABLED', '--bucket', 'castle-hosted-games', '--region', 'us-east-1', '--output', 'json', '--profile', 'ra']);
|
|
279
|
+
answers.push({ status: 254, stdout: '', stderr: 'An error occurred (404) when calling the HeadObject operation: Not Found' });
|
|
280
|
+
assert.deepEqual(await s3.head('k'), { exists: false });
|
|
281
|
+
answers.push({ status: 254, stdout: '', stderr: 'An error occurred (403) when calling the HeadObject operation: Forbidden' });
|
|
282
|
+
await assert.rejects(s3.head('k'), /403/, 'a 403 is not taken as missing');
|
|
283
|
+
|
|
284
|
+
let bodySeen = null;
|
|
285
|
+
const putRun = (cmd, args) => {
|
|
286
|
+
calls.push([cmd, ...args]);
|
|
287
|
+
bodySeen = fs.readFileSync(args[args.indexOf('--body') + 1]);
|
|
288
|
+
return answers.shift();
|
|
289
|
+
};
|
|
290
|
+
const s3p = awsCliS3({ bucket: 'b', run: putRun });
|
|
291
|
+
const body = Buffer.from('{"x":1}');
|
|
292
|
+
answers.push({ status: 0, stdout: '{}', stderr: '' });
|
|
293
|
+
assert.deepEqual(await s3p.put('m.json', body, { contentType: 'application/json', cacheControl: CACHE_CONTROL, sha256: sha256(body) }), { raced: false });
|
|
294
|
+
const args = calls.at(-1);
|
|
295
|
+
const flag = (n) => args[args.indexOf(n) + 1];
|
|
296
|
+
assert.equal(flag('--content-type'), 'application/json');
|
|
297
|
+
assert.equal(flag('--cache-control'), CACHE_CONTROL);
|
|
298
|
+
assert.equal(flag('--if-none-match'), '*');
|
|
299
|
+
assert.equal(flag('--checksum-sha256'), Buffer.from(sha256(body), 'hex').toString('base64'));
|
|
300
|
+
assert.ok(!args.includes('--profile'), 'no profile: the ambient chain');
|
|
301
|
+
assert.ok(bodySeen.equals(body));
|
|
302
|
+
assert.ok(!fs.existsSync(flag('--body')), 'the temp body is removed');
|
|
303
|
+
answers.push({ status: 254, stdout: '', stderr: 'An error occurred (PreconditionFailed) when calling the PutObject operation' });
|
|
304
|
+
assert.deepEqual(await s3p.put('m.json', body, { contentType: 'application/json', cacheControl: CACHE_CONTROL, sha256: sha256(body) }), { raced: true });
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test('args: dry run unless --upload', () => {
|
|
308
|
+
assert.equal(parseArgs(['abc']).upload, false);
|
|
309
|
+
assert.equal(parseArgs(['--upload', 'abc']).upload, true);
|
|
310
|
+
assert.equal(parseArgs(['--upload', '--dry-run', 'abc']).upload, false);
|
|
311
|
+
const o = parseArgs(['--bucket', 'b', '--prefix', 'p', '--decks-root', '/x', 'a', 'b2']);
|
|
312
|
+
assert.deepEqual([o.bucket, o.prefix, o.decksRoots, o.refs, o.baseUrl], ['b', 'p', ['/x'], ['a', 'b2'], 'https://hosted.castle.games']);
|
|
313
|
+
assert.equal(parseArgs([]).bucket, 'castle-hosted-games');
|
|
314
|
+
assert.throws(() => parseArgs(['--bucket']), /needs a value/);
|
|
315
|
+
assert.throws(() => parseArgs(['--nope']), /unknown flag/);
|
|
316
|
+
assert.equal(parseArgs(['abc']).out, path.join(os.tmpdir(), 'nativehub-scenes.json'), 'default out is outside the repo');
|
|
317
|
+
const fx = parseArgs(['--from-export', '/e', '--', '--1ZCdeKzbuy', '-Di1PENM3sS1']);
|
|
318
|
+
assert.equal(fx.fromExport, '/e');
|
|
319
|
+
assert.deepEqual(fx.refs, ['--1ZCdeKzbuy', '-Di1PENM3sS1'], 'ids after -- may start with dashes');
|
|
320
|
+
assert.equal(fx.upload, false, '--from-export is a dry run too unless --upload');
|
|
321
|
+
assert.throws(() => parseArgs(['--from-export']), /needs a value/);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test('--out is refused inside the kits the export hashes', () => {
|
|
325
|
+
const kits = path.resolve(import.meta.dirname, '../../../..');
|
|
326
|
+
assert.equal(path.basename(kits), 'kits');
|
|
327
|
+
assert.throws(() => parseArgs(['--out', path.join(kits, 'hub-game/nativehub-scenes.json'), 'abc']), /inside/);
|
|
328
|
+
assert.throws(() => checkOut(path.join(kits, 'new-dir/x.json')), /inside/, 'a folder not made yet');
|
|
329
|
+
assert.throws(() => checkOut(path.join(import.meta.dirname, 'x.json')), /inside/);
|
|
330
|
+
assert.throws(() => checkOut(kits), /inside/);
|
|
331
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'nativehub-out-'));
|
|
332
|
+
try {
|
|
333
|
+
// A symlink into kits/ is inside, by real path.
|
|
334
|
+
fs.symlinkSync(path.join(kits, 'hub-game'), path.join(tmp, 'link'));
|
|
335
|
+
assert.throws(() => checkOut(path.join(tmp, 'link/x.json')), /inside/);
|
|
336
|
+
assert.equal(checkOut(path.join(tmp, 'x.json')), path.join(fs.realpathSync(tmp), 'x.json'));
|
|
337
|
+
assert.ok(checkOut(path.join(path.dirname(kits), 'kits-sibling.json')), 'beside kits/ is fine');
|
|
338
|
+
} finally {
|
|
339
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test('deck lists and resolution', () => {
|
|
344
|
+
assert.deepEqual(readDeckList('a1\n# comment\n\n b2 # town\n'), ['a1', 'b2']);
|
|
345
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'nativehub-decks-'));
|
|
346
|
+
try {
|
|
347
|
+
const mk = (name, cj) => { fs.mkdirSync(path.join(root, name)); fs.writeFileSync(path.join(root, name, 'castle.json'), JSON.stringify(cj)); };
|
|
348
|
+
mk('hub-a', { deckId: 'deckA_1' });
|
|
349
|
+
mk('hub-unsaved', { title: 'x' });
|
|
350
|
+
assert.deepEqual(resolveDecks(['deckA_1'], [root]), [{ deckId: 'deckA_1', dir: path.join(root, 'hub-a') }]);
|
|
351
|
+
assert.deepEqual(resolveDecks([path.join(root, 'hub-a')], [root]), [{ deckId: 'deckA_1', dir: path.join(root, 'hub-a') }]);
|
|
352
|
+
assert.throws(() => resolveDecks(['missing1'], [root]), /no deck folder/);
|
|
353
|
+
assert.throws(() => resolveDecks([path.join(root, 'hub-unsaved')], [root]), /no deckId/);
|
|
354
|
+
} finally {
|
|
355
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// An export-hub.mjs output (castle-client): <root>/shared/<sha256>.<ext>, and per deck
|
|
360
|
+
// <root>/<deckId>/{manifest.json, export.json, reference.png}, manifests pretty-printed with
|
|
361
|
+
// indent 1 and asset uris `../shared/<sha256>.<ext>`.
|
|
362
|
+
const avatarGlb = Buffer.concat([Buffer.from('glTF'), Buffer.alloc(24, 7)]);
|
|
363
|
+
const H_AVATAR = sha256(avatarGlb);
|
|
364
|
+
const hubExportManifest = (deckId, exportedAt = '2026-10-19T07:47:05.724Z') => ({
|
|
365
|
+
format: 'castle.hubScene', version: 1, hubId: deckId, title: `Hub ${deckId}`,
|
|
366
|
+
source: {
|
|
367
|
+
deckId, url: `https://castle.xyz/d/${deckId}`, exporter: 'export-hub.mjs', access: 'signed-in QA 1199',
|
|
368
|
+
gpu: 'ANGLE (test)', viewport: { width: 726, height: 336 }, dpr: 2, exportedAt, three: '180', notes: [],
|
|
369
|
+
},
|
|
370
|
+
assets: {
|
|
371
|
+
scene: { type: 'glb', uri: `../shared/${H_GLB}.glb`, sha256: H_GLB, bytes: glb.length, shared: false },
|
|
372
|
+
avatar: { type: 'glb', uri: `../shared/${H_AVATAR}.glb`, sha256: H_AVATAR, bytes: avatarGlb.length, shared: true },
|
|
373
|
+
sky: { type: 'png', uri: `../shared/${H_PNG}.png`, sha256: H_PNG, bytes: png.length, shared: true },
|
|
374
|
+
},
|
|
375
|
+
layers: [{ id: 'world', asset: 'scene', role: 'scene' }],
|
|
376
|
+
avatar: { asset: 'avatar', rootAboveFloor: 0.7, gait: 'procedural' },
|
|
377
|
+
// The rest of a manifest validate-manifest.mjs passes.
|
|
378
|
+
render: { clearColor: '#88aacc' },
|
|
379
|
+
lights: { ambient: { color: '#ffffff', intensity: 0.5 } },
|
|
380
|
+
sky: { dome: null, zones: [{ id: 'default', color: '#99bbdd', image: 'sky' }] },
|
|
381
|
+
camera: { fovDeg: 60, near: 0.1, far: 500 },
|
|
382
|
+
spawns: [{ id: 'arrival', kind: 'arrival', position: [0, 0, 0], default: true }],
|
|
383
|
+
doors: [], characters: [], colliders: [], labels: [], actors: {},
|
|
384
|
+
tiers: { default: 'middle', profiles: { middle: {} } },
|
|
385
|
+
});
|
|
386
|
+
function writeHubExport(root, deckIds = ['vSNPV096_Qr2', '--1ZCdeKzbuy']) {
|
|
387
|
+
fs.mkdirSync(path.join(root, 'shared'), { recursive: true });
|
|
388
|
+
for (const [h, ext, buf] of [[H_GLB, 'glb', glb], [H_AVATAR, 'glb', avatarGlb], [H_PNG, 'png', png]]) fs.writeFileSync(path.join(root, 'shared', `${h}.${ext}`), buf);
|
|
389
|
+
for (const id of deckIds) {
|
|
390
|
+
fs.mkdirSync(path.join(root, id));
|
|
391
|
+
fs.writeFileSync(path.join(root, id, 'manifest.json'), JSON.stringify(hubExportManifest(id), null, 1));
|
|
392
|
+
fs.writeFileSync(path.join(root, id, 'export.json'), JSON.stringify({ deckId: id }, null, 1));
|
|
393
|
+
fs.writeFileSync(path.join(root, id, 'reference.png'), png);
|
|
394
|
+
}
|
|
395
|
+
fs.mkdirSync(path.join(root, 'logs'));
|
|
396
|
+
fs.writeFileSync(path.join(root, 'logs', `${deckIds[0]}.log`), 'ok\n');
|
|
397
|
+
return root;
|
|
398
|
+
}
|
|
399
|
+
const withExport = async (fn) => {
|
|
400
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'nativehub-export-'));
|
|
401
|
+
try { return await fn(writeHubExport(root)); } finally { fs.rmSync(root, { recursive: true, force: true }); }
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
test('from-export: finds deck dirs under a root, a single deck dir, or the named ones', () => withExport((root) => {
|
|
405
|
+
assert.deepEqual(findExportDecks(root).map((d) => d.deckId), ['--1ZCdeKzbuy', 'vSNPV096_Qr2'], 'sorted; shared/ and logs/ are not decks');
|
|
406
|
+
assert.deepEqual(findExportDecks(path.join(root, 'vSNPV096_Qr2')), [{ deckId: 'vSNPV096_Qr2', dir: path.join(root, 'vSNPV096_Qr2') }]);
|
|
407
|
+
assert.deepEqual(findExportDecks(root, ['vSNPV096_Qr2']).map((d) => d.dir), [path.join(root, 'vSNPV096_Qr2')]);
|
|
408
|
+
assert.throws(() => findExportDecks(root, ['missingDeck1']), /no missingDeck1\/manifest.json/);
|
|
409
|
+
assert.throws(() => findExportDecks(root, ['../x']), /not a deck id/);
|
|
410
|
+
assert.throws(() => findExportDecks(path.join(root, 'vSNPV096_Qr2'), ['--1ZCdeKzbuy']), /only/);
|
|
411
|
+
assert.throws(() => findExportDecks(path.join(root, 'logs')), /no <deckId>\/manifest.json/);
|
|
412
|
+
}));
|
|
413
|
+
|
|
414
|
+
test('from-export: resolves ../shared uris, rewrites them, keeps provenance but exportedAt', () => withExport((root) => {
|
|
415
|
+
const { deckId, manifest: m, readShared: rs } = readExportDeck(path.join(root, 'vSNPV096_Qr2'));
|
|
416
|
+
assert.equal(deckId, 'vSNPV096_Qr2');
|
|
417
|
+
assert.deepEqual(rs(`${H_AVATAR}.glb`), avatarGlb, 'read from <root>/shared');
|
|
418
|
+
const plan = planManifest(m, { readShared: rs });
|
|
419
|
+
const url = (h, ext) => `https://hosted.castle.games/content-packs/nativehub/assets/${h}.${ext}`;
|
|
420
|
+
assert.deepEqual(Object.fromEntries(Object.entries(plan.manifest.assets).map(([id, a]) => [id, a.uri])),
|
|
421
|
+
{ scene: url(H_GLB, 'glb'), avatar: url(H_AVATAR, 'glb'), sky: url(H_PNG, 'png') });
|
|
422
|
+
assert.equal(plan.manifest.source.exportedAt, undefined);
|
|
423
|
+
const { exportedAt, ...kept } = hubExportManifest('vSNPV096_Qr2').source;
|
|
424
|
+
assert.deepEqual(plan.manifest.source, kept, 'access, exporter and the rest of source stay');
|
|
425
|
+
assert.equal(plan.manifestBytes.toString('utf8'), JSON.stringify(plan.manifest), 'compact bytes, not the export file\'s indent');
|
|
426
|
+
assert.equal(plan.manifestSha256, sha256(plan.manifestBytes));
|
|
427
|
+
assert.deepEqual(plan.uploads.map((u) => u.kind), ['asset', 'asset', 'asset', 'manifest'], 'assets before the manifest');
|
|
428
|
+
assert.deepEqual(plan.uploads.slice(0, 3).map((u) => u.sha256), [H_GLB, H_AVATAR, H_PNG]);
|
|
429
|
+
const entry = allowlistEntry(deckId, plan, '0.4.232');
|
|
430
|
+
assert.deepEqual(entry.source, { exporter: 'export-hub.mjs', access: 'signed-in QA 1199', url: 'https://castle.xyz/d/vSNPV096_Qr2' });
|
|
431
|
+
assert.equal(entry.manifestUrl, `https://hosted.castle.games/content-packs/nativehub/manifests/${plan.manifestSha256}.json`);
|
|
432
|
+
}));
|
|
433
|
+
|
|
434
|
+
test('from-export: deterministic across runs and export times', () => {
|
|
435
|
+
const plans = [0, 1].map((run) => {
|
|
436
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), `nativehub-export-${run}-`));
|
|
437
|
+
try {
|
|
438
|
+
writeHubExport(root);
|
|
439
|
+
if (run) {
|
|
440
|
+
const f = path.join(root, 'vSNPV096_Qr2', 'manifest.json');
|
|
441
|
+
fs.writeFileSync(f, JSON.stringify(hubExportManifest('vSNPV096_Qr2', '2027-01-01T00:00:00.000Z'), null, 1));
|
|
442
|
+
}
|
|
443
|
+
const ex = readExportDeck(path.join(root, 'vSNPV096_Qr2'));
|
|
444
|
+
return planManifest(ex.manifest, { readShared: ex.readShared });
|
|
445
|
+
} finally {
|
|
446
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
assert.equal(plans[0].manifestSha256, plans[1].manifestSha256, 'a later export of the same scene has the same manifest key');
|
|
450
|
+
assert.deepEqual(plans[0].manifestBytes, plans[1].manifestBytes);
|
|
451
|
+
assert.deepEqual(plans[0].uploads.map((u) => u.key), plans[1].uploads.map((u) => u.key));
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test('from-export: a file that does not hold its hash, or is missing, is refused', () => withExport((root) => {
|
|
455
|
+
const dir = path.join(root, 'vSNPV096_Qr2');
|
|
456
|
+
// Same size, other bytes: only the hash can tell.
|
|
457
|
+
fs.writeFileSync(path.join(root, 'shared', `${H_AVATAR}.glb`), Buffer.concat([Buffer.from('glTF'), Buffer.alloc(24, 8)]));
|
|
458
|
+
let ex = readExportDeck(dir);
|
|
459
|
+
assert.throws(() => planManifest(ex.manifest, { readShared: ex.readShared }), /asset avatar: shared\/[0-9a-f]{64}\.glb does not hold its sha256/);
|
|
460
|
+
fs.writeFileSync(path.join(root, 'shared', `${H_AVATAR}.glb`), avatarGlb);
|
|
461
|
+
fs.rmSync(path.join(root, 'shared', `${H_PNG}.png`));
|
|
462
|
+
ex = readExportDeck(dir);
|
|
463
|
+
assert.throws(() => planManifest(ex.manifest, { readShared: ex.readShared }), /asset file missing: .*shared\/[0-9a-f]{64}\.png/);
|
|
464
|
+
// A symlink is not taken for the file.
|
|
465
|
+
fs.symlinkSync(path.join(root, 'shared', `${H_GLB}.glb`), path.join(root, 'shared', `${H_PNG}.png`));
|
|
466
|
+
assert.throws(() => planManifest(ex.manifest, { readShared: ex.readShared }), /is a symlink/);
|
|
467
|
+
}));
|
|
468
|
+
|
|
469
|
+
test('from-export: a manifest whose uri, hub or deck does not match is refused', () => withExport((root) => {
|
|
470
|
+
const dir = path.join(root, 'vSNPV096_Qr2');
|
|
471
|
+
const write = (m) => fs.writeFileSync(path.join(dir, 'manifest.json'), JSON.stringify(m, null, 1));
|
|
472
|
+
const m = hubExportManifest('vSNPV096_Qr2');
|
|
473
|
+
m.assets.scene.uri = `../../elsewhere/${H_GLB}.glb`;
|
|
474
|
+
write(m);
|
|
475
|
+
const ex = readExportDeck(dir);
|
|
476
|
+
assert.throws(() => planManifest(ex.manifest, { readShared: ex.readShared }), /not \.\.\/shared/);
|
|
477
|
+
write({ ...hubExportManifest('vSNPV096_Qr2'), hubId: 'otherHub' });
|
|
478
|
+
assert.throws(() => readExportDeck(dir), /is hub "otherHub"/);
|
|
479
|
+
write({ ...hubExportManifest('vSNPV096_Qr2'), source: { ...hubExportManifest('x').source, deckId: 'otherDeck' } });
|
|
480
|
+
assert.throws(() => readExportDeck(dir), /exported from deck "otherDeck"/);
|
|
481
|
+
write({ ...hubExportManifest('vSNPV096_Qr2'), format: 'nope' });
|
|
482
|
+
assert.throws(() => readExportDeck(dir), /not a castle.hubScene/);
|
|
483
|
+
fs.writeFileSync(path.join(dir, 'manifest.json'), '{ truncated');
|
|
484
|
+
assert.throws(() => readExportDeck(dir), /manifest.json/);
|
|
485
|
+
}));
|
|
486
|
+
|
|
487
|
+
test('from-export: kitVersion from the local deck folder pin', () => {
|
|
488
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'nativehub-decks-'));
|
|
489
|
+
try {
|
|
490
|
+
fs.mkdirSync(path.join(root, 'hub-a'));
|
|
491
|
+
fs.writeFileSync(path.join(root, 'hub-a', 'castle.json'), JSON.stringify({ deckId: 'vSNPV096_Qr2', imports: { 'castle.hub-game': { version: '0.4.250' } } }));
|
|
492
|
+
assert.equal(localKitPin('vSNPV096_Qr2', [root]), '0.4.250');
|
|
493
|
+
assert.equal(localKitPin('missingDeck1', [root]), null);
|
|
494
|
+
assert.equal(kitVersionOf(hubExportManifest('vSNPV096_Qr2')), null, 'export-hub.mjs records no pin');
|
|
495
|
+
} finally {
|
|
496
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
const kitRoot = (pins) => {
|
|
501
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'nativehub-decks-'));
|
|
502
|
+
for (const [id, version] of Object.entries(pins)) {
|
|
503
|
+
fs.mkdirSync(path.join(root, id));
|
|
504
|
+
fs.writeFileSync(path.join(root, id, 'castle.json'), JSON.stringify({ deckId: id, imports: { 'castle.hub-game': { version } } }));
|
|
505
|
+
}
|
|
506
|
+
return root;
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
test('kitVersion rule matches ghost-server: a non-empty string of at most 64 characters', () => {
|
|
510
|
+
assert.equal(KIT_VERSION_MAX_LENGTH, 64);
|
|
511
|
+
for (const ok of ['0.4.232', 'x', 'v'.repeat(64)]) assert.ok(isKitVersion(ok), ok);
|
|
512
|
+
for (const bad of ['', 'v'.repeat(65), null, undefined, 4, { v: 1 }]) assert.ok(!isKitVersion(bad), JSON.stringify(bad));
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
test('--kit-versions: a JSON object of deck id to a valid kitVersion, else refused whole', () => {
|
|
516
|
+
assert.deepEqual([...parseKitVersions('{"vSNPV096_Qr2":"0.4.232","--1ZCdeKzbuy":"0.4.231"}')], [['vSNPV096_Qr2', '0.4.232'], ['--1ZCdeKzbuy', '0.4.231']]);
|
|
517
|
+
assert.throws(() => parseKitVersions('{nope'), /--kit-versions/);
|
|
518
|
+
assert.throws(() => parseKitVersions('["0.4.232"]'), /JSON object/);
|
|
519
|
+
assert.throws(() => parseKitVersions('{"../x":"0.4.232"}'), /not a deck id/);
|
|
520
|
+
assert.throws(() => parseKitVersions('{"vSNPV096_Qr2":""}'), /vSNPV096_Qr2: kitVersion "" must be/);
|
|
521
|
+
assert.throws(() => parseKitVersions(`{"vSNPV096_Qr2":"${'v'.repeat(65)}"}`), /at most 64/);
|
|
522
|
+
assert.throws(() => parseKitVersions('{"vSNPV096_Qr2":null}'), /must be/);
|
|
523
|
+
assert.equal(parseArgs(['--kit-versions', '/k.json', 'abc']).kitVersions, '/k.json');
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
test('resolveKitVersion: manifest pin, then --kit-versions over the local castle.json, else refused', () => {
|
|
527
|
+
const root = kitRoot({ vSNPV096_Qr2: '0.4.250', tooLong1234: 'v'.repeat(65) });
|
|
528
|
+
try {
|
|
529
|
+
const hub = hubExportManifest('vSNPV096_Qr2');
|
|
530
|
+
const opts = { roots: [root], localFallback: true };
|
|
531
|
+
assert.equal(resolveKitVersion('vSNPV096_Qr2', hub, opts), '0.4.250', 'local castle.json fallback');
|
|
532
|
+
assert.equal(resolveKitVersion('vSNPV096_Qr2', hub, { ...opts, kitVersions: new Map([['vSNPV096_Qr2', '0.4.260']]) }), '0.4.260', '--kit-versions wins over castle.json');
|
|
533
|
+
assert.throws(() => resolveKitVersion('vSNPV096_Qr2', hub, { roots: [root] }), /vSNPV096_Qr2: no kitVersion/, 'no fallback unless asked');
|
|
534
|
+
assert.throws(() => resolveKitVersion('missingDeck1', hubExportManifest('missingDeck1'), opts), /missingDeck1: no kitVersion/);
|
|
535
|
+
assert.throws(() => resolveKitVersion('tooLong1234', hubExportManifest('tooLong1234'), opts), /tooLong1234: kitVersion .* at most 64/, 'a found value is checked too');
|
|
536
|
+
// A manifest that pins (export.mjs) is not overridden, and a disagreeing file is a fault.
|
|
537
|
+
assert.equal(resolveKitVersion('deckAbc123', manifest(), opts), '0.4.232');
|
|
538
|
+
assert.equal(resolveKitVersion('deckAbc123', manifest(), { kitVersions: new Map([['deckAbc123', '0.4.232']]) }), '0.4.232');
|
|
539
|
+
assert.throws(() => resolveKitVersion('deckAbc123', manifest(), { kitVersions: new Map([['deckAbc123', '0.4.1']]) }), /disagree|says 0.4.1, the manifest says 0.4.232/);
|
|
540
|
+
} finally {
|
|
541
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
test('runDecks: a deck with no kitVersion gets no entry and none of its keys go up', async () => withExport(async (root) => {
|
|
546
|
+
const planned = findExportDecks(root).map(({ deckId, dir }) => {
|
|
547
|
+
const ex = readExportDeck(dir);
|
|
548
|
+
return { deckId, title: ex.manifest.title, manifest: ex.manifest, plan: planManifest(ex.manifest, { readShared: ex.readShared }) };
|
|
549
|
+
});
|
|
550
|
+
// Distinct manifests (deckId differs) over the same shared assets.
|
|
551
|
+
const [refusedDeck, okDeck] = planned; // '--1ZCdeKzbuy', 'vSNPV096_Qr2'
|
|
552
|
+
const kitVersions = new Map([['vSNPV096_Qr2', '0.4.232']]);
|
|
553
|
+
|
|
554
|
+
const s3 = fakeS3();
|
|
555
|
+
const lines = [];
|
|
556
|
+
const up = await runDecks(planned, s3, { upload: true, log: (l) => lines.push(l), kitVersions, roots: [], localFallback: true });
|
|
557
|
+
assert.deepEqual(up.entries.map((e) => [e.deckId, e.kitVersion]), [['vSNPV096_Qr2', '0.4.232']], 'no entry for the refused deck, never a null kitVersion');
|
|
558
|
+
assert.deepEqual(up.refused.map((r) => r.deckId), ['--1ZCdeKzbuy']);
|
|
559
|
+
assert.match(up.refused[0].reason, /--1ZCdeKzbuy: no kitVersion/);
|
|
560
|
+
const puts = s3.calls.filter((c) => c[0] === 'put').map((c) => c[1]);
|
|
561
|
+
assert.ok(!puts.includes(refusedDeck.plan.manifestKey), 'the refused deck\'s manifest is not put');
|
|
562
|
+
assert.ok(puts.includes(okDeck.plan.manifestKey));
|
|
563
|
+
assert.ok(!s3.calls.some((c) => c[1] === refusedDeck.plan.manifestKey), 'nor even headed');
|
|
564
|
+
assert.ok(lines.some((l) => /^REFUSED --1ZCdeKzbuy: .*nothing of it uploaded/.test(l)));
|
|
565
|
+
|
|
566
|
+
// Every deck refused: nothing at all goes up.
|
|
567
|
+
const none = fakeS3();
|
|
568
|
+
const r0 = await runDecks(planned, none, { upload: true, roots: [] });
|
|
569
|
+
assert.deepEqual([r0.entries.length, r0.refused.length, none.calls.length], [0, 2, 0]);
|
|
570
|
+
|
|
571
|
+
// Dry run: listed as refused, and no 'would put' line for it.
|
|
572
|
+
const dryLines = [];
|
|
573
|
+
const dry = await runDecks(planned, dryRunS3(), { log: (l) => dryLines.push(l), kitVersions, roots: [] });
|
|
574
|
+
assert.deepEqual(dry.entries.map((e) => e.deckId), ['vSNPV096_Qr2']);
|
|
575
|
+
assert.ok(dryLines.some((l) => /^REFUSED --1ZCdeKzbuy: .*nothing of it would go up/.test(l)));
|
|
576
|
+
assert.ok(!dryLines.some((l) => l.includes(refusedDeck.plan.manifestKey)));
|
|
577
|
+
assert.ok(dryLines.some((l) => l.includes(`would put ${okDeck.plan.manifestKey}`)));
|
|
578
|
+
}));
|
|
579
|
+
|
|
580
|
+
test('planManifest checks every entry naming the same bytes, not only the first', () => {
|
|
581
|
+
const m = manifest();
|
|
582
|
+
m.assets.bench.bytes = glb.length + 1; // same sha/type as scene, another declared size
|
|
583
|
+
assert.throws(() => planManifest(m, { readShared }), /asset bench: \d+ bytes, manifest says \d+/);
|
|
584
|
+
const t = manifest();
|
|
585
|
+
t.assets.bench = { ...t.assets.bench, type: 'png' }; // same sha, another type: its uri no longer matches
|
|
586
|
+
assert.throws(() => planManifest(t, { readShared }), /asset bench: uri/);
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
test('from-export: no symlink anywhere below the export root is followed', () => withExport((root) => {
|
|
590
|
+
const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'nativehub-outside-'));
|
|
591
|
+
try {
|
|
592
|
+
writeHubExport(outside, ['vSNPV096_Qr2']);
|
|
593
|
+
const real = fs.realpathSync(root);
|
|
594
|
+
assert.deepEqual(readUnder(real, ['shared', `${H_PNG}.png`]), png);
|
|
595
|
+
assert.throws(() => readUnder(real, ['..', 'x']), /bad path part/);
|
|
596
|
+
// A symlinked shared/ pointing outside the root.
|
|
597
|
+
fs.renameSync(path.join(root, 'shared'), path.join(root, 'shared-real'));
|
|
598
|
+
fs.symlinkSync(path.join(outside, 'shared'), path.join(root, 'shared'));
|
|
599
|
+
let ex = readExportDeck(path.join(root, 'vSNPV096_Qr2'));
|
|
600
|
+
assert.throws(() => planManifest(ex.manifest, { readShared: ex.readShared }), /shared is a symlink/);
|
|
601
|
+
assert.throws(() => findExportDecks(root), /shared is a symlink/, 'a scan refuses it too');
|
|
602
|
+
fs.rmSync(path.join(root, 'shared'));
|
|
603
|
+
fs.renameSync(path.join(root, 'shared-real'), path.join(root, 'shared'));
|
|
604
|
+
// A symlinked manifest.
|
|
605
|
+
const mf = path.join(root, 'vSNPV096_Qr2', 'manifest.json');
|
|
606
|
+
fs.rmSync(mf);
|
|
607
|
+
fs.symlinkSync(path.join(outside, 'vSNPV096_Qr2', 'manifest.json'), mf);
|
|
608
|
+
assert.throws(() => readExportDeck(path.join(root, 'vSNPV096_Qr2')), /manifest.json is a symlink/);
|
|
609
|
+
// A symlinked deck dir, named directly or found by a scan.
|
|
610
|
+
fs.rmSync(path.join(root, 'vSNPV096_Qr2'), { recursive: true });
|
|
611
|
+
fs.symlinkSync(path.join(outside, 'vSNPV096_Qr2'), path.join(root, 'vSNPV096_Qr2'));
|
|
612
|
+
assert.throws(() => readExportDeck(path.join(root, 'vSNPV096_Qr2')), /vSNPV096_Qr2 is a symlink/);
|
|
613
|
+
assert.throws(() => findExportDecks(root), /vSNPV096_Qr2 is a symlink/);
|
|
614
|
+
// The root's own path may go through a symlink.
|
|
615
|
+
const via = path.join(outside, 'via');
|
|
616
|
+
fs.symlinkSync(root, via);
|
|
617
|
+
ex = readExportDeck(path.join(via, '--1ZCdeKzbuy'));
|
|
618
|
+
assert.equal(ex.root, real);
|
|
619
|
+
assert.ok(planManifest(ex.manifest, { readShared: ex.readShared }).manifestSha256);
|
|
620
|
+
} finally {
|
|
621
|
+
fs.rmSync(outside, { recursive: true, force: true });
|
|
622
|
+
}
|
|
623
|
+
}));
|
|
624
|
+
|
|
625
|
+
test('from-export: imported manifests are validated and every asset reference must resolve', () => withExport(async (root) => {
|
|
626
|
+
const dir = path.join(root, 'vSNPV096_Qr2');
|
|
627
|
+
const ok = readExportDeck(dir);
|
|
628
|
+
assert.deepEqual(importFaults(ok.manifest, ok.dir), [], 'the fixture is a valid manifest');
|
|
629
|
+
const bad = (edit) => { const m = hubExportManifest('vSNPV096_Qr2'); edit(m); return importFaults(m, ok.dir); };
|
|
630
|
+
assert.ok(bad((m) => { m.layers[0].asset = 'gone'; }).some((f) => /layers\[0\]: .*gone/.test(f)));
|
|
631
|
+
assert.ok(bad((m) => { delete m.layers[0].asset; }).some((f) => /layers\[0\]: asset undefined is not in assets/.test(f)), 'a layer must name one');
|
|
632
|
+
assert.ok(bad((m) => { m.avatar.asset = 'gone'; }).some((f) => /avatar/.test(f)));
|
|
633
|
+
assert.ok(bad((m) => { m.sky.zones[0].image = 'gone'; }).some((f) => /sky/.test(f)));
|
|
634
|
+
assert.ok(bad((m) => { m.sky.dome = 'gone'; }).some((f) => /sky.dome/.test(f)));
|
|
635
|
+
assert.ok(bad((m) => { m.characters = [{ id: 'c', position: [0, 0, 0], asset: 'gone' }]; }).some((f) => /characters\[0\]\.asset: asset "gone"/.test(f)), 'any other asset field');
|
|
636
|
+
assert.ok(bad((m) => { m.assets.toString = m.assets.scene; m.layers[0].asset = 'constructor'; }).some((f) => /constructor/.test(f)), 'own keys only');
|
|
637
|
+
assert.ok(bad((m) => { delete m.spawns; }).includes('no spawns'), 'the kit validator runs');
|
|
638
|
+
assert.ok(bad((m) => { m.assets.scene.sha256 = H_PNG; }).length, 'the validator checks files too');
|
|
639
|
+
|
|
640
|
+
// A deck with faults is refused by runDecks: no entry, nothing of it put.
|
|
641
|
+
const m = hubExportManifest('vSNPV096_Qr2');
|
|
642
|
+
m.layers.push({ id: 'extra', asset: 'missing', role: 'scene' });
|
|
643
|
+
const plan = planManifest(m, { readShared: ok.readShared });
|
|
644
|
+
const s3 = fakeS3();
|
|
645
|
+
const r = await runDecks([{ deckId: 'vSNPV096_Qr2', title: 't', manifest: m, plan, faults: importFaults(m, ok.dir) }], s3,
|
|
646
|
+
{ upload: true, kitVersions: new Map([['vSNPV096_Qr2', '0.4.232']]) });
|
|
647
|
+
assert.deepEqual([r.entries.length, r.refused.length, s3.calls.length], [0, 1, 0]);
|
|
648
|
+
assert.match(r.refused[0].reason, /manifest faults: .*missing/);
|
|
649
|
+
}));
|
|
650
|
+
|
|
651
|
+
test('the default prefix keeps every key under the CloudFront-served content-packs/', () => {
|
|
652
|
+
assert.equal(parseArgs(['abc']).prefix, 'content-packs');
|
|
653
|
+
assert.equal(assetKey(DEFAULTS.prefix, H_GLB, 'glb'), `content-packs/nativehub/assets/${H_GLB}.glb`);
|
|
654
|
+
assert.equal(manifestKey(DEFAULTS.prefix, H_GLB), `content-packs/nativehub/manifests/${H_GLB}.json`);
|
|
655
|
+
});
|