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

45 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""Isolated Windows mailbox/worker fixture; never relinks the mapped game host."""
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'ops'))
if not all(shutil.which(t) for t in ('clang', 'lld-link', 'wine')) or not (ROOT / 'runtime/native-wine-prefix/gateway-private-prefix.json').exists():
print('SKIP: requires local Windows toolchain and private test prefix')
sys.exit(77)
from build_wine_wire import FLAGS, LIBS
from wine_console import run_console
with tempfile.TemporaryDirectory(prefix='gateway-account-memory-') as temporary:
folder = Path(temporary)
obj, exe = folder / 'memory.obj', folder / 'memory.exe'
subprocess.run(['clang', *FLAGS, '-c', str(ROOT / 'tests/native_account_memory_fixture.c'), '-o', str(obj)], check=True)
subprocess.run(['lld-link', '/entry:fixture_start', '/subsystem:console', '/nodefaultlib', '/timestamp:0', '/out:' + str(exe), str(obj), str(LIBS[2]), str(LIBS[3])], check=True)
env = dict(os.environ, WINEPREFIX=str(ROOT / 'runtime/native-wine-prefix'), WINEDEBUG='-all')
for key in ('LD_PRELOAD', 'GW_NATIVE_BOOTSTRAP', 'GW_NATIVE_EXPECTED_EXE', 'GW_NATIVE_REGISTER'):
env.pop(key, None)
result = run_console(['wine', str(exe)], env=env, timeout=15)
# Wine's own startup/IPC failure can return1 before PE entry; only a marker
# emitted by check() proves that an account-worker assertion actually ran.
lines = result.stdout.splitlines()
failures = [line.removeprefix(b'GW_MEMORY_FIXTURE fail=') for line in lines if line.startswith(b'GW_MEMORY_FIXTURE fail=')]
if failures:
if len(failures) != 1 or not failures[0].isdigit() or len(failures[0]) > 3:
raise RuntimeError('Isolated credential fixture emitted malformed assertion metadata')
raise RuntimeError(f'Isolated Windows credential fixture reached PE entry and failed assertion{int(failures[0])}; exit{result.returncode}')
if b'GW_MEMORY_FIXTURE entry' not in lines:
kinds = [label for needle, label in ((b'Operation not permitted', 'operation-not-permitted'),
(b'could not save registry', 'registry-write-unavailable'),
(b'could not connect', 'Wine-IPC-unavailable'),
(b'failed to start', 'Wine-startup-failed'),
(b'Permission denied', 'permission-denied')) if needle.lower() in result.stderr.lower()]
raise RuntimeError(f'Wine helper never reached PE entry (exit{result.returncode}; stderr_bytes={len(result.stderr)}; categories={kinds}); no worker assertion was observed')
if result.returncode or b'GW_MEMORY_FIXTURE complete' not in lines:
raise RuntimeError(f'Windows credential fixture entered but did not complete (exit{result.returncode}); no numbered assertion was captured')
print('Windows credential worker: one-shot erasure, validation/lifecycle failures, old local/file fallback, frozen explicit IPv4 profile,37/38 routing and strict advertised realm/address defaults passed. Synthetic dispatch only; real proof and actual-client tests are separate.')