feat: add gated CH5 quiver support and unified regression runner
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"""Regression checks for the regression orchestrator's evidence semantics."""
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
spec = importlib.util.spec_from_file_location('xxf_runner', ROOT / 'scripts/test_xxf_all.py')
|
||||
runner = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(runner)
|
||||
|
||||
|
||||
class RunnerTests(unittest.TestCase):
|
||||
def probe(self, text, timeout=5):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
path = Path(folder) / 'probe.py'
|
||||
path.write_text(text)
|
||||
return runner.execute(dict(id='probe', path=str(path), stem='probe', cwd=folder,
|
||||
suite='runner'), Path(folder), timeout)
|
||||
|
||||
def test_assertion_failure_is_failure(self):
|
||||
self.assertEqual(self.probe('assert False')['status'], 'fail')
|
||||
|
||||
def test_top_level_probe_is_distinguished(self):
|
||||
result = self.probe('assert 1 + 1 == 2')
|
||||
self.assertEqual(result['status'], 'pass')
|
||||
self.assertEqual(result['details']['mode'], 'top_level_script_exit_only')
|
||||
|
||||
def test_skip_is_not_pass(self):
|
||||
result = self.probe("import unittest\nclass T(unittest.TestCase):\n @unittest.skip('no device')\n def test_a(self):pass\n")
|
||||
self.assertEqual(result['status'], 'partial')
|
||||
self.assertEqual(result['details']['skip_reasons'], ['no device'])
|
||||
|
||||
def test_timeout(self):
|
||||
self.assertEqual(self.probe('import time\ntime.sleep(10)', .1)['status'], 'timeout')
|
||||
|
||||
def test_premature_success_is_unverified(self):
|
||||
self.assertEqual(self.probe('raise SystemExit(0)')['status'], 'unverified')
|
||||
|
||||
def test_orchestrator_arguments_do_not_leak(self):
|
||||
self.assertEqual(self.probe('import sys\nassert len(sys.argv)==1')['status'], 'pass')
|
||||
|
||||
def test_missing_reference_is_explicitly_blocked(self):
|
||||
jobs = runner.discover()
|
||||
job = next(j for j in jobs if j['path'].endswith('biolog/tests/test_ava2.py'))
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
self.assertEqual(runner.execute(job, Path(folder), 5)['status'], 'blocked')
|
||||
|
||||
def test_uncovered_and_related_pass_never_grant_release(self):
|
||||
features = [dict(id=fid, name=fid, status=dict(implementation='pending')) for fid in ['F03', 'F19']]
|
||||
results = [dict(stem='test_quiver_runtime', id='quiver', status='pass')]
|
||||
mapped = runner.feature_results(features, results)
|
||||
self.assertEqual(mapped[0]['local'], 'not_covered')
|
||||
self.assertEqual(mapped[1]['local'], 'related_tests_pass')
|
||||
self.assertTrue(all(not f['release_ready'] for f in mapped))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -2,6 +2,7 @@
|
||||
// the original locale packs are made: every file COMPRESS (LZO), index LZO + TEA encrypted.
|
||||
//
|
||||
// eterpack_pack <db path without extension> <source dir> <pack prefix, e.g. locale/zh/>
|
||||
// eterpack_pack --read-client <client dir> <registered entry> <new output file>
|
||||
//
|
||||
// Pack names are <prefix><path relative to the source dir>, lowercased with '/' (inlineConvertPackFilename).
|
||||
// An existing <db>.eix/.epk is replaced. The result is reopened read-only and every file read back
|
||||
@@ -30,6 +31,37 @@ static std::vector<char> read_file(const fs::path& path)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// PORT: resolve data through the actual runtime Index/key-fallback path.
|
||||
// Pack-only reads prevent a loose file in the shell cwd from masking a pack.
|
||||
if (argc > 1 && std::strcmp(argv[1], "--read-client") == 0)
|
||||
{
|
||||
if (argc != 5)
|
||||
{
|
||||
std::fprintf(stderr, "usage: %s --read-client <client> <entry> <new output>\n", argv[0]);
|
||||
return 2;
|
||||
}
|
||||
PackSingletons();
|
||||
const auto folder = fs::absolute(fs::path(argv[2]) / "pack");
|
||||
if (!fs::is_regular_file(folder / "Index") || !PackInitialize(folder.string().c_str()))
|
||||
return 1;
|
||||
CMappedFile mapped;
|
||||
LPCVOID data = nullptr;
|
||||
if (!CEterPackManager::Instance().GetFromPack(mapped, argv[3], &data))
|
||||
{
|
||||
std::fprintf(stderr, "registered entry unavailable: %s\n", argv[3]);
|
||||
return 1;
|
||||
}
|
||||
// Exclusive creation: a read-only probe must never overwrite user data.
|
||||
FILE* output = std::fopen(argv[4], "wbx");
|
||||
if (!output)
|
||||
return 1;
|
||||
const bool written = std::fwrite(data, 1, mapped.Size(), output) == mapped.Size();
|
||||
const bool closed = std::fclose(output) == 0;
|
||||
if (!written || !closed)
|
||||
return 1;
|
||||
std::printf("read registered entry %s: %u bytes\n", argv[3], unsigned(mapped.Size()));
|
||||
return 0;
|
||||
}
|
||||
if (argc != 4)
|
||||
{
|
||||
std::fprintf(stderr, "usage: %s <db> <source dir> <pack prefix>\n", argv[0]);
|
||||
|
||||
@@ -942,7 +942,13 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
|
||||
return c.Send(chat)&&c.Send(cmd.c_str(),cmd.size()+1);
|
||||
};
|
||||
const std::string r=std::to_string(request);
|
||||
if(kind=="cap") {if(!reply("MTF1 cap "+r+" 1 63 1700000000"))return Fail(name+": feature cap");}
|
||||
if(kind=="cap") {if(!reply("MTF1 cap "+r+" 1 "+(std::getenv("MT_TEST_QUIVER")?"2111":"63")+" 1700000000"))return Fail(name+": feature cap");}
|
||||
else if(kind=="quiver" && std::getenv("MT_TEST_QUIVER")) {
|
||||
if(!reply("MTF1 begin "+r+" quiver 0 0 0 0 1700000000") || !reply("MTF1 end "+r+" 0"))return Fail(name+": quiver ack");
|
||||
std::uint8_t state[6]={219,0,0,0,0,9};std::uint32_t vid=kMainVID;
|
||||
std::memcpy(state+1,&vid,4);
|
||||
if(!c.Send(state,sizeof(state)))return Fail(name+": quiver state");
|
||||
}
|
||||
else if(kind=="calendar") {
|
||||
if(!reply("MTF1 begin "+r+" calendar 1 0 2 0 1700000000") ||
|
||||
!reply("MTF1 event "+r+" 0 1 1 1700000000 1700003600 0 0 1") ||
|
||||
@@ -976,6 +982,13 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
|
||||
if(!reply("MTF1 end "+r+" "+std::to_string(sent)))return Fail(name+": feature end");
|
||||
}
|
||||
}
|
||||
else if (std::getenv("MT_TEST_QUIVER") && text.rfind("/quiver_test ",0)==0) {
|
||||
unsigned type=0;
|
||||
if(sscanf(text.c_str()+13,"%u",&type)!=1 || (type!=0 && type!=6 && type!=9))return Fail(name+": invalid test quiver");
|
||||
std::uint8_t state[6]={219,0,0,0,0,std::uint8_t(type)};std::uint32_t vid=kMainVID;
|
||||
std::memcpy(state+1,&vid,4);
|
||||
if(!c.Send(state,sizeof(state)))return Fail(name+": test quiver state");
|
||||
}
|
||||
else if (text == "/server_bonuses") {
|
||||
const std::string cmd = "ServerBonuses 200 200 200 200 200 0 200 0";
|
||||
GCChatHead chat = {HDR_GC_CHAT, static_cast<std::uint16_t>(sizeof(GCChatHead) + cmd.size() + 1), 5, 0, 1};
|
||||
|
||||
@@ -445,6 +445,21 @@ int main(int argc, char** argv)
|
||||
CHECK(py("import net\nassert net.IsConnect(), 'disconnected in the game phase'"));
|
||||
|
||||
// Focused batch-pickup regression avoids unrelated legacy economy wire fixtures.
|
||||
if (server && std::getenv("MT_TEST_QUIVER")) {
|
||||
auto type=[] {auto* actor=CPythonCharacterManager::Instance().GetInstancePtr(FakeLoginServer::kMainVID);return actor?int(actor->GetArrowType()):-1;};
|
||||
CHECK(pump_until(8,[&] {return type()==9 || failed();}));
|
||||
CHECK(type()==9 && !failed());
|
||||
for (int expected:{6,0,9}) {
|
||||
CHECK(py("net.SendChatPacket('/quiver_test "+std::to_string(expected)+"')"));
|
||||
CHECK(pump_until(5,[&] {return type()==expected || failed();}));
|
||||
CHECK(type()==expected && !failed());
|
||||
}
|
||||
CHECK(py("import app\napp.Exit()"));
|
||||
pump_until(2,[] {return !PythonBoot::IsAppLooping();});
|
||||
PythonBoot::Stop();
|
||||
std::printf("quiver negotiated packet fixture: %s\n",g_failures?"FAILED":"PASS");
|
||||
return g_failures?1:0;
|
||||
}
|
||||
if (server && std::getenv("MT_TEST_AUTOHUNT_BATCH")) {
|
||||
CHECK(CPythonPlayer::Instance().NEW_GetMainActorPtr());
|
||||
CHECK(CPythonCharacterManager::Instance().GetInstancePtr(FakeLoginServer::kMobVID));
|
||||
|
||||
@@ -35,6 +35,9 @@ class CompatTests(unittest.TestCase):
|
||||
m.Window=type('Window',(Window,),{});m.ImageBox=type('Image',(Image,),{})
|
||||
sys.modules['ui']=m;self.ui=m
|
||||
source=(ROOT/'src/platform/ScriptLib/Ava2UICompatScript.inc').read_text().split('R"PY(',1)[1].rsplit(')PY";',1)[0]
|
||||
# The embedded runtime is Python 2; adapt only its exec statement for this
|
||||
# Python 3 fixture. Native C++ tests run the unmodified runtime script.
|
||||
source=source.replace('exec code in dict','exec(code, dict)')
|
||||
exec(source,{})
|
||||
def tearDown(self):
|
||||
if self.previous is None:sys.modules.pop('ui',None)
|
||||
|
||||
@@ -32,7 +32,7 @@ class Action(Widget):
|
||||
|
||||
# vnum -> (type, subtype, antiflags)
|
||||
ITEMS={11299:(1,0,0),11499:(1,0,0x08|0x10|0x20),12049:(2,0,0x04|0x10|0x20|0x40),8000:(1,6,0),
|
||||
41001:(28,0,0x01),45001:(28,1,0x02),27001:(3,0,0),11259:(2,1,0)}
|
||||
41001:(28,0,0x01),45001:(28,1,0x02),27001:(3,0,0),11259:(2,1,0),8001:(1,9,0)}
|
||||
|
||||
|
||||
class Targets(object):
|
||||
@@ -64,7 +64,7 @@ class PreviewTests(unittest.TestCase):
|
||||
mods['game'].GameWindow=type('GameWindow',(),dict(Open=lambda s:None,Close=lambda s:None))
|
||||
grp=mods['grp'];grp.SetColor=grp.RenderBar=grp.RenderBox=lambda *a:None
|
||||
it=mods['item']
|
||||
for k,v in dict(ITEM_TYPE_WEAPON=1,ITEM_TYPE_ARMOR=2,ITEM_TYPE_COSTUME=28,WEAPON_ARROW=6,ARMOR_BODY=0,
|
||||
for k,v in dict(ITEM_TYPE_WEAPON=1,ITEM_TYPE_ARMOR=2,ITEM_TYPE_COSTUME=28,WEAPON_ARROW=6,WEAPON_QUIVER=9,ARMOR_BODY=0,
|
||||
COSTUME_TYPE_BODY=0,COSTUME_TYPE_HAIR=1,ITEM_ANTIFLAG_FEMALE=0x01,ITEM_ANTIFLAG_MALE=0x02,
|
||||
ITEM_ANTIFLAG_WARRIOR=0x04,ITEM_ANTIFLAG_ASSASSIN=0x08,ITEM_ANTIFLAG_SURA=0x10,
|
||||
ITEM_ANTIFLAG_SHAMAN=0x20).items():setattr(it,k,v)
|
||||
@@ -106,7 +106,7 @@ class PreviewTests(unittest.TestCase):
|
||||
self.assertEqual(spec(12049),('armor',[5,1])) # assassin only
|
||||
self.assertEqual(spec(41001),('armor',[0,5,2,7])) # anti-female costume
|
||||
self.assertEqual(spec(45001),('hair',[4,1,6,3]))
|
||||
for vnum in (8000,27001,11259):self.assertIsNone(spec(vnum)) # arrow, potion, helmet
|
||||
for vnum in (8000,8001,27001,11259):self.assertIsNone(spec(vnum)) # arrow, quiver, potion, helmet
|
||||
self.assertTrue(self.ns['Previewable']('mob',101));self.assertFalse(self.ns['Previewable']('item',27001))
|
||||
|
||||
def test_item_preview_races_and_reset(self):
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
"""Compile the actual client arrow-slot check without invoking the game UI."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
class QuiverClientTests(unittest.TestCase):
|
||||
def test_actual_client_ammunition_gate(self):
|
||||
text = (ROOT/'src/port/UserInterface/PythonPlayerSkill.cpp').read_text()
|
||||
body = text[text.index('bool CPythonPlayer::__HasEnoughArrow()'):text.index('bool CPythonPlayer::__HasItem(')]
|
||||
code = r'''
|
||||
#include <cassert>
|
||||
enum {INVENTORY,c_Equipment_Arrow};
|
||||
struct TItemPos{TItemPos(int,int){}};
|
||||
struct CItemData{
|
||||
enum {ITEM_TYPE_WEAPON=1,WEAPON_ARROW=6,WEAPON_QUIVER=9};
|
||||
int type=ITEM_TYPE_WEAPON,subtype=WEAPON_ARROW;
|
||||
int GetType(){return type;}int GetSubType(){return subtype;}
|
||||
};
|
||||
struct CItemManager{
|
||||
CItemData* item=nullptr;static CItemManager& Instance(){static CItemManager m;return m;}
|
||||
bool GetItemDataPointer(int,CItemData** out){*out=item;return item!=nullptr;}
|
||||
};
|
||||
int errors=0;
|
||||
#define Py_BuildValue(...) nullptr
|
||||
void PyCallClassMemberFunc(void*,const char*,void*){++errors;}
|
||||
struct CPythonPlayer{
|
||||
void* m_ppyGameWindow=nullptr;
|
||||
int GetItemIndex(TItemPos){return 0;}bool __HasEnoughArrow();
|
||||
};
|
||||
''' + body + r'''
|
||||
int main(){
|
||||
CPythonPlayer player;CItemData item;
|
||||
assert(!player.__HasEnoughArrow() && errors==1);
|
||||
CItemManager::Instance().item=&item;
|
||||
assert(player.__HasEnoughArrow());
|
||||
item.subtype=CItemData::WEAPON_QUIVER;assert(player.__HasEnoughArrow());
|
||||
item.subtype=2;assert(!player.__HasEnoughArrow());
|
||||
item.subtype=CItemData::WEAPON_QUIVER;item.type=3;
|
||||
assert(!player.__HasEnoughArrow() && errors==3);
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory(prefix='ch5-quiver-client-') as folder:
|
||||
root = Path(folder)
|
||||
(root/'probe.cpp').write_text(code)
|
||||
subprocess.run(['c++','-std=c++17','-fsanitize=address,undefined',
|
||||
str(root/'probe.cpp'),'-o',str(root/'probe')],check=True)
|
||||
subprocess.run([str(root/'probe')],check=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user