From ab516feb7b1ba304ca7ec84e3e8af844e7f36a43 Mon Sep 17 00:00:00 2001 From: shen <> Date: Sun, 18 Oct 2026 16:43:51 -0700 Subject: [PATCH] Preserve live reconnect endpoints and execute QA commands between frames --- .../2026-10-18-window-lifecycle-qa.md | 8 +++++ audit/history.jsonl | 1 + docs/AVA2-CHANNEL.md | 6 ++++ docs/AVA2-PARITY-PLAN.md | 4 +-- docs/AVA2-SWITCHBOT.md | 12 +++++-- src/host/README.md | 6 ++++ src/host/live_client.cpp | 13 ++++++-- src/host/live_client.h | 2 ++ src/host/main.cpp | 1 + src/host/python_command_file.h | 32 ++++++++++++++++++ src/platform/ScriptLib/LiveEndpointScript.inc | 33 +++++++++++++++++++ src/platform/ScriptLib/PythonBoot.cpp | 2 ++ tests/wiki/test_live_endpoint.py | 32 ++++++++++++++++++ tests/wiki/test_python_command_file.py | 29 ++++++++++++++++ 14 files changed, 175 insertions(+), 6 deletions(-) create mode 100644 src/host/python_command_file.h create mode 100644 src/platform/ScriptLib/LiveEndpointScript.inc create mode 100644 tests/wiki/test_live_endpoint.py create mode 100644 tests/wiki/test_python_command_file.py diff --git a/audit/evidence/2026-10-18-window-lifecycle-qa.md b/audit/evidence/2026-10-18-window-lifecycle-qa.md index e50b8244..4466ada6 100644 --- a/audit/evidence/2026-10-18-window-lifecycle-qa.md +++ b/audit/evidence/2026-10-18-window-lifecycle-qa.md @@ -5,3 +5,11 @@ The scripted reconnect from a QARunner.OnUpdate callback crashed in UI::CWindow: Read and compared CWindow::Update, Clear, DeleteChild and reserve-child removal, plus CWindowManager::DestroyWindow, NotifyDestroyWindow, reserve-deletion drain and Update against the 40250 source. Their update/deletion ordering is unchanged. The test driver invokes login-board focus/order/phase changes inside the window traversal; normal user input is dispatched outside that traversal. This is evidence of an unsafe test/reconnect path, not evidence of a differing port algorithm or a fix. The acceptance driver now performs a process cold start to validate persisted locks. That cold start and server/db restart read back mask 8, material selection 4 and the preserved fourth attribute. In-process scripted reconnect remains unverified and the crash is retained as an open finding; no global parity status is upgraded. + +## Follow-up: frame-boundary commands and endpoint restoration + +The live host now optionally consumes `--py-command-file` between script frames while the fiber is parked. This replaces commands executed from QARunner.OnUpdate; it changes no CWindow/CWindowManager algorithm. Commands are size-bounded and consumed before execution so an error cannot repeat the same mutation every frame. Producers publish using atomic rename. + +A separate reconnect stall was captured with macOS sample: the host was blocked in gethostbyname, called from LoginWindow.Connect after the original LoginWindow.Open replaced the launch endpoint with the packed login configuration. `mt_live_endpoint` now preserves the explicitly selected/last successful endpoint while that original window opens. Manual server selection and the existing explicit channel-switch flow retain ownership of their targets; account credentials are not copied by the module. + +With the new host command boundary and endpoint restoration, the same macOS process completed three logout/login/character-enter cycles against sbtest without a crash or per-cycle address injection. Evidence: build/parity-acceptance-20261018/reconnect-host-pass.json and client-live-endpoint.log. This verifies this scripted reconnect path, not every physical input or arbitrary mutation during CWindow.Update. No 40250 lifecycle parity status is upgraded and no C++ window changes were made. diff --git a/audit/history.jsonl b/audit/history.jsonl index 8b3e7c6e..fd5f386c 100644 --- a/audit/history.jsonl +++ b/audit/history.jsonl @@ -655,3 +655,4 @@ {"date": "2026-10-17", "unit": "UserInterface/PythonPlayerAutoHunt.cpp::__AutoHunt_BuildPath", "action": "user-authorized-extension", "finding": "Live snow floor 1 knockback left the player at (18730.742,22544.762), inside blocked attribute row 225. Exact-start-only exemption rejected every path/attack sample, including monsters 90 units away. Permit only the occupied loaded blocked terrain cell, retaining adjacent blocked cells, scene collision and unloaded-data rejection. AutoHunt is an authorized extension, not a newly claimed 40250 counterpart.", "evidence": ["tests/host/autohunt_navigation_test.cpp", "docs/AVA2-FOLLOWUP-20261016.md"], "remaining": "Live dungeon soak pending; no parity status upgraded. Port-map helper script absent on this branch."} {"time": "2026-10-18T10:49:04.284335+00:00", "event": "platform_fix", "unit": "EterLib/GrpExpandedImageInstance.cpp", "result": "ADAPTED", "reason": "Preserve stage-0 U/V in UI command/sampler path instead of unconditional clamp; repeated Board backgrounds validated on macOS. Aggregate UI remains PARTIAL.", "evidence": ["audit/evidence/2026-10-18-ui-addressing.md", "tests/port/port_grp_resource_test.cpp", "tests/host/ui_sampler_capture_test.cpp"]} {"time": "2026-10-18T17:58:20.857552+00:00", "event": "lifecycle_investigation", "units": ["EterPythonLib/PythonWindow.cpp", "EterPythonLib/PythonWindowManager.cpp"], "finding": "Scripted reconnect during OnUpdate crashed; relevant window lifecycle group matches 40250. No code changes or status upgrades; use cold-start QA and retain reconnect finding.", "evidence": ["audit/evidence/2026-10-18-window-lifecycle-qa.md"]} +{"time": "2026-10-18T23:43:15.072652+00:00", "event": "platform_endpoint_fix", "unit": "host/live_client + ScriptLib/LiveEndpointScript", "finding": "Preserve explicitly selected live endpoint across login reopen; execute optional local QA commands between parked script frames rather than from window traversal. No original CWindow/CWindowManager code changed.", "evidence": ["tests/wiki/test_live_endpoint.py", "tests/wiki/test_python_command_file.py", "audit/evidence/2026-10-18-window-lifecycle-qa.md", "docs/AVA2-SWITCHBOT.md"], "result": "Three same-process relogins and two cross-core map transfers verified on macOS/sbtest; native cross-channel switching remains pending; no global parity status upgraded."} diff --git a/docs/AVA2-CHANNEL.md b/docs/AVA2-CHANNEL.md index c8d37a43..22bef54b 100644 --- a/docs/AVA2-CHANNEL.md +++ b/docs/AVA2-CHANNEL.md @@ -52,3 +52,9 @@ - 副本等地图没有做客户端限制:退出后重新登录由服务端按原规则决定角色位置。 - macOS 桌面客户端没有中文字体,窗口文字显示为 `?`。 - Android 真机测试未做。 + +## 2026-10-18 核实与后续 + +本地现已提取 AVA2 服务端源码,旧文“服务端源码不在本机”已过时。启用的路径是 do_cmd(SCMD_CHANGE_CHANNEL)→3秒事件→CHARACTER::MoveChannel;原生 uisystem.ChangeChannelWindow 发送 /move_channel。另一个 do_change_channel/ChannelSwitch 分支是注释掉的旧代码,不能照它实现。 + +当前 v1 仍是退出重登,故会停止自动洗练。跨核心地图传送已在双测试核心验证 P2P 续洗;跨频道续洗尚未实现。移植实际启用的路径时需适配203的端口布局,不能直接使用 AVA2 写死的100端口步长。 diff --git a/docs/AVA2-PARITY-PLAN.md b/docs/AVA2-PARITY-PLAN.md index 4e5437c7..16a52dda 100644 --- a/docs/AVA2-PARITY-PLAN.md +++ b/docs/AVA2-PARITY-PLAN.md @@ -23,7 +23,7 @@ 原生 uitrack 双页窗口、五个世界首领刷新、地图 357 和原生门票兑换商店已接入 sbtest;已验证真实刷新/传送/实体、八项价格与实际道具兑换。旧副本增加真实冷却字段兼容,但八个副本的任务和入场条件尚未全部替换为 AVA2。提醒持久化冷启动已通过,Android 验收继续进行,详见 [AVA2-TRACK.md](AVA2-TRACK.md)。 -属性锁定已在 sbtest 验证:选第4条、实际消耗、洗练保留锁定值、重复操作拒绝、全测试集群冷重启后读回,以及取消和解锁。实现与边界见 [属性锁定说明](../tools/server/ava2-attr-lock/README.md)。进程内脚本重连发生窗口遍历崩溃,冷启动通过不替代该项;其他玩家/交易/商店锁定提示和物理触控仍未闭合。 +属性锁定已在 sbtest 验证:选第4条、实际消耗、洗练保留锁定值、重复操作拒绝、全测试集群冷重启后读回,以及取消和解锁。实现与边界见 [属性锁定说明](../tools/server/ava2-attr-lock/README.md)。进程内脚本重连的测试命令已移到帧间执行,另修复重新打开登录界面时丢失目标端点,同一进程三次重登通过;其他玩家/交易/商店锁定提示和物理触控仍未闭合。 ## 1. 对齐的含义 @@ -105,7 +105,7 @@ AVA2 功能包头号在当前服务端基本空闲,可以直接沿用: 改动玩家正在用的系统,旧版和新版需要同时切换,并有回滚方案。 -1. 自动洗练(原生实现已部署,纯释放速度自然完成已通过;仍待跨核心续洗和 Android 真机验收)+ 属性锁定(sbtest 已补选择流程和自有装备提示;其他容器/玩家提示待做):SWITCHBOT 窗口类型、CG/GC 171、`new_switchbot` 和 `PythonSwitchbot`、`uiswitchbot`;锁定改成拖 50348/50349 并在物品提示里显示,存储继续用独立表。 +1. 自动洗练(原生实现已部署,纯释放速度自然完成已通过;跨核心换地图续洗已通过;仍待原生跨频道换线和 Android 真机验收)+ 属性锁定(sbtest 已补选择流程和自有装备提示;其他容器/玩家提示待做):SWITCHBOT 窗口类型、CG/GC 171、`new_switchbot` 和 `PythonSwitchbot`、`uiswitchbot`;锁定改成拖 50348/50349 并在物品提示里显示,存储继续用独立表。 2. 批量开箱:`/chest_drop`、滑块、Ctrl + Z、`AutoGiveItemChest`。 3. 批量拾取:CG 235、70002 自动拾取。 4. 世界 Boss / 副本追踪:uitrack。 diff --git a/docs/AVA2-SWITCHBOT.md b/docs/AVA2-SWITCHBOT.md index 6a5000bb..d9e8b45b 100644 --- a/docs/AVA2-SWITCHBOT.md +++ b/docs/AVA2-SWITCHBOT.md @@ -56,7 +56,7 @@ ## 未完成 -- 跨核心换线(P2P 转移)的联机测试:测试环境只有一个核心。 +- 跨核心换地图续洗已通过;跨频道换线仍需从当前退出重登流程改为原生服务端传送。 - 正式服当前版本的实际开始/停止和跨核心续洗验收仍需补齐;2026-10-17 已确认现役 game 含 CSwitchbotManager / switchbot_end,player.item.window 也已有 SWITCHBOT,不能再写成正式服仅有 v1。 - Android 构建和真机测试。 - 属性锁定:他人装备、交易和商店提示同步;物理拖放与 Android 触控验收。 @@ -84,6 +84,14 @@ ## 2026-10-18 纯释放速度自然完成 -macOS 真实客户端连接 sbtest,普通 QA1017 的测试武器(19)起初无释放速度。三个备选方案均只设类型9(释放速度)≥1,未混入攻击速度7。开始后不发送手动 Stop:71084 总数2082→2069,约1.315秒后 active=0、finished=1,最终五条属性含 (9,10)。属性匹配、消耗和自然停止同时成立;不是“已有目标立即完成”测试。证据:build/parity-acceptance-20261018/switchbot-cast-natural.json。验收后物品移回背包,测试轮询窗口隐藏。 +macOS 真实客户端连接 sbtest,普通 QA1017 的测试武器(19)起初无释放速度。所有备选方案均只设类型9(释放速度)≥1,未混入攻击速度7。开始后不发送手动 Stop:71084 总数2082→2069,约1.315秒后 active=0、finished=1,最终五条属性含 (9,10)。属性匹配、消耗和自然停止同时成立;不是“已有目标立即完成”测试。证据:build/parity-acceptance-20261018/switchbot-cast-natural.json。验收后物品移回背包,测试轮询窗口隐藏。 Android APK 已构建并保留数据安装,用户于本轮明确选择“暂时不测手机”,因此手机联机/触控保留未验收。 + +## 2026-10-18 跨核心传送续洗 + +临时将 sbtest 主核心限制为地图1/62,增加同频道的独立测试核心:13040/P2P14040 与13041/P2P14041,后者只载入地图61。正式服配置和二进制未变。QA1017 通过原生追踪传送从地图1→61→62,服务端日志确认两次跨核心连接。 + +开始配置为释放速度20、暴击10、穿透10、动物系20、不死系20,填入两个实际备选;武器第4条 (4,6) 已锁定。两个目标核心进入后 active 均为1,目标表一致,锁定值始终不变;71084总数2069→1811→1595,确认是持续真实洗练。最后主动停止、武器退回159格并解锁,测试集群重启后恢复原 MAP_ALLOW,临时核心关闭,QA位置恢复主城。证据:crosscore-{before,outbound,return,summary,cleanup}.json,以及远端 crosscore/primary-syslog、aux-syslog。 + +这验证的是跨核心换地图。当前换线窗口仍使用退出重登,会按原注销路径停止洗练;不能把该证据计为“跨频道换线续洗”通过。AVA2 的实际 `ENABLE_CHANNEL_CHANGE` 实现在现已提取的 cmd_general.cpp/do_cmd、char.cpp/MoveChannel 和 uisystem.py/ChangeChannelWindow,后续需移植服务端换线及原生窗口。 diff --git a/src/host/README.md b/src/host/README.md index af8f4b5c..0be655e8 100644 --- a/src/host/README.md +++ b/src/host/README.md @@ -187,3 +187,9 @@ The cache includes every specialization value, while alpha reference, fog and te `--generic-shaders` / `MT_GENERIC_SHADERS=1` disables specialization for rendering comparisons. Android Adreno 512 starts in 30 FPS saver mode when no frame-rate preference exists; saved preferences and test overrides take priority. See [Mi 8 Lite measurements](../../docs/XIAOMI8LITE-ADAPTATION-20260930.md). + +### Local QA commands between frames + +`--py-command-file /absolute/path/command.py` optionally consumes local Python commands between script frames, while the script fiber is parked. Publish a complete file with atomic rename. Commands are removed before execution, including on a Python error; files over 1 MiB are rejected. This is an explicit development hook like `--py-exec`, disabled when omitted. Do not execute login/focus/phase changes from a test window's `OnUpdate`: those callbacks run during the native window-list traversal. + +When reopening login, the selected live endpoint is retained instead of the packed legacy login address. A later manual server selection or explicit channel change still selects its own target; the successful game entry becomes the saved endpoint. No credentials are stored by this adapter. diff --git a/src/host/live_client.cpp b/src/host/live_client.cpp index fa2845cb..11ec9cf3 100644 --- a/src/host/live_client.cpp +++ b/src/host/live_client.cpp @@ -7,6 +7,7 @@ #include "host_util.h" #include "native_audio.h" #include "perf_log.h" +#include "python_command_file.h" #include "texture_decode.h" #include "ui_scale.h" #include "ui_quality.h" @@ -40,6 +41,7 @@ namespace mt_host { // --py-exec: a test hook run once the auto-login run reaches the GameWindow (or, with --login-screen, // once the LoginWindow is up). std::string g_py_exec_after_login; +std::string g_py_command_file; // --perf-log / MT_PERF_LOG=1: src/host/perf_log.h. bool g_perf_log = false; @@ -236,7 +238,7 @@ int run_live_client( std::snprintf( conn_cmd, sizeof(conn_cmd), - "_stream.SetConnectInfo('%s', %d, '%s', %d)\n" + "__import__('mt_live_endpoint').Configure(_stream, '%s', %d, '%s', %d)\n" "_w = _stream.curPhaseWindow\n" "_w._LoginWindow__OpenServerBoard()", server_host.c_str(), @@ -257,7 +259,7 @@ int run_live_client( std::snprintf( login_cmd, sizeof(login_cmd), - "_stream.SetConnectInfo('%s', %d, '%s', %d)\n" + "__import__('mt_live_endpoint').Configure(_stream, '%s', %d, '%s', %d)\n" "_w = _stream.curPhaseWindow\n" "_w._LoginWindow__OpenLoginBoard()\n" "_w.idEditLine.SetText('%s')\n" @@ -458,6 +460,13 @@ int run_live_client( } }; while ((frames == 0 || completed < frames) && renderer.poll(true) && PythonBoot::IsAppLooping()) { + // The script fiber is parked here. UI callbacks can change focus/order/phase safely before traversal. + if (!g_py_command_file.empty()) { + std::string command_error; + if (!consume_python_command_file(g_py_command_file,py_exec,command_error) && !command_error.empty()) + std::cerr << command_error << '\n'; + if (!PythonBoot::IsAppLooping()) break; + } apply_policy(); save_ui_height_if_changed(); double pace_ms = 0.0; diff --git a/src/host/live_client.h b/src/host/live_client.h index 0a9c5260..eede776d 100644 --- a/src/host/live_client.h +++ b/src/host/live_client.h @@ -10,6 +10,8 @@ class VulkanWindow; // --py-exec: a test hook run once the auto-login run reaches the GameWindow (or, with --login-screen, // once the LoginWindow is up). extern std::string g_py_exec_after_login; +// --py-command-file: optional local QA commands executed while the script fiber is parked. +extern std::string g_py_command_file; // --perf-log / MT_PERF_LOG=1: src/host/perf_log.h. extern bool g_perf_log; diff --git a/src/host/main.cpp b/src/host/main.cpp index 51c6cb10..51f71ebd 100644 --- a/src/host/main.cpp +++ b/src/host/main.cpp @@ -137,6 +137,7 @@ int main(int argc, char** argv) { else if (arg == "--show-fps") show_fps = true; #ifdef MT_NATIVE_HAS_LIVE_CLIENT else if (arg == "--py-exec" && i+1 < argc) g_py_exec_after_login = argv[++i]; + else if (arg == "--py-command-file" && i+1 < argc) g_py_command_file = argv[++i]; else if (arg == "--perf-log") g_perf_log = true; else if (arg == "--fps-cap" && i+1 < argc) g_fps_cap = std::max(0, std::stoi(argv[++i])); else if (arg == "--refresh-rate" && i+1 < argc) g_refresh_rate = std::max(0, std::stoi(argv[++i])); diff --git a/src/host/python_command_file.h b/src/host/python_command_file.h new file mode 100644 index 00000000..155142d5 --- /dev/null +++ b/src/host/python_command_file.h @@ -0,0 +1,32 @@ +#pragma once +// Optional local QA input, consumed between script frames, never from a window OnUpdate callback. +#include +#include +#include + +namespace mt_host { +template +bool consume_python_command_file(const std::string& path, Execute execute, std::string& error) { + if (path.empty()) return true; + std::error_code ec; + const bool exists=std::filesystem::exists(path,ec); + if (ec) { error="cannot inspect Python command file";return false; } + if (!exists) return true; + const auto size=std::filesystem::file_size(path,ec); + if (ec) { error="cannot stat Python command file";return false; } + if (size>1024*1024) { + std::filesystem::remove(path,ec); + error="Python command file exceeds 1 MiB";return false; + } + std::ifstream in(path,std::ios::binary); + if (!in) { error="cannot read Python command file";return false; } + std::string code(static_cast(size),'\0'); + if (size && !in.read(&code[0],static_cast(size))) { + error="incomplete Python command file";return false; + } + in.close(); + // A failed command must not execute again on the next frame. Producers publish with atomic rename. + if (!std::filesystem::remove(path,ec) || ec) { error="cannot consume Python command file";return false; } + return execute(code); +} +} diff --git a/src/platform/ScriptLib/LiveEndpointScript.inc b/src/platform/ScriptLib/LiveEndpointScript.inc new file mode 100644 index 00000000..2dfd7bd5 --- /dev/null +++ b/src/platform/ScriptLib/LiveEndpointScript.inc @@ -0,0 +1,33 @@ +// PORT: keep the explicitly selected live endpoint when the original login UI reopens. +static const char c_szLiveEndpointScript[] = R"PY( +import game,introLogin,networkModule,mt_channel +_set=networkModule.MainStream.SetConnectInfo +_login=introLogin.LoginWindow.Open +_game=game.GameWindow.Open + +def Configure(stream,host,port,account_host,account_port): + stream._portLiveEndpoint=(host,port,account_host,account_port) + _set(stream,host,port,account_host,account_port) + +def SetConnectInfo(self,host,port,account_host=0,account_port=0): + saved=getattr(self,'_portLiveEndpoint',None) + if saved and getattr(self,'_portRestoreLiveEndpoint',False):host,port,account_host,account_port=saved + return _set(self,host,port,account_host,account_port) + +def LoginOpen(self): + stream=self.stream + # An explicit channel change owns its new target; ordinary logout retains the last successful endpoint. + stream._portRestoreLiveEndpoint=not mt_channel.g_switcher.Busy() + try:return _login(self) + finally:stream._portRestoreLiveEndpoint=False + +def GameOpen(self): + result=_game(self) + stream=self.stream + stream._portLiveEndpoint=(stream.addr,stream.port,stream.account_addr,stream.account_port) + return result + +networkModule.MainStream.SetConnectInfo=SetConnectInfo +introLogin.LoginWindow.Open=LoginOpen +game.GameWindow.Open=GameOpen +)PY"; diff --git a/src/platform/ScriptLib/PythonBoot.cpp b/src/platform/ScriptLib/PythonBoot.cpp index d00d8d8d..bcc5cbdb 100644 --- a/src/platform/ScriptLib/PythonBoot.cpp +++ b/src/platform/ScriptLib/PythonBoot.cpp @@ -1042,6 +1042,7 @@ namespace PythonBoot #include "RingsScript.inc" #include "ItemActionsScript.inc" #include "AttrLockScript.inc" +#include "LiveEndpointScript.inc" #include "MinimapOuterRingScript.inc" #ifdef MT_HAS_MESHPORT #include "MeshPortScript.inc" @@ -1146,6 +1147,7 @@ bool RunMainScript(const char* lpCmdLine, std::string* error) install_script_module("mt_rings", c_szRingsScript); install_script_module("mt_item_actions", c_szItemActionsScript); install_script_module("mt_attr_lock", c_szAttrLockScript); + install_script_module("mt_live_endpoint", c_szLiveEndpointScript); install_script_module("mt_minimap_buttons", c_szMinimapOuterRingScript); if (g_touch_input) install_script_module("mt_mobile_hud", c_szMobileHUDScript); diff --git a/tests/wiki/test_live_endpoint.py b/tests/wiki/test_live_endpoint.py new file mode 100644 index 00000000..d80193e2 --- /dev/null +++ b/tests/wiki/test_live_endpoint.py @@ -0,0 +1,32 @@ +"""Reopening the legacy login board must not replace the explicit live endpoint.""" +import unittest,types,sys +from pathlib import Path +class LiveEndpointTest(unittest.TestCase): + def setUp(self): + self.previous={};self.mods={n:types.ModuleType(n) for n in ('game','introLogin','networkModule','mt_channel')};m=self.mods + class Stream: + def SetConnectInfo(self,h,p,a=0,ap=0):self.addr,self.port,self.account_addr,self.account_port=h,p,a,ap + class Login: + def Open(self):self.stream.SetConnectInfo('legacy.invalid',13000,'legacy.invalid',11000) + m['networkModule'].MainStream=Stream;m['introLogin'].LoginWindow=Login + m['game'].GameWindow=type('GameWindow',(),{'Open':lambda self:7}) + self.busy=False;m['mt_channel'].g_switcher=types.SimpleNamespace(Busy=lambda:self.busy) + for n,mod in m.items():self.previous[n]=sys.modules.get(n);sys.modules[n]=mod + self.ns={};source=(Path(__file__).resolve().parents[2]/'src/platform/ScriptLib/LiveEndpointScript.inc').read_text().split('R"PY(',1)[1].rsplit(')PY";',1)[0];exec(source,self.ns) + self.stream=Stream();self.login=Login();self.login.stream=self.stream + def tearDown(self): + for n,old in self.previous.items(): + if old is None:sys.modules.pop(n,None) + else:sys.modules[n]=old + def test_explicit_endpoint_survives_login_open(self): + self.ns['Configure'](self.stream,'192.0.2.1',13040,'192.0.2.2',11040);self.login.Open() + self.assertEqual((self.stream.addr,self.stream.port,self.stream.account_addr,self.stream.account_port),('192.0.2.1',13040,'192.0.2.2',11040)) + self.assertFalse(self.stream._portRestoreLiveEndpoint) + def test_manual_selection_and_explicit_channel_change_remain_allowed(self): + self.ns['Configure'](self.stream,'192.0.2.1',13040,'192.0.2.1',11040) + self.stream.SetConnectInfo('192.0.2.3',13050,'192.0.2.3',11050) + game=self.mods['game'].GameWindow();game.stream=self.stream;self.assertEqual(game.Open(),7) + self.login.Open();self.assertEqual(self.stream.port,13050) + self.busy=True;self.login.Open();self.assertEqual(self.stream.addr,'legacy.invalid') + def test_original_default_when_no_endpoint_selected(self): + self.login.Open();self.assertEqual(self.stream.addr,'legacy.invalid') diff --git a/tests/wiki/test_python_command_file.py b/tests/wiki/test_python_command_file.py new file mode 100644 index 00000000..13e43903 --- /dev/null +++ b/tests/wiki/test_python_command_file.py @@ -0,0 +1,29 @@ +"""Commands are consumed once, outside the UI callback which caused the reconnect crash.""" +from pathlib import Path +import tempfile,subprocess,unittest +ROOT=Path(__file__).resolve().parents[2] +class CommandFileTest(unittest.TestCase): + def test_consumption_and_failure(self): + code=r''' +#include "python_command_file.h" +#include +int main(){ + std::string err;int calls=0; + auto run=[&](const std::string& c){++calls;assert(c=="test()");return true;}; + assert(mt_host::consume_python_command_file("",run,err) && calls==0); + assert(mt_host::consume_python_command_file("command.py",run,err) && calls==0); + {std::ofstream f("command.py");f<<"test()";} + assert(mt_host::consume_python_command_file("command.py",run,err) && calls==1); + assert(mt_host::consume_python_command_file("command.py",run,err) && calls==1); + {std::ofstream f("command.py");f<<"fail()";} + assert(!mt_host::consume_python_command_file("command.py",[&](const std::string&){++calls;return false;},err)); + assert(!std::filesystem::exists("command.py") && calls==2); + {std::ofstream f("command.py");f<