Files
WoW-Hybrid-gateway/tests/world_self_publication_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

59 lines
4.6 KiB
Python

#!/usr/bin/env python3
"""Selected SELF metadata through the real registry and pipe batch boundaries."""
import pathlib, subprocess, tempfile
R=pathlib.Path(__file__).resolve().parents[1]
reg=(R/'native/wine_wire_registry.cpp').read_text(); reg=reg[reg.index(' case GW_WIRE_WORLD_PACKET:if(transport){'):reg.index(' case GW_WIRE_AUTHENTICATED:')]
pipe=(R/'native/wine_pipe_host.c').read_text(); batch=pipe[pipe.index(' count=u32(converted);if(count>1024)'):pipe.index(' /* Queries are generated from actual Turtle create blocks.')]
session=(R/'native/session.cpp').read_text(); state=session[session.index('extern "C" int gw_native_transport_world_self_created('):session.index('extern "C" int gw_native_transport_world_packet(')]
code=r'''
#include <cassert>
#include <cstdint>
#include <cstring>
#include <vector>
#define GW_WORLD_CALL_PHASE_MAGIC 0x47570000u
#define GW_WORLD_SELF_CREATE_QUEUED 2
using LONG=long;
void InterlockedOr(volatile LONG* p,LONG v){*p|=v;}
struct World { unsigned realm=70; bool self_created=false,logout_complete=false; };
struct gw_native_transport { World* world; };
'''+state+r'''
namespace gateway { struct Reader { Reader(std::span<const unsigned char>) {} uint64_t le(unsigned){return 0;} }; }
struct Call { unsigned reserved=0,input_bytes=8,value=0,index=0,realm_id=70,virtual_address=1,capacity=1024,required=0; const unsigned char* input=nullptr; unsigned char* output=nullptr; int result=-1; };
struct SourceCodec { static int serialize(unsigned,const unsigned char*,unsigned,unsigned,unsigned char*,unsigned,unsigned*){return 0;} };
unsigned gw_native_transport_world_call_state(gw_native_transport*,unsigned){return 0x8000001b;}
int gw_native_transport_world_packet(gw_native_transport*,unsigned,unsigned,uint64_t,int(*)(unsigned,const unsigned char*,unsigned,unsigned,unsigned char*,unsigned,unsigned*),unsigned char*,unsigned,unsigned* n){*n=4;return 0;}
constexpr int GW_WIRE_WORLD_PACKET=1;
void invoke(Call& c,gw_native_transport* transport){switch(GW_WIRE_WORLD_PACKET){
'''+reg+r'''
}}
struct gw_pipe_world_control { unsigned ignored=0,queued=0,last_modern=0,last_bytes=0,self_create=0; LONG realm_context_bound=0; } world;
struct Failure { int phase=0,result=0; unsigned count=0,index=0,modern_opcode=0,modern_bytes=0; } gw_wire_world_failure;
unsigned char converted[1024];std::vector<unsigned> seen;bool fail=false;unsigned clears=0;
uint32_t u32(const unsigned char* p){uint32_t x;std::memcpy(&x,p,4);return x;}
int transfer_presentation(uint32_t){return 0;}
int submit(uint32_t op,const unsigned char*,unsigned){seen.push_back(op);assert(world.self_create==0);return fail?-1:0;}
void world_trace(int,unsigned,unsigned){} void clear_transfer_bridge(){++clears;}
int run(Call& c,unsigned source_received){unsigned count,index,at=4,modern,size;auto* w=&world;
'''+batch+r'''
return 0;}
void packet(unsigned n){std::memcpy(converted,&n,4);for(unsigned i=0;i<n;++i){unsigned op=0x5e0000,z=0;std::memcpy(converted+4+i*8,&op,4);std::memcpy(converted+8+i*8,&z,4);}}
int main(){unsigned char clock[8]{};World s;gw_native_transport t{&s}; Call c;c.input=clock;c.output=converted;
assert(!gw_native_transport_world_self_created(nullptr,70)); assert(!gw_native_transport_world_self_created(&t,70));
// An inventory packet by itself cannot publish SELF.
invoke(c,&t);packet(1);c.required=12;assert(run(c,1)==0 && !world.self_create && !world.realm_context_bound && !clears);
// Translator has now observed real SELF; an inventory create precedes it in this batch.
world={};seen.clear();s.self_created=true;invoke(c,&t);packet(2);c.required=20;assert(run(c,1)==0 && seen.size()==2 && world.self_create && (world.realm_context_bound&2) && clears==1);
// SELF with no earlier inventory also publishes after its successful enqueue.
world={};seen.clear();invoke(c,&t);packet(1);c.required=12;assert(run(c,1)==0 && world.self_create && (world.realm_context_bound&2));
// Failed enqueue is not a published SELF. Wrong realm and logout cannot assert it.
world={};seen.clear();fail=true;invoke(c,&t);packet(1);c.required=12;assert(run(c,1)==-1 && !world.self_create);fail=false;
assert(!gw_native_transport_world_self_created(&t,71));s.logout_complete=true;assert(!gw_native_transport_world_self_created(&t,70));
}
'''
code='#include <span>\n'+code
with tempfile.TemporaryDirectory(prefix='gw-world-self-') as d:
p=pathlib.Path(d);(p/'test.cpp').write_text(code)
subprocess.run(['g++','-std=c++20','-Wall','-Wextra','-Werror','-Wno-volatile',str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)
print('Selected SELF publication: staged, direct and enqueue failure passed')