Add native gameplay outcomes, recovery verification, and realm diagnostics
Core tests / core (push) Successful in 40s

This commit is contained in:
Codex
2026-09-22 21:18:32 -04:00
parent 9d586f4c44
commit 290926f33f
18 changed files with 264 additions and 21 deletions
+14
View File
@@ -0,0 +1,14 @@
from pathlib import Path
from lupa import LuaRuntime
l=LuaRuntime();l.execute('''hooks={};timers={};sql={};function AuthDBExecute(s)table.insert(sql,s)end
function RegisterPlayerEvent(id,fn)hooks[id]=fn end
function CreateLuaEvent(fn) table.insert(timers,fn)end
function PrintInfo()end
p={};function p:IsPlayerbot()return true end;function p:GetGUIDLow()return 9 end
human={};function human:IsPlayerbot()return false end
''')
l.execute((Path(__file__).resolve().parents[1]/'ale/azerothai_outcomes.lua').read_text())
l.execute('hooks[32](32,p,nil,3);hooks[54](54,p);hooks[38](38,p);hooks[32](32,human,nil,99);timers[1]()')
assert 'VALUES (9,1,1,1,3,0)' in l.eval('sql[#sql]')
n=l.eval('#sql');l.execute('timers[1]()');assert l.eval('#sql')==n
print('Native counters exclude humans, aggregate quantities and flush once')
+9
View File
@@ -0,0 +1,9 @@
import importlib.util
from pathlib import Path
spec=importlib.util.spec_from_file_location('evidence',Path(__file__).resolve().parents[1]/'scripts/realm-evidence.py')
m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
p=m.normalize_performance({'generatedAt':10,'enabled':True,'fullTickCount':2,'fullTickTotalTime':4000,'metrics':[{'type':'action','rows':[{'name':'move','count':2,'totalTime':3000,'avgTime':1500,'maxTime':2000,'timePerTick':1500}]}]})
assert p['averageTickMs']==2 and p['rows'][0]['averageMs']==1.5
assert m.normalize_performance({'fullTickCount':0})['averageTickMs']==0
assert m.normalize_performance({'fullTickTotalTime':float('nan')})['averageTickMs']==0
print('Native profiler microsecond conversion and malformed measurements passed')
+1
View File
@@ -9,3 +9,4 @@ test('report closes at six UTC, records partial baseline and observed totals',()
test('activity distinguishes stale data and guarded actions from inferred stalls',()=>{const b=bot();assert.equal(activityReason(b,now).label,'Possible stall');b.world.inCombat=true;assert.equal(activityReason(b,now).label,'In combat');b.world.at=now-121;assert.equal(activityReason(b,now).label,'Telemetry delayed');b.world.at=now;b.world.inCombat=false;b.world.casting=true;assert.equal(activityReason(b,now).label,'Casting');b.world.casting=false;b.lastDecision.action='rest';assert.equal(activityReason(b,now).label,'Intends to rest');});
test('pending social events count once after native confirmation',()=>{const s=state();s.community.feed=[{id:'social-1:reply',kind:'conversation',status:'pending',at:new Date(now*1000).toISOString(),names:['A','B']}];const a=observeInsights(s,undefined,now);s.community.feed[0].status='confirmed';const b=observeInsights(s,a.cursor,now+60);assert.equal(b.events.length,1);assert.equal(observeInsights(s,b.cursor,now+120).events.length,0);});
test('enabling failure tracking does not backfill old failed party actions',()=>{const s=state();const a=observeInsights(s,undefined,now);s.community.feed=[{id:'party-old',kind:'party',status:'failed',at:new Date((now-600)*1000).toISOString(),names:['A','B']},{id:'party-new',kind:'party',status:'failed',at:new Date((now+20)*1000).toISOString(),names:['A','B']}];const b=observeInsights(s,a.cursor,now+60);assert.deepEqual(b.events.map(e=>e.id),['social:party-new']);});
+6
View File
@@ -0,0 +1,6 @@
const {test}=require('node:test'),assert=require('node:assert/strict');
const {outcomeChanges,attentionItems}=require('../.test-build/realm-outcomes.js');
const row={guid:1,name:'A',quests:10,abandoned:1,lootEvents:4,lootItems:10,partyKills:2,rewarded:8};
test('outcome baseline excludes history, reports native deltas, handles resets without invented gains',()=>{const first=outcomeChanges([row],undefined,100);assert.equal(first.events.length,0);const next=outcomeChanges([{...row,lootItems:14,rewarded:9}],first.baseline,160);assert.deepEqual(next.events.map(e=>[e.kind,e.amount]),[['lootItems',4],['rewarded',1]]);assert.equal(outcomeChanges(next.baseline.rows,next.baseline,220).events.length,0);assert.equal(outcomeChanges([{...row,lootItems:0}],next.baseline,280).events.length,0);});
test('attention skips false population alarms when roster is stale and prioritizes resource pressure',()=>{const s={bots:[],aleRosterAt:0};const h=[{host:'ubuntu',at:1000,memoryAvailableMB:100,memoryTotalMB:8000,diskFreeGB:20,cpuPercent:10},{host:'windows',at:1000,memoryAvailableMB:2000,memoryTotalMB:16000,diskFreeGB:20,cpuPercent:10}];const a=attentionItems(s,1000,1000,1000,{at:1000,enabled:true},[],h);assert.equal(a[0].key,'memory:ubuntu');assert.equal(a.some(x=>x.key==='population'),false);});
test('resolved old recovery failures do not remain actionable',()=>{const b={id:'a',name:'A',status:'online',autonomy:{managed:true,characterGuid:1},world:{at:1000,stationarySince:990},lastDecision:{action:'quest'}};const a=attentionItems({bots:[b]},1000,1000,1000,null,[{id:1,guid:1,name:'A',at:900,status:'no_progress'}],[]);assert.equal(a.some(x=>x.key.startsWith('recovery:')),false);});
+6 -1
View File
@@ -3,7 +3,7 @@ from lupa import LuaRuntime
code=(Path(__file__).resolve().parents[1]/'ale/azerothai_recovery.lua').read_text()
setup='''
now=1000;os.time=function()return now end;attempts=0;expired=0;last=nil;active=true;player={x=0};ai={};captured={}
function AuthDBExecute(sql) if string.find(sql,'INSERT INTO',1,true) then last=now end end
function AuthDBExecute(sql) table.insert(captured,sql);if string.find(sql,'INSERT INTO azerothai_recovery_log',1,true) then last=now end end
function AuthDBQuery(sql) if string.find(sql,'recovery_log',1,true) then return last and now-last<1800 and {} or nil end;return active and {} or nil end
function GetPlayerByName(n) return n=='Test' and player or nil end
function CreateLuaEvent(fn) tick=fn end
@@ -55,3 +55,8 @@ print('Intent, movement, health progress, active identity and stale input guards
l=new();l.execute('player.group={GetMembers=function()return {{IsPlayerbot=function()return false end}} end,GetMembersCount=function()return 1 end};step(0);step(601);assert(attempts==0)')
l=new();l.execute('player.motion=7;step(0);step(601);assert(attempts==1 and expired==1)')
print('Human group exclusion and stale flight recovery passed')
l=new();l.execute("step(0);step(600);player.x=8;step(30);assert(string.find(captured[#captured], '726573756D6564'))")
l=new();l.execute("step(0);step(600);step(180);assert(string.find(captured[#captured], '6E6F5F70726F6772657373'))")
l=new();l.execute("step(0);step(600);player.dead=true;step(30);assert(string.find(captured[#captured], '756E7665726966696564'))")
print('Recovery outcomes distinguish native progress, no progress, and unavailable residents')