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

86 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""Compile the actual account adapter in isolation; no Wine, sockets or auth."""
import json
import pathlib
import subprocess
import sys
def main():
root = pathlib.Path(__file__).resolve().parents[1]
out = pathlib.Path(sys.argv[1]).resolve()
out.mkdir(parents=True, exist_ok=True)
source = (root / 'native/wine_wire_account.c').read_text()
signature = '__declspec(dllexport) NTSTATUS WINAPI gw_wire_account_transport('
start = source.index(signature)
brace = source.index('{', start)
depth = 1
end = brace + 1
while depth:
depth += (source[end] == '{') - (source[end] == '}')
end += 1
function = source[start:end]
harness = r'''
#include <assert.h>
#include <stdint.h>
#include "wine_wire_abi.h"
#define __declspec(x)
#define WINAPI
typedef int32_t NTSTATUS;
static uint64_t prepared_channel=123;
static struct {int state,cancel;} gw_wire_auth_data={2,0};
static int channel_lock,locked,dispatches;
static void AcquireSRWLockShared(int* lock){assert(lock==&channel_lock && !locked);locked=1;}
static void ReleaseSRWLockShared(int* lock){assert(lock==&channel_lock && locked);locked=0;}
static NTSTATUS gw_wire_dispatch(struct gw_wire_call* call){
assert(locked && !call->login && call->transport==prepared_channel);
assert(call->operation==GW_WIRE_INITIAL_SPELL_IDS || call->operation==GW_WIRE_WORLD_PACKET);
++dispatches;call->result=0;return 0;
}
''' + function + r'''
int main(void){
struct gw_wire_call call={0};
call.abi=GW_WINE_WIRE_ABI;call.size=sizeof(call);call.operation=GW_WIRE_INITIAL_SPELL_IDS;
call.login=999;call.transport=777;
assert(gw_wire_account_transport(&call)==0 && !call.result && dispatches==1);
assert(!call.login && !call.transport && !locked);
/* New read-only operation retains the exact existing channel guard. */
prepared_channel=0;
assert(gw_wire_account_transport(&call)==(NTSTATUS)0xc0000184 && dispatches==1 && !locked);
prepared_channel=123;gw_wire_auth_data.state=1;
assert(gw_wire_account_transport(&call)==(NTSTATUS)0xc0000184 && dispatches==1 && !locked);
gw_wire_auth_data.state=2;gw_wire_auth_data.cancel=1;
assert(gw_wire_account_transport(&call)==(NTSTATUS)0xc0000184 && dispatches==1 && !locked);
gw_wire_auth_data.cancel=0;
call.abi=0;
assert(gw_wire_account_transport(&call)==(NTSTATUS)0xc000000d && dispatches==1 && !locked);
call.abi=GW_WINE_WIRE_ABI;--call.size;
assert(gw_wire_account_transport(&call)==(NTSTATUS)0xc000000d && dispatches==1 && !locked);
call.size=sizeof(call);call.operation=0xffffffff;
assert(gw_wire_account_transport(&call)==(NTSTATUS)0xc000000d && dispatches==1 && !locked);
assert(gw_wire_account_transport(0)==(NTSTATUS)0xc000000d && dispatches==1 && !locked);
call.operation=GW_WIRE_WORLD_PACKET;
assert(gw_wire_account_transport(&call)==0 && dispatches==2 && !call.transport && !locked);
return 0;
}
'''
generated = out / 'account-adapter-fixture.private.c'
generated.write_text(harness)
argv = ['cc', '-std=c11', '-Wall', '-Wextra', '-Wpedantic', '-Werror',
'-I' + str(root / 'native'), str(generated), '-o', str(out / 'account-adapter-fixture')]
record = {'scope': 'actual function extracted unchanged; only channel/dispatch dependencies mocked', 'compile_argv': argv}
with (out / 'account-adapter-test.private.log').open('w') as log:
result = subprocess.run(argv, stdout=log, stderr=subprocess.STDOUT)
record['compile_returncode'] = result.returncode
if result.returncode == 0:
result = subprocess.run([str(out / 'account-adapter-fixture')], stdout=log, stderr=subprocess.STDOUT)
record['test_returncode'] = result.returncode
record['status'] = 'PASS' if record.get('test_returncode') == 0 else 'FAILED'
(out / 'account-adapter-test.private.json').write_text(json.dumps(record, indent=2) + '\n')
print('Initial spell IDs account routing: ' + record['status'])
return 0 if record['status'] == 'PASS' else 1
if __name__ == '__main__':
raise SystemExit(main())