Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

test(assets): a registry-backed loader may not keep a copy of its own

esengine1574c7a34a1f
diff --git a/tools/check-live-asset-rebind.mjs b/tools/check-live-asset-rebind.mjs
index 926695983..1ff7d2964 100644
--- a/tools/check-live-asset-rebind.mjs
+++ b/tools/check-live-asset-rebind.mjs
@@ -30,6 +30,10 @@
* holds by handle, `registry` for one it holds by ref. Two doors to the
* same asset is two answers about who owns it — and the registry door
* exists because publication has to be the slot's, not an era's.
+ * 8. A registry-backed loader only PREPARES. Registering what it parsed into
+ * a subsystem's own map as well is a second copy of "which asset this name
+ * means" — and a module-global one crosses realms, so an editor world and
+ * a play world answered each other's lookups.
*
* Run: node tools/check-live-asset-rebind.mjs (exit 1 on violation)
*/
@@ -177,6 +181,10 @@ for (const file of REBIND_PATH) {
findings.push(`${file}:${code.slice(0, hit.index).split('\n').length} works out who owns an entity's assets for itself — call assetScopeForEntity.`);
}
+// A registry-backed loader writes nothing. `register*`/`publish*` inside one is
+// the mirror this model exists to remove.
+const PUBLISHES = /\b(?:register|publish|unregister|unpublish)[A-Z]\w*\s*\(/;
+
// One door per loader. A registry-backed loader that also published from a
// `load` would be an era writing the registry, which is how a retiring one
// deletes the entry its successor just put under the same name.
@@ -191,6 +199,10 @@ for (const name of readdirSync(LOADERS_DIR).filter((f) => f.endsWith('.ts'))) {
if (registry === direct) {
findings.push(`sdk/src/asset/loaders/${name} has ${registry ? 'BOTH doors' : 'neither door'} — a loader answers with load/unload or with registry, never both.`);
}
+ const writes = registry ? PUBLISHES.exec(code) : null;
+ if (writes) {
+ findings.push(`sdk/src/asset/loaders/${name}:${code.slice(0, writes.index).split('\n').length} publishes into a registry of its own (${writes[0].trim()}) — a registry-backed loader only prepares; the slot holds the era and answers the lookup.`);
+ }
}
if (loaders < 10) {
console.error(`check-live-asset-rebind: found only ${loaders} loader(s) — the parser no longer matches how they are declared.`);