import {test} from 'node:test'; import assert from 'node:assert/strict'; import {readFileSync,existsSync} from 'node:fs'; import {getGameDefinition,gameBundleName,gameResourcePath} from '../../YouleNexus/assets/app/composition/game-definitions.ts'; test('selected entry resolves through the injected class lookup without a game registry',()=>{ const definition={key:'third_game'} as any; const names:string[]=[]; assert.equal(getGameDefinition('third_game',name=>{names.push(name);return {definition};}),definition); assert.deepEqual(names,['GameEntry_third_game']); assert.throws(()=>getGameDefinition('third_game',()=>null),/entry/); assert.throws(()=>getGameDefinition('third_game',()=>({definition:{key:'other'}} as any)),/mismatch/); assert.throws(()=>gameBundleName('../other'),/gameKey/); assert.equal(gameBundleName('third_game'),'game-third_game'); }); test('each game root and nested version bundle have explicit ownership and imported entries',()=>{ for(const [directory,key] of [['template','Game_Surface_3'],['erqiwang','erqiwang']]){ const root=new URL('../../YouleNexus/assets/games/'+directory,import.meta.url); const game=JSON.parse(readFileSync(new URL(root.href+'.meta'),'utf8')).userData; const version=JSON.parse(readFileSync(new URL(root.href+'/resources.meta'),'utf8')).userData; assert.equal(game.isBundle,true);assert.equal(game.bundleName,'game-'+key); assert.equal(version.isBundle,true);assert.equal(version.bundleName,'version-'+key); assert.ok(version.priority>game.priority,'nested version assets must belong to the version bundle'); assert.ok(existsSync(new URL(root.href+'/GameEntry.ts.meta')),'entry must be imported by asset-db'); } }); test('private resource paths must remain inside the selected game root',()=>{ assert.equal(gameResourcePath('games/third','games/third/Room.prefab'),'Room'); for(const resource of ['games/other/Room.prefab','games/third/../other/Room.prefab','games/third/Room.scene']){ assert.throws(()=>gameResourcePath('games/third',resource),/resource/); } });