const {test}=require('node:test'); const assert=require('node:assert/strict'); const {compileAleOperatorRequest,wrapAleCommand,ALE_SURFACE}=require('../.test-build/ale.js'); test('ALE command lane compiles server commands without raw execution',()=>{ const source=compileAleOperatorRequest({kind:'command',command:'server info'},false); assert.match(source,/RunCommand/); assert.match(source,/server info/); }); test('ALE typed calls compile global player and playerbot AI methods',()=>{ assert.match(compileAleOperatorRequest({kind:'global',method:'SendWorldMessage',args:['Hello']},false),/SendWorldMessage/); assert.match(compileAleOperatorRequest({kind:'player',player:'Zaku',method:'GetHealth'},false),/GetPlayerByName/); assert.match(compileAleOperatorRequest({kind:'playerbotAI',player:'Zaku',method:'DoSpecificAction',args:['follow']},false),/GetBotAI/); }); test('ALE method names are identifier-only',()=>{ assert.throws(()=>compileAleOperatorRequest({kind:'global',method:'RunCommand); os.execute("x") --'},false),/Invalid ALE method name/); }); test('raw ALE execution is disabled unless explicitly enabled',()=>{ assert.throws(()=>compileAleOperatorRequest({kind:'raw',source:'return GetPlayerCount()'},false),/disabled/); assert.equal(compileAleOperatorRequest({kind:'raw',source:'return GetPlayerCount()'},true),'return GetPlayerCount()'); }); test('wrapped ALE command reports completion through the bridge callback',()=>{ const source=wrapAleCommand('11111111-1111-4111-8111-111111111111','return 7'); assert.match(source,/AzerothAIComplete/); assert.match(source,/return 7/); }); test('surface inventory includes every documented ALE class family',()=>{ assert.equal(ALE_SURFACE.gameClasses.length,30); assert.equal(ALE_SURFACE.playerbotClasses.length,7); assert.equal(ALE_SURFACE.modelAccess,'none'); }); test('snapshot batch saves once and does not commit a partial invalid roster',async()=>{ const {applyAuthoritativeAleSnapshots}=require('../.test-build/service.js'); const {seed}=require('../.test-build/seed.js'); let state=seed(),writes=0; const store={load:async()=>structuredClone(state),save:async(s,r)=>{assert.equal(r,state.revision);writes++;state=s;}}; await applyAuthoritativeAleSnapshots(store,[{roster:true,observedAt:100,characterGuids:[]},{roster:true,observedAt:101,characterGuids:[]}]); assert.equal(writes,1);assert.equal(state.aleRosterAt,101); await assert.rejects(()=>applyAuthoritativeAleSnapshots(store,[{roster:true,observedAt:102,characterGuids:[]},{roster:true,observedAt:103,characterGuids:[-1]}])); assert.equal(writes,1);assert.equal(state.aleRosterAt,101); });