const {test}=require('node:test'); const assert=require('node:assert/strict'); const ale=require('../.test-build/ale-store.js'); const llm=require('../.test-build/llm/index.js'); const {runLiveAutonomyTick}=require('../.test-build/autonomy.js'); test('inference preserves intervening observations and cancels after retirement',async()=>{ const now=Date.now(); const bot={id:'hero',name:'Zaku',status:'online',tier:'hero',decisions:0, personality:{activities:['explore']},autonomy:{managed:true},level:5,zone:'Old zone'}; let state={revision:1,bots:[bot],events:[],sequence:0,settings:{hardcore:{enabled:false}}}; const store={load:async()=>structuredClone(state),save:async(s,revision)=>{ assert.equal(revision,state.revision);state=s; }}; ale.recentAleEvents=async()=>[{at:new Date(now).toISOString(),kind:'player.snapshot',payload:{name:'Zaku',isBot:true,level:5,zoneName:'Old zone'}}]; let queued=0,retire=false; ale.queueAleCommand=async()=>{queued++;return {id:'intent'};}; llm.providerForBot=()=>({route:{provider:'ollama',model:'test'},provider:{decide:async()=>{ state.revision++; state.bots[0].level=6;state.bots[0].zone='New zone'; state.bots[0].autonomy.observedAt=new Date(now+1000).toISOString(); if(retire)state.bots[0].status='retired'; return {action:'explore',goal:'Explore nearby',reason:'Curious'}; }}}); assert.equal((await runLiveAutonomyTick(store,{}, {},{now})).ran,true); assert.equal(state.bots[0].level,6);assert.equal(state.bots[0].zone,'New zone'); assert.equal(queued,1); retire=true; assert.equal((await runLiveAutonomyTick(store,{}, {},{now,forceBotId:'hero'})).ran,false); assert.equal(queued,1); }); test('rest requests never enable indefinite stay',()=>{ const {compileLivePlayerbotIntent}=require('../.test-build/autonomy.js'); const source=compileLivePlayerbotIntent('A',{action:'rest',goal:'Recover',reason:'Tired'}); assert.doesNotMatch(source,/\+stay/);assert.match(source,/-stay/);assert.match(source,/GetHealthPct/);assert.match(source,/AzerothAITrainingOverride/); });