Files
WoW-Hybrid-gateway/tests/native_model_probe_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

104 lines
7.0 KiB
Python

#!/usr/bin/env python3
"""Original-API probe macros: path lookup may be nil/zero despite a valid ID."""
from pathlib import Path
import shutil
import subprocess
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
from native_model_probe import commands,lookup_commands,actor_path_commands,batch_commands
from native_item_render_test import commands as item_commands
from native_item_metadata_test import source_level_matches
assert source_level_matches(0,dict(level=1,baseLevel=0,effectiveLevel=1))
assert source_level_matches(55,dict(level=55,baseLevel=55,effectiveLevel=55))
assert source_level_matches(55,dict(level=55))
batch=[dict(path='Spells/bloodlust_state_hand.m2',file_data_id=165728),dict(path='Spells/strike_impact_chest.m2',file_data_id=166986)]
phases=batch_commands(batch,'01234567')
assert len(phases)==2 and all(len(row)<=255 and '`'not in row and '~'not in row for phase in phases for row in phase)
assert all('nativeModelBatch' in phase[-1]for phase in phases)
for bad in ([],batch+batch,[dict(batch[0],path='Spells/../escape.m2')],batch+[dict(path='Spells/bad.m2',file_data_id=-1)]):
try:batch_commands(bad,'01234567')
except ValueError:pass
else:raise AssertionError('Invalid model batch accepted before preflight')
for observed in (dict(level=1),dict(level=1,baseLevel=2,effectiveLevel=1),dict(level=1,baseLevel=0),dict(level=1,baseLevel=0,effectiveLevel=2),dict(level=1,baseLevel=False,effectiveLevel=1)):
assert not source_level_matches(0,observed)
for ident in (25,33184,2147483647):
rows=item_commands(ident,'01234567')
assert len(rows)==7 and all(len(row)<=255 and '`'not in row and '~'not in row for row in rows)
assert any('pcall(DressUpItemLink'in row for row in rows)
assert not any('EquipItem'in row or 'UseItem'in row for row in rows)
for ident,run in ((0,'01234567'),(-1,'01234567'),(True,'01234567'),(2147483648,'01234567'),(25,'badnonce')):
try:item_commands(ident,run)
except ValueError:pass
else:raise AssertionError('Unbounded preview input accepted')
for path in ('Spells/Sap_Cast_Base.m2', 'Item/ObjectComponents/Weapon/example.m2',
'Creature/Dragon/onyxiamount.m2'):
for ident in (None, 166761):
rows = commands(path, '01234567', ident)
assert len(rows) == 4 and all(len(row) <= 255 and not any(c in row for c in '`~') for row in rows)
for path, ident in (('Spells/../WowB.m2', None), ('Spells//bad.m2', None),
('Creature/../WowB.m2', None), ('Creature//bad.m2', None),
('Spells/bad.mdx', None), ('/Spells/bad.m2', None),
('Spells/good.m2', True), ('Spells/good.m2', -1)):
try: commands(path, '01234567', ident)
except ValueError: pass
else: raise AssertionError('Unbounded model probe input accepted')
lua = shutil.which('lua')
if lua:
for accepted,loaded,control_file in (('true','true',143077),('false','true',143077),('true','false',143077),('true','true',999)):
rows=actor_path_commands('Item/ObjectComponents/Weapon/example.m2','Item/ObjectComponents/Shield/control.m2',143077,33135,'01234567')
body='''GatewayDiagnosticsSaved={};local calls=0;function GetCVar()return "0"end;function DressUpItemLink()end
local actor={};function actor:SetModelByPath(path)calls=calls+1;return ACCEPTED end
function actor:IsLoaded()return LOADED end;function actor:GetModelFileID()return CONTROL_FILE end
DressUpFrame={ModelScene={GetPlayerActor=function()return actor end}}
'''.replace('ACCEPTED',accepted).replace('LOADED',loaded).replace('CONTROL_FILE',str(control_file))+'\n'.join(r[5:]for r in rows)
allowed=accepted=='true'and loaded=='true'and control_file==143077
body+='\nassert(calls=='+('2'if allowed else'1')+');assert(GatewayDiagnosticsSaved.nativeModelProbe.attempted=='+('true'if allowed else'nil')+')'
subprocess.run([lua,'-'],input=body,text=True,check=True)
rows=actor_path_commands('Item/ObjectComponents/Weapon/example.m2','Item/ObjectComponents/Shield/control.m2',143077,33135,'01234567',numeric_control=True)
assert 'pcall(GWPathActor.SetModelByFileID,GWPathActor,143077)'in rows[2]
assert 'GWPathActor.SetModelByPath'in rows[4]
for value in ('nil','0','-608','143077'):
rows=lookup_commands('Item/ObjectComponents/Weapon/example.m2','01234567')
assert len(rows)==2 and all(len(r)<=255 and not any(c in r for c in '`~')for r in rows)
body='GatewayDiagnosticsSaved={};function GetCVar()return "0"end;function GetFileIDFromPath()return '+value+' end;function CreateFrame()error("lookup-only must not create a model")end\n'
body+='\n'.join(r[5:]for r in rows)+'\nlocal r=GatewayDiagnosticsSaved.nativeModelProbe;assert(r.lookupOK and r.lookupValue=='+value+');assert(r.loadAccepted==nil)'
subprocess.run([lua,'-'],input=body,text=True,check=True)
# Actor transmog records contain methods. Export only nonsecret scalar IDs,
# never object/mixin functions or secret values into the data-only report.
body='''GatewayDiagnosticsSaved={itemRender={samples={[25]={}}}}
local actor={GetItemTransmogInfoList=function()return {{appearanceID=12,Clear=function()end},{appearanceID="SECRET",Init=function()end}}end}
DressUpFrame={ModelScene={GetPlayerActor=function()return actor end}}
function issecretvalue(v)return v=="SECRET"end
'''+ '\n'.join(row[5:]for row in item_commands(25,'01234567')[-2:])+'''
assert(GatewayDiagnosticsSaved.itemRender.samples[25].slots[1]==12)
assert(GatewayDiagnosticsSaved.itemRender.samples[25].slots[2]==nil)
assert(GWPreviewSlots==nil)
'''
subprocess.run([lua,'-'],input=body,text=True,check=True)
for lookup in ('nil', '0', '166761'):
for explicit in (None, 166761):
rows = commands('Spells/Sap_Cast_Base.m2', '01234567', explicit)
# Execute only inert original-API stubs, never a client or service.
body = '''GatewayDiagnosticsSaved={};local loaded=nil
function GetCVar(name)assert(name=="overrideArchive");return "0"end
function GetFileIDFromPath(path)assert(path=="Spells/Sap_Cast_Base.m2");return LOOKUP end
function CreateFrame(kind,name,parent)
assert(kind=="PlayerModel");local model={}
for _,method in ipairs({"SetSize","SetPoint","SetFrameStrata","Show"})do model[method]=function()end end
function model:SetModel(id)loaded=id end
function model:GetModelFileID()return loaded end
return model
end
'''.replace('LOOKUP', lookup) + '\n'.join(row[5:] for row in rows)
expected = explicit if lookup in ('nil', '0') else 166761
body += '\nlocal r=GatewayDiagnosticsSaved.nativeModelProbe\n'
if expected is None:
body += 'assert(r.fileID==nil and loaded==nil and r.loadAccepted==nil)\n'
else:
body += f'assert(r.fileID=={expected} and loaded=={expected} and r.loadAccepted==true)\n'
body += 'assert(r.overrideArchive=="0")\n'
subprocess.run([lua, '-'], input=body, text=True, check=True)
print('PASS: bounded original model macros preserve nil/zero path lookup, explicit native ID fallback, and no archive override.')