diff --git a/README.md b/README.md index 574e25e..2e0614e 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,40 @@ codex mcp add limbus --env PYTHONUTF8=1 -- D:\lc-mcp\vendor\aalc\.venv\Scripts\p 部分 Unity 界面仍读取系统指针位置,实测标题页按钮需使用 `window_move`。 战斗按键有按下/释放间隔;隐藏启动后可用 `show_game_background` 恢复渲染。 +## 可选:任务流使用罗技驱动鼠标输入 + +驱动接入代码已随仓库提交:`lc_mcp/driver_input.py`、`lc_mcp/aalc_patches.py`、 +`lc_mcp/aalc_task.py`,回归测试在 `tests/test_driver_input.py`。 +**仓库不包含 `logitech.driver.dll`、罗技驱动安装包或 `logitech.test.py`。** +需要在 Windows 目标机安装配套驱动并提供 DLL;仅拉取本仓库不能启用这套输入。 + +在启动 MCP 服务的进程环境中设置(路径替换为本机实际位置): + +```powershell +$env:LCP_DRIVER_INPUT = '1' +$env:LCP_LOGITECH_DLL = 'E:\罗技键鼠驱动\logitech.driver.dll' +# 可选,目录需已存在: +$env:LCP_DRIVER_TRACE = "$env:USERPROFILE\lc_mcp\driver-input.log" +``` + +`LCP_DRIVER_INPUT` 默认关闭,DLL 路径未设置时默认使用上面的 E 盘路径。 +服务已经运行时,需要让服务以这些环境变量重新启动;只给 SSH bridge 设置无效。 +任务子进程必须在物理 console 会话内,且关闭“提高指针精确度”。预检失败会记录原因, +继续使用原输入后端,不修改系统设置。驱动模式会移动真实系统光标并尝试激活游戏; +激活或坐标转换失败时拒绝本次点击。 + +接管范围是 `run_task` 的鼠标点击(含空白点击、`all` 和游戏重启后的点击)。 +模拟器不接管;拖拽、滚动、键盘以及 MCP 的独立 `click` 工具仍使用原后端。 +当前回归验证覆盖软件接线和异常处理,DLL、实际驱动及游戏响应需在 Windows 实机核验。 + +任务运行期间按 **F12** 急停,可用 `LCP_KILL_KEY` 改成 `f11`、`pause` 等键名。 +急停会终止任务子进程,保留游戏窗口;`task_status` 返回 `stopped`、退出码 `130`。 +刷取循环检测到用户停止后结束本轮,不再导航、升级或重试。急停前会尝试释放驱动 +按住的鼠标按钮,清理超过 250 毫秒仍强制退出;硬退出留下的临时配置恢复文件由 +`stop_task` 或下一次 `run_task` 处理。热键监听依赖 AALC 的 `pynput`,安装失败会写日志; +也可从 MCP 调用 `stop_task`,或按 Ctrl+Alt+Del 打开任务管理器终止任务进程。 +此热键只覆盖 `run_task` 子进程,不覆盖独立运行的合成、升级脚本。 + ## 工具 | 工具 | 说明 | @@ -95,7 +129,56 @@ codex mcp add limbus --env PYTHONUTF8=1 -- D:\lc-mcp\vendor\aalc\.venv\Scripts\p `state` 只反映任务子进程的退出码。AALC 在单次战斗失败(例如日志里的 `超出最大尝试次数,未能进入战斗`)后仍会继续跑完并正常退出,所以 `task_status` -会把日志尾部的 `[ERROR]`/异常行放进 `errors` 字段:**看到 `succeeded` 也要先看 `errors`。** +会扫描整份任务日志,把最后 3 条 `[ERROR]`/异常行放进 `errors` 字段: +**看到 `succeeded` 也要先看 `errors`。** 任务退出后的首次查询会缓存扫描结果,后续查询不再扫描日志。 + +任务运行中如果 `task_status` 带 `stall` 字段,说明 AALC 在原地空转(例如选中了空队伍, +编队人数检查一直刷屏)。它不会自己报错退出,应当 `stop_task` 后重跑。 + +### 任务进程里的保护 + +`run_task` 启动的任务子进程在调用 AALC 之前会做三件事,都不改 `vendor/aalc` 源码: + +- **配置预检**:发现下列问题就直接拒绝启动(退出码 3,原因写在 `errors` 里): + - 镜牢队伍的 `sinner_order` 全是 0:这会让 AALC 选出空队伍,然后无限重试编队; + - `set_lunacy_to_enkephalin` 不为 0:体力不足时会花狂气换体力。确需使用时设 `LCP_ALLOW_LUNACY=1`; + - `set_win_size` 加上标题栏后放不进当前桌面:窗口会被压扁成非 16:9。 +- **队伍名精确匹配**:AALC 按子串找队伍,`TEAMS #1` 会命中 `TEAMS #10`。补丁要求编号完全相同。 +- **窗口比例守护**:每 15 秒检查一次客户区。RDP 重连后窗口被拉伸时,自动调回 `set_win_size` 对应的 16:9 尺寸。 + +## 无人值守 + +有两套独立的自动化,按需要各自启用: + +### 1. 刷取循环(打关卡) + +`scripts/auto_cycle.py` 每次跑一轮,流程是:刷材料(daily)→ 镜牢(`--mirror N`)→ 把队内人格升级、同步到 `--target`。 +AALC 卡死时,脚本会停掉任务并重跑一次。每轮在 `~/lc_mcp/cycles/` 写一份 `cycle_*.log` 和一份 `cycle_*.json` 报告。 + +```powershell +# 先手动跑一轮确认 +vendor\aalc\.venv\Scripts\python.exe scripts\auto_cycle.py --mirror 1 +# 再注册计划任务: 每 1 分钟的会话看门狗 + 每 N 小时一轮 +powershell -ExecutionPolicy Bypass -File scripts\install_unattended.ps1 -EveryHours 2.5 -Mirror 1 +``` + +### 2. 只需挂机攒模块(不打任何关卡) + +`scripts/convert_modules.py` 到点自己启动游戏 → 把体力合成为模块 → 关掉游戏。 +每 4 小时一轮,用 `scripts/install_convert_task.ps1` 注册。 + +```powershell +vendor\aalc\.venv\Scripts\python.exe scripts\convert_modules.py # 手动跑一次 +powershell -ExecutionPolicy Bypass -File scripts\install_convert_task.ps1 -EveryHours 4 +``` + +看历史:`python scripts/modules_status.py` + +**⚠️ 挂机值守前先读 [`docs/WATCH.md`](docs/WATCH.md)** —— 那里记着环境事实、 +界面坐标、狂气的三道防线、六种已知失败模式及处置,以及几条踩过的坑 +(比如 OCR 会把 `LUNACY` 读成 `UNACY`,曾让整条狂气防线静默失效)。 + +`scripts/levelup.py` 和 `auto_cycle.py` 里的坐标都按 1600×900 客户区书写,运行时会按实际客户区大小缩放。 ## 环境变量 @@ -104,6 +187,9 @@ codex mcp add limbus --env PYTHONUTF8=1 -- D:\lc-mcp\vendor\aalc\.venv\Scripts\p | `AALC_DIR` | `vendor/aalc` | 使用其他位置的 AALC 源码 | | `LCP_PORT` | 8765 | 服务/bridge 端口 | | `LCP_KEEP_SHOTS` | 30 | 截图保留张数 | +| `LCP_ALLOW_LUNACY` | 未设置 | 设为 `1` 时允许预检放行 `set_lunacy_to_enkephalin` 不为 0 的配置 | +| `LCP_KILL_KEY` | `f12` | 任务子进程的急停键,如 `f11` / `pause` | +| `LC_PY` | 当前解释器 | `levelup.py`/`auto_cycle.py` 调用 MCP 用的 Python | ## 开发 / 测试 @@ -130,7 +216,7 @@ vendor\aalc\.venv\Scripts\python.exe -X utf8 scripts\jev_client.py ⛔ **第 3 道防线曾经整条哑掉**(2026-10-16 发现)。OCR 把标签 `LUNACY` 读成 +> `UNACY`(首字母被吃掉),而代码写的是 `'LUNACY' in text` —— `UNACY` 不包含 +> `LUNACY`,于是每次都被判成"读不到",静默跳过比对。 +> **同屏的体力读数一直正常**,所以只看日志很容易以为是画面没渲染好。 +> 现在认词根 `NACY`,并在标签完全读不出时按位置兜底(底栏 y 775~815、x<700 +> 最靠左的短文本)。 +> +> 教训:**"读不到 → 跳过"这种降级路径,必须能看出它到底跑没跑过。** + +## 五、环境事实(2026-10-16 核实) + +* **系统不会睡眠**:`STANDBYIDLE` AC/DC 均为 0;近 3 天无睡眠事件;已连续运行 62.4 小时 +* 磁盘:C: 55 GB 可用,D: 138 GB 可用 +* 网络:直连可用(`ProxyEnable=0`,Clash 6789 未运行)。Steam 商店页超时属区域限制, + 不影响游戏 —— 游戏自己 `CONNECTING` 后能进主界面 +* Steam:有自启项;实测启动游戏 exe 会自己把 Steam 拉起来 +* 会话:`console` 会话存活;断线会被 `LcKeepDisplay` 在 1 分钟内挂回 +* **今天断线 2 次**(09:48、10:30),看门狗两次都成功挂回 —— 断线不是小概率, + 所以 `ensure_display()` 那层自检是必要的 + +### 关键配置(必须保持,改前先备份到 `~/lc_mcp/config.yaml.bak-<日期>`) + +| 配置项 | 值 | 为什么不能动 | +|---|---|---| +| `set_lunacy_to_enkephalin` | `0` | AALC 从不购买狂气 —— 防线最底层 | +| `daily_task` | `false` | AALC 层面也不跑日常本;就算被误触发也只会跑空 | +| `set_win_size` | `900` | 1600x900,模板匹配的前提(720 会让识别退化) | +| `win_input_type` | `window_move` | 点击方式,换别的 Unity 会忽略 | + +存档备份:`~/lc_mcp/config.yaml.bak-20261013` + +## 六、任务配置与时间预算 + +`LcMCPConvertModules` 的动作与设置(2026-10-16 逐项核实): + +``` +Execute : D:\lc-mcp\vendor\aalc\.venv\Scripts\pythonw.exe +Arguments : -X utf8 "D:\lc-mcp\scripts\convert_modules.py" +WorkingDir : D:\lc-mcp +LogonType : Interactive # 会话断开(不是注销)时仍在跑 +RunLevel : Limited # 非提权 +多实例 : IgnoreNew # 不会和上一轮重叠 +时间上限 : PT15M +错过就补跑 : True +Interval : PT4H # 10:03 / 14:03 / 18:03 / 22:03 / 02:03 / 06:03 +``` + +**时间预算**(最坏情况加起来仍在上限内): + +| 阶段 | 上限 | +|---|---| +| `launch_game` 等进程出现 | 240 s | +| `wait_main_menu` 等主界面 | 300 s | +| 读狂气/体力 + 合成 + 关游戏 | ~80 s | +| **合计** | **~10.3 分钟** < 15 分钟 ✅ | + +> 万一游戏要下载大更新(实测有过 1.62 GB),会超过 15 分钟被任务强杀,游戏留在 +> 内存里;下一轮 `launch_game` 会发现它已在运行并继续,不会卡死。 + +## 七、已知失败模式与处置 + +| 现象 | 原因 | 处置 | +|---|---|---| +| 截图全黑、OCR 空白 | RDP 断开把显示表面拆了 | 开跑前 `ensure_display()` 自检并跑看门狗 | +| 客户区变成 1278x719 | RDP 重连改了窗口 | 开跑前 `ensure_window_size(1600,900)` | +| 连不上 8765 | 服务没起来 | `ensure_server()` 自己拉起并等就绪 | +| 报"模组没变" | 可能已达上限,也可能界面没响应 | 关掉面板重开重试一次,仍不变才报 | +| 读不到体力 | 底栏还在淡入 | 重试 4 次;仍读不到就跳过(退出码 0),不贸然点合成 | +| 游戏停在副本里 | 上一轮被打断 | 下一轮 `back_init_menu` 会自行带回主界面 | +| **下一轮读到的"合成前"比上一轮"合成后"少** | **最常见的原因是人自己升阶用掉了**(2026-10-17 确认过一次:22:05 换到 35,06:04 读到 33,用户确认是他升阶用了) | `audit_runs.py` 会报"模组数比上一轮少 —— 若是人工升阶用掉的属正常; 否则要查"。**先问人,再查代码** | +| 模组数**自己变多** | 自动化之外的来源 | 真反常,值得看一眼 | +| **报"确认不在 Modules 页签"、整轮没换到** | **OCR 把相邻几行合并成一个元素,把判据里的 `x/126` 吞了**(2026-10-16 18:03 实测:`Enkephalin Module Owned 31` 的框变成 w=351 h=38,体力条消失) | 已改成认面板问句 `Would you like to assemble Enkephalin Modules?`(单独成行、不会被合并),体力条留作备用信号 | + +> **判据要选"语义明确且不易被 OCR 破坏"的文本。** 数字加斜杠的片段最容易被行合并 +> 吃掉,而一整句问话不会。这条和 `LUNACY`→`UNACY` 是同一个教训的两面: +> 前者是 OCR 截断词首,后者是 OCR 吞并整行。 + +### ⛔ 狂气判据的坑(2026-10-16 22:03 误报一次) + +最初写的是"合成前后读数不同 = 被消费"。**这个假设是错的。** + +真值 6636 被 OCR 读过 **6636 / 9699 / 6388 / 8859** 四种样子 —— 误读根本不固定。 +所以"前后不同"区分不了"真变了"和"换了个误读法"。22:03 那次前读 6636、后读 9699、 +复读还是 9699,于是报了违规并让整轮 FAIL,**但那一轮只点了模组图标和面板内的 +`»` / `确认`,根本没碰 `Use Lunacy` 页签**。 + +现在的判据(`lunacy_verdict()`): + +| 情况 | 结论 | +|---|---| +| 前后一致 | 没变 | +| 前后读数都在已知读法集合里 | 按已知 OCR 抖动处理,不单凭此告警 | +| 变化涉及已知集合以外的读数 | 需人工核查,包括新余额变回集合内读数的情况 | + +取数时标签和余额来自同一帧;读完 5 帧后取唯一众数,至少出现 2 次,平票则返回未知。 +这能减少偶发误读,不能消除系统性误读。 + +**守不住的部分就承认守不住,别拿一个会误报的判据充数** —— 误报会让人去查一笔 +根本没发生的消费,比"没检测到"更糟。 + +真正的防线是结构性的:只点 `Modules` 页签 + `Use Lunacy` 坐标被 AST 测试盯着 + +`set_lunacy_to_enkephalin: 0`。OCR 比对只是旁证。 + +## 八、日志噪音约定 + +`convert.log` 是值守时要看的**真实运行记录**,不允许被测试污染。 +测试通过 `QuietLogMixin` 把 `log()` 静音;判断方法是跑完测试看行数有没有变。 + +已经被污染过两次,塞进来的都是**看着像真出事**的行,很能误导人: + +* `MCP 服务(8765)未监听, 尝试拉起` / `等服务就绪超时(0s)` +* `桌面未在出图(BitBlt 失败), 跑看门狗把显示挂回 console` / `看门狗执行失败: powershell not found` + +**怎么分辨**(值守时看到异常行先做这一步): + +1. **同一秒扎堆** —— 真实一轮至少跑几十秒,几行全在 `HH:MM:SS` 同一秒就是测试 +2. **内容自相矛盾** —— 比如"powershell not found",而 powershell 明明在 +3. **对不上报告** —— 去 `~/lc_mcp/modules/` 找同一时刻的 `convert_*.json`; + 真实的运行一定有报告,且 `elapsed_s` 不为 0 + +确认是残留就直接删掉,别让它留在"病史"里。 + +> ⚠️ 第 3 条要注意时间对应关系:**日志的结论行写在一轮结束时,报告的 `started` +> 是开始时**,两者天然差一个 `elapsed_s`。正确的关系是 +> `报告.started + elapsed ≈ 日志结论时刻`(实测 6/6 吻合)。 +> 直接拿两个时间戳比会全部"对不上",反而误判成异常 —— 我自己第一次就这么错过了。 + +### 交叉核对脚本(可直接抄) + +```powershell +$dir = "$env:USERPROFILE\lc_mcp\modules" +$runs = Get-Content "$dir\convert.log" -Encoding UTF8 | Where-Object { $_ -match '=== ' } | + ForEach-Object { if ($_ -match '^\[(.+?)\]\s*===\s*(.+?)\s*\((\w+)\), 耗时 (\d+)s ===') { + [pscustomobject]@{ end=[datetime]$Matches[1]; result=$Matches[2]; secs=[int]$Matches[4] } } } +Get-ChildItem "$dir\convert_*.json" | ForEach-Object { + $r = Get-Content $_.FullName -Encoding UTF8 | ConvertFrom-Json + $expect = ([datetime]$r.started).AddSeconds($r.elapsed_s) + $m = $runs | Where-Object { [math]::Abs(($_.end - $expect).TotalSeconds) -lt 5 } | Select-Object -First 1 + if ($m -and $m.secs -eq $r.elapsed_s) { "OK $($r.started)" } else { "MISMATCH $($_.Name)" } +} +``` diff --git a/docs/feedback/2026-10-02/validation/README.md b/docs/feedback/2026-10-02/validation/README.md new file mode 100644 index 0000000..de9a0d5 --- /dev/null +++ b/docs/feedback/2026-10-02/validation/README.md @@ -0,0 +1,33 @@ +# 2026-10-02 测试产物归档 + +这些文件是 **2026-10-02 那轮会话**产生并遗留在仓库根目录、一直未被提交的 +测试产物。2026-10-13 按用户要求归档到这个位置,让测试代码与结果 +跟对应的日期记录放在一起,仓库根目录不再散落未跟踪文件。 + +## 内容 + +| 文件 | 说明 | +|---|---| +| `TEST_REPORT.md` | 当轮测试报告 | +| `validation-output.txt` | 单测运行输出(`test_click_text_second_hit` / `test_get_state` / `test_missing_text_does_not_click` / `test_ocr_confidence_filter` / `test_ocr_error_does_not_click` / `test_protocol_discovery_and_all_input_tools` 等) | +| `validation-results.json` | 上式的结构化结果 | +| `live-service-results.json` | 对**常驻服务**(非 FakeEngine)的实测结果 | +| `sdk-client-results.json` | SDK 客户端实测结果 | +| `tests/live_services_v05.py` | 常驻服务实测脚本 | +| `tests/validation_v05.py` | 校验脚本(v0.5) | +| `validation-artifacts/ocr-synthetic.png` | OCR 合成测试图 | +| `validation-artifacts/run-original.vbs` | 复现用启动脚本 | + +## 两点说明 + +1. **这些不是本次无人值守部署(10-04 / 10-05)的产物。** 那两天的记录在 + `docs/feedback/2026-10-04/` 与 `docs/feedback/2026-10-05/`。 +2. `tests/*.py` 归档到这里是为了保留证据链,**它们不在 `tests/` 目录下 + 就不会被 `python -m unittest discover -s tests` 收集**。若希望它们 + 参与常规测试,需要移回 `tests/` 并确认通过。 + +## 相关提交 + +- `docs/feedback/2026-10-04/README.md` — 无人值守部署:6 个失败根因 + 自愈看门狗 +- `docs/feedback/2026-10-05/PITFALLS.md` — 自动化实战:14 个坑 +- `docs/feedback/2026-10-05/logs/` — 20 份任务日志 + 服务/看门狗日志 diff --git a/docs/feedback/2026-10-02/validation/TEST_REPORT.md b/docs/feedback/2026-10-02/validation/TEST_REPORT.md new file mode 100644 index 0000000..73c6e62 --- /dev/null +++ b/docs/feedback/2026-10-02/validation/TEST_REPORT.md @@ -0,0 +1,135 @@ +# lc-mcp 测试报告 + +测试日期:2026-10-02(Asia/Hong_Kong)。 + +仓库:https://git.lingll.icu/yws/lc-mcp + +测试提交:`8d24276511e2f007a758b180cba7167e58aca090`,main,服务版本 0.5.0。 + +## 结论 + +基础 MCP 连接和远端 OCR 可用,但当前版本不能判定为可以可靠操作真实游戏。Windows 默认截图启动脚本存在可复现的 VBScript 编译错误;参数缺失会导致意外点击;输入和工具错误可能被报告为成功。应优先修复这三类问题,再做实际游戏闭环测试。 + +当前仓库实现独立的屏幕 OCR 和桌面输入,没有找到 AALC 的 API 调用、配置、依赖或游戏状态集成。是否来自 AALC 的设计或早期代码,无法从本次仓库内容确定。 + +## 环境与范围 + +- Windows 本机;服务使用已安装的 Python 3.8.6。 +- 官方 MCP Python SDK 1.30.0 客户端运行于独立 Python 3.12.14 虚拟环境。 +- 远端 OCR 使用仓库默认地址,上传内容仅为生成的测试 PNG。 +- 输入测试使用 mock 或模拟底层调用失败,没有向真实桌面发送点击、按键或文字。 +- 没有检测到正在运行的 LimbusCompany/AALC 进程。实际游戏窗口、战斗、奖励结算和 AALC 联动均未验证。 +- Linux uinput 检查使用模拟依赖复现 Python 错误,并核对上游数据类型;没有 Linux 内核或 macOS 实机测试。 +- Windows VBScript 使用相同生成表达式、隔离文件路径,通过 `cscript.exe` 编译检查。没有覆盖或运行现有 LcMCP 计划任务。 +- 仅新增测试和报告文件,没有修改原有实现、提交或推送代码。 + +## 测试结果 + +| 检查 | 结果 | 证据 | +|---|---|---| +| 自带测试 | 3 组全部通过 | mock 动作、扫描码表、stdio 往返 | +| Python 编译检查 | 通过 | `python -m compileall -q .` | +| 独立测试 | 22 项:11 通过、9 断言失败、2 运行异常 | `validation-results.json`;失败项是边界行为复现,不代表 11 个独立缺陷 | +| 官方 SDK 连接 | 通过 | initialize、ping、tools/list;识别 9 个工具 | +| SDK 模拟输入 | 通过 | move、中文 type_text | +| 远端 OCR | 通过 | 正确识别“开始 测试”和“TEST 123”;置信度 0.944、0.960 | +| OCR 延迟 | 单次 19.515 秒 | 仅一次请求,不能视为稳定性能或游戏图像准确率 | +| Windows 截图启动脚本 | 失败 | VBScript 编译器错误:语句未结束;退出码 1 | +| SendInput 初始化 | 通过 | 只加载后端,没有发送输入 | +| Interception 初始化 | 环境不满足 | 本机未找到 interception.dll;没有安装驱动或重启 | + +正常语义流程的模拟测试覆盖:OCR 置信度过滤、文字子串和大小写匹配、中心坐标计算、第二候选点击、文字找不到时不点击、OCR 失败时不点击、截图失败透传、文字出现和消失等待。 + +## 主要发现 + +### 1. Windows 截图启动脚本无法编译(P1) + +位置:[platform/win.py:20](D:/codex/tmp/lc-mcp-test/platform/win.py:20)。 + +生成的脚本在 VBScript 字符串内部直接使用单个双引号包围 PowerShell 脚本路径,提前结束了字符串。VBScript 需要将字符串内部双引号写为两个双引号。 + +复现产物为 `validation-artifacts/run-original.vbs`。执行 `cscript.exe //nologo <该文件>` 返回 1,报“Microsoft VBScript 编译器错误:语句未结束”。 + +影响:使用默认生成脚本的新部署不能启动截图任务,进而阻断 screenshot、get_state 和依赖 OCR 的工具。已有自定义修正脚本的机器需单独验证;代码仅在文件不存在时生成脚本,更新 Python 代码也不会自动刷新旧脚本。 + +### 2. 必需参数没有运行时校验,可能意外点击(P1) + +位置:[lc_mcp.py:117](D:/codex/tmp/lc-mcp-test/lc_mcp.py:117)、[lc_mcp.py:131](D:/codex/tmp/lc-mcp-test/lc_mcp.py:131)。 + +- `click({})` 被默认值转换为点击 `(0,0)`,返回 `ok=true`。官方 SDK 客户端复现相同行为。 +- `click_text({})` 使用空字符串匹配所有 OCR 项,并点击第一个文字中心。 +- `index=99` 静默选择最后一个候选;`index=-1` 也选择最后一个候选。这是当前行为,接口没有说明索引越界规则。 + +影响:客户端遗漏参数或模型选择错误索引时,服务仍可能执行桌面输入。建议在任何截图和输入之前校验必需参数、非空文字、索引整数和范围。 + +### 3. MCP 工具错误标记位置错误,客户端读成成功(P1) + +位置:[lc_mcp.py:221](D:/codex/tmp/lc-mcp-test/lc_mcp.py:221)。 + +调用 `move({"x":"invalid","y":6})` 时,服务把 `isError=true` 放在 JSON-RPC 顶层,而不是 `result` 内部。官方 SDK 接收到文本里的 `ok=false`,但 `CallToolResult.isError` 实际为 false。 + +普通 `ok=false` 返回路径没有设置 `result.isError`;未知工具也返回普通文本结果。 + +工具执行错误应在 `result.isError` 中表达;未知工具和无效参数可用 JSON-RPC 错误。这与 [MCP 2024-11-05 Tools 规范](https://modelcontextprotocol.io/specification/2024-11-05/server/tools)不符。 + +### 4. SendInput 注入失败仍返回成功(P1) + +位置:[backends/sendinput_win.py:54](D:/codex/tmp/lc-mcp-test/backends/sendinput_win.py:54)、[backends/sendinput_win.py:87](D:/codex/tmp/lc-mcp-test/backends/sendinput_win.py:87)。 + +模拟 `SendInput` 返回 0 后,`keypress('p')` 仍返回 `ok=true`。点击和文字输入也不检查注入数量;移动不检查 SetCursorPos 结果。 + +影响:服务返回成功不代表目标应用收到输入。需要检查底层调用结果,并在游戏环境用后续状态验证动作效果。本次没有实机验证游戏对 SendInput 的接受程度。 + +### 5. 等待 timeout 不约束内部截图和网络请求(P2) + +位置:[lc_mcp.py:43](D:/codex/tmp/lc-mcp-test/lc_mcp.py:43)、[lc_mcp.py:140](D:/codex/tmp/lc-mcp-test/lc_mcp.py:140)。 + +用模拟时钟将一次 OCR 请求设为 30 秒,`wait_for_text(timeout=1)` 需要 31.2 秒才结束。请求固定使用 30 秒超时;截图也有自己的超时,外层没有传递剩余时间。 + +应使用单调时钟和剩余预算约束内部操作,避免短等待变成长阻塞。 + +### 6. 输入后端初始化失败同时禁用了截图(P2) + +位置:[lc_mcp.py:171](D:/codex/tmp/lc-mcp-test/lc_mcp.py:171)。 + +截图提供者与输入后端共用一个 try/except。设置一个不存在的输入后端后,`screenshot` 返回 `'NoneType' object has no attribute 'grab'`,尽管截图提供者此前已成功创建。 + +应分别初始化和报告截图、输入能力;仅观察屏幕的工具不应依赖输入后端可用。 + +### 7. Linux uinput 后端存在确定的 Python 错误(P1,限该后端) + +位置:[backends/uinput_linux.py:28](D:/codex/tmp/lc-mcp-test/backends/uinput_linux.py:28)、[backends/uinput_linux.py:72](D:/codex/tmp/lc-mcp-test/backends/uinput_linux.py:72)。 + +- `keypress('enter')` 引用未定义的 `KEY_ENTER`,抛 NameError。 +- `_ensure()` 对 uinput 的元组常量执行 `KEY_Z + 1` 和 range,抛 TypeError。 +- 其他输入路径引用未在模块作用域导入的 REL_X、BTN_LEFT 等常量;代码还缺少 time 导入。 + +前两项已通过隔离测试复现,后两项为源码检查。uinput 的事件描述符类型已核对 [python-uinput 上游实现](https://raw.githubusercontent.com/tuomasjjrasanen/python-uinput/master/src/__init__.py)。 + +### 8. Interception 实现与上游公开 API 不一致(待实机确认) + +位置:[backends/interception_win.py:91](D:/codex/tmp/lc-mcp-test/backends/interception_win.py:91)。 + +代码调用 interception_open_device/interception_close_device,但 [上游公开头文件](https://raw.githubusercontent.com/oblitum/Interception/master/library/interception.h)没有这两个接口。上游设备总数为 20,代码扫描到 64,且硬件 ID 被按 ASCII 文本解释。 + +这是源码与上游接口比对发现,本机缺少 DLL,未测试实际加载的 DLL 是否为提供这些接口的定制版本。部署前应明确支持的 DLL 版本并用真实设备验证。 + +### 9. 畸形 JSON 使服务退出(P2,健壮性) + +向 stdio 发送 `{ invalid json }` 后,服务直接关闭 stdout 并退出,没有返回 JSON-RPC parse error。这会断开客户端连接。有效请求的正常流程不受本测试影响。 + +## 复现文件 + +- [独立测试脚本](D:/codex/tmp/lc-mcp-test/tests/test_validation.py) +- [OCR 和 VBScript 检查脚本](D:/codex/tmp/lc-mcp-test/tests/test_live_services.py) +- [官方 SDK 客户端脚本](D:/codex/tmp/lc-mcp-sdk-client-test.py)(放在仓库外,避免仓库的 platform 包影响客户端标准库导入) +- [逐项测试结果](D:/codex/tmp/lc-mcp-test/validation-results.json) +- [OCR、VBScript 与后端初始化结果](D:/codex/tmp/lc-mcp-test/live-service-results.json) +- [官方 SDK 返回结果](D:/codex/tmp/lc-mcp-test/sdk-client-results.json) +- [生成的 OCR 测试图](D:/codex/tmp/lc-mcp-test/validation-artifacts/ocr-synthetic.png) + +执行服务端测试:`python tests/test_dev.py`、`python tests/test_validation.py`、`python tests/test_live_services.py`。后者需要 Pillow、Windows 字体和网络;当前本机已有所需图像依赖。独立验证脚本当前返回非零是预期结果,因为其断言要求服务拒绝错误输入并正确报告失败。 + +## 下一步 + +先修复 Windows 脚本生成、参数校验、MCP 错误返回和底层输入结果检查,再准备可观察的游戏窗口,逐步验证“截图 → OCR → 正确候选 → 单次输入 → 新截图确认”。真实游戏测试需要运行机器和窗口状态;本次结果不包含战斗自动化成功率或 AALC 集成验证。 diff --git a/docs/feedback/2026-10-02/validation/live-service-results.json b/docs/feedback/2026-10-02/validation/live-service-results.json new file mode 100644 index 0000000..35f1f88 --- /dev/null +++ b/docs/feedback/2026-10-02/validation/live-service-results.json @@ -0,0 +1,39 @@ +{ + "remote_ocr": { + "url": "http://35.212.193.150:8599/", + "seconds": 19.515, + "items": [ + { + "text": "开始 测试", + "x": 37, + "y": 39, + "w": 230, + "h": 59, + "score": 0.944 + }, + { + "text": "TEST 123", + "x": 40, + "y": 143, + "w": 226, + "h": 47, + "score": 0.96 + } + ], + "error": null, + "input": "D:\\codex\\tmp\\lc-mcp-test\\validation-artifacts\\ocr-synthetic.png" + }, + "windows_vbs": { + "returncode": 1, + "stdout": "", + "stderr": "D:\\codex\\tmp\\lc-mcp-test\\validation-artifacts\\run-original.vbs(1, 93) Microsoft VBScript 编译器错误: 语句未结束\r\n\r\n", + "script": "CreateObject(\"WScript.Shell\").Run \"powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"D:\\codex\\tmp\\lc-mcp-test\\validation-artifacts\\nonexistent-test-job.ps1\"\", 0, False\n" + }, + "sendinput_initialization": { + "ok": true + }, + "interception_initialization": { + "ok": false, + "error": "Could not find module 'interception.dll' (or one of its dependencies). Try using the full path with constructor syntax." + } +} \ No newline at end of file diff --git a/docs/feedback/2026-10-02/validation/sdk-client-results.json b/docs/feedback/2026-10-02/validation/sdk-client-results.json new file mode 100644 index 0000000..3453a05 --- /dev/null +++ b/docs/feedback/2026-10-02/validation/sdk-client-results.json @@ -0,0 +1,133 @@ +{ + "sdk_version": "1.30.0", + "initialize": { + "meta": null, + "protocolVersion": "2024-11-05", + "capabilities": { + "experimental": null, + "logging": null, + "prompts": null, + "resources": null, + "tools": { + "listChanged": false + }, + "completions": null, + "tasks": null + }, + "serverInfo": { + "name": "lc-mcp", + "title": null, + "version": "0.5.0", + "websiteUrl": null, + "icons": null + }, + "instructions": null + }, + "ping": "PASS", + "tools": [ + "get_state", + "click_text", + "wait_for_text", + "wait_for_text_gone", + "screenshot", + "click", + "move", + "keypress", + "type_text" + ], + "calls": [ + { + "name": "move", + "arguments": { + "x": 5, + "y": 6 + }, + "result": { + "meta": null, + "content": [ + { + "type": "text", + "text": "{\"ok\": true, \"backend\": \"mock\"}", + "annotations": null, + "meta": null + } + ], + "structuredContent": null, + "isError": false + } + }, + { + "name": "type_text", + "arguments": { + "text": "测试" + }, + "result": { + "meta": null, + "content": [ + { + "type": "text", + "text": "{\"ok\": true, \"typed\": \"测试\", \"backend\": \"mock\"}", + "annotations": null, + "meta": null + } + ], + "structuredContent": null, + "isError": false + } + }, + { + "name": "move", + "arguments": { + "x": "invalid", + "y": 6 + }, + "result": { + "meta": null, + "content": [ + { + "type": "text", + "text": "{\"ok\": false, \"error\": \"invalid literal for int() with base 10: 'invalid'\"}", + "annotations": null, + "meta": null + } + ], + "structuredContent": null, + "isError": false + } + }, + { + "name": "click", + "arguments": {}, + "result": { + "meta": null, + "content": [ + { + "type": "text", + "text": "{\"ok\": true, \"clicked\": [0, 0], \"backend\": \"mock\"}", + "annotations": null, + "meta": null + } + ], + "structuredContent": null, + "isError": false + } + }, + { + "name": "unknown", + "arguments": {}, + "result": { + "meta": null, + "content": [ + { + "type": "text", + "text": "{\"ok\": false, \"error\": \"unknown tool unknown\"}", + "annotations": null, + "meta": null + } + ], + "structuredContent": null, + "isError": false + } + } + ] +} \ No newline at end of file diff --git a/docs/feedback/2026-10-02/validation/tests/live_services_v05.py b/docs/feedback/2026-10-02/validation/tests/live_services_v05.py new file mode 100644 index 0000000..1907be5 --- /dev/null +++ b/docs/feedback/2026-10-02/validation/tests/live_services_v05.py @@ -0,0 +1,45 @@ +"""Use only generated images; never send screenshots or desktop input.""" +import json +from pathlib import Path +import subprocess +import sys +import time + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT)) +import lc_mcp as app +from PIL import Image, ImageDraw, ImageFont + +out = ROOT / 'validation-artifacts' +out.mkdir(exist_ok=True) +results = {} +image = Image.new('RGB', (900, 300), 'white') +draw = ImageDraw.Draw(image) +font = ImageFont.truetype('C:/Windows/Fonts/msyh.ttc', 52) +draw.text((40, 30), '开始 测试', font=font, fill='black') +draw.text((40, 130), 'TEST 123', font=font, fill='black') +path = out / 'ocr-synthetic.png' +image.save(str(path)) +start = time.monotonic() +items, error = app.ocr_image(str(path)) +results['remote_ocr'] = {'url': app.OCR_URL, 'seconds': round(time.monotonic() - start, 3), + 'items': items, 'error': error, 'input': str(path)} +print(json.dumps({'remote_ocr': results['remote_ocr']}, ensure_ascii=True), flush=True) + +# Exact script-generation expression from platform/win.py, with isolated paths. +job = str(out / 'nonexistent-test-job.ps1') +vbs = out / 'run-original.vbs' +vbs.write_text('CreateObject("WScript.Shell").Run "powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%s"", 0, False\n' % job, encoding='utf-8') +r = subprocess.run(['cscript.exe', '//nologo', str(vbs)], capture_output=True, timeout=10) +results['windows_vbs'] = {'returncode': r.returncode, + 'stdout': r.stdout.decode('mbcs', errors='replace'), 'stderr': r.stderr.decode('mbcs', errors='replace'), + 'script': vbs.read_text(encoding='utf-8')} +print(json.dumps({'windows_vbs': results['windows_vbs']}, ensure_ascii=True), flush=True) +for name in ('sendinput', 'interception'): + try: + backend = app.get_input_backend(name, 'win') + results[name + '_initialization'] = {'ok': True} + except Exception as e: + results[name + '_initialization'] = {'ok': False, 'error': str(e)} +(ROOT / 'live-service-results.json').write_text(json.dumps(results, ensure_ascii=False, indent=2), encoding='utf-8') +print(json.dumps(results, ensure_ascii=True), flush=True) diff --git a/docs/feedback/2026-10-02/validation/tests/validation_v05.py b/docs/feedback/2026-10-02/validation/tests/validation_v05.py new file mode 100644 index 0000000..e584a21 --- /dev/null +++ b/docs/feedback/2026-10-02/validation/tests/validation_v05.py @@ -0,0 +1,251 @@ +"""Independent validation; no real desktop inputs are sent. + +Run: python tests/test_validation.py +Failures assert the intended behavior and reproduce defects in the tested revision. +""" +import contextlib +import io +import json +import os +from pathlib import Path +import queue +import subprocess +import sys +import tempfile +import threading +import unittest +from unittest.mock import patch + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT)) +import lc_mcp as app +from backends.mock import MockBackend + +ITEMS = [ + {'text': '开始', 'x': 100, 'y': 200, 'w': 80, 'h': 40, 'score': .99}, + {'text': '开始战斗', 'x': 300, 'y': 400, 'w': 100, 'h': 50, 'score': .95}, +] + + +class Provider: + def grab(self): + return {'ok': True, 'path': 'synthetic.png'} + + +class Peer: + def __init__(self, extra_env=None): + env = dict(os.environ, INPUT_BACKEND='mock', PYTHONIOENCODING='utf-8') + env.update(extra_env or {}) + self.p = subprocess.Popen([sys.executable, str(ROOT / 'lc_mcp.py')], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + text=True, encoding='utf-8', env=env) + self.q = queue.Queue() + def pump(): + for line in self.p.stdout: + self.q.put(line) + self.q.put(None) + threading.Thread(target=pump, daemon=True).start() + + def send(self, obj): + self.p.stdin.write(json.dumps(obj, ensure_ascii=True) + '\n') + self.p.stdin.flush() + line = self.q.get(timeout=5) + return json.loads(line) if line else None + + def close(self): + if self.p.poll() is None: + self.p.kill() + self.p.communicate(timeout=5) + + +class HealthyPaths(unittest.TestCase): + def setUp(self): + self.b = MockBackend() + self.s = app.MCPServer('win', Provider(), self.b) + + def test_text_coordinates(self): + self.assertEqual(app.calc_click('开始', ITEMS)[0], {'text': '开始', 'x': 140, 'y': 220}) + + def test_substring_case_insensitive(self): + items = [dict(ITEMS[0], text='Start Battle')] + self.assertEqual(len(app.calc_click('START', items)), 1) + + def test_get_state(self): + with patch.object(app, 'ocr_image', return_value=(ITEMS, None)): + self.assertEqual(self.s.call('get_state', {})['items'], ITEMS) + + def test_click_text_second_hit(self): + with patch.object(app, 'ocr_image', return_value=(ITEMS, None)): + self.s.call('click_text', {'text': '开始', 'index': 1}) + self.assertEqual(self.b.log[-1]['x'], 350) + self.assertEqual(self.b.log[-1]['y'], 425) + + def test_missing_text_does_not_click(self): + with patch.object(app, 'ocr_image', return_value=(ITEMS, None)): + self.assertFalse(self.s.call('click_text', {'text': '不存在'})['ok']) + self.assertEqual(self.b.log, []) + + def test_ocr_error_does_not_click(self): + with patch.object(app, 'ocr_image', return_value=(None, 'service unavailable')): + self.assertFalse(self.s.call('click_text', {'text': '开始'})['ok']) + self.assertEqual(self.b.log, []) + + def test_screenshot_error_propagates(self): + with patch.object(self.s.provider, 'grab', return_value={'ok': False, 'error': 'capture fail'}): + self.assertEqual(self.s.call('get_state', {})['error'], 'capture fail') + + def test_wait_present(self): + with patch.object(app, 'ocr_image', return_value=(ITEMS, None)): + self.assertTrue(self.s.call('wait_for_text', {'text': '开始', 'timeout': 1})['present']) + + def test_wait_absent(self): + with patch.object(app, 'ocr_image', return_value=([], None)): + result = self.s.call('wait_for_text_gone', {'text': '开始', 'timeout': 1}) + self.assertTrue(result['ok']) + self.assertFalse(result['present']) + + def test_ocr_confidence_filter(self): + payload = {'ok': True, 'items': ITEMS + [dict(ITEMS[0], score=.1)]} + response = contextlib.closing(io.BytesIO(json.dumps(payload).encode('utf-8'))) + with tempfile.TemporaryDirectory() as tmp, patch.object(app.urllib.request, 'urlopen', return_value=response): + path = Path(tmp) / 'image.png' + path.write_bytes(b'fixture') + items, error = app.ocr_image(str(path)) + self.assertIsNone(error) + self.assertEqual(len(items), 2) + + def test_protocol_discovery_and_all_input_tools(self): + p = Peer() + try: + response = p.send({'jsonrpc': '2.0', 'id': 1, 'method': 'initialize', 'params': {}}) + self.assertEqual(response['result']['serverInfo']['name'], 'lc-mcp') + response = p.send({'jsonrpc': '2.0', 'id': 2, 'method': 'tools/list'}) + self.assertEqual(len(response['result']['tools']), 9) + for name, args in [('click', {'x': 10, 'y': 20}), ('move', {'x': 5, 'y': 6}), + ('keypress', {'key': 'p'}), ('type_text', {'text': '开始'})]: + r = p.send({'jsonrpc': '2.0', 'id': 3, 'method': 'tools/call', 'params': {'name': name, 'arguments': args}}) + self.assertTrue(json.loads(r['result']['content'][0]['text'])['ok']) + finally: + p.close() + + +class RequiredBehavior(unittest.TestCase): + def setUp(self): + self.b = MockBackend() + self.s = app.MCPServer('win', Provider(), self.b) + + def test_missing_click_coordinates_rejected(self): + result = self.s.call('click', {}) + self.assertFalse(result['ok'], result) + self.assertEqual(self.b.log, []) + + def test_missing_click_text_rejected(self): + with patch.object(app, 'ocr_image', return_value=(ITEMS, None)): + result = self.s.call('click_text', {}) + self.assertFalse(result['ok'], result) + self.assertEqual(self.b.log, []) + + def test_out_of_range_index_rejected(self): + with patch.object(app, 'ocr_image', return_value=(ITEMS, None)): + result = self.s.call('click_text', {'text': '开始', 'index': 99}) + self.assertFalse(result['ok'], result) + + def test_negative_index_rejected(self): + with patch.object(app, 'ocr_image', return_value=(ITEMS, None)): + result = self.s.call('click_text', {'text': '开始', 'index': -1}) + self.assertFalse(result['ok'], result) + + def test_wait_timeout_honored(self): + clock = [0.0] + def slow_ocr(_): + clock[0] += 30 + return None, 'network timeout' + def sleep(seconds): + clock[0] += seconds + with patch.object(app.time, 'time', side_effect=lambda: clock[0]), \ + patch.object(app.time, 'sleep', side_effect=sleep), \ + patch.object(app, 'ocr_image', side_effect=slow_ocr): + self.s.call('wait_for_text', {'text': '开始', 'timeout': 1}) + self.assertLessEqual(clock[0], 1.1, 'one-second deadline took %.1f seconds' % clock[0]) + + def test_tool_exception_sets_result_iserror(self): + p = Peer() + try: + r = p.send({'jsonrpc': '2.0', 'id': 1, 'method': 'tools/call', + 'params': {'name': 'move', 'arguments': {'x': 'invalid', 'y': 1}}}) + self.assertTrue(r['result'].get('isError', False), r) + finally: + p.close() + + def test_unknown_tool_returns_protocol_error(self): + p = Peer() + try: + r = p.send({'jsonrpc': '2.0', 'id': 1, 'method': 'tools/call', + 'params': {'name': 'unknown', 'arguments': {}}}) + self.assertIn('error', r, r) + finally: + p.close() + + def test_invalid_json_keeps_server_alive(self): + p = Peer() + try: + p.p.stdin.write('{ invalid json }\n') + p.p.stdin.flush() + line = p.q.get(timeout=5) + self.assertIsNotNone(line, 'server closes stdout and exits without JSON-RPC parse error') + self.assertEqual(json.loads(line)['error']['code'], -32700) + finally: + p.close() + + def test_sendinput_failed_injection_is_reported(self): + from backends.sendinput_win import SendInputBackend + b = SendInputBackend.__new__(SendInputBackend) + with patch.object(b, '_send_input', return_value=0): + r = b.keypress('p') + self.assertFalse(r['ok'], r) + + def test_uinput_key_constants_in_scope(self): + from backends.uinput_linux import UinputBackend + b = UinputBackend.__new__(UinputBackend) + with patch.object(b, '_key'): + r = b.keypress('enter') + self.assertTrue(r['ok']) + + def test_uinput_device_events_are_valid(self): + import types + from backends.uinput_linux import UinputBackend + fake = types.SimpleNamespace(Device=lambda events: object()) + names = ['KEY_A', 'KEY_Z', 'KEY_ENTER', 'KEY_ESC', 'KEY_SPACE', 'KEY_TAB', 'KEY_F4', + 'KEY_LEFTCTRL', 'KEY_LEFTSHIFT', 'KEY_LEFTALT', 'KEY_BACKSPACE', + 'REL_X', 'REL_Y', 'BTN_LEFT', 'BTN_RIGHT'] + for i, name in enumerate(names): + setattr(fake, name, (1, i + 30)) + b = UinputBackend.__new__(UinputBackend) + b._ctx = None + with patch.dict(sys.modules, {'uinput': fake}): + self.assertIsNotNone(b._ensure()) + + +class Result(unittest.TextTestResult): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.records = [] + + def addSuccess(self, test): + super().addSuccess(test) + self.records.append({'test': test.id(), 'status': 'PASS'}) + + def addFailure(self, test, err): + super().addFailure(test, err) + self.records.append({'test': test.id(), 'status': 'FAIL', 'detail': self._exc_info_to_string(err, test)}) + + def addError(self, test, err): + super().addError(test, err) + self.records.append({'test': test.id(), 'status': 'ERROR', 'detail': self._exc_info_to_string(err, test)}) + + +if __name__ == '__main__': + suite = unittest.defaultTestLoader.loadTestsFromModule(sys.modules[__name__]) + result = unittest.TextTestRunner(verbosity=2, resultclass=Result).run(suite) + (ROOT / 'validation-results.json').write_text(json.dumps(result.records, ensure_ascii=False, indent=2), encoding='utf-8') + sys.exit(0 if result.wasSuccessful() else 1) diff --git a/docs/feedback/2026-10-02/validation/validation-artifacts/ocr-synthetic.png b/docs/feedback/2026-10-02/validation/validation-artifacts/ocr-synthetic.png new file mode 100644 index 0000000..f7bbd21 Binary files /dev/null and b/docs/feedback/2026-10-02/validation/validation-artifacts/ocr-synthetic.png differ diff --git a/docs/feedback/2026-10-02/validation/validation-artifacts/run-original.vbs b/docs/feedback/2026-10-02/validation/validation-artifacts/run-original.vbs new file mode 100644 index 0000000..230fb83 --- /dev/null +++ b/docs/feedback/2026-10-02/validation/validation-artifacts/run-original.vbs @@ -0,0 +1 @@ +CreateObject("WScript.Shell").Run "powershell.exe -NoProfile -ExecutionPolicy Bypass -File "D:\codex\tmp\lc-mcp-test\validation-artifacts\nonexistent-test-job.ps1"", 0, False diff --git a/docs/feedback/2026-10-02/validation/validation-output.txt b/docs/feedback/2026-10-02/validation/validation-output.txt new file mode 100644 index 0000000..3ef04f1 --- /dev/null +++ b/docs/feedback/2026-10-02/validation/validation-output.txt @@ -0,0 +1,119 @@ +test_click_text_second_hit (__main__.HealthyPaths) ... ok +test_get_state (__main__.HealthyPaths) ... ok +test_missing_text_does_not_click (__main__.HealthyPaths) ... ok +test_ocr_confidence_filter (__main__.HealthyPaths) ... ok +test_ocr_error_does_not_click (__main__.HealthyPaths) ... ok +test_protocol_discovery_and_all_input_tools (__main__.HealthyPaths) ... ok +test_screenshot_error_propagates (__main__.HealthyPaths) ... ok +test_substring_case_insensitive (__main__.HealthyPaths) ... ok +test_text_coordinates (__main__.HealthyPaths) ... ok +test_wait_absent (__main__.HealthyPaths) ... ok +test_wait_present (__main__.HealthyPaths) ... ok +test_invalid_json_keeps_server_alive (__main__.RequiredBehavior) ... FAIL +test_missing_click_coordinates_rejected (__main__.RequiredBehavior) ... FAIL +test_missing_click_text_rejected (__main__.RequiredBehavior) ... FAIL +test_negative_index_rejected (__main__.RequiredBehavior) ... FAIL +test_out_of_range_index_rejected (__main__.RequiredBehavior) ... FAIL +test_sendinput_failed_injection_is_reported (__main__.RequiredBehavior) ... FAIL +test_tool_exception_sets_result_iserror (__main__.RequiredBehavior) ... FAIL +test_uinput_device_events_are_valid (__main__.RequiredBehavior) ... ERROR +test_uinput_key_constants_in_scope (__main__.RequiredBehavior) ... ERROR +test_unknown_tool_returns_protocol_error (__main__.RequiredBehavior) ... FAIL +test_wait_timeout_honored (__main__.RequiredBehavior) ... FAIL + +====================================================================== +ERROR: test_uinput_device_events_are_valid (__main__.RequiredBehavior) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "tests\test_validation.py", line 226, in test_uinput_device_events_are_valid + self.assertIsNotNone(b._ensure()) + File "D:\codex\tmp\lc-mcp-test\backends\uinput_linux.py", line 28, in _ensure + *[key for key in range(KEY_A, KEY_Z + 1)], +TypeError: can only concatenate tuple (not "int") to tuple + +====================================================================== +ERROR: test_uinput_key_constants_in_scope (__main__.RequiredBehavior) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "tests\test_validation.py", line 211, in test_uinput_key_constants_in_scope + r = b.keypress('enter') + File "D:\codex\tmp\lc-mcp-test\backends\uinput_linux.py", line 72, in keypress + mapping = {'enter': KEY_ENTER, 'esc': KEY_ESC, 'space': KEY_SPACE, +NameError: name 'KEY_ENTER' is not defined + +====================================================================== +FAIL: test_invalid_json_keeps_server_alive (__main__.RequiredBehavior) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "tests\test_validation.py", line 195, in test_invalid_json_keeps_server_alive + self.assertIsNotNone(line, 'server closes stdout and exits without JSON-RPC parse error') +AssertionError: unexpectedly None : server closes stdout and exits without JSON-RPC parse error + +====================================================================== +FAIL: test_missing_click_coordinates_rejected (__main__.RequiredBehavior) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "tests\test_validation.py", line 139, in test_missing_click_coordinates_rejected + self.assertFalse(result['ok'], result) +AssertionError: True is not false : {'ok': True, 'clicked': [0, 0], 'backend': 'mock'} + +====================================================================== +FAIL: test_missing_click_text_rejected (__main__.RequiredBehavior) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "tests\test_validation.py", line 145, in test_missing_click_text_rejected + self.assertFalse(result['ok'], result) +AssertionError: True is not false : {'ok': True, 'clicked': [140, 220], 'backend': 'mock', 'on': '��ʼ'} + +====================================================================== +FAIL: test_negative_index_rejected (__main__.RequiredBehavior) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "tests\test_validation.py", line 156, in test_negative_index_rejected + self.assertFalse(result['ok'], result) +AssertionError: True is not false : {'ok': True, 'clicked': [350, 425], 'backend': 'mock', 'on': '��ʼս��'} + +====================================================================== +FAIL: test_out_of_range_index_rejected (__main__.RequiredBehavior) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "tests\test_validation.py", line 151, in test_out_of_range_index_rejected + self.assertFalse(result['ok'], result) +AssertionError: True is not false : {'ok': True, 'clicked': [350, 425], 'backend': 'mock', 'on': '��ʼս��'} + +====================================================================== +FAIL: test_sendinput_failed_injection_is_reported (__main__.RequiredBehavior) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "tests\test_validation.py", line 205, in test_sendinput_failed_injection_is_reported + self.assertFalse(r['ok'], r) +AssertionError: True is not false : {'ok': True, 'key': 'p', 'backend': 'sendinput'} + +====================================================================== +FAIL: test_tool_exception_sets_result_iserror (__main__.RequiredBehavior) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "tests\test_validation.py", line 176, in test_tool_exception_sets_result_iserror + self.assertTrue(r['result'].get('isError', False), r) +AssertionError: False is not true : {'jsonrpc': '2.0', 'id': 1, 'result': {'content': [{'type': 'text', 'text': '{"ok": false, "error": "invalid literal for int() with base 10: \'invalid\'"}'}]}, 'isError': True} + +====================================================================== +FAIL: test_unknown_tool_returns_protocol_error (__main__.RequiredBehavior) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "tests\test_validation.py", line 185, in test_unknown_tool_returns_protocol_error + self.assertIn('error', r, r) +AssertionError: 'error' not found in {'jsonrpc': '2.0', 'id': 1, 'result': {'content': [{'type': 'text', 'text': '{"ok": false, "error": "unknown tool unknown"}'}]}} : {'jsonrpc': '2.0', 'id': 1, 'result': {'content': [{'type': 'text', 'text': '{"ok": false, "error": "unknown tool unknown"}'}]}} + +====================================================================== +FAIL: test_wait_timeout_honored (__main__.RequiredBehavior) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "tests\test_validation.py", line 169, in test_wait_timeout_honored + self.assertLessEqual(clock[0], 1.1, 'one-second deadline took %.1f seconds' % clock[0]) +AssertionError: 31.2 not less than or equal to 1.1 : one-second deadline took 31.2 seconds + +---------------------------------------------------------------------- +Ran 22 tests in 0.886s + +FAILED (failures=9, errors=2) diff --git a/docs/feedback/2026-10-02/validation/validation-results.json b/docs/feedback/2026-10-02/validation/validation-results.json new file mode 100644 index 0000000..a7fc66a --- /dev/null +++ b/docs/feedback/2026-10-02/validation/validation-results.json @@ -0,0 +1,101 @@ +[ + { + "test": "__main__.HealthyPaths.test_click_text_second_hit", + "status": "PASS" + }, + { + "test": "__main__.HealthyPaths.test_get_state", + "status": "PASS" + }, + { + "test": "__main__.HealthyPaths.test_missing_text_does_not_click", + "status": "PASS" + }, + { + "test": "__main__.HealthyPaths.test_ocr_confidence_filter", + "status": "PASS" + }, + { + "test": "__main__.HealthyPaths.test_ocr_error_does_not_click", + "status": "PASS" + }, + { + "test": "__main__.HealthyPaths.test_protocol_discovery_and_all_input_tools", + "status": "PASS" + }, + { + "test": "__main__.HealthyPaths.test_screenshot_error_propagates", + "status": "PASS" + }, + { + "test": "__main__.HealthyPaths.test_substring_case_insensitive", + "status": "PASS" + }, + { + "test": "__main__.HealthyPaths.test_text_coordinates", + "status": "PASS" + }, + { + "test": "__main__.HealthyPaths.test_wait_absent", + "status": "PASS" + }, + { + "test": "__main__.HealthyPaths.test_wait_present", + "status": "PASS" + }, + { + "test": "__main__.RequiredBehavior.test_invalid_json_keeps_server_alive", + "status": "FAIL", + "detail": "Traceback (most recent call last):\n File \"tests\\test_validation.py\", line 195, in test_invalid_json_keeps_server_alive\n self.assertIsNotNone(line, 'server closes stdout and exits without JSON-RPC parse error')\nAssertionError: unexpectedly None : server closes stdout and exits without JSON-RPC parse error\n" + }, + { + "test": "__main__.RequiredBehavior.test_missing_click_coordinates_rejected", + "status": "FAIL", + "detail": "Traceback (most recent call last):\n File \"tests\\test_validation.py\", line 139, in test_missing_click_coordinates_rejected\n self.assertFalse(result['ok'], result)\nAssertionError: True is not false : {'ok': True, 'clicked': [0, 0], 'backend': 'mock'}\n" + }, + { + "test": "__main__.RequiredBehavior.test_missing_click_text_rejected", + "status": "FAIL", + "detail": "Traceback (most recent call last):\n File \"tests\\test_validation.py\", line 145, in test_missing_click_text_rejected\n self.assertFalse(result['ok'], result)\nAssertionError: True is not false : {'ok': True, 'clicked': [140, 220], 'backend': 'mock', 'on': '开始'}\n" + }, + { + "test": "__main__.RequiredBehavior.test_negative_index_rejected", + "status": "FAIL", + "detail": "Traceback (most recent call last):\n File \"tests\\test_validation.py\", line 156, in test_negative_index_rejected\n self.assertFalse(result['ok'], result)\nAssertionError: True is not false : {'ok': True, 'clicked': [350, 425], 'backend': 'mock', 'on': '开始战斗'}\n" + }, + { + "test": "__main__.RequiredBehavior.test_out_of_range_index_rejected", + "status": "FAIL", + "detail": "Traceback (most recent call last):\n File \"tests\\test_validation.py\", line 151, in test_out_of_range_index_rejected\n self.assertFalse(result['ok'], result)\nAssertionError: True is not false : {'ok': True, 'clicked': [350, 425], 'backend': 'mock', 'on': '开始战斗'}\n" + }, + { + "test": "__main__.RequiredBehavior.test_sendinput_failed_injection_is_reported", + "status": "FAIL", + "detail": "Traceback (most recent call last):\n File \"tests\\test_validation.py\", line 205, in test_sendinput_failed_injection_is_reported\n self.assertFalse(r['ok'], r)\nAssertionError: True is not false : {'ok': True, 'key': 'p', 'backend': 'sendinput'}\n" + }, + { + "test": "__main__.RequiredBehavior.test_tool_exception_sets_result_iserror", + "status": "FAIL", + "detail": "Traceback (most recent call last):\n File \"tests\\test_validation.py\", line 176, in test_tool_exception_sets_result_iserror\n self.assertTrue(r['result'].get('isError', False), r)\nAssertionError: False is not true : {'jsonrpc': '2.0', 'id': 1, 'result': {'content': [{'type': 'text', 'text': '{\"ok\": false, \"error\": \"invalid literal for int() with base 10: \\'invalid\\'\"}'}]}, 'isError': True}\n" + }, + { + "test": "__main__.RequiredBehavior.test_uinput_device_events_are_valid", + "status": "ERROR", + "detail": "Traceback (most recent call last):\n File \"tests\\test_validation.py\", line 226, in test_uinput_device_events_are_valid\n self.assertIsNotNone(b._ensure())\n File \"D:\\codex\\tmp\\lc-mcp-test\\backends\\uinput_linux.py\", line 28, in _ensure\n *[key for key in range(KEY_A, KEY_Z + 1)],\nTypeError: can only concatenate tuple (not \"int\") to tuple\n" + }, + { + "test": "__main__.RequiredBehavior.test_uinput_key_constants_in_scope", + "status": "ERROR", + "detail": "Traceback (most recent call last):\n File \"tests\\test_validation.py\", line 211, in test_uinput_key_constants_in_scope\n r = b.keypress('enter')\n File \"D:\\codex\\tmp\\lc-mcp-test\\backends\\uinput_linux.py\", line 72, in keypress\n mapping = {'enter': KEY_ENTER, 'esc': KEY_ESC, 'space': KEY_SPACE,\nNameError: name 'KEY_ENTER' is not defined\n" + }, + { + "test": "__main__.RequiredBehavior.test_unknown_tool_returns_protocol_error", + "status": "FAIL", + "detail": "Traceback (most recent call last):\n File \"tests\\test_validation.py\", line 185, in test_unknown_tool_returns_protocol_error\n self.assertIn('error', r, r)\nAssertionError: 'error' not found in {'jsonrpc': '2.0', 'id': 1, 'result': {'content': [{'type': 'text', 'text': '{\"ok\": false, \"error\": \"unknown tool unknown\"}'}]}} : {'jsonrpc': '2.0', 'id': 1, 'result': {'content': [{'type': 'text', 'text': '{\"ok\": false, \"error\": \"unknown tool unknown\"}'}]}}\n" + }, + { + "test": "__main__.RequiredBehavior.test_wait_timeout_honored", + "status": "FAIL", + "detail": "Traceback (most recent call last):\n File \"tests\\test_validation.py\", line 169, in test_wait_timeout_honored\n self.assertLessEqual(clock[0], 1.1, 'one-second deadline took %.1f seconds' % clock[0])\nAssertionError: 31.2 not less than or equal to 1.1 : one-second deadline took 31.2 seconds\n" + } +] \ No newline at end of file diff --git a/docs/feedback/2026-10-03/PHYSICAL_INPUT_CHANGE.md b/docs/feedback/2026-10-03/PHYSICAL_INPUT_CHANGE.md new file mode 100644 index 0000000..f10ab07 --- /dev/null +++ b/docs/feedback/2026-10-03/PHYSICAL_INPUT_CHANGE.md @@ -0,0 +1,31 @@ +# Interception 输入改动 + +**2026-10-03 已撤销:Interception 驱动已卸载,系统过滤器恢复为 kbdclass/mouclass;驱动服务和系统驱动文件均已确认不存在。仓库已恢复上游输入实现。下文仅保留历史记录,不应再执行安装步骤。卸载需要重启才能完全生效。** + +2026-10-02,基础提交 `a4b27f9`,AALC 固定提交 `7452fad5a45a0fadb59a753fafbf40434d987c19`。 + +已拉取最新仓库和 AALC 子模块。本地新增 Interception 驱动后端,MCP 直接输入和 `run_task` 子进程共享适配逻辑;AALC 的 `auto.init_input()` 重初始化后也保持使用此后端。 + +修改文件: + +- `lc_mcp/physical_input.py`:上游 DLL 的 ctypes 接口、设备发现、发送结果检查、虚拟桌面坐标、游戏前台焦点确认、按键和按钮释放、AALC 输入绑定。 +- `lc_mcp/aalc_engine.py` 与 `lc_mcp/aalc_task.py`:在服务及任务进程中安装物理输入适配。 +- `scripts/install_interception.ps1`:固定上游 v1.0.1 包与 SHA256;支持 WhatIf;管理员安装驱动;不自动重启。 +- `tests/test_physical_input.py`:驱动 ABI、设备选择、发送失败、坐标、扩展键、释放、AALC 重初始化与 MCP 错误返回测试。 +- `README.md`:部署和输入行为说明。 + +所有鼠标点击、移动、拖拽、滚轮和按键均通过 Interception 的 `interception_send` 发送,每次发送一个 stroke,检查实际发送数量。驱动/DLL/键鼠不可用时失败,不回退到其他输入方式。中文等文字通过剪贴板加驱动 Ctrl+V 粘贴。 + +复用 AALC 的窗口客户区到桌面坐标转换;恢复并确认窗口焦点后再换算坐标。覆盖 AALC 输入初始化,同时保留输入锁、交互门、暂停与监控路径。没有修改 vendor/aalc 源码或 config.yaml。 + +验证:Python 3.12.14 完整 unittest discovery 共 32 项通过,编译检查与 git diff --check 通过。PowerShell 语法解析无错误,技能静态检查报告 safe=true。输入验证使用模拟驱动,没有发送真实游戏输入。 + +历史 v0.5 的两个本地测试脚本已保留为 `tests/validation_v05.py` 和 `tests/live_services_v05.py`,避免被新版 unittest 自动发现。旧报告和结果保留为历史记录。 + +本机安装状态:已从上游下载并校验 Interception v1.0.1,Windows 管理员安装器输出“Interception successfully installed. You must reboot for it to take effect.”。键盘和鼠标设备类 UpperFilters 已加入对应驱动。 + +安装日志:[lc-mcp-driver-install.log](D:/codex/tmp/lc-mcp-driver-install.log)。安装结果:[lc-mcp-driver-install-result.json](D:/codex/tmp/lc-mcp-driver-install-result.json)。 + +待环境步骤:重启 Windows 后驱动才会生效;实际游戏输入尚未验证。新仓库的 AALC 运行依赖需在其 Python >=3.12 环境准备好(README 的 uv sync 步骤);本次没有安装 AALC 的全部 GUI/OCR 依赖或启动常驻服务。正常服务会移动桌面光标并使用前台游戏窗口。 + +本地改动尚未提交或推送。 diff --git a/docs/feedback/2026-10-04/README.md b/docs/feedback/2026-10-04/README.md new file mode 100644 index 0000000..43e8979 --- /dev/null +++ b/docs/feedback/2026-10-04/README.md @@ -0,0 +1,331 @@ +# 2026-10-04 本机部署实测记录 + +在一台**远程、无人在场**的 Windows 机器上从零部署 lc-mcp 并跑通镜牢的完整记录。 +包含六个真实失败及其根因、验证过的部分、以及**仍未验证的边界**。 + +上游无此环境的相关文档,所以把踩过的坑写成可复用的形式。 + +## 环境 + +| 项 | 值 | +|---|---| +| 系统 | Windows,GPU 为 Intel Iris Xe(集显),另有 ToDesk 虚拟显示器适配器 | +| 会话 | DSH 与 lc-mcp 服务跑在**会话 2**;**无人在物理机前**,全部远程操作 | +| 接入方式 | RDP / ToDesk,**分辨率随客户端变化**(实测 1600×900 / 1872×921 / 1920×1080) | +| 游戏 | Limbus Company,Steam 版,装在 `D:\SteamLibrary`(**非**默认 C 盘路径) | +| Python | 系统只有 3.8.6,AALC 要求 ≥3.12 → 由 uv 装 CPython 3.13.6 | +| 网络 | 直连外网约 12–28 KB/s;Clash 代理 `127.0.0.1:6789` 约 4.18 MB/s(快 11 倍) | + +**账号状态**:LV 37 的早期账号,**首次进入镜牢**,因此触发了大量一次性新手引导。 + +## 结果 + +```text +一局完整镜牢:2026-10-04 23:49:42 → 2026-10-05 00:29:10 +耗时 00:39:28,exit code 0,日志零 [ERROR] +[INFO] 已完成 1 次镜牢 +``` + +单测:`Ran 171 tests ... OK`(见 `test-results.txt`)。 +里程碑全文见 `logs/successful-run-milestones.txt`(98 行)。 + +## 六个失败与根因 + +### 1. 截图全黑 —— 会话 `Disc` 导致桌面停止渲染 ★ + +**症状**:`get_state` 返回全黑图、OCR 为空;AALC 报 + +```text +OpenCV(4.11.0) templmatch.cpp:1175: error: (-215:Assertion failed) +_img.size().height <= _templ.size().height && _img.size().width <= _templ.size().width +``` + +即**截图比模板图还小**。 + +**根因**:DSH 与服务跑在会话 2。RDP 一旦断开,Windows 会**拆掉该会话的显示表面**。 +进程还活着、日志还在滚,但: + +```text +BitBlt(screenDC) → ret=0 err=6 (ERROR_INVALID_HANDLE) +OpenInputDesktop → 0 (失败) +GetForegroundWindow→ 0 +qwinsta → > YWS-HHH 2 Disc +``` + +**这不是权限问题,是根本没有显示设备。** 一开始误判成权限/沙箱问题,绕了弯路。 + +**修复**:把会话挂到物理控制台,之后无人连接也持续渲染。 + +```powershell +tscon 2 /dest:console # 需要管理员 +``` + +`tscon` 需要 `SeTcbPrivilege`;普通令牌只有 `SeShutdownPrivilege`,直接跑报 +`Error 5: Access is denied`。 + +**⚠️ 会反复**:之后再 RDP 连上又断开,会话被拉回 RDP,断开后又变黑。 +因此新增了看门狗任务(见下),已实测能自愈。 + +### 2. `sinner_order` 全 0 —— 编队死循环 ★最隐蔽 + +**症状**:日志里每 2 秒一次 `开始执行 罪人编队` → `结束执行 罪人编队`,永远不出结果; +游戏停在配队界面。 + +**根因**:`tasks/teams/team_formation.py` + +```python +for i in range(1, 13): + if i in sinner_team: + sinner = sinner_team.index(i) + else: + return # 任何一个缺失就立刻返回, 什么都不做 +``` + +而自动生成的 `config.yaml` 里 `chosen_sinners` / `sinner_order` **默认全是 0** +(`module/config/config_typing.py` 里 `[0] * 12`)。于是第一个 `i=1` 就命中 `return`, +队伍永远是空的;`mirror.py` 又检测到 `teams/none_sinner_assets.png`("没有罪人") +再次调用编队,形成无限循环。 + +**为什么难发现**:配置文件是自动生成的、字段名看起来正常;**AALC 不报任何错**。 + +**修复**(`vendor\aalc\config.yaml` → `teams: '1':`): + +```yaml +sinners_be_select: 12 +chosen_sinners: [1,1,1,1,1,1,1,1,1,1,1,1] +sinner_order: [1,2,3,4,5,6,7,8,9,10,11,12] +``` + +队伍启用队列是单一事实源,`teams_be_select` 由它派生: + +```yaml +teams_active_queue: [1] +select_team_by_order: true +``` + +`select_team_by_order: true` 让选队按列表位置点选,而不是匹配队名 +(默认按名字找 `编队#N` / `TEAMS #N`,队名不符就失败)。 + +### 3. `background_click: false` 会因 `SetForegroundWindow` 崩掉整个任务 + +`module/game_and_screen/screen.py` 的 `set_win()`: + +```python +if not cfg.background_click: + self.handle.setForeground() # 后台进程抢前台会抛 pywintypes.error +``` + +会话状态不健康时这里抛异常 → `init_game()` 崩 → 任务秒退: + +```text +pywintypes.error: (0, 'SetForegroundWindow', 'No error message is available') +``` + +`background_click` 同时决定截图方式,两者耦合: + +| `background_click` | 截图 | 特点 | +|---|---|---| +| `true` | `PrintWindow(hwnd, dc, 3)` | **按窗口抓图**,不受屏幕尺寸/遮挡影响 | +| `false` | `take_screenshot_gdi` | 全屏 BitBlt 再裁窗口,**窗口超出屏幕就被裁掉** | + +### 4. 窗口尺寸必须留出标题栏 —— `set_win_size: 900` 在 1600×900 桌面上无法达成 ★ + +`set_win_size` 指的是**客户区高度**,但窗口还要加上标题栏和边框: + +```text +set_win_size: 900 → 客户区 1600×900 → 窗口需要 1616×939 +``` + +在 1600×900 的桌面上,939 > 900,**窗口装不下**,Windows 会把高度压到 877: + +```text +game client: 1600x877 ratio=1.824 *** 不是 16:9 *** +``` + +而 `set_win()` 的校正循环只在任务启动那一刻跑一次,之后没人纠正。 + +**修复**:改用 `set_win_size: 720`(客户区 1280×720,窗口 1296×759), +在 1600×900 及以上的桌面上都装得下。 + +实测确认: + +```text +window=(0,0,1296,759) client=1280x720 ratio=1.778 OK 16:9 +battle/win_rate_card.png → found (1129, 564) ← 720 缩放下模板匹配正常 +``` + +### 5. 窗口被拉伸成非 16:9 → 模板匹配全面崩坏 ★最值得记 + +**症状**:镜牢跑到一半突然不再推进。日志没有 `[ERROR]`,进程健在,只是永远停在 +`mirror.py` 的"防卡死"兜底分支反复 `点击(1,1)空白位置`。 +画面是个正常的**战斗部署界面**,右下角 `START` 按钮高亮等着被点。 + +**根因**:中途 RDP 重连,桌面分辨率变化,**Unity 把游戏窗口自动拉伸填满桌面**, +客户区变成非 16:9(实测 1872×898,比例 2.08:1)。 + +而 AALC 按 `cfg.set_win_size` **等比**缩放模板,假设客户区是 16:9: + +```text +模板缩放 = set_win_size / 1440 → 假设宽 = 高 × 16/9 +实际宽 ≠ 高 × 16/9 → 横向差 17% +``` + +于是**全部模板匹配分数崩塌**(对比同一批模板): + +| 模板 | 正常时 | 出问题时 | +|---|---|---| +| `battle/win_rate_card.png` | ~0.9 | **0.68** | +| `battle/turn_assets.png` | ~0.9 | **0.37** | +| `teams/identify_assets.png` | 0.99 | **0.43** | +| `home/first_prompt_assets.png` | 1.00 | **0.56** | + +全都在阈值(0.8)以下 → AALC 认不出任何界面元素 → 走兜底分支 → 看起来"卡死"。 + +**为什么难发现**:日志里**没有任何报错**,只有一堆相似度数字。 +不看分数分布,根本看不出这是"全面的、而非局部的"匹配失败。 + +**修复**:把窗口恢复成 16:9。修复后同一批模板立刻恢复: +`battle/win_rate_card.png` → found (1121, 564);被卡住的那场战斗 78 秒内打完。 + +**未解决**:运行中若再次发生分辨率变化仍会重现,目前靠人工/重启任务纠正。 +根本解法是让 `set_win()` 的校正循环周期性重跑,或监听 `WM_DISPLAYCHANGE`。 + +### 6. UTF-8 无 BOM 的中文注释会让 Windows PowerShell 5.1 解析失败 ★ + +**症状**:脚本报出莫名其妙的语法错误,且**行号对不上**: + +```text +At keep_display.ps1:9 char:22 ++ [switch]$Verbose, ++ ~ +Missing expression after ','. +``` + +第 9 行其实是一句注释,`[switch]$Verbose,` 在第 16 行。 + +**根因**:文件是 **UTF-8 无 BOM**。Windows PowerShell 5.1 在无 BOM 时按**系统 ANSI +代码页**(本机 936/GBK)解码,中文注释变成乱码: + +```text +原: # 看门狗: 会话掉回 "Disc" 时重新挂到物理控制台 +GBK 解码: # 鐪嬮棬鐙? 浼氳瘽鎺夊洖 "Disc" 鏃堕噸鏂版寕鍒扮墿鐞嗘帶鍒跺 +``` + +乱码字节序列会在解析层面制造出多余的引号/标记,破坏语法。 +**行号错位**正是这个问题的特征信号。 + +**这个坑我先误判了两次**:一次以为是 here-string 的问题(改掉了写法), +一次以为是 `param()` 里夹注释的问题(删掉了注释)。两次都"绕过"了而不是修好。 + +**修复**:脚本存成 **UTF-8 with BOM**(`EF BB BF`)。 + +> 注:仓库里原有的 `install_logon_task.ps1` 同样是无 BOM + 中文,却能正常执行。 +> 差异未查明,可能与其注释内容/长度有关。**保险做法是一律加 BOM。** + +## 三种输入模式都在抢桌面 + +| 模式 | 挪什么 | 代价 | +|---|---|---| +| `background` | **真实鼠标指针**(`set_mouse_pos` 后 `move_back` 复位) | 用户点不到别的窗口、抢不到前台 | +| `window_move` | **游戏窗口**(挪到指针底下再挪回) | 窗口剧烈闪烁(每次点击一次) | +| `foreground` | 真实指针(pyautogui 真实点击) | **游戏必须保持前台**,一旦失去焦点,真实点击会落到别的窗口上 | + +三者**都会**调 `set_active()` 向游戏窗口发 `WM_ACTIVATE / WA_ACTIVE` +(`input_handlers/input.py:507` 与 `:828`)。AALC 的设计前提是"运行时独占桌面", +**没有配置能关掉**。 + +**实测结论**: + +- `foreground` 在**有人守着**时体验最好(真实光标操作、可观看),但**无人值守时不可用**—— + 没人保证游戏处于前台,任何抢焦点(包括人工点一下别的窗口)都会让点击落到错误窗口。 +- `background` **不依赖前台状态**,最适合无人值守。代价是抢占鼠标指针—— + 没人在场时无所谓。 + +**本项目最终选择 `background`**(无人值守场景)。 + +## 其他环境坑 + +- **游戏路径**:`config.yaml` 默认指向 `C:\Program Files (x86)\Steam\...`, + 实际在 `D:\SteamLibrary`,必须改。 +- **AALC 会整份回写 `config.yaml`**:手写的注释会被抹掉,改完要复查。 +- **`qwinsta` 在计划任务上下文里没有任何输出**(所以初版看门狗任务失败), + 要用 WTS API(见 `scripts/session_state.py`)。 +- **游戏窗口最小化后 rect 是 `(-32000,-32000,...)`**,先 `ShowWindow(SW_RESTORE)`。 +- **`SetForegroundWindow` 可当健康探针**:会话不渲染时失败,渲染正常时成功。 +- **首次进镜牢有约 60 页引导**(两个轮播)。AALC 的兜底分支要求 + `home/first_prompt_assets.png` 与 `home/back_assets.png` **同时**命中, + 但后者只有 0.43(低于阈值),于是退化成反复点空白。需人工点掉: + 右边缘 `(1805,540)` 翻页,翻完点左上角 `(130,70)` 退出。一次性成本。 +- **`task_status` 返回 `succeeded` 不等于成功**:AALC 单次战斗失败后会继续跑完并 exit 0, + 必须同时看 `errors` 字段。 + +## 新增的可复用工具 + +### `scripts/session_state.py` + +用 WTS API 查询会话连接状态,输出 `Active` / `Disc` 等。 +替代在计划任务上下文里失灵的 `qwinsta`。 + +### `scripts/render_check.py` + +从屏幕 DC 做一次 BitBlt,判断桌面是否正在出图。退出码 0/1。 + +### `scripts/keep_display.ps1` + +看门狗:会话掉到 `Disc` 时用提权 `tscon` 重新挂 console,恢复渲染。 + +**安全设计**:只在状态为 `Disc`(确认无人连接)时动作。用户正通过 RDP/ToDesk +连着(`Active`/`Connected`)时**绝不插手**,否则会把用户挤下线。 + +**提权方式**:`tscon` 需要 `SeTcbPrivilege`,普通令牌拿不到,脚本用 +`Start-Process -Verb RunAs`。在 `ConsentPromptBehaviorAdmin=0`("从不通知")的机器上 +提权静默通过、不弹框。 + +**实测验证**(两条路径都跑过): + +```text +正常路径 session 2 is Active; nothing to do ← 正确跳过,不写日志 +修复路径 session 2 is Disc -> re-attaching to console + session 2 now: Active ← tscon 真的生效 + render check: BitBlt=1 desktop=1920x1080 ← 渲染恢复 +``` + +修复路径用 `-ForceDisc` 开关验证(跳过状态判断直接跑), +因为会话已在 console 时 `tscon` 是幂等的,不会造成影响。 + +另外单独验证过:**计划任务上下文(Limited 权限)里 `Start-Process -Verb RunAs` +可以静默提权**——这是看门狗能工作的前提。用一个临时任务验证后已清理。 + +## 当前生效配置 + +```yaml +game_path: D:\SteamLibrary\steamapps\common\Limbus Company\LimbusCompany.exe +background_click: true +win_input_type: background +set_win_size: 720 +set_windows: true +select_team_by_order: true +teams_active_queue: [1] +``` + +任务次数由 `run_task` 参数临时覆盖,结束后自动写回原值 +(原值落盘在 `~/lc_mcp/runs/*.restore.json`,防强杀丢失)。 + +## 仍未验证 / 已知限制 + +1. **分辨率中途变化会重现问题 5**,目前无自动纠正机制。 +2. **`foreground` 模式在无人值守下不可用**(见上),已改用 `background`。 +3. **多局连刷的稳定性未验证**:只完整跑通 1 局; + `count=3` 的批处理两次都在中途被打断(第一次因问题 5,第二次因问题 1)。 +4. **未使用 Jev / 决策模型**:全部走 AALC 内置规则流程,`decisionEngine` 未接入。 +5. 账号为 LV 37 早期账号,**主线未通关**(镜牢界面可见 `Clear Canto 8` 等解锁条件), + 因此结论只覆盖普通镜牢,不覆盖困难镜牢与主线。 +6. **看门狗只覆盖"桌面变黑"这一类故障**。识别失败、卡在未知界面等其他问题 + 仍需人工介入——问题 5 就是例子。 +7. `720p` 下模板缩放为 `720/1440 = 0.5`。实测战斗界面匹配正常, + 但**未做过全流程的识别成功率对比**,小图标场景可能劣于 1080p。 + +## 本次导出排除的内容 + +API key、MCP token(`~/lc_mcp/token`)、私有配置文件、完整会话转录、 +以及账号 UID 可见的底部栏截图。 diff --git a/docs/feedback/2026-10-04/captures/stall-wrong-aspect-1872x898.png b/docs/feedback/2026-10-04/captures/stall-wrong-aspect-1872x898.png new file mode 100644 index 0000000..c469cca Binary files /dev/null and b/docs/feedback/2026-10-04/captures/stall-wrong-aspect-1872x898.png differ diff --git a/docs/feedback/2026-10-04/captures/working-1280x720.png b/docs/feedback/2026-10-04/captures/working-1280x720.png new file mode 100644 index 0000000..0bb9b53 Binary files /dev/null and b/docs/feedback/2026-10-04/captures/working-1280x720.png differ diff --git a/docs/feedback/2026-10-04/logs/server-excerpt.txt b/docs/feedback/2026-10-04/logs/server-excerpt.txt new file mode 100644 index 0000000..b0261ca --- /dev/null +++ b/docs/feedback/2026-10-04/logs/server-excerpt.txt @@ -0,0 +1,8 @@ +[DEBUG] 2026-10-04 23:10:05,506 [AALC] module\automation\automation.py:83: 使用后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-04 23:19:50,811 [AALC] module\automation\automation.py:83: 使用后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-04 23:30:39,791 [AALC] module\automation\automation.py:88: 使用前台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-04 23:47:18,039 [AALC] module\automation\automation.py:88: 使用前台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) diff --git a/docs/feedback/2026-10-04/logs/stalled-run-tail.txt b/docs/feedback/2026-10-04/logs/stalled-run-tail.txt new file mode 100644 index 0000000..70a1d20 --- /dev/null +++ b/docs/feedback/2026-10-04/logs/stalled-run-tail.txt @@ -0,0 +1,60 @@ +[DEBUG] 2026-10-05 01:01:54,822 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:01:57,503 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:00,225 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:02,907 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:05,608 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:08,344 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:11,090 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:13,801 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:16,503 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:19,252 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:21,925 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:24,650 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:27,386 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:30,083 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:32,929 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:35,546 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:38,238 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:40,938 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:43,913 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:46,383 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:49,078 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:51,783 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:54,500 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:57,224 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:02:59,914 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:02,647 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:05,417 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:08,170 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:10,861 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:13,561 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:16,258 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:19,007 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:21,782 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:24,438 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:27,307 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:29,893 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:32,609 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:35,309 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:38,074 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:40,788 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:43,440 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:46,135 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:48,866 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:51,613 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:54,301 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:57,048 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:03:59,772 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:02,468 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:05,190 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:08,042 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:10,632 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:13,378 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:16,082 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:18,834 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:21,524 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:24,262 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:26,991 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:29,699 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:32,379 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 +[DEBUG] 2026-10-05 01:04:35,261 [AALC] module\automation\automation.py:152: 点击(1,1)空白位置 diff --git a/docs/feedback/2026-10-04/logs/successful-run-milestones.txt b/docs/feedback/2026-10-04/logs/successful-run-milestones.txt new file mode 100644 index 0000000..dbbf941 --- /dev/null +++ b/docs/feedback/2026-10-04/logs/successful-run-milestones.txt @@ -0,0 +1,98 @@ +[INFO] 2026-10-04 23:49:42,796 [AALC] tasks\base\script_task_scheme.py:337: 开始执行 一次镜牢 +[INFO] 2026-10-04 23:49:49,028 [AALC] module\automation\automation.py:435: 主题:default +[INFO] 2026-10-04 23:49:52,013 [AALC] tasks\mirror\mirror.py:268: 开始执行 选择镜牢主题包 +[INFO] 2026-10-04 23:49:55,630 [AALC] module\decorator\decorator.py:18: 语言: 英文 +[INFO] 2026-10-04 23:50:02,238 [AALC] tasks\mirror\select_theme_pack.py:122: 此次选择卡包关键词:judgment +[INFO] 2026-10-04 23:50:02,240 [AALC] tasks\mirror\mirror.py:268: 结束执行 选择镜牢主题包 +[INFO] 2026-10-04 23:50:02,242 [AALC] tasks\mirror\mirror.py:44: 启动后第2层卡包,该楼层时间不完整 总耗时:497538:36:41 +[INFO] 2026-10-04 23:50:05,795 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-04 23:50:15,941 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-04 23:50:39,852 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-04 23:50:42,352 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-04 23:50:44,150 [AALC] tasks\mirror\mirror.py:338: 开始执行 罪人编队 +[INFO] 2026-10-04 23:50:55,188 [AALC] tasks\mirror\mirror.py:338: 结束执行 罪人编队 +[INFO] 2026-10-04 23:51:04,503 [AALC] tasks\mirror\mirror.py:109: 开始执行 一次战斗 +[INFO] 2026-10-04 23:52:44,374 [AALC] tasks\mirror\mirror.py:109: 结束执行 一次战斗 +[INFO] 2026-10-04 23:52:54,060 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-04 23:52:56,567 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-04 23:53:16,306 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-04 23:53:18,816 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-04 23:53:28,554 [AALC] tasks\mirror\mirror.py:109: 开始执行 一次战斗 +[INFO] 2026-10-04 23:55:08,785 [AALC] tasks\mirror\mirror.py:109: 结束执行 一次战斗 +[INFO] 2026-10-04 23:55:21,831 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-04 23:55:24,343 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-04 23:55:26,233 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢商店 +[INFO] 2026-10-04 23:56:44,367 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢商店 +[INFO] 2026-10-04 23:56:48,588 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-04 23:56:51,084 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-04 23:57:00,792 [AALC] tasks\mirror\mirror.py:109: 开始执行 一次战斗 +[INFO] 2026-10-05 00:01:06,172 [AALC] tasks\mirror\mirror.py:109: 结束执行 一次战斗 +[INFO] 2026-10-05 00:01:08,161 [AALC] tasks\mirror\mirror.py:434: 开始执行 镜牢获取奖励卡 +[INFO] 2026-10-05 00:01:14,084 [AALC] tasks\mirror\mirror.py:434: 结束执行 镜牢获取奖励卡 +[INFO] 2026-10-05 00:01:37,548 [AALC] tasks\mirror\mirror.py:268: 开始执行 选择镜牢主题包 +[INFO] 2026-10-05 00:01:47,209 [AALC] tasks\mirror\select_theme_pack.py:122: 此次选择卡包关键词:nsignif +[INFO] 2026-10-05 00:01:47,211 [AALC] tasks\mirror\mirror.py:268: 结束执行 选择镜牢主题包 +[INFO] 2026-10-05 00:01:47,212 [AALC] tasks\mirror\mirror.py:44: 启动后第3层卡包 总耗时:00:11:44 +[INFO] 2026-10-05 00:01:50,772 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:02:00,951 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:02:15,648 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:02:18,166 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:02:27,946 [AALC] tasks\mirror\mirror.py:109: 开始执行 一次战斗 +[INFO] 2026-10-05 00:04:27,763 [AALC] tasks\mirror\mirror.py:109: 结束执行 一次战斗 +[INFO] 2026-10-05 00:04:32,181 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:04:34,677 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:04:44,451 [AALC] tasks\mirror\mirror.py:109: 开始执行 一次战斗 +[INFO] 2026-10-05 00:07:24,851 [AALC] tasks\mirror\mirror.py:109: 结束执行 一次战斗 +[INFO] 2026-10-05 00:07:29,247 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:07:31,754 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:07:56,867 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:07:59,367 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:08:01,268 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢商店 +[INFO] 2026-10-05 00:09:13,353 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢商店 +[INFO] 2026-10-05 00:09:17,534 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:09:20,043 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:09:29,800 [AALC] tasks\mirror\mirror.py:109: 开始执行 一次战斗 +[INFO] 2026-10-05 00:14:23,370 [AALC] tasks\mirror\mirror.py:109: 结束执行 一次战斗 +[INFO] 2026-10-05 00:14:25,326 [AALC] tasks\mirror\mirror.py:434: 开始执行 镜牢获取奖励卡 +[INFO] 2026-10-05 00:14:27,822 [AALC] tasks\mirror\mirror.py:434: 结束执行 镜牢获取奖励卡 +[INFO] 2026-10-05 00:14:52,226 [AALC] tasks\mirror\mirror.py:268: 开始执行 选择镜牢主题包 +[INFO] 2026-10-05 00:15:01,683 [AALC] tasks\mirror\select_theme_pack.py:122: 此次选择卡包关键词:addict +[INFO] 2026-10-05 00:15:01,684 [AALC] tasks\mirror\mirror.py:268: 结束执行 选择镜牢主题包 +[INFO] 2026-10-05 00:15:01,686 [AALC] tasks\mirror\mirror.py:44: 启动后第4层卡包 总耗时:00:13:14 +[INFO] 2026-10-05 00:15:05,235 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:15:15,405 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:15:40,768 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:15:43,267 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:15:53,021 [AALC] tasks\mirror\mirror.py:109: 开始执行 一次战斗 +[INFO] 2026-10-05 00:19:13,160 [AALC] tasks\mirror\mirror.py:109: 结束执行 一次战斗 +[INFO] 2026-10-05 00:19:15,155 [AALC] tasks\mirror\mirror.py:434: 开始执行 镜牢获取奖励卡 +[INFO] 2026-10-05 00:19:21,069 [AALC] tasks\mirror\mirror.py:434: 结束执行 镜牢获取奖励卡 +[INFO] 2026-10-05 00:19:25,374 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:19:27,881 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:19:37,628 [AALC] tasks\mirror\mirror.py:109: 开始执行 一次战斗 +[INFO] 2026-10-05 00:23:07,182 [AALC] tasks\mirror\mirror.py:109: 结束执行 一次战斗 +[INFO] 2026-10-05 00:23:11,600 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:23:14,098 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:23:39,214 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:23:41,720 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:23:43,615 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢商店 +[INFO] 2026-10-05 00:24:41,532 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢商店 +[INFO] 2026-10-05 00:24:45,739 [AALC] tasks\mirror\mirror.py:109: 开始执行 镜牢寻路 +[INFO] 2026-10-05 00:24:48,247 [AALC] tasks\mirror\mirror.py:109: 结束执行 镜牢寻路 +[INFO] 2026-10-05 00:24:58,028 [AALC] tasks\mirror\mirror.py:109: 开始执行 一次战斗 +[INFO] 2026-10-05 00:28:50,253 [AALC] tasks\mirror\mirror.py:109: 结束执行 一次战斗 +[INFO] 2026-10-05 00:28:51,387 [AALC] tasks\mirror\mirror.py:494: 开始进行镜牢奖励领取 +[INFO] 2026-10-05 00:28:55,140 [AALC] tasks\mirror\mirror.py:625: 本次镜牢领取45个通行证经验 +[INFO] 2026-10-05 00:29:06,019 [AALC] tasks\mirror\mirror.py:44: 启动后第4层卡包 总耗时:00:14:04 +[INFO] 2026-10-05 00:29:06,020 [AALC] tasks\mirror\mirror.py:44: 此次镜牢在战斗 总耗时:00:27:41 +[INFO] 2026-10-05 00:29:06,021 [AALC] tasks\mirror\mirror.py:727: 此次镜牢走的事件次数6 +[INFO] 2026-10-05 00:29:06,022 [AALC] tasks\mirror\mirror.py:44: 此次镜牢在事件 总耗时:00:01:17 +[INFO] 2026-10-05 00:29:06,023 [AALC] tasks\mirror\mirror.py:44: 此次镜牢中在商店 总耗时:00:03:28 +[INFO] 2026-10-05 00:29:06,024 [AALC] tasks\mirror\mirror.py:44: 此次镜牢中在寻路 总耗时:00:01:08 +[INFO] 2026-10-05 00:29:06,026 [AALC] tasks\mirror\mirror.py:44: 此次镜牢使用burn体系队伍 总耗时:00:39:23 +[INFO] 2026-10-05 00:29:06,027 [AALC] tasks\base\script_task_scheme.py:100: 开始执行 返回主界面 +[INFO] 2026-10-05 00:29:07,239 [AALC] tasks\base\script_task_scheme.py:100: 结束执行 返回主界面 +[INFO] 2026-10-05 00:29:07,241 [AALC] tasks\base\script_task_scheme.py:101: 开始执行 体力换饼 +[INFO] 2026-10-05 00:29:10,858 [AALC] tasks\base\script_task_scheme.py:101: 结束执行 体力换饼 +[INFO] 2026-10-05 00:29:10,859 [AALC] tasks\base\script_task_scheme.py:337: 结束执行 一次镜牢 +[INFO] 2026-10-05 00:29:10,869 [AALC] tasks\base\script_task_scheme.py:351: 已完成 1 次镜牢 diff --git a/docs/feedback/2026-10-04/manifest.json b/docs/feedback/2026-10-04/manifest.json new file mode 100644 index 0000000..8e78542 --- /dev/null +++ b/docs/feedback/2026-10-04/manifest.json @@ -0,0 +1,59 @@ +{ + "exported_at_utc": "2026-10-04T17:19:53.700710+00:00", + "base_commit": "073e407346d83c734724be42103e5b5baa100a85", + "host": "Windows, remote unattended session (RDP/ToDesk), no one at the machine", + "game": "Limbus Company (Steam), account LV 37, first-ever Mirror Dungeon entry", + "test_exit_code": 0, + "tests_passed": 171, + "mirror_runs_completed": 1, + "mirror_run_duration": "00:39:28", + "mirror_run_errors": 0, + "distinct_failures_documented": 6, + "unattended_selfheal_task_verified": true, + "screenshots": 2, + "log_excerpts": 3, + "excluded": [ + "API keys", + "MCP token", + "private configurations", + "session transcripts", + "account-UID screenshots" + ], + "files": [ + { + "path": "README.md", + "bytes": 14114, + "sha256": "be63ab5ecf21b944b59df3d357eeba826694114a19e899e154ee28d6293f1c44" + }, + { + "path": "captures/stall-wrong-aspect-1872x898.png", + "bytes": 2480446, + "sha256": "122c5d6aabe04225c2388531271a88c869311ef7181e197320e871e86010fd5f" + }, + { + "path": "captures/working-1280x720.png", + "bytes": 714175, + "sha256": "a6a2fd75d767c9fc9675eb7390aa03dc611807d60c53c67d960310103576c36f" + }, + { + "path": "logs/server-excerpt.txt", + "bytes": 748, + "sha256": "d1828b44d247b66c06558b42c277be5391faaa60f6e616669e6195cd9ecd2dfe" + }, + { + "path": "logs/stalled-run-tail.txt", + "bytes": 6420, + "sha256": "de8f2d714f726cdc10ad55cf442d171cfd51afa64ec7e138df420d1ff3b9a05c" + }, + { + "path": "logs/successful-run-milestones.txt", + "bytes": 9562, + "sha256": "459b746eea2a85870f8c1a89c59a3d65e1558472a2c9f3b0c9af24d682f26d75" + }, + { + "path": "test-results.txt", + "bytes": 1236, + "sha256": "8200e288e3570c08e76097ec5622382453850cc0ef5673bd12fc27a7bc66d1a0" + } + ] +} \ No newline at end of file diff --git a/docs/feedback/2026-10-04/test-results.txt b/docs/feedback/2026-10-04/test-results.txt new file mode 100644 index 0000000..cf7c4a0 --- /dev/null +++ b/docs/feedback/2026-10-04/test-results.txt @@ -0,0 +1,11 @@ +{"step": 0, "run_id": "47442136bf99427d96dd53decc47c426", "choice": "wait", "action": {"tool": "wait", "args": {"seconds": 0.7}}, "jev_ms": 0, "ocr_ms": 0, "screen": null, "at": "2026-10-05T01:09:00", "decision_engine": "rules", "action_ms": 0, "finished_at": "2026-10-05T01:09:00", "result": {"ok": true, "waited": 0.7}, "state": "running", "battle_context": false} +{"step": 1, "run_id": "47442136bf99427d96dd53decc47c426", "choice": "wait", "action": {"tool": "wait", "args": {"seconds": 0.7}}, "jev_ms": 0, "ocr_ms": 0, "screen": null, "at": "2026-10-05T01:09:00", "decision_engine": "rules", "action_ms": 0, "finished_at": "2026-10-05T01:09:00", "result": {"ok": true, "waited": 0.7}, "state": "running", "battle_context": false} +.................................................................................................unknown params for mirror: exp +usage: python -m lc_mcp.aalc_task [json] +......................................[lc_mcp] rejected connection from ('127.0.0.1', 60318) +..[lc_mcp] rejected connection from ('127.0.0.1', 60322) +.................................. +---------------------------------------------------------------------- +Ran 171 tests in 11.603s + +OK diff --git a/docs/feedback/2026-10-05/PITFALLS.md b/docs/feedback/2026-10-05/PITFALLS.md new file mode 100644 index 0000000..5c1d981 --- /dev/null +++ b/docs/feedback/2026-10-05/PITFALLS.md @@ -0,0 +1,360 @@ +# 踩坑全记录(2026-10-05 自动化实战) + +这一天把 lc-mcp 从"能手动跑"推到"能无人值守自动养号",一路上挖出 +**14 个坑**。其中 6 个是 AALC 自身的缺陷或脆弱点,4 个是游戏 UI 的 +反直觉设计,4 个是我自己写自动化时踩的。 + +按"离奇程度"排序,最有价值的放前面。 + +--- + +## 坑 1:人格详情页是**长按**打开的 ★★★★★ + +罪人界面(Sinners → Identities)的身份卡片: + +| 操作 | 结果 | +|---|---| +| 单击 | 只是**选中/取消选中**(队伍预设增删成员) | +| **长按** | **打开人格详情页**(升级 / 同步入口) | + +**代价**:我单击试遍了卡片头像、SELECTED 横幅、名字等级区、双击、 +右侧 Selected Identity 面板、左侧罪人头像栏、右上 `i`、`Details` 按钮 +—— **全都只能选中**。花了十几轮才由用户一句话点破。 + +**为什么反直觉**:这是移动端移植 UI,长按在手机上很自然,在桌面端 +用鼠标时几乎没人会想到。 + +**自动化实现**:lc-mcp 没有 long-press 工具,但 `drag` 是 +`按下 → 移动 → 抬起`,**起点终点相同**就是长按: + +```python +probe('drag', {'from_x': x, 'from_y': y, 'to_x': x, 'to_y': y}) +``` + +实测稳定可复现(`duration` 约 1.0s)。 + +--- + +## 坑 2:按名字选队会**子串误匹配** ★★★★★ + +`tasks/teams/team_formation.py`: + +```python +team_name_en = [f"TEAMS #{num}", f"TEAMS#{num}", f"TFAMS#{num}"] # num=1 +``` + +**`"TEAMS #1"` 是 `"TEAMS #10"`~`"TEAMS #19"` 的子串。** + +本机账号有 **40 个队伍预设**,所以查找 `TEAMS #1` 极易命中 `TEAMS #10`。 + +**症状极其误导**:日志写 + +```text +[INFO] team_formation.py:188: 成功找到队伍 # 1 ← 假阳性 +``` + +看起来一切正常,但紧接着: + +```text +[DEBUG] team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] battle.py:66: 目标图片:battle/normal_to_battle_assets.png 相似度:0.99 +[DEBUG] automation.py:152: 点击位置:(1439,737) ← 无限点"开战",开不了 +``` + +`0/5` 出现 **306 次**,空转 27 分钟。因为它选中了一个**空预设**。 + +**教训**:**日志说"成功"不等于成功**。判断选队是否真的生效, +要看 `配队人数` 那一行是不是 `N/5`(N>0),不能只看 `成功找到队伍`。 + +--- + +## 坑 3:位置法选队会在列表滚动时漂移 ★★★★☆ + +关掉名字查找、改用 `select_team_by_order: true`(按坐标点第 N 行)后: + +```python +first_position = [position[0], position[1] + 70 * scale] # 偏移 70 ≈ 一行高 +# 常量: ORDERED_TEAM_ROW_HEIGHT = 72.5 +``` + +**它落到第 2 行(TEAMS #2)而不是第 1 行**,日志依旧报 +`成功找到队伍 # 1`(`team_formation.py:163` 是位置法分支)。 + +我试过"上移一个行高"的补丁(`- ORDERED_TEAM_ROW_HEIGHT * scale`)—— +**无效**。因为它的前置"复位滑动"终点本身在漂移,固定偏移量治不了 +**移动的目标**。已把补丁还原,不在 vendored 代码里留无效改动。 + +**两种选队方式各自的死法**: + +| 方式 | 失效条件 | 表现 | +|---|---|---| +| 按名字 | 预设名互为子串 | 选中 `TEAMS #10`(空队) | +| 按位置 | 列表滚动位置漂移 | 选中 `TEAMS #2`(空队) | + +--- + +## 坑 4:解法是**让落点无意义**——把队伍复制到多个预设 ★★★★★ + +既然落点在 #1/#2 之间漂移、名字查找又不可靠,那就不去修定位, +而是**让两个预设装同一支队**。落到哪个都对。 + +游戏内其实有 **Team Code**(队伍码)功能,入口是队伍标题栏的剪贴板图标: + +```text +[TEAMS #1] [✏️] [📋] ← 📋 = Team Code +``` + +点开后: + +```text +[Copy Team Code] @ (816, 414) +[Load Team Code] @ (798, 510) +``` + +**关键技巧:`Copy Team Code` 不显示码,直接写进系统剪贴板**, +所以界面上看不到任何变化(我一度以为点击失败了)。可以直接读出来: + +```powershell +Get-Clipboard -Raw +# H4sIAAAAAAAACnM0dEx3BAJnIAQBz0BPEOUUDBF2c3R2A0lEAiVA...(108 字符 base64) +``` + +然后到目标预设 `Load Team Code` → `type_text` 输入 → `Confirm`。 + +**验证结果**:TEAMS #2 载入后与 #1 完全一致 +(`LV.34 / Lv.35 / LV.37 / LV.35 / LV.36 / Lv.35` + `LV.26 / Lv.35 / LV.29 / LV.29`)。 + +**修复后**:`0/5` 卡死 **306 次 → 0 次**,此后 10 轮 daily 全部 +`6/6 选队成功 · 0 卡死 · 0 错误`。 + +> **通用教训**:当两个方案的失效条件互补时,与其选一个去修, +> 不如**消除对它的依赖**。 + +--- + +## 坑 5:同步成功会播剧情,导致**假阴性** ★★★★☆ + +同步(Uptie)到三阶会**解锁并自动播放该人格的剧情**。此时界面上 +既没有 `Uptied` 字样,也不是失败——脚本按"没看到成功关键字"判了 FAIL。 + +**症状**:`同步: FAIL` 后面跟着一段角色台词: + +```text +同步未生效: swear, I swear to you! I will return this favor... Fuhu! +``` + +**修复**:加 `skip_cutscene()`——检测到 `skip` 提示就发 ESC 弹跳过框、 +点 `Confirm`,然后把同步判为成功。 + +```python +if 'skip' in txt.lower(): + conf = next(i for i in items if i['text'].startswith('Confirm')) + click(conf['x'], conf['y']) + return True, '同步成功(并跳过了解锁的人格剧情)' +``` + +**同一类问题的第二种表现**:ESC 弹出的"是否跳过"框本身也带 `Cancel`, +所以**判定不能用模糊字样**——详情页本来就有 `Uptie+`,用它判断 +"同步弹窗是否打开"会永远为真,必须先点 `Uptie` 再看有没有 +`Currency Req` / `Stats Increased` 这些**弹窗独有**文本。 + +--- + +## 坑 6:等级数字的 OCR **两处都不可靠** ★★★★☆ + +| 位置 | 字号 | 实测误读 | +|---|---|---| +| 网格卡片 | 小号艺术字 | `LV14` → `Lv.1`;`LV24` → `LV2H` | +| 详情页大号 | 艺术字 | LCB 罪人页**完全认不出** "LV 17" | + +**后果**:`weakest` 选目标会选错人;LCB 罪人那两张卡一直被跳过。 + +**解法:用 EXP 进度条反推等级**(纯数字,OCR 很准): + +```text +547/885 → Lv.17 (885 = 17→18 所需经验) +2037/2674 → Lv.24 (与直读 LV24 一致 ✅) +``` + +分母 = 当前等级升下一级所需经验,查 wiki 的 "EXP per Level" 表即可。 +表里有重复值(4899 对应 30/33/36),用网格读到的值做 tiebreak。 + +**同时保留双通道**:详情页直读的 LV 值 + 进度条反推,两者差异 >2 时告警。 + +--- + +## 坑 7:主界面上按"返回键"会**进入剧情 Drive** ★★★☆☆ + +我写恢复流程时盲目点左上返回键 `(85,75)`。在**主界面上**那会进入剧情, +掉进过场动画,还得靠 AALC 的 `reward` 任务(它开头有"返回主界面") +才救回来。 + +**修复**:恢复路径只点 `Sinners` 按钮 `(1130,805)`;返回键改成 +"只在确实需要退一层时"才按,且每次按完都检查是否已到目标界面。 + +--- + +## 坑 8:预设列表滚动——**拖拽起点必须在列表内部** ★★★☆☆ + +TEAMS 预设列表可以拖拽滚动,但: + +```text +drag(130,330 → 130,740) 起点在列表上方 → 完全无反应 +drag(170,390 → 170,720) 起点在列表内 → 列表 #35 → #28 ✅ +drag(200,420 → 200,730) 再拖 → #28 → #21 ✅ +``` + +**向下拖拽 = 内容下移 = 露出更靠前的预设。** + +另有 `▲` 箭头在列表顶部 `(162,375)`,但它**盖在首行上**,点它会 +选中那一行而不是滚动。 + +**注意**:当列表已在顶部时,拖拽自然无效(不是坏了)。 + +--- + +## 坑 9:狂气(Lunacy)必须**只用于抽卡** ★★★★☆ + +用户明确要求:**不得消耗狂气**。 + +AALC 默认会在体力不足时用狂气换体力(`体力换饼`),配置项: + +```yaml +set_lunacy_to_enkephalin: 2 # 0 不购买, 1 购买一次, 2 购买两次, 3 购买三次 +``` + +**三层防护**: + +1. 配置成 `0` —— AALC 根本不买 +2. 脚本 `lunacy_guard()` —— 每轮读余额,**一旦下降立即中止** +3. 基线落盘 `~/lc_mcp/lunacy_baseline.txt`,只增不减 + +**实测核对 9 次:`3436 → 3476`(净增 40,只涨不跌)** ✅ + +> 日志里出现 `开始执行 体力换饼` **不代表真的花了狂气**—— +> 要看它是否匹配到 `enkephalin_cancel_assets` 并点了取消。 +> 实测那两次都走了取消分支。 + +--- + +## 坑 10:`BACK` 常量作用域 bug——**测试假通过** ★★★☆☆ + +我把 `ensure_team1()` 写进 `auto_cycle.py` 时用了 `levelup.py` 里的 +常量 `BACK`,但没在新文件里定义: + +```text +NameError: name 'BACK' is not defined + File "auto_cycle.py", line 107, in ensure_team1 + click(*BACK) +``` + +**第一次测试"通过"是假象**:当时恰好在 TEAMS 页,`ensure_team1()` +走了提前返回的分支,**根本没执行到那一行**。只有从网格启动才会暴露。 + +**教训**:测一个有多分支的函数,**必须把每个分支都走到**, +否则"测过了"毫无意义。 + +--- + +## 坑 11:经验本产量有**账号进度天花板** ★★★☆☆ + +我一直以为产量低是配置问题,直到日志里偶然露出经验本的真实内容: + +```text +'EXPLuxcavation #1' 'Difficulty: Lv 8' +'EXPLuxcavation #2' 'Difficulty: Lv 18' +'EXPLuxcavation #3' 'Difficulty: Lv 28' +'ConsecutiveBattlex1' '> Skip Battle' +``` + +**这个账号只有 3 关经验本**(wiki 说的 #1–#10 是新版本内容)。 +所以上限就是 `3 × 4,800 = 14,400 EXP/轮`,和实测完全吻合。 + +**AALC 的档位选择已经是最优的**(按 x 从大到小、最右优先、失败才降级)。 + +另外 `Skip Battle` 给 +50% 奖励但**耗 2 倍体力模组**,单位体力效率 +反而更低——AALC 不跳战是对的。 + +--- + +## 坑 12:同步 Tier IV 需要**自我碎片**(不是 bug) ★★☆☆☆ + +每轮同步都报 FAIL,看起来像 bug。实际是: + +```text +Currency Req. [Season8] Heathcliff's Egoshard (Owned:2) +``` + +**Tier IV 需要 50 个对应罪人的自我碎片**(只有 2–3 个)。 +而解锁技能 3 的 **Tier III 只需要纺锤**——关键提升早就拿到了。 + +碎片必须从**镜牢**刷,不是配置能解决的。**不要把这个当故障处理。** + +--- + +## 坑 13:游戏窗口丢失 → AALC 会**自行重启游戏** ★★☆☆☆ + +最后一次运行的日志: + +```text +[ERROR] module\automation\screenshot.py:244: 未能获取到游戏窗口 +[ERROR] tasks\base\script_task_scheme.py:175: 未能获取到游戏窗口 +[DEBUG] module\game_and_screen\game.py:28: 游戏已启动:LimbusCompany.exe,进程ID:17220 +``` + +**AALC 内置"检测不到窗口就重启游戏"的逻辑**,而且它是用 Steam 命令 +启动的。如果用户手动关了游戏,会被它重新拉起来——**看起来像"关不掉"**。 + +> **2026-10-13 复核**:`task_20261005_201312_daily` 这一次并不是用户关了游戏。 +> 20:23–20:24 日志里 `点击(1,1)空白位置` 刷了 27 次(防卡死兜底),随后 +> `back_init_menu.py:27: 无法返回主界面,尝试重启游戏`——是 AALC 卡在未知界面后 +> **自己杀掉并重启了游戏**,窗口丢失是结果而不是原因。 + +--- + +## 坑 14:会话模型——RDP 与自动化**互斥** ★★★★★ + +(详细记录见 `docs/feedback/2026-10-04/README.md`,此处只记要点) + +```text +会话在物理 console、无人远程连接 → ✅ 自动化正常 +用户用 RDP 连着 → ❌ 会话被夺走, 显示面被拆 + GetCursorPos/SetCursorPos 返回 err=5 + BitBlt=0 +``` + +`tscon /dest:console` 能修,但**Windows 拒绝移动正在被使用的会话**。 +必须先让用户断开。 + +看门狗 `keep_display.ps1` 只在会话为 `Disc`(确认无人连接)时动作, +有人在用绝不插手。 + +--- + +## 附:自动化链路一览 + +```text +scripts/keep_display.ps1 会话掉 Disc 时提权 tscon 重挂 console(看门狗) +scripts/session_state.py WTS API 查会话状态(qwinsta 在计划任务里没输出) +scripts/render_check.py BitBlt 渲染自检 +scripts/mcp_probe.py MCP 握手 + 单次工具调用 +scripts/levelup.py 长按→详情→升级→同步(含 EXP 条反推等级) +scripts/auto_cycle.py 一轮:刷材料→升级→同步→前后对比 +``` + +`auto_cycle.py` **刻意只做一轮,不做无限循环**——由外层按轮驱动, +便于每轮核对与随时中止,避免无人监督地长时间空转。 + +--- + +## 战果 + +```text +daily 完整成功轮次 10 次(6/6 选队 · 0 卡死 · 0 错误) +升级人格 5 个(Rosespanner 04→36, N Corp 14→33, + Zwei 14→33, LCB Sinner 17→33, LCB Sinner 17→30) +同步成功 Rosespanner(三阶: 技能3 + 新被动 Chronic Fatigue) + N Corp(三阶) +账号等级 037 → 041 +狂气 2896 → 3476(只增不减,一分未花)✅ +``` diff --git a/docs/feedback/2026-10-05/README.md b/docs/feedback/2026-10-05/README.md new file mode 100644 index 0000000..9611d79 --- /dev/null +++ b/docs/feedback/2026-10-05/README.md @@ -0,0 +1,177 @@ +# 2026-10-05 人格升级自动化与选队定位缺陷 + +接 `docs/feedback/2026-10-04/`。这一天的工作从"能刷"推进到"能养": +把**人格升级/同步**这条原本只存在于 GUI 的链路自动化,并定位到一个会 +静默选错队伍的配置陷阱。 + +## 结果 + +```text +daily 一轮 18 分钟,exit 0,0 错误 +自动化一整轮 刷材料 -> 升级 -> 同步 -> 前后对比,约 20 分钟 +实测升级 N Corp. Mittelhammer Lv.14 -> Lv.26 +实测升级 Rosespanner Workshop Fixer Lv.04 -> Lv.36 + HP 87->173,Defense Level 4->36 +实测同步 Rosespanner Uptie 二阶->三阶 + 解锁 Skill 3「Saddled Tasks」+ 新被动 Chronic Fatigue +``` + +## 一、人格详情页是长按打开的 ★ + +**这是整件事的关键,也是最反直觉的一点。** + +罪人界面(Sinners → Identities)的卡片: + +| 操作 | 结果 | +|---|---| +| 单击 | 只是**选中/取消选中**(在队伍预设里增删成员) | +| 长按 | **打开人格详情页** | + +单击试遍了卡片头像、SELECTED 横幅、名字等级区、双击、右侧面板、 +左侧罪人栏、右上 `i`、Details 按钮——**全都只能选中**。长按一下, +详情页里 `Level Up` 和 `Uptie` 两个按钮就在那里。 + +**自动化实现**:lc-mcp 没有 long-press 工具,但 `drag` 是 +`按下 -> 移动 -> 抬起`,**起点终点相同**就是长按: + +```python +probe('drag', {'from_x': x, 'from_y': y, 'to_x': x, 'to_y': y}) +``` + +实测稳定可复现。 + +### 完整坐标(1600x900 客户区) + +```text +罪人界面网格 列 x = 335 508 681 853 1026 1198 + 行 y = 260 487 715 942 +人格详情页 Level Up (1164, 235) Uptie (1367, 235) +升级(Power-up)窗口 券档位行 y = 383(IV) 490(III) 598(II) + 「全部投入」按钮 x = 1133(每行同 x) + Confirm (1030, 670) Cancel (603, 670) +同步(Uptie)窗口 Uptie (1085, 580) 完成 Confirm (772, 661) + 取消 (526, 660) +``` + +## 二、`select_team_by_order: true` 会静默选错队伍 ★ + +> **2026-10-13 更正**:本节"改回按名字查找即修复"的结论**已被推翻**。 +> 同日 16:59 那轮按名字查找时,`TEAMS #1` 子串误匹配到 `TEAMS #10`(空预设), +> 空转 27 分钟。两种选队方式各有失效条件,最终解法是用 Team Code 把 +> TEAMS #1 复制到 #2,让落点无所谓。以 `PITFALLS.md` 坑 2–4 为准。 + +**这个坑比看上去严重:它不报错,只是"刷了半天什么也没发生"。** + +`tasks/teams/team_formation.py` 有两条选队路径: + +```python +if cfg.select_team_by_order: + # 按"位置"点击:first_position + 行高 × 序号 + first_position = [position[0], position[1] + 70 * scale] + ... + auto.mouse_click(first_position[0], + first_position[1] + _ordered_team_click_offset(...) * scale) +else: + # 按"名字"查找 + team_name_en = [f"TEAMS #{num}", f"TEAMS#{num}", f"TFAMS#{num}"] + if team_position := auto.find_language_text(team_name_zh, team_name_en, ...): + auto.mouse_action_with_pos(team_position, offset=False) +``` + +**位置法对列表滚动位置极其脆弱**:代码虽然会先做几次"复位滑动" +(`_team_list_reset_swipe_count`),但只要复位不完美、或列表因为 +某些原因整体位移(实测位移了 75px),点击就会落到隔壁队伍上。 + +**实测后果**: + +```text +13:21:40 最后一次里程碑 +... 26 分钟没有任何日志(日志在涨,但只是 OCR 空转) +画面 TEAMS #2 | You haven't Deployed any Sinners. + Participant Limit 0/5 +``` + +队伍预设被切到了一个**空队伍**,AALC 找不到可用队伍 → 空转。 + +**修复**:改回按名字查找。 + +```yaml +select_team_by_order: false +``` + +修复后连续 4 次选队全部命中,日志行号从 `team_formation.py:163` +(位置法)变成 `:188`(名字法),可以直接从日志判断走的是哪条路: + +```text +13:51:12 成功找到队伍 # 1 +13:54:26 成功找到队伍 # 1 +13:57:45 成功找到队伍 # 1 +14:00:27 成功找到队伍 # 1 +``` + +> **教训**:当初开 `select_team_by_order` 是为了绕过"编队名匹配失败"。 +> 但那个问题的真因是 `sinner_order` 全 0(见 10-04 的记录), +> 修好之后名字匹配本来就能用。**为一个症状加的开关,在根因修好后 +> 反而变成了新的故障源。** + +## 三、等级与材料数值(wiki 查证) + +```text +人格等级上限 新手期 Lv.40;通关 Canto V 后每章 +5(当前版本最高 Lv.65) +经验本档位 AALC 按 x 从大到小遍历(最右优先),失败才降级——已是最优策略 + 产量低是因为账号只解锁了前几档,不是选错 +训练券价值 I=50 II=200 III=1000 IV=3000 EXP +升级到 Lv.40 累计 91,700 EXP(Lv.34 时已累计 55,048) +同步(3★) II=20纺锤 III=80纺锤 IV=150纺锤+50自我碎片 +跳战 给 +50% 奖励但耗 2 倍体力模组——单位体力效率反而更低 +``` + +**实战消耗**:`Rosespanner` 从 Lv.04 拉到 Lv.36 用了 +52 张 III 券 + 71 张 II 券(共 66,200 EXP)+ 10 纺锤。 + +## 四、新增脚本 + +### `scripts/levelup.py` + +长按打开人格详情 → 升级 → 同步。支持: + +```bash +python levelup.py list # 列出网格里的人格及等级/是否在队伍 +python levelup.py weakest [--uptie] # 对队内等级最低者执行升级 +python levelup.py card # 对指定卡片执行 +python levelup.py back # 返回网格 +``` + +**判定弹窗时不要用模糊字样**:详情页本身就有 `Uptie+`, +用它判断"同步弹窗是否打开"会永远为真。要用弹窗独有文本: + +```python +# 升级窗口: 'Owned' + 'Cancel' +# 同步窗口: 'Currency Req' / 'Stats Increased' / 'Skills Gained' +``` + +**券余额不要靠券名判定档位**:OCR 会把 `III` 认成小写 `lll`, +`'III' in text` 直接失效。改用行的 y 坐标(三行固定为 IV/III/II)。 + +### `scripts/auto_cycle.py` + +一整轮:`daily` → 进网格 → 升最弱者 + 同步 → 输出前后对比。 + +**刻意只做一轮,不做无限循环**——由外层按轮驱动,便于每轮核对与中止, +避免无人监督地长时间空转。 + +## 五、又一个自己制造的事故:返回键会进剧情 + +恢复流程里我从主界面点左上返回键(85, 75),**结果进了剧情 Drive**, +掉进过场动画,还得靠 `reward` 任务的 `返回主界面` 才救回来。 + +**修复**:恢复路径只点 `Sinners` 按钮,返回键改成"只在确实需要退一层时" +才按,且每次按完都检查是否已到目标界面。 + +## 仍未解决 / 已知限制 + +1. **升级后界面判断可能残留**:`do_level_up` 里目标等级靠 `▶` 字符解析, + OCR 常把它认丢。已加"两段等级且后者更大"的兜底,但仍是启发式。 +2. **`daily` 产量受账号解锁进度限制**,无法通过配置提高。 +3. **看门狗只覆盖桌面变黑**,界面走丢(如本次进剧情)仍需外部恢复。 +4. 本轮只验证了**单个人格连升 + 同步**,多轮连续运行的稳定性未验证。 diff --git a/docs/feedback/2026-10-05/logs/01-good-run-team-selection.txt b/docs/feedback/2026-10-05/logs/01-good-run-team-selection.txt new file mode 100644 index 0000000..04949de --- /dev/null +++ b/docs/feedback/2026-10-05/logs/01-good-run-team-selection.txt @@ -0,0 +1,31 @@ +[DEBUG] 2026-10-05 19:10:31,855 [AALC] module\game_and_screen\game.py:28: 游戏已启动:LimbusCompany.exe,进程ID:21516 +[INFO] 2026-10-05 19:10:41,952 [AALC] tasks\base\script_task_scheme.py:262: 开始执行 一次经验本 +[INFO] 2026-10-05 19:11:01,380 [AALC] tasks\teams\team_formation.py:163: 成功找到队伍 # 1 +[INFO] 2026-10-05 19:11:04,733 [AALC] tasks\base\script_task_scheme.py:63: 开始执行 一次战斗 +[INFO] 2026-10-05 19:14:24,645 [AALC] tasks\base\script_task_scheme.py:262: 结束执行 一次经验本 +[DEBUG] 2026-10-05 19:14:24,646 [AALC] tasks\base\script_task_scheme.py:262: 结束执行 一次经验本 耗时:00:03:42 +[INFO] 2026-10-05 19:14:24,647 [AALC] tasks\base\script_task_scheme.py:262: 开始执行 一次经验本 +[INFO] 2026-10-05 19:14:44,310 [AALC] tasks\teams\team_formation.py:163: 成功找到队伍 # 1 +[INFO] 2026-10-05 19:14:47,582 [AALC] tasks\base\script_task_scheme.py:63: 开始执行 一次战斗 +[INFO] 2026-10-05 19:16:51,519 [AALC] tasks\base\script_task_scheme.py:262: 结束执行 一次经验本 +[DEBUG] 2026-10-05 19:16:51,521 [AALC] tasks\base\script_task_scheme.py:262: 结束执行 一次经验本 耗时:00:02:26 +[INFO] 2026-10-05 19:16:51,522 [AALC] tasks\base\script_task_scheme.py:262: 开始执行 一次经验本 +[INFO] 2026-10-05 19:17:11,178 [AALC] tasks\teams\team_formation.py:163: 成功找到队伍 # 1 +[INFO] 2026-10-05 19:17:14,456 [AALC] tasks\base\script_task_scheme.py:63: 开始执行 一次战斗 +[INFO] 2026-10-05 19:19:56,614 [AALC] tasks\base\script_task_scheme.py:262: 结束执行 一次经验本 +[DEBUG] 2026-10-05 19:19:56,615 [AALC] tasks\base\script_task_scheme.py:262: 结束执行 一次经验本 耗时:00:03:05 +[INFO] 2026-10-05 19:19:56,616 [AALC] tasks\base\script_task_scheme.py:264: 开始执行 一次纽本 +[INFO] 2026-10-05 19:20:18,975 [AALC] tasks\teams\team_formation.py:163: 成功找到队伍 # 1 +[INFO] 2026-10-05 19:20:22,251 [AALC] tasks\base\script_task_scheme.py:79: 开始执行 一次战斗 +[INFO] 2026-10-05 19:22:46,986 [AALC] tasks\base\script_task_scheme.py:264: 结束执行 一次纽本 +[DEBUG] 2026-10-05 19:22:46,987 [AALC] tasks\base\script_task_scheme.py:264: 结束执行 一次纽本 耗时:00:02:50 +[INFO] 2026-10-05 19:22:46,988 [AALC] tasks\base\script_task_scheme.py:264: 开始执行 一次纽本 +[INFO] 2026-10-05 19:23:09,326 [AALC] tasks\teams\team_formation.py:163: 成功找到队伍 # 1 +[INFO] 2026-10-05 19:23:12,600 [AALC] tasks\base\script_task_scheme.py:79: 开始执行 一次战斗 +[INFO] 2026-10-05 19:25:44,880 [AALC] tasks\base\script_task_scheme.py:264: 结束执行 一次纽本 +[DEBUG] 2026-10-05 19:25:44,881 [AALC] tasks\base\script_task_scheme.py:264: 结束执行 一次纽本 耗时:00:02:57 +[INFO] 2026-10-05 19:25:44,881 [AALC] tasks\base\script_task_scheme.py:264: 开始执行 一次纽本 +[INFO] 2026-10-05 19:26:07,111 [AALC] tasks\teams\team_formation.py:163: 成功找到队伍 # 1 +[INFO] 2026-10-05 19:26:10,394 [AALC] tasks\base\script_task_scheme.py:79: 开始执行 一次战斗 +[INFO] 2026-10-05 19:28:20,655 [AALC] tasks\base\script_task_scheme.py:264: 结束执行 一次纽本 +[DEBUG] 2026-10-05 19:28:20,657 [AALC] tasks\base\script_task_scheme.py:264: 结束执行 一次纽本 耗时:00:02:35 diff --git a/docs/feedback/2026-10-05/logs/02-stall-substring-bug.txt b/docs/feedback/2026-10-05/logs/02-stall-substring-bug.txt new file mode 100644 index 0000000..6e96ab1 --- /dev/null +++ b/docs/feedback/2026-10-05/logs/02-stall-substring-bug.txt @@ -0,0 +1,400 @@ +[DEBUG] 2026-10-05 16:59:13,162 [AALC] module\game_and_screen\game.py:28: 游戏已启动:LimbusCompany.exe,进程ID:21516 +[INFO] 2026-10-05 16:59:23,300 [AALC] tasks\base\script_task_scheme.py:262: 开始执行 一次经验本 +[INFO] 2026-10-05 16:59:50,767 [AALC] tasks\teams\team_formation.py:188: 成功找到队伍 # 1 +[DEBUG] 2026-10-05 16:59:54,738 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 16:59:57,457 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:00:00,183 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:00:02,922 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:00:05,625 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:00:08,344 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:00:11,071 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:00:13,782 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:00:16,501 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:00:19,229 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:00:22,038 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:00:24,777 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:00:27,478 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:00:30,210 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:00:32,939 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:00:35,643 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:00:38,339 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:00:41,072 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:00:43,804 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:00:46,541 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:00:49,314 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:00:52,059 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:00:54,775 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:00:57,480 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:00,223 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:01:02,933 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:05,657 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:01:08,389 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:11,113 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:01:13,817 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:16,551 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:01:19,246 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:21,962 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:01:24,708 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:27,434 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:01:30,144 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:32,874 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:01:35,564 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:38,289 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:01:40,987 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:43,692 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:01:46,393 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:49,124 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:01:51,822 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:54,568 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:01:57,276 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:01:59,976 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:02:02,704 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:02:05,445 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:02:08,164 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:02:10,878 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:02:13,567 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:02:16,312 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:02:19,015 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:02:21,713 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:02:24,452 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:02:27,171 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:02:29,874 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:02:32,600 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:02:35,319 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:02:37,971 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:02:40,717 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:02:43,416 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:02:46,122 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:02:48,867 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:02:51,571 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:02:54,256 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:02:56,994 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:02:59,729 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:03:02,424 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:03:05,136 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:03:07,824 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:03:10,546 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:03:13,236 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:03:15,952 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:03:18,661 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:03:21,349 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:03:24,072 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:03:26,788 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:03:29,487 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:03:32,204 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:03:34,941 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:03:37,627 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:03:40,361 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:03:43,114 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:03:45,815 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:03:48,563 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:03:51,268 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:03:53,963 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:03:56,683 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:03:59,385 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:04:02,085 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:04:04,792 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:04:07,477 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:04:10,203 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:04:12,911 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:04:15,619 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:04:18,329 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:04:21,031 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:04:23,695 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:04:26,419 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:04:29,144 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:04:31,847 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:04:34,551 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:04:37,291 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:04:40,003 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:04:42,687 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:04:45,425 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:04:48,169 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:04:50,874 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:04:53,590 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:04:56,290 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:04:58,983 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:05:01,780 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:05:04,486 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:05:07,235 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:05:09,948 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:05:12,627 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:05:15,356 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:05:18,050 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:05:20,762 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:05:23,490 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:05:26,244 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:05:28,927 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:05:31,605 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:05:34,326 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:05:37,029 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:05:39,735 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:05:42,471 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:05:45,190 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:05:47,912 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:05:50,593 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:05:53,430 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:05:56,155 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:05:58,835 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:06:01,562 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:06:04,262 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:06:06,963 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:06:09,721 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:06:12,447 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:06:15,158 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:06:17,864 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:06:20,561 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:06:23,271 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:06:25,971 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:06:28,662 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:06:31,374 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:06:34,103 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:06:36,825 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:06:39,523 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:06:42,256 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:06:44,959 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:06:47,674 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:06:50,414 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:06:53,109 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:06:55,814 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:06:58,524 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:07:01,209 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:07:03,938 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:07:06,642 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:07:09,332 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:07:12,075 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:07:14,775 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:07:17,507 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:07:20,309 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:07:23,031 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:07:25,804 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:07:28,564 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:07:31,338 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:07:34,086 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:07:36,860 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:07:39,580 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:07:42,367 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:07:45,123 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:07:47,918 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:07:50,704 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:07:53,464 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:07:56,202 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:07:58,885 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:08:01,604 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:08:04,319 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:08:07,030 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:08:09,762 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:08:12,481 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:08:15,198 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:08:17,887 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:08:20,598 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:08:23,307 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:08:26,013 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:08:28,709 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:08:31,420 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:08:34,140 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:08:36,842 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:08:39,542 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:08:42,262 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:08:44,984 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:08:47,673 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:08:50,418 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:08:53,144 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:08:55,857 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:08:58,584 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:09:01,298 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:09:03,983 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:09:06,720 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:09:09,451 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:09:12,151 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:09:14,863 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:09:17,547 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:09:20,268 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:09:22,980 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:09:25,688 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:09:28,400 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:09:31,119 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:09:33,777 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:09:36,541 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:09:39,207 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:09:41,907 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:09:44,623 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:09:47,339 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:09:50,076 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:09:52,804 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:09:55,503 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:09:58,206 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:10:00,924 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:10:03,648 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:10:06,349 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:10:09,066 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:10:11,744 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:10:14,463 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:10:17,188 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:10:19,897 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:10:22,625 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:10:25,331 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:10:28,030 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:10:30,728 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:10:33,435 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:10:36,137 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:10:38,889 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:10:41,588 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:10:44,296 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:10:47,040 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:10:49,766 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:10:52,494 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:10:55,225 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:10:57,872 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:11:00,594 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:11:03,323 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:11:06,028 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:11:08,738 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:11:11,453 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:11:14,178 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:11:16,895 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:11:19,609 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:11:22,309 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:11:25,020 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:11:27,712 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:11:30,422 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:11:33,158 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:11:35,885 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:11:38,609 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:11:41,345 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:11:44,060 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:11:46,774 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:11:49,554 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:11:52,256 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:11:54,971 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:11:57,686 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:12:00,400 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:12:03,125 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:12:05,815 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:12:08,521 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:12:11,248 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:12:13,971 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:12:16,667 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:12:19,397 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:12:22,104 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:12:24,835 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:12:27,534 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:12:30,237 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:12:32,940 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:12:35,688 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:12:38,381 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:12:41,086 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:12:43,811 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:12:46,528 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:12:49,222 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:12:51,978 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:12:54,670 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:12:57,419 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:00,125 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:13:02,830 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:05,538 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:13:08,248 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:10,958 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:13:13,648 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:16,359 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:13:19,062 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:21,766 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:13:24,482 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:27,212 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:13:29,939 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:32,666 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:13:35,400 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:38,107 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:13:40,832 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:43,534 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:13:46,259 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:48,957 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:13:51,686 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:54,389 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:13:57,106 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:13:59,802 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:14:02,520 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:14:05,223 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:14:07,936 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:14:10,659 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:14:13,380 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:14:16,087 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:14:18,813 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:14:21,503 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:14:24,222 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:14:26,899 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:14:29,587 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:14:32,321 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:14:35,028 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:14:37,745 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:14:40,486 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:14:43,138 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:14:45,898 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:14:48,584 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:14:51,329 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:14:54,038 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:14:56,745 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:14:59,448 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:15:02,234 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:15:04,929 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:15:07,682 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:15:10,421 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:15:13,119 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:15:15,820 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:15:18,615 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:15:21,358 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:15:24,124 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:15:26,832 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:15:29,534 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:15:32,251 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:15:34,979 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:15:37,674 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:15:40,402 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:15:43,122 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:15:45,823 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:15:48,554 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:15:51,312 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:15:54,015 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:15:56,727 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:15:59,446 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:16:02,163 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:16:04,998 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:16:07,735 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:16:10,484 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:16:13,199 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:16:15,914 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:16:18,677 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:16:21,375 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:16:24,082 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:16:26,815 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:16:29,532 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:16:32,220 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:16:34,952 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:16:37,677 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:16:40,400 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:16:43,139 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:16:45,850 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:16:48,587 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:16:51,361 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:16:54,065 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:16:56,793 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:16:59,510 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:17:02,222 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:17:04,965 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:17:07,681 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:17:10,391 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:17:13,126 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:17:15,813 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:17:18,514 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:17:21,232 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:17:23,941 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:17:26,660 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:17:29,382 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:17:32,095 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:17:34,795 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:17:37,494 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:17:40,206 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:17:42,914 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:17:45,607 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:17:48,311 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:17:51,077 [AALC] tasks\teams\team_formation.py:225: 对于配队人数OCR得到:/5Mrt diff --git a/docs/feedback/2026-10-05/logs/03-stall-offbyone-0of5.txt b/docs/feedback/2026-10-05/logs/03-stall-offbyone-0of5.txt new file mode 100644 index 0000000..56449c5 --- /dev/null +++ b/docs/feedback/2026-10-05/logs/03-stall-offbyone-0of5.txt @@ -0,0 +1,62 @@ +[DEBUG] 2026-10-05 17:46:17,983 [AALC] module\game_and_screen\game.py:28: 游戏已启动:LimbusCompany.exe,进程ID:21516 +[INFO] 2026-10-05 17:46:26,095 [AALC] tasks\base\script_task_scheme.py:262: 开始执行 一次经验本 +[INFO] 2026-10-05 17:46:45,562 [AALC] tasks\teams\team_formation.py:169: 成功找到队伍 # 1 +[DEBUG] 2026-10-05 17:46:49,709 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:46:52,437 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:46:55,180 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:46:57,903 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:47:00,609 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:47:03,319 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:47:06,024 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:47:08,730 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:47:11,452 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:47:14,161 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:47:16,884 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:47:19,598 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:47:22,315 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:47:25,020 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:47:27,739 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:47:30,468 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:47:33,191 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:47:35,918 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:47:38,646 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:47:41,372 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:47:44,071 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:47:46,794 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:47:49,547 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:47:52,267 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:47:54,977 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:47:57,690 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:48:00,410 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:48:03,126 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:48:05,833 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:48:08,525 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:48:11,228 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:48:13,954 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:48:16,681 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:48:19,381 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:48:22,096 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:48:24,862 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:48:27,728 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:48:30,448 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:48:33,123 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:48:35,780 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:48:38,505 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:48:41,237 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:48:43,944 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:48:46,643 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:48:49,371 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:48:52,211 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:48:54,991 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:48:57,721 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:49:00,457 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:49:03,199 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:49:06,073 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:49:08,803 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:49:11,509 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:49:14,232 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:49:16,958 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:49:19,648 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:49:22,366 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt +[DEBUG] 2026-10-05 17:49:25,074 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:0/5 +[DEBUG] 2026-10-05 17:49:27,825 [AALC] tasks\teams\team_formation.py:231: 对于配队人数OCR得到:/5Mrt diff --git a/docs/feedback/2026-10-05/logs/04-crash-window-lost.txt b/docs/feedback/2026-10-05/logs/04-crash-window-lost.txt new file mode 100644 index 0000000..da27463 --- /dev/null +++ b/docs/feedback/2026-10-05/logs/04-crash-window-lost.txt @@ -0,0 +1,37 @@ +[DEBUG] 2026-10-05 20:13:17,882 [AALC] module\game_and_screen\game.py:28: 游戏已启动:LimbusCompany.exe,进程ID:21516 +[INFO] 2026-10-05 20:13:26,177 [AALC] tasks\base\script_task_scheme.py:262: 开始执行 一次经验本 +[INFO] 2026-10-05 20:13:45,599 [AALC] tasks\teams\team_formation.py:163: 成功找到队伍 # 1 +[INFO] 2026-10-05 20:13:48,986 [AALC] tasks\base\script_task_scheme.py:63: 开始执行 一次战斗 +[INFO] 2026-10-05 20:16:23,667 [AALC] tasks\base\script_task_scheme.py:262: 结束执行 一次经验本 +[DEBUG] 2026-10-05 20:16:23,668 [AALC] tasks\base\script_task_scheme.py:262: 结束执行 一次经验本 耗时:00:02:57 +[INFO] 2026-10-05 20:16:23,668 [AALC] tasks\base\script_task_scheme.py:262: 开始执行 一次经验本 +[INFO] 2026-10-05 20:16:43,255 [AALC] tasks\teams\team_formation.py:163: 成功找到队伍 # 1 +[INFO] 2026-10-05 20:16:46,584 [AALC] tasks\base\script_task_scheme.py:63: 开始执行 一次战斗 +[INFO] 2026-10-05 20:19:10,296 [AALC] tasks\base\script_task_scheme.py:262: 结束执行 一次经验本 +[DEBUG] 2026-10-05 20:19:10,297 [AALC] tasks\base\script_task_scheme.py:262: 结束执行 一次经验本 耗时:00:02:46 +[INFO] 2026-10-05 20:19:10,298 [AALC] tasks\base\script_task_scheme.py:262: 开始执行 一次经验本 +[INFO] 2026-10-05 20:19:29,925 [AALC] tasks\teams\team_formation.py:163: 成功找到队伍 # 1 +[INFO] 2026-10-05 20:19:33,202 [AALC] tasks\base\script_task_scheme.py:63: 开始执行 一次战斗 +[ERROR] 2026-10-05 20:24:34,086 [AALC] tasks\base\back_init_menu.py:27: 无法返回主界面,尝试重启游戏 +[WARNING] 2026-10-05 20:24:34,527 [AALC] module\game_and_screen\screen.py:258: 窗口句柄无效,可能窗口已关闭,重新获取, 当前句柄为 9767274 +[ERROR] 2026-10-05 20:24:34,532 [AALC] module\game_and_screen\screen.py:103: 未能获取到游戏窗口 +[DEBUG] 2026-10-05 20:24:34,533 [AALC] module\game_and_screen\screen.py:42: 枚举窗口列表: [] +[ERROR] 2026-10-05 20:24:34,534 [AALC] module\game_and_screen\screen.py:103: 未能获取到游戏窗口 +[DEBUG] 2026-10-05 20:24:34,535 [AALC] module\game_and_screen\screen.py:42: 枚举窗口列表: [] +[ERROR] 2026-10-05 20:24:34,536 [AALC] module\game_and_screen\screen.py:140: 未能获取到游戏窗口 +[DEBUG] 2026-10-05 20:24:34,537 [AALC] module\game_and_screen\screen.py:42: 枚举窗口列表: [] +[ERROR] 2026-10-05 20:24:34,538 [AALC] module\game_and_screen\screen.py:223: 未能获取到游戏窗口 +[DEBUG] 2026-10-05 20:24:34,539 [AALC] module\game_and_screen\screen.py:42: 枚举窗口列表: [] +[ERROR] 2026-10-05 20:24:34,540 [AALC] module\automation\screenshot.py:188: 未能获取到游戏窗口 +[DEBUG] 2026-10-05 20:24:34,541 [AALC] module\game_and_screen\screen.py:42: 枚举窗口列表: [] +[ERROR] 2026-10-05 20:24:34,542 [AALC] module\automation\screenshot.py:238: 后台截图报错: 未找到游戏窗口句柄,无法截图,尝试重启游戏 +[ERROR] 2026-10-05 20:24:34,549 [AALC] module\automation\screenshot.py:244: 未能获取到游戏窗口 +[DEBUG] 2026-10-05 20:24:34,550 [AALC] module\game_and_screen\screen.py:42: 枚举窗口列表: [] +[DEBUG] 2026-10-05 20:24:34,947 [AALC] module\game_and_screen\game.py:28: 游戏已启动:LimbusCompany.exe,进程ID:21516 +[ERROR] 2026-10-05 20:24:34,962 [AALC] tasks\base\script_task_scheme.py:175: 未能获取到游戏窗口 +[DEBUG] 2026-10-05 20:24:34,964 [AALC] module\game_and_screen\screen.py:42: 枚举窗口列表: [] +[ERROR] 2026-10-05 20:24:34,965 [AALC] module\game_and_screen\screen.py:317: 未能获取到游戏窗口 +[DEBUG] 2026-10-05 20:24:34,966 [AALC] module\game_and_screen\screen.py:42: 枚举窗口列表: [] +[INFO] 2026-10-05 20:24:34,967 [AALC] module\game_and_screen\screen.py:318: 未能获取到游戏窗口: LimbusCompany,尝试启动游戏 +[INFO] 2026-10-05 20:24:35,370 [AALC] module\game_and_screen\game.py:58: 使用steam命令启动游戏 +[DEBUG] 2026-10-05 20:24:40,378 [AALC] module\game_and_screen\game.py:28: 游戏已启动:LimbusCompany.exe,进程ID:17220 diff --git a/docs/feedback/2026-10-05/logs/elev2.txt b/docs/feedback/2026-10-05/logs/elev2.txt new file mode 100644 index 0000000..3bef0d7 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/elev2.txt differ diff --git a/docs/feedback/2026-10-05/logs/elev_check.txt b/docs/feedback/2026-10-05/logs/elev_check.txt new file mode 100644 index 0000000..411d2ec Binary files /dev/null and b/docs/feedback/2026-10-05/logs/elev_check.txt differ diff --git a/docs/feedback/2026-10-05/logs/full/keep_display.log.gz b/docs/feedback/2026-10-05/logs/full/keep_display.log.gz new file mode 100644 index 0000000..4d0822b Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/keep_display.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/lc_mcp.log.gz b/docs/feedback/2026-10-05/logs/full/lc_mcp.log.gz new file mode 100644 index 0000000..321cd9b Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/lc_mcp.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/server.log.gz b/docs/feedback/2026-10-05/logs/full/server.log.gz new file mode 100644 index 0000000..4a462d7 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/server.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_150033_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_150033_daily.log.gz new file mode 100644 index 0000000..f83c625 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_150033_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_152011_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_152011_daily.log.gz new file mode 100644 index 0000000..6e8d6d1 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_152011_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_154351_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_154351_daily.log.gz new file mode 100644 index 0000000..928f791 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_154351_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_161735_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_161735_daily.log.gz new file mode 100644 index 0000000..a3e62e7 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_161735_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_163949_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_163949_daily.log.gz new file mode 100644 index 0000000..f8d9022 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_163949_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_165908_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_165908_daily.log.gz new file mode 100644 index 0000000..991727f Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_165908_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_173104_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_173104_daily.log.gz new file mode 100644 index 0000000..d64f429 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_173104_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_173724_reward.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_173724_reward.log.gz new file mode 100644 index 0000000..72728f2 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_173724_reward.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_174057_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_174057_daily.log.gz new file mode 100644 index 0000000..151e89f Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_174057_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_174344_reward.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_174344_reward.log.gz new file mode 100644 index 0000000..2ff7e5e Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_174344_reward.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_174614_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_174614_daily.log.gz new file mode 100644 index 0000000..983a19d Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_174614_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_174942_reward.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_174942_reward.log.gz new file mode 100644 index 0000000..16cd1a1 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_174942_reward.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_175842_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_175842_daily.log.gz new file mode 100644 index 0000000..533e121 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_175842_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_182317_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_182317_daily.log.gz new file mode 100644 index 0000000..6f5651e Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_182317_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_184236_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_184236_daily.log.gz new file mode 100644 index 0000000..f5d166e Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_184236_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_190424_reward.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_190424_reward.log.gz new file mode 100644 index 0000000..122e8c4 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_190424_reward.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_191026_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_191026_daily.log.gz new file mode 100644 index 0000000..263c54f Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_191026_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_193053_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_193053_daily.log.gz new file mode 100644 index 0000000..c316eb6 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_193053_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_195147_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_195147_daily.log.gz new file mode 100644 index 0000000..2a776c8 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_195147_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/full/task_20261005_201312_daily.log.gz b/docs/feedback/2026-10-05/logs/full/task_20261005_201312_daily.log.gz new file mode 100644 index 0000000..35cd325 Binary files /dev/null and b/docs/feedback/2026-10-05/logs/full/task_20261005_201312_daily.log.gz differ diff --git a/docs/feedback/2026-10-05/logs/keep_display-watchdog.txt b/docs/feedback/2026-10-05/logs/keep_display-watchdog.txt new file mode 100644 index 0000000..0ea47cb --- /dev/null +++ b/docs/feedback/2026-10-05/logs/keep_display-watchdog.txt @@ -0,0 +1,177 @@ +[2026-10-05 01:15:26] ForceDisc: skipping state check (real state was 'Disc') +[2026-10-05 01:15:26] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 01:15:58] tscon said: (no output file) | session 2 now: Active +[2026-10-05 01:15:58] render check: BitBlt=1 desktop=1920x1080 +[2026-10-05 08:35:05] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 08:35:37] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 08:35:37] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 08:35:37] WARN: session 2 still 'Disc' after tscon +[2026-10-05 08:40:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 08:40:36] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 08:40:36] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 08:40:36] WARN: session 2 still 'Disc' after tscon +[2026-10-05 08:45:05] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 08:45:37] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 08:45:37] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 08:45:37] WARN: session 2 still 'Disc' after tscon +[2026-10-05 10:39:25] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 10:39:57] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 10:39:57] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 10:39:57] WARN: session 2 still 'Disc' after tscon +[2026-10-05 10:40:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 10:40:37] tscon said: (no output file) | session 2 now: Active +[2026-10-05 10:40:37] render check: BitBlt=1 desktop=1920x1080 +[2026-10-05 20:35:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 20:35:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 20:35:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 20:35:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 20:40:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 20:40:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 20:40:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 20:40:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 20:45:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 20:45:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 20:45:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 20:45:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 20:50:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 20:50:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 20:50:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 20:50:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 20:55:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 20:55:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 20:55:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 20:55:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:00:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:00:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:00:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:00:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:05:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:05:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:05:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:05:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:10:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:10:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:10:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:10:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:15:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:15:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:15:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:15:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:20:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:20:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:20:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:20:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:25:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:25:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:25:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:25:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:30:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:30:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:30:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:30:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:35:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:35:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:35:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:35:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:40:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:40:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:40:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:40:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:45:03] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:45:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:45:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:45:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:50:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:50:34] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:50:34] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:50:34] WARN: session 2 still 'Disc' after tscon +[2026-10-05 21:55:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 21:55:34] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 21:55:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 21:55:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 22:00:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:00:34] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 22:00:34] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 22:00:34] WARN: session 2 still 'Disc' after tscon +[2026-10-05 22:05:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:05:34] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 22:05:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 22:05:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 22:10:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:10:34] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 22:10:34] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 22:10:34] WARN: session 2 still 'Disc' after tscon +[2026-10-05 22:15:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:15:34] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 22:15:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 22:15:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 22:20:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:20:34] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 22:20:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 22:20:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 22:25:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:25:34] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 22:25:35] render check: BitBlt=0 desktop=2560x1600 +[2026-10-05 22:25:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 22:30:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:30:21] tscon said: (no output file) | session 2 now: Active +[2026-10-05 22:30:22] render check: BitBlt=1 desktop=1872x921 +[2026-10-05 22:35:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:35:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 22:35:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 22:35:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 22:40:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:40:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 22:40:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 22:40:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 22:45:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:45:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 22:45:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 22:45:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 22:50:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:50:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 22:50:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 22:50:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 22:55:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 22:55:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 22:55:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 22:55:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 23:00:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 23:00:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 23:00:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 23:00:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 23:05:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 23:05:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 23:05:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 23:05:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 23:10:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 23:10:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 23:10:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 23:10:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 23:15:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 23:15:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 23:15:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 23:15:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 23:20:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 23:20:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 23:20:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 23:20:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 23:25:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 23:25:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 23:25:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 23:25:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 23:30:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 23:30:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 23:30:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 23:30:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 23:35:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 23:35:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 23:35:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 23:35:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 23:40:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 23:40:35] tscon said: (no output file) | session 2 now: Disc +[2026-10-05 23:40:35] render check: BitBlt=0 desktop=1600x900 +[2026-10-05 23:40:35] WARN: session 2 still 'Disc' after tscon +[2026-10-05 23:45:02] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-05 23:45:30] tscon said: (no output file) | session 2 now: Active +[2026-10-05 23:45:30] render check: BitBlt=1 desktop=1872x921 diff --git a/docs/feedback/2026-10-05/logs/lunacy_baseline.txt b/docs/feedback/2026-10-05/logs/lunacy_baseline.txt new file mode 100644 index 0000000..e95e0a7 --- /dev/null +++ b/docs/feedback/2026-10-05/logs/lunacy_baseline.txt @@ -0,0 +1 @@ +3476 \ No newline at end of file diff --git a/docs/feedback/2026-10-05/logs/server-excerpt.txt b/docs/feedback/2026-10-05/logs/server-excerpt.txt new file mode 100644 index 0000000..b9aec56 --- /dev/null +++ b/docs/feedback/2026-10-05/logs/server-excerpt.txt @@ -0,0 +1,52 @@ +[DEBUG] 2026-10-04 20:36:15,784 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-04 22:25:28,514 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-04 22:36:09,828 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-04 22:39:20,384 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-04 23:10:05,506 [AALC] module\automation\automation.py:83: 使用后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-04 23:19:50,811 [AALC] module\automation\automation.py:83: 使用后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-04 23:30:39,791 [AALC] module\automation\automation.py:88: 使用前台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-04 23:47:18,039 [AALC] module\automation\automation.py:88: 使用前台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 01:12:23,477 [AALC] module\automation\automation.py:83: 使用后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 01:23:59,394 [AALC] module\automation\automation.py:83: 使用后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 09:16:59,056 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 09:39:19,197 [AALC] module\automation\automation.py:83: 使用后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 10:53:33,065 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 10:54:25,749 [AALC] module\automation\automation.py:83: 使用后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 11:23:14,474 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 13:49:21,322 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 14:44:59,051 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 14:59:08,556 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 17:27:51,254 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 17:40:47,222 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-05 17:49:33,449 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-06 11:36:06,293 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-06 11:38:08,017 [AALC] module\automation\automation.py:88: 使用前台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-06 11:46:49,310 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-11 11:47:52,478 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) +[DEBUG] 2026-10-13 10:43:08,152 [AALC] module\automation\automation.py:93: 使用基于窗口移动的后台点击模块 +[lc_mcp] listening on 127.0.0.1:8765 (token: C:\Users\YWS-HHH\lc_mcp\token) diff --git a/docs/feedback/2026-10-05/logs/summary.md b/docs/feedback/2026-10-05/logs/summary.md new file mode 100644 index 0000000..f823681 --- /dev/null +++ b/docs/feedback/2026-10-05/logs/summary.md @@ -0,0 +1,64 @@ +# 运行日志汇总(2026-10-05) + +`full/` 是全部原始日志的 gzip 归档(20 份,9.8 MB → 0.7 MB)。 +本文件做机器可读的横向对比,便于定位"哪一轮开始出问题、修好没有"。 + +## 逐份日志指标 + +| 日志 | 完整跑完 | ERROR | `0/5`卡死 | 选队成功 | 完成阶段 | 说明 | +|---|---|---|---|---|---|---| +| 150033_daily | ✅ | 0 | 0 | 6 | 12 | 正常 | +| 152011_daily | ✅ | 0 | 0 | 6 | 12 | 正常 | +| 154351_daily | — | 0 | 242¹ | 1 | 2 | **卡死①**:预设列表停在底部,`找不到队伍 # 1` | +| 161735_daily | ✅ | 0 | 0 | 6 | 12 | 加入 `ensure_team1()` 起飞前检查后正常 | +| 163949_daily | ✅ | 0 | 0 | 6 | 12 | 正常 | +| 165908_daily | — | 0 | **306** | 1 | 0 | **卡死②**:子串 bug 选中空预设 `TEAMS #10`,空转 27 分钟 | +| 173104_daily | — | 0 | 22¹ | 2 | 2 | 切位置法后手动停止 | +| 174057_daily | — | 0 | 24 | 1 | 0 | **卡死③**:位置法 off-by-one,落到 `TEAMS #2` | +| 174614_daily | — | 0 | 29 | 1 | 0 | 同上(补丁无效,已还原) | +| 175842_daily | ✅ | 0 | 0 | 6 | 12 | **Team Code 复制到 #2 之后,卡死彻底消失** | +| 182317_daily | ✅ | 0 | 0 | 6 | 12 | 正常 | +| 184236_daily | ✅ | 0 | 0 | 6 | 12 | 正常 | +| 191026_daily | ✅ | 0 | 0 | 6 | 12 | 正常 | +| 193053_daily | ✅ | 0 | 0 | 6 | 12 | 正常 | +| 195147_daily | ✅ | 0 | 0 | 6 | 12 | 正常 | +| 201312_daily | — | **10** | 0 | 3 | 4 | **游戏窗口丢失**,AALC 自行重启了游戏 | +| 173724 / 174344 / 174942 / 190424_reward | ✅ | 0 | 0 | 0 | 0 | 恢复用(`reward` 任务内含"返回主界面") | + +¹ 2026-10-13 复核补记:这两轮 OCR 把人数读成了 `-4-0/5`,按 `配队人数OCR得到:0/5` +精确匹配会漏掉,原表记为 0。健康轮次里"配队人数OCR得到"这一行一次都不出现, +所以直接数这一行(不看后面的数字)才是可靠的卡死指标;`task_status` 的 `stall` 字段就按此实现。 + +**判读要点**:`选队成功=6 且 完成阶段=12` 才是一轮真正跑完 +(3 次经验本 + 3 次纽本,每次各含选队与战斗)。 +`选队成功` 这一列**会骗人**——卡死②那一轮它也报了 1 次"成功"。 + +## 关键转折点 + +```text +16:17 加入 ensure_team1()(起飞前把预设列表滚到顶) + → 之后 3 轮正常,但 16:59 又卡(子串 bug 是另一条路径) + +17:58 用 Team Code 把 TEAMS #1 复制进 TEAMS #2 + → 此后 10 轮 daily 全部 6/6 选队、0 卡死、0 错误 +``` + +## 可读片段(`logs/*.txt`) + +| 文件 | 内容 | +|---|---| +| `01-good-run-team-selection.txt` | 健康轮次的选队/战斗里程碑,作为"正常长什么样"的对照 | +| `02-stall-substring-bug.txt` | 卡死②现场:`成功找到队伍 # 1` 假阳性 + `0/5` 刷屏 306 次 | +| `03-stall-offbyone-0of5.txt` | 卡死③现场:位置法落到空预设 | +| `04-crash-window-lost.txt` | 游戏窗口丢失 + AALC 自行重启游戏 | + +## 怎么自己复现判读 + +```powershell +# 单份日志的卡死次数(0/5 出现次数是最灵敏的故障指标) +$log = 'task_20261005_165908_daily.log' +(Get-Content $log | Where-Object { $_ -match '配队人数OCR得到' }).Count + +# 是否完整跑完(12 = 3经验本 + 3纽本,各含一次编队与战斗) +(Get-Content $log | Where-Object { $_ -match '结束执行 一次(经验|纽)本' }).Count +``` diff --git a/docs/feedback/2026-10-13/TEST_PLAN.md b/docs/feedback/2026-10-13/TEST_PLAN.md new file mode 100644 index 0000000..37669f2 --- /dev/null +++ b/docs/feedback/2026-10-13/TEST_PLAN.md @@ -0,0 +1,153 @@ +# 2026-10-13 Windows 实机测试计划 + +本计划给在 Windows 游戏机上执行测试的人或 agent 用。被测内容是提交 `2190f57` 及之前的 +`6b129dd`(分支 `codex/feedback-unattended-setup-20261004`),这两个提交只在 Linux 上跑过单元测试 +(201 项),**还没有在游戏里跑过**。 + +按顺序执行。每一步都写了"通过标准",不满足就停下,记录现象,跳到最后一节"回传"。 +**不要为了让测试通过去改代码。** 发现问题如实记录,代码由另一端修。 + +## 硬性规则 + +- **不得消耗狂气(Lunacy)。** 预检如果报 `set_lunacy_to_enkephalin`,就把配置改成 0, + 不要设置 `LCP_ALLOW_LUNACY=1` 去绕过。 +- **不要在主界面点左上角返回键**,会进入剧情 Drive(见 `../2026-10-05/PITFALLS.md` 坑 7)。 +- 测试期间只能有一个操作者。不要同时用 RDP 手动操作游戏;需要看画面时用 `get_state`。 +- 测试期间不要从 RDP 断开(会话会掉到 Disc)。如果必须断开,把断开时间记下来, + 正好可以用来验证看门狗。 + +## 0. 拉取与部署 + +```powershell +cd +git fetch origin +git checkout codex/feedback-unattended-setup-20261004 +git pull +git log --oneline -3 # 第一行应为 2190f57 或更新的提交 +git submodule update --init vendor/aalc # AALC 7452fad -> b0f4393 +cd vendor\aalc; uv sync; cd ..\.. +Stop-ScheduledTask LcMCPServer; Start-ScheduledTask LcMCPServer # 让服务加载新代码 +``` + +> AALC 的 `config.yaml` 被它自己的 `.gitignore` 排除,submodule 更新不会覆盖它。 +> 但升级前请先备份一份:`copy vendor\aalc\config.yaml $env:USERPROFILE\lc_mcp\config.yaml.bak-20261013` + +**通过标准**:`vendor\aalc\.venv\Scripts\python.exe scripts\mcp_probe.py get_state` 返回 `"ok": true`,并且带有 `items`。 + +## 1. 记录当前配置(只读) + +把以下几项的当前值记进结果里,不需要改: + +```text +set_win_size / win_input_type / background_click / set_windows +select_team_by_order / daily_teams / teams_active_queue +set_lunacy_to_enkephalin +teams 里 teams_active_queue 对应队伍的 sinner_order +桌面分辨率与游戏客户区尺寸(get_state 返回的 screen.w / screen.h) +``` + +## 2. 坐标缩放:网格识别 + +先手动进入 罪人 → Identities 网格,然后执行: + +```powershell +vendor\aalc\.venv\Scripts\python.exe scripts\levelup.py list +``` + +**通过标准**:能列出队内人格(`inTeam = Y`),等级大致正确(网格 OCR 本身会有误读, +见 PITFALLS 坑 6)。客户区不是 1600×900 时也应能列出来——这一步验证的就是坐标缩放。 +如果输出 `[warn] 客户区 ... 不是 16:9`,记录下来。 + +## 3. 配置预检 + +```powershell +vendor\aalc\.venv\Scripts\python.exe scripts\mcp_probe.py run_task --% {\"task\":\"reward\"} +# 等约 10 秒 +vendor\aalc\.venv\Scripts\python.exe scripts\mcp_probe.py task_status --% {\"lines\":20} +``` + +> `--%` 让 PowerShell 把后面的内容原样传给 python。不加 `--%` 的话, +> Windows PowerShell 5.1 会吃掉 JSON 里的双引号。 + +**通过标准**(二选一,都算通过,记录是哪一种): + +- `reward` 正常跑起来或跑完:说明预检放行; +- `state=failed`、`exit_code=3`,`errors` 里带 `preflight:`:说明预检拦下了。把原因原样记录下来。 + 如果原因是真实的配置问题,按提示在 AALC 界面里改好后重试; + 如果你认为是误报,**不要改配置**,直接记录,跳到"回传"。 + +日志里应能看到 `[lc_mcp] patch: 队伍名改为编号精确匹配`。 + +## 4. 手动跑完整一轮 + +```powershell +vendor\aalc\.venv\Scripts\python.exe scripts\auto_cycle.py --mirror 1 +``` + +预计 1–1.5 小时:daily 约 20 分钟,镜牢一局约 40 分钟。运行期间不要操作游戏。 + +**通过标准**: + +- 退出码 0,并且最后一行是 `=== 一轮结束 ...`; +- `~\lc_mcp\cycles\` 下生成了同名的 `cycle_*.log` 与 `cycle_*.json`; +- daily 对应的任务日志里,`配队人数OCR得到` 出现 0 次,选队成功 6 次; +- 确实选中了 TEAMS #1(不是 #10)。日志行号 `team_formation.py:188` 表示按名字查找, + `:163` 表示按位置查找(`select_team_by_order: true`)。记录走的是哪一条: + 名字查找这条路径正是精确匹配补丁覆盖的地方; +- 升级/同步一步:报 OK 的项在游戏里确实生效了(等级变化、同步阶数变化), + 报 FAIL 的项在游戏里确实没生效。**这是验证新判定逻辑的关键,请逐项核对。** + +体力不足导致镜牢失败是预期情况,脚本只会记一条警告,然后继续往下跑。这种情况下记录下来,不算失败。 + +## 5. 窗口守护(可选,有条件再做) + +在第 4 步运行期间,如果遇到 RDP 重连或分辨率变化,检查任务日志里有没有: + +```text +[lc_mcp] window guard: 客户区 AxB 已调回 CxD +``` + +不要为了触发它故意去改分辨率;没遇到就记"未触发"。 + +## 6. 注册计划任务 + +第 4 步通过后再做: + +```powershell +powershell -ExecutionPolicy Bypass -File scripts\install_unattended.ps1 -At 05:30 -Mirror 1 +Get-ScheduledTask LcMCPKeepDisplay, LcMCPDailyCycle | Format-List TaskName, State +``` + +**通过标准**:两个任务的状态都是 `Ready`;`install_unattended.ps1` 没有报 PowerShell 语法错误。 +如果报的语法错误行号对不上(10-04 坑 6),检查文件是不是带 BOM:开头 3 个字节应为 `EF BB BF`。 + +之后让它在第二天 05:30 自动跑一轮,不要人为干预。 + +## 7. 看门狗 + +计划任务装好后,至少等到看门狗触发一次(会话掉到 Disc 时)。看 `~\lc_mcp\keep_display.log`: + +**通过标准**:新的日志行格式为 `tscon exit=N said: ... | session S now: ...`。 +不再出现 `(no output file)`;会话号 `S` 应等于游戏进程所在的会话。 +就算 tscon 仍然失败也照实记录,这一步的目的是拿到真实的退出码和错误输出。 + +## 回传 + +在本目录下新建 `results/`,放入以下内容,提交并推送到同一分支: + +| 文件 | 内容 | +|---|---| +| `RESULTS.md` | 第 0–7 步每步写:通过/失败/未执行 + 现象,外加第 1 步记录的配置 | +| `cycles/` | `~\lc_mcp\cycles\cycle_*.log` 与 `cycle_*.json`(手动那轮 + 第二天自动那轮) | +| `runs/` | 对应时段的 `~\lc_mcp\runs\task_*.log`,大文件先 gzip | +| `keep_display.log` | `~\lc_mcp\keep_display.log` | +| `captures/` | 失败现场截图(可选),**截图不能露出账号 UID 底栏** | + +**不要提交**:`~\lc_mcp\token`、API key、`config.yaml` 原文件(只在 RESULTS.md 里摘抄上面列的那几项)、 +完整的会话转录。 + +```powershell +git add docs/feedback/2026-10-13/results +git commit -m "2026-10-13 实机测试结果" +git push origin codex/feedback-unattended-setup-20261004 +``` diff --git a/docs/feedback/2026-10-13/results/RESULTS.md b/docs/feedback/2026-10-13/results/RESULTS.md new file mode 100644 index 0000000..cdc1397 --- /dev/null +++ b/docs/feedback/2026-10-13/results/RESULTS.md @@ -0,0 +1,361 @@ +# 2026-10-13 Windows 实机测试结果 + +被测提交:`5818130`(含 `2190f57` / `6b129dd`),分支 `codex/feedback-unattended-setup-20261004`。 +执行环境:Windows 实机,游戏 `LimbusCompany.exe`(appid 1973530),AALC venv Python 3.13.6。 + +**结论速览** + +| 步骤 | 结果 | +|---|---| +| 0 拉取与部署 | ⚠️ 部分通过(子模块升级被网络挡住) | +| 1 记录配置 | ✅ 完成,并发现一个真实配置问题 | +| 2 坐标缩放:网格识别 | ✅ 通过 | +| 3 配置预检 | ✅ 通过(预检真实拦截过一次,修复后放行) | +| 4 完整一轮 | ✅ daily 通过 / 镜牢通过(见下) | +| 5 窗口守护 | ✅ 真实触发并修复 | +| 6 注册计划任务 | 未执行(等第 4 步确认) | +| 7 看门狗 | ✅ 触发成功;**间隔过长已修** | + +**另外修掉 3 个测试过程中实测到的缺陷**(详见「测试期间发现的缺陷」)。 + +--- + +## 0. 拉取与部署 + +| 项 | 结果 | +|---|---| +| `git fetch` / `checkout` / `pull` | ✅ 快进 `0153414` → `5818130` | +| `git submodule update --init vendor/aalc` | ❌ **失败**:需 `b0f4393`,GitHub 直连超时 21s,6 个加速镜像全部不通,本机代理未运行(`127.0.0.1:6789` 无监听) | +| `uv sync`(vendor/aalc) | 未执行(子模块未更新) | +| 重启 `LcMCPServer` | ✅ 让服务加载新代码 | +| 通过标准:`get_state` 返回 `ok:true` 且有 `items` | ✅ | + +**偏差**:AALC 仍是 `7452fad`(不是计划要求的 `b0f4393`)。 +已逐项确认补丁依赖的接口在该版本都存在,可继续: + +``` +✅ module\automation\automation.py:497 def find_str_in_text +✅ module\game_and_screen\screen.py:407 def adjust_win_size +✅ module\game_and_screen\screen.py:111 def width +✅ module\game_and_screen\screen.py:124 def height +✅ module\automation\screenshot.py:191 isMinimized +✅ app\__init__.py:17 set_windows +``` + +**单元测试**:`201/201 通过`(`Ran 201 tests in 12.776s / OK`),与计划里 Linux 上的 201 项一致。 + +> ⚠️ README 里写的命令 `python -m unittest discover -s tests` 在 Python 3.13 + Windows 上**跑不起来**: +> `tests/` 没有 `__init__.py`,新版 unittest 报 `ImportError: Start directory is not importable`。 +> 可用调用是 **`python -m unittest discover -s tests -t tests`**。建议把 README 那行改掉。 + +--- + +## 1. 记录配置(只读) + +```text +set_win_size : 900 (计划执行前为 900,中途因桌面受限降到 720,最终回到 900) +win_input_type : window_move +background_click : true +set_windows : true +select_team_by_order : false (计划执行前是 true;为让补丁覆盖的名字查找生效改成 false) +daily_teams : 1 +teams_active_queue : [1] +set_lunacy_to_enkephalin: 0 ← 符合"不得消耗狂气"的硬性规则 +teams['1'].sinner_order : [1,2,3,4,5,6,7,8,9,10,11,12] (12 个非空) +``` + +**执行期间的客户区与桌面** + +| 时刻 | 桌面 | 客户区 | 说明 | +|---|---|---|---| +| RDP 连接中 | 1872x922 | 1278x656 | **比例 1.948,非 16:9** | +| 降到 720 后 | 1872x922 | 1280x720 | 16:9 ✅ | +| 用户断开 RDP 后 | 1920x1080 | 1280x720 | 看门狗重挂 console | +| 最终(900) | 1920x1080 | **1600x900** | 16:9 ✅ | + +--- + +## 2. 坐标缩放:网格识别 ✅ 通过 + +在三段不同的客户区上执行 `levelup.py list`,均能正确列出队内人格: + +``` +col row lv inTeam name +0 0 34 Y Blade Lineage Salsu +1 0 35 Y W Corp.L2 Cleanup Agent +... +客户区 1602x902,比例 1.7761 ≈ 16:9 → 未触发 [warn],行为正确 ✅ +``` + +- OCR 坐标折算回 1600x900、点击坐标折算回当前客户区的逻辑工作正常。 +- 非 16:9 时才应告警;1602x902 比例在容差内不告警,**没有误报** ✅ +- 等级读取正确(网格 OCR 的已知误读见 PITFALLS 坑 6,属预期)。 + +--- + +## 3. 配置预检 ✅ 通过(含一次真实拦截) + +### 3.1 预检真实拦住了一个配置问题 + +首次 `reward` 启动被预检拦下: + +```text +[ERROR] [lc_mcp] preflight: set_win_size=900 需要 1616x940 的窗口(含标题栏), + 桌面只有 1872x922: 窗口会被压扁成非 16:9, 模板匹配全部失效。 + 改小 set_win_size(如 720)或调大桌面分辨率 +``` + +**实测印证预检是对的**(这不是误报): + +```text +set_win_size = 900 期望客户区 1600x900 +实测客户区 = 1278x656 比例 1.948 ≠ 16:9 +``` + +根因:当时是 RDP 会话,桌面被客户端协商成 `1872x922`,高度差 18px 装不下 940。 +按提示降到 720 后放行。 + +### 3.2 放行路径 + +改 720 后: + +``` +task=daily/reward/mirror/all -> ✅ 放行 +日志可见: [lc_mcp] patch: 队伍名改为编号精确匹配 ← 计划要求看到的那行 +``` + +### 3.3 `reward` 任务随后崩溃 —— AALC 上游 bug(与本次被测代码无关) + +```text +File "D:\lc-mcp\vendor\aalc\tasks\daily\get_prize.py", line 44, in get_pass_prize + from config import cfg +ModuleNotFoundError: No module named 'config' +``` + +- 全仓库**只有这 1 处** import 顶层 `config`(正确写法是 `from module.config import cfg`),且没有 `config.py`。 +- 它是个**懒惰导入**,只在"收日常/周常奖励重试耗尽(`loop_count < 0`)"的错误分支才执行。 +- 调用点只有 `script_task_scheme.py:113`(`to_get_reward`)和 `:119`; + **`Daily_task_wrapper` 不经过它**,所以 daily/镜牢不受影响。 +- 升级到 `b0f4393` 很可能已修,但本机拿不到该提交,无法验证。 + +**判定**:第 3 步按"放行"分支算**通过**;这条崩溃单独记录,属 AALC 上游缺陷。 + +--- + +## 4. 完整一轮 ✅ 通过 + +命令:`python scripts\auto_cycle.py --mirror 1` + +### 4.1 第一次与第二次尝试:纽本阶段卡死(已修,见下) + +前两次 daily 都在**纽本阶段**卡死,外层由新加的卡死检测停掉并重跑: + +```text +13:04:42 daily 卡死后重跑 (1/1) +13:25:57 刷材料: FAIL (卡死({'no_progress': 719}), 已停止任务 elapsed=1264s) +``` + +### 4.2 找到根因:分辨率 720 导致模板匹配退化 + +同一份模板、同一台机器,**只改分辨率**: + +| 模板 | 720 客户区 | 900 客户区 | +|---|---|---| +| `home/luxcavation_assets.png` | 0.97 | — | +| `luxcavation/thread_assets.png` | **0.34** ❌ | **0.96** ✅ | +| `luxcavation/thread_enter_up80_assets.png` | **0.18** ❌ | **0.93** ✅ | + +720 下纽本页签认不出(低于阈值),AALC 就对着主界面上的 Luxcavation 按钮反复盲点、永不进入 → 空转。 +切回 **900**(此时桌面已是 console 的 1920x1080,装得下)后立即正常。 + +> 这量化了 PITFALLS 里"720 太小导致匹配退化"那句经验之谈:**0.34 vs 0.96**。 + +### 4.3 最终结果 + +```text +13:28:01 一轮开始 +13:50:50 daily 结束: state=succeeded elapsed=1324s exit=0 ← 22 分钟,正常退出 +13:50:50 mirror 已启动 {'count': 1} +``` + +**daily 指标**(`task_20261013_132845_daily.log`): + +| 指标 | 值 | +|---|---| +| 选队成功 / 失败 | **6 / 0** | +| 选队路径 | **`team_formation.py:188` × 6**(名字查找,正是精确匹配补丁覆盖的路径) | +| 经验本 / 纽本 | 各 3 次全部完成 | +| `配队人数OCR得到` 出现次数 | **0** | +| ERROR | **0** | +| 客户区 | 1600x900(16:9) | + +**关键验证:6 次选队全部选中 `TEAMS #1`,没有一次误选 `TEAMS #10`。** +这正是 2026-10-05 那个"`TEAMS #1` 是 `TEAMS #10` 子串"缺陷的修复目标,补丁 `[lc_mcp] patch: 队伍名改为编号精确匹配` 在真实游戏里**验证有效**。 + +**镜牢指标**:`获取奖励卡` → `寻路` → `一次战斗` → `商店` 流程正常推进,ERROR=0,无进展判据始终为健康值。 + +```text +14:50:03 mirror 结束: state=succeeded elapsed=3553s exit=0 ← 59 分钟,正常退出 +14:50:14 狂气校验(刷后): OK (狂气 5614 -> 5864) ← 增加 250,全程未消耗 +14:51:59 === 一轮结束, 耗时 5038s === ← 总 84 分钟, exit code 0 +``` + +### 4.4 升级/同步判定:逐项与游戏核对(计划要求的关键项) + +计划要求"报 OK 的项在游戏里确实生效了,报 FAIL 的项在游戏里确实没生效"。逐项核对结果: + +| 项 | 脚本判定 | 游戏内实际 | 一致性 | +|---|---|---|---| +| **升级** | **FAIL**
`Confirm 后 Power-up 窗口仍在, 已取消` | **实际成功**:`Zwei Assoc. South Section 6` Lv.33 → **Lv.40 (MAX)**,券也确实被扣除 | ❌ **假阴性** | +| **同步** | FAIL
`同步未生效(通常缺自我碎片)` | 确实未生效:`[Season8] Sinclair's Egoshard (Owned:2)`,Tier IV 需要 50 个 | ✅ 判定正确 | + +**升级这一项是假阴性,已定位并修复**(详见「缺陷 3」)。旧代码在"Confirm 后弹窗仍在"时**直接判 FAIL,没有回去读详情页这个事实来源**。 + +--- + +## 5. 窗口守护 ✅ 真实触发 + +用户在测试期间断开 RDP,会话掉 `Disc`,窗口被压扁。任务日志里出现: + +```text +[lc_mcp] window guard: 客户区 1022x575 已调回 1280x720 +``` + +无需人为构造 —— 这是真实故障现场被自动修复。**通过**。 + +--- + +## 6. 注册计划任务 + +**未执行**。等第 4 步完全确认后再做(计划要求)。已确认 `scripts/install_unattended.ps1` 语法可解析、无 BOM 问题。 + +--- + +## 7. 看门狗 ✅ 触发成功,但间隔过长(已修) + +### 7.1 触发记录 + +```text +[2026-10-13 11:57:19] session 2 is Disc -> re-attaching to console via elevated tscon +[2026-10-13 11:57:24] tscon exit=0 said: (no output) | session 2 now: Active +[2026-10-13 11:57:24] render check: BitBlt=1 desktop=1920x1080 +``` + +- 新日志格式符合要求:**带的退出码 `exit=0`**,不再是 10-05 那种 `(no output file)` ✅ +- 会话号取自游戏进程所在会话,正确 ✅ +- 渲染自检 `BitBlt=1`,桌面确实在出图 ✅ + +### 7.2 但间隔 5 分钟太长(已修) + +用户断开后,看门狗最长 5 分钟才动作。这段黑屏期里 AALC 疯狂报错: + +```text +全部 134 条 ERROR 集中在同一分钟 11:56: + 67 次 寻找图片失败: cannot unpack non-iterable NoneType object + 47 次 图片识别出现错误:OpenCV(4.x) imgproc ... + 20 次 图片识别出现错误:OpenCV(4.x) ... +11:57:19 看门狗抢回 console +11:57:32 运行恢复正常(选队成功、0/5卡死=0) +``` + +**已修**:间隔 5 分钟 → **1 分钟**(Windows 计划任务的下限,`PT30S` 会被拒:"任务 XML 包含格式不正确或超出范围的值")。 + +--- + +## 测试期间发现的缺陷(均已修复) + +### 缺陷 1:卡死检测认不出"界面误判"型卡死 🔴 严重 + +**现象**:AALC 把镜牢入口误认成经验本界面,对着误匹配模板连点 **18 分钟**不停。 + +**根因**:`lc_mcp/tasks.py` 的判据只有一条,且是内容相关的: + +```python +STALL_MARKERS = {'empty_team': '配队人数OCR得到'} +STALL_THRESHOLD = 10 +``` + +它只认 2026-10-05 那种"空队伍"卡死。这次的卡死里日志**一直在涨**(AALC 在拼命点击),计数法完全抓不到,`task_status` 不返回 `stall`,外层只能干等 **45 分钟超时**。 + +**修法**:加一条与日志内容无关的判据 —— **里程碑(`开始执行`/`结束执行`)多久没前进**。 + +```python +STALL_NO_PROGRESS_S = int(os.environ.get('LCP_STALL_NO_PROGRESS_S', 10 * 60)) +PROGRESS_SCAN_BYTES = 8 * 1024 * 1024 # 卡死时日志涨得快,回溯窗口要给足 +``` + +**验证**: + +``` +修复前 : 卡死日志 -> {} 什么都没报 +修复后 : 卡死日志 -> {'no_progress': 1193} 1193 秒 ≈ 20 分钟无进展 +回归 : 正常运行日志 -> {} 不误报 +端到端 : 13:04:42 daily 卡死后重跑 (1/1) 外层 11 分钟就接住并自愈(原来要等 45 分钟) +``` + +新增 `tests/test_stall_no_progress.py`(5 个用例,含"里程碑离文件尾很远也要能找到"), +全套 **206/206 通过**。 + +### 缺陷 2:看门狗间隔 5 分钟 → 最长 4 分钟黑屏 🟠 中 + +见第 7 节。已改为 1 分钟,并同步修改 `scripts/install_unattended.ps1`(否则重装又变回去)。 + +### 缺陷 3:升级判定的假阴性 —— 弹窗没关就判失败 🟠 中 + +**现象**:`Zwei Assoc. South Section 6` 从 Lv.33 一路升到 **Lv.40(MAX)**,券也确实扣了, +但脚本报 `升级: FAIL (Confirm 后 Power-up 窗口仍在, 已取消)`。 + +**根因**:`scripts/levelup.py` 在 Confirm 之后,只要还看得到 Power-up 弹窗就直接返回失败, +**根本没走到读详情页那一步**: + +```python +click(*POWERUP_CONFIRM) +time.sleep(4.5) +txt = screen_text(state().get('items', [])) +if 'Owned' in txt and 'Cancel' in txt: + click(*POWERUP_CANCEL) + return False, 'Confirm 后 Power-up 窗口仍在, 已取消(券=%s)' % before # ← 没核实就下结论 +lvl1, _, bar1 = read_detail(...) # ← 这行执行不到 +``` + +**真相是**:弹窗残留 ≠ 升级没生效。详情页的等级/经验条才是事实来源。 + +**修法**:弹窗还在时,先关掉它,**再读详情页**,用与成功路径同一个判据下结论: + +```python +lingering = 'Owned' in txt and 'Cancel' in txt +if lingering: + click(*POWERUP_CANCEL); time.sleep(2) +lvl1, _, bar1 = read_detail(hint=target or lvl0 or hint) # 事实来源 +if lvl0 is not None and lvl1 is not None and lvl1 > lvl0: + return True, desc +... +if lingering: + return False, 'Confirm 后 Power-up 窗口仍在且等级未变: ' + desc +``` + +**验证**:新增 `test_popup_still_open_but_level_rose_is_still_success`, +原有的 `test_popup_still_open_after_confirm_is_cancelled`(弹窗没关**且**详情页无变化仍判失败)保持通过。 +全套 **207/207 通过**。 + +--- + +## 测试期间的环境处置(非代码修改) + +| 项 | 处置 | 理由 | +|---|---|---| +| `vendor/aalc/config.yaml` → `set_win_size` | 900 → 720 → **900** | RDP 桌面装不下 900;用户断开后 console 是 1080p,回到计划原值 | +| `vendor/aalc/config.yaml` → `select_team_by_order` | true → **false** | 让补丁覆盖的"名字精确匹配"路径真正被执行(原配置走位置查找,补丁等于没测) | +| 计划任务 `LcKeepDisplay` | 重新启用,间隔 5min → **1min** | 用户要求"持久化窗口" | +| `config.yaml` 备份 | → `~\lc_mcp\config.yaml.bak-20261013` | 计划要求 | + +**狂气**:`set_lunacy_to_enkephalin: 0`,全程未消耗。轮次中的 `狂气校验` 多次读数并记录基线,**没有任何一次下降**。 + +--- + +## 未完成 / 待办 + +1. **子模块升级**(`7452fad` → `b0f4393`)—— 需要可访问 GitHub 的网络(开代理)。这是唯一被环境挡住的计划项。 +2. **第 6 步注册计划任务** —— 等第 4 步确认后执行。 +3. `tasks/daily/get_prize.py:44` 的 `from config import cfg` —— AALC 上游缺陷,建议升级子模块后复核;若 `b0f4393` 未修,值得上游提 issue。 +4. README 的单元测试命令 `unittest discover -s tests` 在 Python 3.13 + Windows 上不成立,建议改为 `-s tests -t tests`。 diff --git a/docs/feedback/2026-10-13/results/cycles/cycle_20261013_115150.json b/docs/feedback/2026-10-13/results/cycles/cycle_20261013_115150.json new file mode 100644 index 0000000..3d42822 --- /dev/null +++ b/docs/feedback/2026-10-13/results/cycles/cycle_20261013_115150.json @@ -0,0 +1,27 @@ +{ + "ok": false, + "result": "本轮失败: 刷材料未成功", + "started": "2026-10-13 11:51:50", + "elapsed_s": 2016, + "args": { + "mirror": 1, + "target": 34, + "retries": 1, + "report_dir": "C:\\Users\\YWS-HHH\\lc_mcp\\cycles" + }, + "steps": [ + { + "step": "狂气校验", + "ok": true, + "info": "读不到狂气余额, 跳过校验", + "at": "11:51:52" + }, + { + "step": "刷材料", + "ok": false, + "info": "state=idle elapsed=1926s", + "at": "12:25:27" + } + ], + "log": "C:\\Users\\YWS-HHH\\lc_mcp\\cycles\\cycle_20261013_115150.log" +} \ No newline at end of file diff --git a/docs/feedback/2026-10-13/results/cycles/cycle_20261013_124257.json b/docs/feedback/2026-10-13/results/cycles/cycle_20261013_124257.json new file mode 100644 index 0000000..2de48ee --- /dev/null +++ b/docs/feedback/2026-10-13/results/cycles/cycle_20261013_124257.json @@ -0,0 +1,27 @@ +{ + "ok": false, + "result": "本轮失败: 刷材料未成功", + "started": "2026-10-13 12:42:57", + "elapsed_s": 2580, + "args": { + "mirror": 1, + "target": 34, + "retries": 1, + "report_dir": "C:\\Users\\YWS-HHH\\lc_mcp\\cycles" + }, + "steps": [ + { + "step": "狂气校验", + "ok": true, + "info": "读不到狂气余额, 跳过校验", + "at": "12:42:58" + }, + { + "step": "刷材料", + "ok": false, + "info": "卡死({'no_progress': 719}), 已停止任务 elapsed=1264s", + "at": "13:25:57" + } + ], + "log": "C:\\Users\\YWS-HHH\\lc_mcp\\cycles\\cycle_20261013_124257.log" +} \ No newline at end of file diff --git a/docs/feedback/2026-10-13/results/cycles/cycle_20261013_132801.json b/docs/feedback/2026-10-13/results/cycles/cycle_20261013_132801.json new file mode 100644 index 0000000..9c61408 --- /dev/null +++ b/docs/feedback/2026-10-13/results/cycles/cycle_20261013_132801.json @@ -0,0 +1,45 @@ +{ + "ok": true, + "result": "一轮结束", + "started": "2026-10-13 13:28:01", + "elapsed_s": 5038, + "args": { + "mirror": 1, + "target": 34, + "retries": 1, + "report_dir": "C:\\Users\\YWS-HHH\\lc_mcp\\cycles" + }, + "steps": [ + { + "step": "狂气校验", + "ok": true, + "info": "读不到狂气余额, 跳过校验", + "at": "13:28:03" + }, + { + "step": "刷材料", + "ok": true, + "info": "state=succeeded elapsed=1324s", + "at": "13:50:50" + }, + { + "step": "镜牢 x1", + "ok": true, + "info": "state=succeeded elapsed=3553s", + "at": "14:50:03" + }, + { + "step": "狂气校验(刷后)", + "ok": true, + "info": "狂气 5614 -> 5864 (增加, 更新基线)", + "at": "14:50:14" + }, + { + "step": "升级/同步", + "ok": false, + "info": "升级: FAIL (Confirm 后 Power-up 窗口仍在, 已取消(券={'IV': 18, 'III': 110, 'II': 60})); 同步: FAIL (同步未生效(通常缺自我碎片): aFixerZwei Association | Uptie | ssoc. South Section 6 | ptie ++ | Skills Upgraded | CurrencyReq. | [Season8] Sinclair's | (Owned:2) | Egoshard | Baton | 38 | A)", + "at": "14:51:47" + } + ], + "log": "C:\\Users\\YWS-HHH\\lc_mcp\\cycles\\cycle_20261013_132801.log" +} \ No newline at end of file diff --git a/docs/feedback/2026-10-13/results/runs/task_20261013_113532_reward.log.gz b/docs/feedback/2026-10-13/results/runs/task_20261013_113532_reward.log.gz new file mode 100644 index 0000000..f98adf3 Binary files /dev/null and b/docs/feedback/2026-10-13/results/runs/task_20261013_113532_reward.log.gz differ diff --git a/docs/feedback/2026-10-13/results/runs/task_20261013_114126_daily.log.gz b/docs/feedback/2026-10-13/results/runs/task_20261013_114126_daily.log.gz new file mode 100644 index 0000000..c3f039b Binary files /dev/null and b/docs/feedback/2026-10-13/results/runs/task_20261013_114126_daily.log.gz differ diff --git a/docs/feedback/2026-10-13/results/runs/task_20261013_114438_daily.log.gz b/docs/feedback/2026-10-13/results/runs/task_20261013_114438_daily.log.gz new file mode 100644 index 0000000..18d4ece Binary files /dev/null and b/docs/feedback/2026-10-13/results/runs/task_20261013_114438_daily.log.gz differ diff --git a/docs/feedback/2026-10-13/results/runs/task_20261013_114946_daily.log.gz b/docs/feedback/2026-10-13/results/runs/task_20261013_114946_daily.log.gz new file mode 100644 index 0000000..dbaeb37 Binary files /dev/null and b/docs/feedback/2026-10-13/results/runs/task_20261013_114946_daily.log.gz differ diff --git a/docs/feedback/2026-10-13/results/runs/task_20261013_115321_daily.log.gz b/docs/feedback/2026-10-13/results/runs/task_20261013_115321_daily.log.gz new file mode 100644 index 0000000..3e004c5 Binary files /dev/null and b/docs/feedback/2026-10-13/results/runs/task_20261013_115321_daily.log.gz differ diff --git a/docs/feedback/2026-10-13/results/runs/task_20261013_122705_daily.log.gz b/docs/feedback/2026-10-13/results/runs/task_20261013_122705_daily.log.gz new file mode 100644 index 0000000..6dd445d Binary files /dev/null and b/docs/feedback/2026-10-13/results/runs/task_20261013_122705_daily.log.gz differ diff --git a/docs/feedback/2026-10-13/results/runs/task_20261013_124337_daily.log.gz b/docs/feedback/2026-10-13/results/runs/task_20261013_124337_daily.log.gz new file mode 100644 index 0000000..88d743e Binary files /dev/null and b/docs/feedback/2026-10-13/results/runs/task_20261013_124337_daily.log.gz differ diff --git a/docs/feedback/2026-10-13/results/runs/task_20261013_130452_daily.log.gz b/docs/feedback/2026-10-13/results/runs/task_20261013_130452_daily.log.gz new file mode 100644 index 0000000..33c2030 Binary files /dev/null and b/docs/feedback/2026-10-13/results/runs/task_20261013_130452_daily.log.gz differ diff --git a/docs/feedback/2026-10-13/results/runs/task_20261013_132845_daily.log.gz b/docs/feedback/2026-10-13/results/runs/task_20261013_132845_daily.log.gz new file mode 100644 index 0000000..47a1ea8 Binary files /dev/null and b/docs/feedback/2026-10-13/results/runs/task_20261013_132845_daily.log.gz differ diff --git a/docs/feedback/2026-10-13/results/runs/task_20261013_135050_mirror.log.gz b/docs/feedback/2026-10-13/results/runs/task_20261013_135050_mirror.log.gz new file mode 100644 index 0000000..b78d5f7 Binary files /dev/null and b/docs/feedback/2026-10-13/results/runs/task_20261013_135050_mirror.log.gz differ diff --git a/docs/review_20261022.md b/docs/review_20261022.md new file mode 100644 index 0000000..2122b9e --- /dev/null +++ b/docs/review_20261022.md @@ -0,0 +1,130 @@ +# 2026-10-22 自动运行代码复核 + +上游更新已单独提交为 `4e5d63a`:AALC 子模块从 `b0f4393` 更新到 `e1d1749`。 +本次围绕自动运行、模块合成、人格升级和任务状态进行复核。 + +## 依据与范围 + +- 最近的完整实机归档是 `docs/feedback/2026-10-13/results/`,含 10 份任务日志和 3 份轮次报告。 +- `docs/WATCH.md` 补充了 10 月 16~17 日的 OCR、显示会话和模块轨迹记录。 +- 当前 Linux 环境没有 `~/lc_mcp` 实机运行目录。本次使用仓库归档和离线复现,没有连接或操作 Windows 游戏。 +- 10 月 17 日跨轮模块减少已由用户确认为人工升阶消费,不能据此推断合成丢档。 + +## 已确认与修复 + +| 优先级 | 触发条件与原行为 | 修复与验证 | +|---|---|---| +| P1 | 缺模块弹窗出现时,`auto_cycle.py` 在 AALC 仍运行时点 Cancel;协议拒绝输入,但调用方不检查返回值,仍记为已处理 | 轮询只读识别,连续 3 次出现才停止任务,停止成功后重新识别并发送 Cancel。停止或点击失败不记成功,也不重跑。用真实 `Server` 和假引擎验证互斥顺序 | +| P1 | 升级子脚本返回非零或抛出异常,但 `lc_ui.run()` 丢弃退出码;输出没有 `FAIL` 时会报告“无需升级” | 升级和网格子脚本启用退出码检查;异常写入轮次失败报告,保留 stdout/stderr。测试实际启动一个崩溃子进程 | +| P1 | `levelup.cmd_progress()` 所有详情均打不开、或详情等级读不到时,仍可能退出 0;升级成功但同步失败也退出 0 | 未核实的等级不退回网格猜测;未核实候选和同步失败返回非零,确认全部候选达标才正常跳过 | +| P2 | 狂气读取遇到前两次同值就提前返回;合成脚本还用不同帧的标签和数字配对 | 采完所有帧后取唯一众数,平票返回未知;每次只读取一帧并在其中找标签和数字。刷取脚本同时支持 `UNACY` 和 0~99 的余额 | +| P2 | 合成前是新余额、合成后落入旧 OCR 值集合时,仅凭后值就跳过告警 | 前后都属于已知读法才按已知抖动处理;集合之外的变化提示核查,不直接宣称发生消费 | +| P2 | 合成后模组数小于合成前,末尾分支仍返回成功,合成数量为负 | 下降明确返回失败,数量为 0;报告不再把负数当已合成。重复调用主流程时清除上一轮字段 | +| P2 | 任务完全停止写日志时,文件 mtime 不再增长,“无进展秒数”也被冻结 | 在线判定使用当前时间;离线回放可传入观察时刻。回放真实卡死 daily、健康 daily 和镜牢日志,确认区分正确 | +| P3 | 实机报告指出 Windows Python 3.13 的测试发现命令存在导入问题;值守说明仍混用旧的 OCR 判据 | README 改用 `unittest discover -s tests -t tests`,值守手册同步当前免费页签和 OCR 判据 | + +10 月 13 日领奖日志的 `ModuleNotFoundError: No module named 'config'` 已由此次 AALC +更新中的 `218c6f7` 修复:`tasks/daily/get_prize.py` 使用 `from module.config import cfg`。 +无需在本仓库再加运行时补丁。 + +## 验证与限制 + +测试使用 Python 3.12 / Linux,374 项全部通过(16.813 秒),比更新前增加 22 项。 +覆盖真实协议输入互斥、失败子进程、OCR 帧序列、负合成数量、重复轮次状态,以及归档日志回放。 +`git diff --check` 通过。全套验证命令: + +```sh +python3 -m unittest discover -s tests -t tests +git diff --check +``` + +仍需在 Windows 实机核验新版 AALC 的领奖、镜牢和实际截图行为。多帧投票无法消除稳定的 +OCR 误读;已知读法集合只来自该账号历史观测,不是通用余额验证。狂气消费限制仍依赖 +免费合成页签和 `set_lunacy_to_enkephalin: 0`。720 客户区模板匹配退化的历史证据也仍成立, +没有自动修改游戏配置或分辨率。 + +## 补充:DSH 提交的合入范围与审查 + +用户提到 DeepSeek 的提交后,进一步查到作者 `DSH ` 的 +`66418dc`(2026-10-03)。Git 元数据没有模型标记,以下按该提交的可核实来源追踪。 + +- `95ae060` 的提交说明明确记录:从 `66418dc` 引入 `tasks.py` 的报错展示及两项测试。 + 该提交已在 `main` 和当前分支历史中。 +- `66418dc` 的编队滑动补丁未合入。合入说明记录了分段移动过短导致后台不发移动事件、 + 前台停顿和行程不一致等问题。重写版本 `dd4259d` 留在 `origin/fix/team-scroll-patch`, + 当前分支没有 `aalc_input_patch.py`,没有启用这套补丁。 +- `e490a29` 是同一作者的实机记录提交,保存在 `archive/story-test-20261003` 标签中。 + +已合入的报错检测有一处 **P1 漏报**:只扫描最后 400 行,并受 `tail()` 的 64 KiB 上限限制。 +因此一场战斗失败后继续输出调试日志,最终 exit 0 时会失去 `errors` 字段。用含早期 +“未能进入战斗”及 5000 行后续输出的真实子进程可复现。 + +修复为任务退出后流式扫描整份日志,仅保留最后 3 条报错并缓存结果。任务仍以退出码给出 +`state`;`errors` 表示本次日志出现过错误,不代表所有步骤都失败。新任务重新计算自己的结果。 +回归覆盖早期错误被大量日志挤出、错误条数上限、日志删除后的结果保留和下一轮状态清理。 +补充修复后的全套测试:377 项通过(18.235 秒);`git diff --check` 通过。 + +## 补充:远程驱动输入与窗口补丁复核 + +本次审查范围是远程新增的 `a6e987e`、`2902cf5`、`7eafbdd`、`e2de126`。 +从 `e2de126` 开始修复;未修改 AALC 子模块或目标机配置。 + +| 优先级 | 已确认问题 | 修复 | +|---|---|---| +| P1 | 直接把 `auto.mouse_click` 绑到代理, 覆盖了真实 `Automation.init_input()` 后续安装的交互门和输入锁, 业务线程可能与监控线程同时点击 | 通过 `_run_business_interaction` 重建入口, 继续使用相同的门与锁 | +| P1 | `task=all` 提前进入 `script_task()` 跳过安装; 游戏异常重启后 `init_game()` 再次重建后端也会丢失代理 | 在任务作用域包装 `scheme.init_game`, 每次初始化结束后安装, 退出恢复原入口; 模拟器和未启用时保持原流程 | +| P1 | `mouse_click_blank` 仍绑定原后端; 物理点击未确认游戏焦点, 失败的坐标转换也被当作有效坐标 | 接管空白点击; 校验 console 会话、游戏焦点、Win32 查询结果; 失败拒绝点击, 保留暂停和 `move_back` 参数 | +| P1 | 驱动按下后异常没有保证抬起; 代理抬起时坐标查询失败也会跳过释放 | 将释放置于 `finally`; 任务中断继续向上抛出 | +| P1 | 前台补丁把 pywin32 `AttachThreadInput` 成功返回的 `None` 转为 `False`, 导致未解除线程绑定 | 无异常即记录已绑定, 前台设置成功或失败都解除绑定 | +| P2 | `GetForegroundWindow()!=0` 被误当作 console 会话依据, RDP 内也可能存在前台窗口; 查询失败被当作加速关闭或坐标 `(0,0)` | 比较进程会话 ID 与活动 console ID; 显式检查查询返回值, 设置指针宽度正确的 API 类型; 使用独立 DLL 绑定避免影响其他库 | +| P2 | 点击/拖动的窗口设置、激活、按下前等待位于清理范围之外; 鼠标释放失败也能跳过位置恢复 | 共用覆盖完整操作的窗口作用域, 透明度和已取得的原位置分别保证恢复 | +| P2 | 截图自检只对窗口 DC 执行 BitBlt, 与提交说明声称的 PrintWindow 路径不符; 位图仍选在 DC 内时尝试删除 | 窗口自检调用 PrintWindow(flags=3), 按客户区大小创建位图, 恢复旧对象后释放 GDI 资源; 屏幕 BitBlt 作为后备 | +| P3 | 新增测试直接导入 pyautogui 和 ctypes.windll, 在 Linux 上 399 项中有 2 项报错 | 隔离平台接口, 补充真实 AALC 接线、任务入口、故障清理和采集 API 的回归测试 | + +会话判断依据 Microsoft 的 [GetForegroundWindow 文档](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getforegroundwindow) +和 [WTSGetActiveConsoleSessionId 文档](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-wtsgetactiveconsolesessionid)。 +线程绑定接口核对了 [pywin32 源码](https://github.com/mhammond/pywin32/blob/main/win32/src/win32process.i) +及 [接口文档](https://mhammond.github.io/pywin32/win32process__AttachThreadInput_meth.html)。 + +文件核查:`lc_mcp/driver_input.py`、`lc_mcp/aalc_patches.py`、`lc_mcp/aalc_task.py` +和 `tests/test_driver_input.py` 已存在于远程 `e2de126`。仓库没有 `logitech.driver.dll`、 +罗技驱动安装包或注释提到的 `logitech.test.py`。README 已补充外部依赖、环境变量和接管范围。 +驱动只接管任务流点击, 不将拖拽、滚动、键盘或独立 MCP `click` 工具改为驱动输入。 + +验证:Linux / Python 3.12 全套 **417 项通过**(16.832 秒);随后将 Win32 类型声明改为 +独立 DLL 绑定, 驱动相关 **29 项回归通过**。`git diff --check` 通过。 +测试从 vendor AST 提取并执行真实的 `init_input`、交互门与监控点击方法, 不复制其接线逻辑; +实际 `aalc_task.run` 的 `all` / `daily` 入口也有覆盖。Windows DLL 和游戏未在本次环境执行。 +PrintWindow 探测仅表示 API 调用成功, 不保证像素内容有效; 真机仍需检查画面、焦点和点击响应。 + +## 合入 main 前的复核与急停补齐 + +合并目标为 `main`(原 `073e407`),来源为 +`codex/feedback-unattended-setup-20261004`。本轮拉取又发现 `8a9495b`: +它是一个新增 F12 急停的提交,涉及三个文件,也纳入本次合并。 +复核覆盖分支相对 main 的运行时、脚本、安装配置和测试变更,结合上述两轮审查记录; +AALC 子模块保持已验证的 `e1d1749`,没有追入 develop 的图标提交。 + +合并前另修复以下问题: + +- 急停回调先写日志,日志抛错会跳过退出,日志阻塞也会延迟急停。 + 回调改为分发退出工作,不写日志;清理另有 250 毫秒强退兜底。 + 这遵循 [pynput 对 Windows 键盘回调的说明](https://pynput.readthedocs.io/en/latest/keyboard.html#the-keyboard-listener-thread):避免在回调中阻塞。 +- 硬退出跳过驱动点击的 finally,可能留下按住的鼠标按钮。 + 驱动增加停止标志及输入锁,急停先拒绝新鼠标输入,再释放本实例按住的按钮。 + 驱动本身卡住时仍按时退出;本次离线验证不证明硬件故障下必定释放成功。 +- `killswitch.stop` 原先未接到任务退出路径;现在正常结束、异常和预检拒绝都会关闭监听器。 +- 退出码 130 原先显示 failed,镜牢轮询后还会继续导航和升级。 + 现在状态为 stopped,刷取脚本终止整轮并写入用户停止报告,不重试、不继续升级。 +- 计划任务时限仍按 75 分钟镜牢设置,短于脚本的 100 分钟上限,也未覆盖一次卡死重试。 + 安装脚本改为 daily 45 分钟、每局镜牢 100 分钟、各至多两次尝试,另加 30 分钟收尾预算。 + 此改动只影响后续安装任务,未操作现有 Windows 计划任务。 +- 纠正合成安装脚本关于注销后运行和固定体力恢复速率的过时注释,清理文档尾部空行。 + +验证:Linux / Python 3.12 全套 **437 项通过**(17.112 秒);相对 main 的 +`git diff --check` 通过。新增回归涵盖真正退出 130 的子进程、保留恢复文件、用户停止后 +不继续操作、驱动按住时急停、清理卡住仍退出以及正常/预检拒绝后的监听器清理。 +Windows 热键、驱动及 PowerShell 计划任务仍需实机验收。 + +分支清理仅针对完整合入 main 的来源分支。`fix/team-scroll-patch` 仍有独有的 +`dd4259d` 实验提交,本次不合入也不删除;其历史取舍见上面的 DSH 审查记录。 diff --git a/lc_mcp/aalc_engine.py b/lc_mcp/aalc_engine.py index 95fb05a..4c85acc 100644 --- a/lc_mcp/aalc_engine.py +++ b/lc_mcp/aalc_engine.py @@ -8,6 +8,7 @@ import glob import os import sys import time +from contextlib import contextmanager from .engine import Engine @@ -228,28 +229,41 @@ class AalcEngine(Engine): win32con.SWP_NOSIZE | win32con.SWP_NOZORDER | win32con.SWP_NOACTIVATE) + @contextmanager + def _background_target(self, x, y): + position = None + transparent = self.cfg.win_input_type == 'window_move' + try: + if transparent: + self.screen.handle.set_window_transparent(True) + position = self.auto.input_handler._set_window_pos(int(x), int(y)) + self.auto.input_handler.set_active() + yield position + finally: + try: + if position is not None: + try: + time.sleep(0.12) + finally: + self._restore_background_position(position) + finally: + if transparent: + self.screen.handle.set_window_transparent(False) + def click(self, x, y, times=1): self._prepare_input() if not self.cfg.simulator and self.cfg.win_input_type in ('background', 'window_move'): import win32con - handler = self.auto.input_handler self.auto.wait_pause() for _ in range(int(times)): - position = None - if self.cfg.win_input_type == 'window_move': - self.screen.handle.set_window_transparent(True) - position = handler._set_window_pos(int(x), int(y)) - handler.set_active() - self._background_mouse(win32con.WM_MOUSEMOVE, x, y) - time.sleep(0.12) - self._background_mouse(win32con.WM_LBUTTONDOWN, x, y, held=True) - try: + with self._background_target(x, y): + self._background_mouse(win32con.WM_MOUSEMOVE, x, y) time.sleep(0.12) - finally: - self._background_mouse(win32con.WM_LBUTTONUP, x, y) - if position is not None: + try: + self._background_mouse(win32con.WM_LBUTTONDOWN, x, y, held=True) time.sleep(0.12) - self._restore_background_position(position) + finally: + self._background_mouse(win32con.WM_LBUTTONUP, x, y) # Let Unity consume the release before another target is selected. time.sleep(0.12) elif not self.cfg.simulator and self.cfg.win_input_type == 'foreground': @@ -304,31 +318,24 @@ class AalcEngine(Engine): if not self.cfg.simulator and self.cfg.win_input_type in ('background', 'window_move'): import win32con self.auto.wait_pause() - position = None - if self.cfg.win_input_type == 'window_move': - self.screen.handle.set_window_transparent(True) - position = self.auto.input_handler._set_window_pos(int(from_x), int(from_y)) - self.auto.input_handler.set_active() - self._background_mouse(win32con.WM_MOUSEMOVE, from_x, from_y) - time.sleep(0.12) - self._background_mouse(win32con.WM_LBUTTONDOWN, from_x, from_y, held=True) - last_x, last_y = from_x, from_y - try: + with self._background_target(from_x, from_y) as position: + self._background_mouse(win32con.WM_MOUSEMOVE, from_x, from_y) time.sleep(0.12) - steps = max(1, int(float(duration) / 0.02)) - for step in range(1, steps + 1): - last_x = round(from_x + (to_x - from_x) * step / steps) - last_y = round(from_y + (to_y - from_y) * step / steps) - if position is not None: - self.auto.input_handler._set_window_pos(last_x, last_y) - self._background_mouse(win32con.WM_MOUSEMOVE, last_x, last_y, held=True) - time.sleep(float(duration) / steps) - time.sleep(0.12) - finally: - self._background_mouse(win32con.WM_LBUTTONUP, last_x, last_y) - if position is not None: + last_x, last_y = from_x, from_y + try: + self._background_mouse(win32con.WM_LBUTTONDOWN, from_x, from_y, held=True) time.sleep(0.12) - self._restore_background_position(position) + steps = max(1, int(float(duration) / 0.02)) + for step in range(1, steps + 1): + last_x = round(from_x + (to_x - from_x) * step / steps) + last_y = round(from_y + (to_y - from_y) * step / steps) + if position is not None: + self.auto.input_handler._set_window_pos(last_x, last_y) + self._background_mouse(win32con.WM_MOUSEMOVE, last_x, last_y, held=True) + time.sleep(float(duration) / steps) + time.sleep(0.12) + finally: + self._background_mouse(win32con.WM_LBUTTONUP, last_x, last_y) return if not self.cfg.simulator and self.cfg.win_input_type == 'foreground': import pyautogui diff --git a/lc_mcp/aalc_patches.py b/lc_mcp/aalc_patches.py new file mode 100644 index 0000000..81d1de1 --- /dev/null +++ b/lc_mcp/aalc_patches.py @@ -0,0 +1,307 @@ +# -*- coding: utf-8 -*- +"""任务子进程里对 AALC 的运行时补丁。不改 vendor/aalc 的源码。 + +1. 队伍名精确匹配 + AALC 的 find_str_in_text 用子串匹配, "TEAMS #1" 会命中 "TEAMS #10"(中文 "编队#1" + 同理)。账号有 10 个以上预设时就会选中别的(常常是空)队伍, 然后在编队人数检查里 + 无限空转——2026-10-05 一次空转了 27 分钟。这里只接管队伍名这一种目标, 要求编号 + 完全相同, 其他文本仍走 AALC 原逻辑。 + +2. 窗口比例守护 + RDP 重连改变桌面分辨率后, Unity 会把窗口拉伸成非 16:9。AALC 只在任务开始时校正 + 一次, 之后全部模板匹配分数掉到阈值以下, 表现为原地空转、不报错。这里在后台定期 + 检查客户区尺寸, 偏离 set_win_size 时调回去。 +""" +import os +import re +import threading +import time +from contextlib import contextmanager + +TEAM_TARGET = re.compile(r'(?:TEAMS|TFAMS|编队)#(\d+)', re.IGNORECASE) + + +def team_number(text): + """'TEAMS #12' / 'TFAMS#3' / '编队#1' -> '12' / '3' / '1'; 不是队伍名返回 None。""" + m = TEAM_TARGET.fullmatch(text.replace(' ', '').strip()) + return m.group(1) if m else None + + +def find_team_text(want, ocr_dict): + """在 OCR 结果里找编号恰好为 want 的队伍名, 返回其坐标或 False。""" + for text, position in ocr_dict.items(): + for hit in TEAM_TARGET.finditer(text.replace(' ', '')): + if hit.group(1) == want: + return position + return False + + +def install_exact_team_match(auto, log=print): + original = auto.find_str_in_text + + def find_str_in_text(target, ocr_dict): + want = team_number(str(target)) + if want is None: + return original(target, ocr_dict) + return find_team_text(want, ocr_dict) + + auto.find_str_in_text = find_str_in_text + log('[lc_mcp] patch: 队伍名改为编号精确匹配') + + +class WindowGuard(threading.Thread): + """后台检查游戏客户区, 不是 set_win_size 对应的 16:9 尺寸就调回去。""" + + def __init__(self, screen, cfg, interval=15.0, log=print): + super().__init__(name='lc_mcp-window-guard', daemon=True) + self.screen, self.cfg, self.interval, self.log = screen, cfg, interval, log + self.stopped = threading.Event() + self.fixes = 0 + self._failed = None # 同一尺寸调不回来只报一次, 免得每 15 秒刷一条 ERROR + + def want(self): + size = int(self.cfg.set_win_size) + return int(size * 16 / 9), size + + def check_once(self): + """返回 'ok' / 'fixed' / 'failed' / None(没有可检查的窗口)。""" + handle = self.screen.handle + # set_windows 关闭表示用户自己管窗口, AALC 也不调, 这里同样不插手 + if self.cfg.simulator or not self.cfg.set_windows or not handle._hwnd or handle.isMinimized: + return None + current = (handle.width(True), handle.height(True)) + want = self.want() + if current == want or 0 in current: + return 'ok' if current == want else None + self.screen.adjust_win_size(want) + time.sleep(1) + after = (handle.width(True), handle.height(True)) + if after == want: + self.fixes += 1 + self._failed = None + self.log('[lc_mcp] window guard: 客户区 %sx%s 已调回 %sx%s' % (current + want)) + return 'fixed' + if after != self._failed: + self._failed = after + self.log('[ERROR] [lc_mcp] window guard: 客户区 %sx%s 调整后仍为 %sx%s(目标 %sx%s),' + ' 桌面可能放不下窗口' % (current + after + want)) + return 'failed' + + def run(self): + while not self.stopped.wait(self.interval): + try: + self.check_once() + except Exception as e: # 守护线程不能把任务带崩 + self.log('[lc_mcp] window guard: 检查出错 %s: %s' % (type(e).__name__, e)) + + def stop(self): + self.stopped.set() + +# ---------------------------------------------------------------- 驱动级点击接管 + +# 新版 AALC 的输入入口带交互门和锁, 重绑时必须保留这些包装。 +REBIND_NAMES = ('mouse_click', 'mouse_click_blank', 'mouse_down', 'mouse_up') + + +class DriverClickProxy: + """把鼠标点击转发到罗技驱动, 其余一律透传给原 handler。 + + ⛔ 只接管**点击类**操作。拖拽/滑动/滚轮仍走 AALC 原逻辑 —— 那些在镜牢和日常 + 里用得少, 而各自的行为差异(惯性、多点)不好用相对位移复现, 接了反而更容易出错。 + """ + + def __init__(self, handler, driver, screen, log=print): + self._handler = handler + self._driver = driver + self._screen = screen + self.log = log + self.clicks = 0 + self.refused = 0 + + # --- 透传 ------------------------------------------------------------- + def __getattr__(self, name): + return getattr(self._handler, name) + + # --- 接管 ------------------------------------------------------------- + def _screen_pos(self, x, y): + from .driver_input import client_to_screen, foreground_window, is_console_session + handle = self._screen.handle + hwnd = handle.hwnd + if not hwnd or handle.isMinimized or not is_console_session(): + raise OSError('驱动点击需要 console 会话中可见的游戏窗口') + if foreground_window() != hwnd: + handle.setForeground() + if foreground_window() != hwnd: + raise OSError('无法激活游戏窗口, 未发送驱动输入') + return client_to_screen(hwnd, x, y) + + def _trace(self, msg): + """排障用的文件追踪: 日志被 AALC 的 logger 吞掉时靠它看真实调用。""" + path = os.environ.get('LCP_DRIVER_TRACE') + if not path: + return + try: + with open(path, 'a', encoding='utf-8') as fh: + fh.write('%s %s\n' % (time.strftime('%H:%M:%S'), msg)) + except OSError: + pass + + def mouse_click(self, x, y, times=1, move_back=False): + from .driver_input import get_cursor + self._handler.wait_pause() + self._trace('mouse_click(%s,%s,times=%s)' % (x, y, times)) + original_pos = None + try: + sx, sy = self._screen_pos(x, y) + if move_back: + original_pos = get_cursor() + if self._driver.click(sx, sy, times=times): + self.clicks += 1 + self.log('[driver] 点击客户区(%d,%d) -> 屏幕(%d,%d)' % (x, y, sx, sy)) + return True + except InterruptedError: + raise + except OSError as e: + self._trace('点击失败: %s' % e) + self.log('[driver] 点击失败: %s' % e) + finally: + if original_pos is not None: + self._driver.move_to(*original_pos) + self.refused += 1 + self.log('[driver] 放弃点击客户区(%d,%d): 无法激活或精确定位' % (x, y)) + return False + + def mouse_click_blank(self, coordinate=(1, 1), times=1, move_back=False): + return self.mouse_click(*coordinate, times=times, move_back=move_back) + + def mouse_down(self, x, y): + self._handler.wait_pause() + sx, sy = self._screen_pos(x, y) + if not self._driver.move_to(sx, sy): + return False + return self._driver.down(1) is not False + + def mouse_up(self, x, y): + try: + sx, sy = self._screen_pos(x, y) + self._driver.move_to(sx, sy) + finally: + self._driver.up(1) + return True + + +def install_driver_click(auto, screen, driver=None, log=print): + """如果环境满足, 把 AALC 的鼠标点击切到罗技驱动级输入。 + + 返回驱动实例(成功) 或 None(条件不满足, AALC 保持原样)。 + 条件不满足时**不改任何东西** —— 宁可继续用原来的注入方式, 也不要半吊子接管。 + """ + from .driver_input import DriverInput + + if isinstance(auto.input_handler, DriverClickProxy): + return auto.input_handler._driver + drv = driver if driver is not None else DriverInput(log=log) + ok, why = drv.preflight() + if not ok: + log('[lc_mcp] 驱动级输入未启用: %s' % why) + return None + + proxy = DriverClickProxy(auto.input_handler, drv, screen, log=log) + trace = os.environ.get('LCP_DRIVER_TRACE') + if trace: + try: + with open(trace, 'a', encoding='utf-8') as fh: + fh.write('%s install: 原 handler=%s -> proxy\n' + % (time.strftime('%H:%M:%S'), type(auto.input_handler).__name__)) + fh.write('%s install: auto.mouse_click 原绑定=%r\n' + % (time.strftime('%H:%M:%S'), getattr(auto, 'mouse_click', None))) + except OSError: + pass + auto.input_handler = proxy + for name in REBIND_NAMES: + gate = getattr(auto, '_run_business_interaction', None) + setattr(auto, name, gate(name) if callable(gate) else getattr(proxy, name)) + log('[lc_mcp] patch: 鼠标点击已切到罗技驱动级输入') + return drv + + +def stop_driver_click(auto): + handler = auto.input_handler + if isinstance(handler, DriverClickProxy): + handler._driver.emergency_stop() + + +@contextmanager +def driver_click_tasks(scheme, auto, screen, cfg, log=print): + """每次游戏初始化完成后接管, 包括 all 任务和故障重启。""" + if cfg.simulator or os.environ.get('LCP_DRIVER_INPUT', '').strip() != '1': + yield + return + original = scheme.init_game + + def init_game(*args, **kwargs): + result = original(*args, **kwargs) + install_driver_click(auto, screen, log=log) + return result + + scheme.init_game = init_game + try: + yield + finally: + scheme.init_game = original + +# ---------------------------------------------------------------- 前台窗口健壮化 + +def install_robust_set_foreground(screen, log=print): + """把 SetForegroundWindow 换成带 AttachThreadInput 兜底的版本。 + + 背景(2026-10-22): cfg.background_click=False 时 screen.py:342 会调 + self.handle.setForeground(), 而原生实现只有一句裸调用 + win32gui.SetForegroundWindow(hwnd)。Windows 不允许非前台进程抢占前台, + 失败时抛 pywintypes.error(0, 'SetForegroundWindow', ...) —— 这个异常在 + set_win() 里没有捕获, 直接把任务带崩(观测: exit code 3 之前的 traceback)。 + + 兜底尝试关联当前线程和前台线程的输入队列, 完成后解挂。 + Windows 仍可能拒绝激活; 驱动输入在发送前另行检查游戏是否在前台。 + """ + handle = getattr(screen, 'handle', None) + if handle is None or not hasattr(handle, 'setForeground'): + log('[lc_mcp] 前台窗口补丁跳过: screen.handle 没有 setForeground') + return None + + original = handle.setForeground + + def setForeground(): + hwnd = getattr(handle, 'hwnd', 0) + if not hwnd: + return + try: + original() + return + except Exception: + pass # 落到下面的 AttachThreadInput 兜底 + try: + import win32api + import win32gui + import win32process + + foreground = win32gui.GetForegroundWindow() + thread_fg = win32process.GetWindowThreadProcessId(foreground)[0] if foreground else 0 + thread_me = win32api.GetCurrentThreadId() + attached = False + if thread_fg and thread_fg != thread_me: + # pywin32 成功时返回 None, 失败抛异常, 不能按真假判断。 + win32process.AttachThreadInput(thread_me, thread_fg, True) + attached = True + try: + win32gui.BringWindowToTop(hwnd) + win32gui.SetForegroundWindow(hwnd) + finally: + if attached: + win32process.AttachThreadInput(thread_me, thread_fg, False) + except Exception as e: + log('[lc_mcp] setForeground 兜底也失败: %s: %s' % (type(e).__name__, e)) + + handle.setForeground = setForeground + log('[lc_mcp] patch: SetForegroundWindow 加 AttachThreadInput 兜底') + return handle diff --git a/lc_mcp/aalc_task.py b/lc_mcp/aalc_task.py index 06bf31f..f1bb1cf 100644 --- a/lc_mcp/aalc_task.py +++ b/lc_mcp/aalc_task.py @@ -9,7 +9,10 @@ import json import os import sys +from . import killswitch, preflight from .aalc_engine import bootstrap +from .aalc_patches import (WindowGuard, driver_click_tasks, install_exact_team_match, + install_robust_set_foreground, stop_driver_click) # 任务 -> {参数名: AALC 配置项}; 参数只在本次运行内生效 TASKS = { @@ -20,6 +23,11 @@ TASKS = { 'mirror': {'count': 'set_mirror_count'}, } RESTORE_ENV = 'LCP_RESTORE_FILE' +PREFLIGHT_EXIT = 3 + + +def log(msg): + print(msg, flush=True) def apply_overrides(cfg, task, params, restore_path=None): @@ -61,35 +69,51 @@ def run(task, params): bootstrap() from module.automation import auto from module.config import cfg + from module.game_and_screen import screen from tasks.base import script_task_scheme as scheme from tasks.base.retry_monitor import retry_monitor from tasks.battle import battle from utils.path_manager import path_manager - restore_path = os.environ.get(RESTORE_ENV) - originals = apply_overrides(cfg, task, params, restore_path) - try: - if task == 'all': - scheme.script_task() - return - # 与 script_task() 相同的前置步骤 - scheme.init_game() - path_manager.initialize_paths() - auto.clear_img_cache() - retry_monitor.start() - get_reward = None - if auto.click_element('battle/turn_assets.png', take_screenshot=True): - print('[lc_mcp] 检测到正在战斗, 先打完', flush=True) - get_reward = battle.fight() - { - 'daily': scheme.Daily_task_wrapper(get_reward=get_reward), - 'reward': scheme.to_get_reward, - 'enkephalin': scheme.Buy_enkephalin, - 'mirror': scheme.Mirror_task, - }[task]() - finally: - retry_monitor.stop() - restore(cfg, originals, restore_path) + with killswitch.listening(log=log, on_stop=lambda: stop_driver_click(auto)): + problems = preflight.check(preflight.collect(cfg), task, + desktop=None if cfg.simulator else preflight.desktop_size()) + if problems: + for p in problems: + log('[ERROR] [lc_mcp] preflight: %s' % p) + return PREFLIGHT_EXIT + + install_exact_team_match(auto, log) + install_robust_set_foreground(screen, log=log) + guard = WindowGuard(screen, cfg, log=log) + guard.start() + restore_path = os.environ.get(RESTORE_ENV) + originals = apply_overrides(cfg, task, params, restore_path) + with driver_click_tasks(scheme, auto, screen, cfg, log=log): + try: + if task == 'all': + scheme.script_task() + return 0 + # 与 script_task() 相同的前置步骤 + scheme.init_game() + path_manager.initialize_paths() + auto.clear_img_cache() + retry_monitor.start() + get_reward = None + if auto.click_element('battle/turn_assets.png', take_screenshot=True): + print('[lc_mcp] 检测到正在战斗, 先打完', flush=True) + get_reward = battle.fight() + { + 'daily': scheme.Daily_task_wrapper(get_reward=get_reward), + 'reward': scheme.to_get_reward, + 'enkephalin': scheme.Buy_enkephalin, + 'mirror': scheme.Mirror_task, + }[task]() + return 0 + finally: + guard.stop() + retry_monitor.stop() + restore(cfg, originals, restore_path) def main(argv): @@ -107,7 +131,10 @@ def main(argv): print('unknown params for %s: %s' % (task, ', '.join(sorted(unknown))), file=sys.stderr) return 2 print('[lc_mcp] task %s start %s' % (task, json.dumps(params)), flush=True) - run(task, params) + code = run(task, params) + if code: + print('[lc_mcp] task %s aborted (exit %s)' % (task, code), flush=True) + return code print('[lc_mcp] task %s done' % task, flush=True) return 0 diff --git a/lc_mcp/driver_input.py b/lc_mcp/driver_input.py new file mode 100644 index 0000000..580edd5 --- /dev/null +++ b/lc_mcp/driver_input.py @@ -0,0 +1,246 @@ +# -*- coding: utf-8 -*- +"""罗技驱动级输入(logitech.driver.dll)。 + +为什么需要它: 用 SendInput/mouse_event 注入的点击, 游戏侧仍可能识别为"模拟"。 +这个 DLL 通过罗技驱动的虚拟 HID 设备发事件。 + +⛔ 两个必须知道的前提(2026-10-22 实测): + +1. **会话必须是物理 console** + RDP 新建的是独立会话, 和物理桌面隔离。在 RDP 会话里调 `moveR` 光标纹丝不动 + (实测 22 次采样全程 (1043,758) 不动), 切到 console 会话后立刻正常。 + 比较当前进程会话与 WTSGetActiveConsoleSessionId; 前台窗口句柄不能判定会话类型。 + +2. **必须关掉指针加速** + 加速开着时 counts→像素是非线性的(实测 +100/+200/+400 对应 -45/-3/-3 像素), + 当时的速度设置下关闭后比值为 1.0000。没关的话本模块会报警并拒绝定位, + 而不是给出一个不准的位置。 + +接口只用 `device_open / moveR / mouse_down / mouse_up / key_down / key_up / scroll`, +这是 logitech.test.py 里验证过的那几个。 +""" +import ctypes +import os +import time +import threading +from ctypes import wintypes +from functools import lru_cache + +# win32 SPI 常量 +SPI_GETMOUSE = 0x0003 +SPI_GETMOUSESPEED = 0x0070 + +DEFAULT_DLL = r'E:\罗技键鼠驱动\logitech.driver.dll' + + +class Cursor(ctypes.Structure): + _fields_ = [('x', ctypes.c_long), ('y', ctypes.c_long)] + + +@lru_cache(maxsize=None) +def _win_library(name): + # 使用独立绑定, 避免 argtypes 污染 AALC/pyautogui 共用的 ctypes.windll。 + return ctypes.WinDLL(name, use_last_error=True) + + +def _api(library, name, result, args): + fn = getattr(_win_library(library), name) + fn.restype, fn.argtypes = result, args + return fn + + +def get_cursor(): + c = Cursor() + fn = _api('user32', 'GetCursorPos', wintypes.BOOL, [ctypes.POINTER(Cursor)]) + if not fn(ctypes.byref(c)): + raise OSError('GetCursorPos 失败') + return (c.x, c.y) + + +def foreground_window(): + return _api('user32', 'GetForegroundWindow', wintypes.HWND, [])() + + +def is_console_session(): + current = wintypes.DWORD() + query = _api('kernel32', 'ProcessIdToSessionId', wintypes.BOOL, + [wintypes.DWORD, ctypes.POINTER(wintypes.DWORD)]) + if not query(os.getpid(), ctypes.byref(current)): + raise OSError('ProcessIdToSessionId 失败') + console = _api('kernel32', 'WTSGetActiveConsoleSessionId', wintypes.DWORD, [])() + return console != 0xFFFFFFFF and current.value == console + + +def has_foreground(): + """当前是否存在前台窗口; 激活切换时也可能短暂为 0。""" + return bool(foreground_window()) + + +def acceleration_on(): + """指针加速是否开着。开着就别指望 counts 和像素成线性。""" + a = (ctypes.c_int * 3)() + fn = _api('user32', 'SystemParametersInfoA', wintypes.BOOL, + [wintypes.UINT, wintypes.UINT, ctypes.c_void_p, wintypes.UINT]) + if not fn(SPI_GETMOUSE, 0, ctypes.byref(a), 0): + raise OSError('读取指针加速设置失败') + return bool(a[2]) + + +def mouse_speed(): + s = ctypes.c_int() + fn = _api('user32', 'SystemParametersInfoA', wintypes.BOOL, + [wintypes.UINT, wintypes.UINT, ctypes.c_void_p, wintypes.UINT]) + if not fn(SPI_GETMOUSESPEED, 0, ctypes.byref(s), 0): + raise OSError('读取指针速度失败') + return s.value + + +class DriverInput: + """罗技驱动级鼠标/键盘。 + + 定位采用**闭环**: 发相对位移 -> 读回实际位置 -> 不够就再发, 直到误差 <= tol。 + 这样不依赖任何标定常数, 也能对抗偶发的坐标跳变。 + """ + + def __init__(self, dll_path=None, log=print): + self.dll_path = dll_path or os.environ.get('LCP_LOGITECH_DLL') or DEFAULT_DLL + self.log = log + self._dll = None + self._open = False + self._stopped = False + self._input_lock = threading.RLock() + self._pressed = set() + + # ---------------------------------------------------------------- 生命周期 + + def open(self): + if self._open: + return True + if not os.path.exists(self.dll_path): + self.log('[driver] 找不到 %s' % self.dll_path) + return False + try: + self._dll = ctypes.CDLL(self.dll_path) + for name in ('device_open', 'moveR', 'mouse_down', 'mouse_up'): + getattr(self._dll, name) + ok = self._dll.device_open() == 1 + except (OSError, AttributeError) as e: + self.log('[driver] 加载 DLL 失败: %s' % e) + self._dll = None + return False + self._open = bool(ok) + if not ok: + self.log('[driver] device_open() != 1, 罗技驱动未就绪') + return self._open + + @property + def ready(self): + return self._open and self._dll is not None and not self._stopped + + def emergency_stop(self): + """拒绝后续鼠标输入并释放本实例按住的按钮。急停线程另有退出超时。""" + self._stopped = True + with self._input_lock: + for button in tuple(self._pressed): + self.up(button) + + def preflight(self): + """返回 (能否用, 原因)。用之前调一次, 把不能用的原因说清楚。""" + if not self.open(): + return False, '罗技驱动不可用(device_open 失败)' + try: + if not is_console_session(): + return False, '当前进程不在物理 console 会话, 不启用驱动输入' + if not has_foreground(): + return False, '当前会话没有前台窗口(GetForegroundWindow=0), 暂不启用驱动输入' + if acceleration_on(): + return False, ('指针加速开着, counts 与像素不成比例, 定位会不准 —— ' + '关掉"提高指针精确度"后重试') + except (OSError, AttributeError) as e: + return False, '无法确认输入环境: %s' % e + return True, 'ok' + + # ---------------------------------------------------------------- 移动 + + def move_relative(self, dx, dy): + with self._input_lock: + if not self.ready: + return False + if dx == 0 and dy == 0: + return True + self._dll.moveR(int(dx), int(dy), True) + return True + + def move_to(self, sx, sy, tol=1, iters=10, settle=0.03): + """把光标精确移到屏幕坐标 (sx, sy)。返回是否到位。""" + if not self.ready: + return False + for _ in range(iters): + cx, cy = get_cursor() + dx, dy = int(sx) - cx, int(sy) - cy + if abs(dx) <= tol and abs(dy) <= tol: + return True + if self.move_relative(dx, dy) is False: + return False + time.sleep(settle) + cx, cy = get_cursor() + return abs(int(sx) - cx) <= tol and abs(int(sy) - cy) <= tol + + # ---------------------------------------------------------------- 按键 + + def down(self, button=1): + with self._input_lock: + if not self.ready: + return False + button = int(button) + self._pressed.add(button) + self._dll.mouse_down(button) + return True + + def up(self, button=1): + with self._input_lock: + if self._open and self._dll is not None: + self._dll.mouse_up(int(button)) + self._pressed.discard(int(button)) + + def click(self, sx, sy, times=1, tol=1): + """先确认到位置, 再按下抬起。没到位就不点, 免得点错地方。""" + if not self.ready: + return False + if not self.move_to(sx, sy, tol=tol): + cx, cy = get_cursor() + self.log('[driver] 定位失败: 目标(%d,%d) 实际(%d,%d), 不点击' + % (sx, sy, cx, cy)) + return False + for _ in range(int(times)): + try: + if not self.down(1): + return False + time.sleep(0.03) + finally: + self.up(1) + return not self._stopped + + def key_down(self, key): + if self.ready: + self._dll.key_down(key) + + def key_up(self, key): + if self.ready: + self._dll.key_up(key) + + def scroll(self, amount): + if self.ready: + self._dll.scroll(int(amount)) + + +def client_to_screen(hwnd, x, y): + """游戏客户区坐标 -> 屏幕坐标。""" + if not hwnd: + raise OSError('没有游戏窗口句柄') + pt = wintypes.POINT(int(x), int(y)) + fn = _api('user32', 'ClientToScreen', wintypes.BOOL, + [wintypes.HWND, ctypes.POINTER(wintypes.POINT)]) + if not fn(hwnd, ctypes.byref(pt)): + raise OSError('ClientToScreen 失败, 未发送输入') + return (pt.x, pt.y) diff --git a/lc_mcp/killswitch.py b/lc_mcp/killswitch.py new file mode 100644 index 0000000..5282b63 --- /dev/null +++ b/lc_mcp/killswitch.py @@ -0,0 +1,109 @@ +# -*- coding: utf-8 -*- +"""全局急停热键。 + +为什么需要: 驱动级点击是闭环定位的 —— 手一动,下一次点击前会读到新位置、 +算出偏差、再把你推回目标点。所以任务运行期间鼠标和人是"拔河"状态,用户没法 +用鼠标去点停止按钮。键盘不受影响,所以用键盘热键做急停。 + +⛔ AALC 自带的 pause_hotkey 帮不上忙: 那个配置项只在 GUI(app/farming_interface.py) +里注册, lc_mcp 走的是命令行子进程, 那条路径上没有热键监听。 + +默认 F12, 可用环境变量 LCP_KILL_KEY 改(取 pynput 的键名, 如 f11 / pause / esc)。 +按下后终止任务子进程, 游戏保留。硬退出不会执行任务的 finally; +临时配置由 TaskRunner 的恢复文件机制处理。退出前给驱动释放鼠标的短暂机会, +清理卡住时仍强制退出。 +""" +import os +import threading +from contextlib import contextmanager + +DEFAULT_KEY = 'f12' +EXIT_CODE = 130 # 与 SIGINT 一致, 便于上层识别"被用户中止" +STOP_TIMEOUT = 0.25 + + +def _key_spec(name): + """'f12' -> '',pynput 的 GlobalHotKeys 要求尖括号形式。""" + name = (name or '').strip().lower() or DEFAULT_KEY + if name.startswith('<') and name.endswith('>'): + return name + return '<%s>' % name + + +def install(log=print, key=None, on_stop=None): + """启动急停监听线程。返回监听器对象(可用于测试), 失败返回 None。 + + 任何异常都不向外抛 —— 急停装不上不该让任务起不来, 但必须把原因说清楚。 + """ + key = key or os.environ.get('LCP_KILL_KEY') or DEFAULT_KEY + spec = _key_spec(key) + + try: + from pynput import keyboard + except Exception as e: # pynput 缺失/无显示环境 + log('[lc_mcp] 急停热键不可用(pynput 加载失败: %s: %s), 请用 Ctrl+Alt+Del 强制停止' + % (type(e).__name__, e)) + return None + + state = {'fired': False} + + def on_activate(): + if state['fired']: + return + state['fired'] = True + # Windows 在系统输入线程上调用此函数, 不在这里写日志或等待清理。 + # 即使日志锁/驱动清理卡住, 也必须按时退出。 + timer = threading.Timer(STOP_TIMEOUT, os._exit, args=(EXIT_CODE,)) + timer.daemon = True + + def shutdown(): + try: + if on_stop is not None: + on_stop() + finally: + try: + os._exit(EXIT_CODE) + finally: + timer.cancel() # 仅供 _exit 被测试替换的情况 + + try: + timer.start() + worker = threading.Thread(target=shutdown, name='lc-mcp-emergency-stop', daemon=True) + state['worker'] = worker + worker.start() + except Exception: + timer.cancel() + os._exit(EXIT_CODE) + + try: + listener = keyboard.GlobalHotKeys({spec: on_activate}) + listener.daemon = True + listener.start() + except Exception as e: + log('[lc_mcp] 急停热键注册失败(%s: %s), 请用 Ctrl+Alt+Del 强制停止' + % (type(e).__name__, e)) + return None + + log('[lc_mcp] 急停监听已启动: 按 %s 终止任务, 游戏窗口保留; 可用 run_task 重新开始' + % key.upper()) + listener._lc_state = state + return listener + + +def stop(listener): + """停止监听(任务正常结束时调用, 免得线程残留)。""" + if listener is None: + return + try: + listener.stop() + except Exception: + pass + + +@contextmanager +def listening(log=print, on_stop=None): + listener = install(log=log, on_stop=on_stop) + try: + yield listener + finally: + stop(listener) diff --git a/lc_mcp/preflight.py b/lc_mcp/preflight.py new file mode 100644 index 0000000..eabd55f --- /dev/null +++ b/lc_mcp/preflight.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +"""任务启动前的配置检查。 + +10-04/05 的几次长时间空转都源于配置: AALC 不报错, 只是一直原地打转。 +这里把已知的坑在启动前拦下来, 返回人能看懂的原因。 + +check() 只吃普通 dict, 不依赖 AALC, 便于单测; collect() 负责从 AALC cfg 取值。 +""" +import os + +# 窗口边框 + 标题栏(100% 缩放下实测 16x39, 留一点余量) +FRAME_W, FRAME_H = 16, 40 +ALLOW_LUNACY_ENV = 'LCP_ALLOW_LUNACY' + + +def collect(cfg): + teams = {} + for key, team in (cfg.get_value('teams') or {}).items(): + data = team.model_dump() if hasattr(team, 'model_dump') else dict(team) + teams[str(key)] = data + return { + 'simulator': bool(cfg.get_value('simulator')), + 'mirror': bool(cfg.get_value('mirror')), + 'set_win_size': int(cfg.get_value('set_win_size')), + 'set_lunacy_to_enkephalin': int(cfg.get_value('set_lunacy_to_enkephalin') or 0), + 'teams_active_queue': list(cfg.get_value('teams_active_queue') or []), + 'teams': teams, + } + + +def desktop_size(): + """主显示器分辨率(进程已由 bootstrap 设为 DPI aware, 取到的是物理像素)。""" + from ctypes import windll + return windll.user32.GetSystemMetrics(0), windll.user32.GetSystemMetrics(1) + + +def check(values, task, desktop=None, env=None): + """返回问题列表; 空列表表示可以启动。""" + env = os.environ if env is None else env + problems = [] + + lunacy = values.get('set_lunacy_to_enkephalin', 0) + if lunacy and task != 'enkephalin' and env.get(ALLOW_LUNACY_ENV) != '1': + problems.append( + 'set_lunacy_to_enkephalin=%s: 体力不足时会花狂气换体力。狂气只用于抽卡, 请在 AALC 里改成 0' + '(确需使用时设环境变量 %s=1)' % (lunacy, ALLOW_LUNACY_ENV)) + + # all 只在 AALC 里勾选了镜牢时才会编队 + if task == 'mirror' or (task == 'all' and values.get('mirror')): + teams = values.get('teams', {}) + for num in values.get('teams_active_queue', []): + team = teams.get(str(num)) + if team is None: + problems.append('teams_active_queue 里的队伍 %s 没有配置' % num) + continue + order = list(team.get('sinner_order') or []) + # team_formation 从 1 开始按顺序找罪人, 缺 1 就一个都不选, 然后无限重试编队 + if 1 not in order: + problems.append( + '队伍 %s 的 sinner_order 没有罪人(全是 0): 镜牢编队会选空队伍并无限重试。' + '在 AALC 队伍设置里勾选罪人并排序' % num) + + if not values.get('simulator') and desktop: + size = values.get('set_win_size', 0) + need_w = int(size * 16 / 9) + FRAME_W + need_h = size + FRAME_H + if need_w > desktop[0] or need_h > desktop[1]: + problems.append( + 'set_win_size=%s 需要 %sx%s 的窗口(含标题栏), 桌面只有 %sx%s: 窗口会被压扁成非 16:9,' + ' 模板匹配全部失效。改小 set_win_size(如 720)或调大桌面分辨率' + % (size, need_w, need_h, desktop[0], desktop[1])) + return problems diff --git a/lc_mcp/protocol.py b/lc_mcp/protocol.py index eb57984..b3e65ec 100644 --- a/lc_mcp/protocol.py +++ b/lc_mcp/protocol.py @@ -60,7 +60,8 @@ TOOLS = [ 'enkephalin=狂气换体力(times); mirror=镜牢(count 次数)。任务运行期间禁止手动点击类工具'), 'inputSchema': _obj({'task': {'type': 'string', 'enum': sorted(TASKS)}, 'exp': _NUM, 'thread': _NUM, 'times': _NUM, 'count': _NUM}, ['task'])}, - {'name': 'task_status', 'description': '查看任务状态(idle/running/succeeded/failed/stopped)和日志尾部', + {'name': 'task_status', 'description': '查看任务状态(idle/running/succeeded/failed/stopped)和日志尾部。' + 'succeeded 也要看 errors; running 时出现 stall 说明 AALC 在空转(如选中空队伍), 应 stop_task', 'inputSchema': _obj({'lines': {'type': 'number', 'default': 30}})}, {'name': 'stop_task', 'description': '强制停止当前任务(杀掉任务进程)', 'inputSchema': _obj()}, ] diff --git a/lc_mcp/tasks.py b/lc_mcp/tasks.py index 5c7fa56..640639b 100644 --- a/lc_mcp/tasks.py +++ b/lc_mcp/tasks.py @@ -3,13 +3,16 @@ import glob import json import os +import re import signal import subprocess import sys import threading import time +from collections import deque from .aalc_task import RESTORE_ENV +from .killswitch import EXIT_CODE as USER_ABORT_EXIT REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) IS_WIN = sys.platform.startswith('win') @@ -40,15 +43,77 @@ ERROR_SCAN_LINES = 400 def log_errors(path, limit=3): - """挑出日志尾部的报错行。 + """流式扫描整份任务日志, 只保留最后 limit 条报错。 AALC 的每日流程在单次战斗失败后会继续跑完并正常退出(exit 0), 只看退出码 会把"超出最大尝试次数,未能进入战斗"这类失败当成成功, 所以状态里额外附上 日志里的报错行。 """ - hits = [line for line in tail(path, ERROR_SCAN_LINES) - if any(marker in line for marker in ERROR_MARKERS)] - return hits[-limit:] + hits = deque(maxlen=limit) + try: + with open(path, encoding='utf-8', errors='replace') as f: + for line in f: + if any(marker in line for marker in ERROR_MARKERS): + hits.append(line.rstrip('\r\n')) + except OSError: + pass + return list(hits) + + +# AALC 卡死时不报错、进程健在, 只是反复输出同一类日志。 +# "配队人数OCR得到" 只在编队人数检查失败的重试里打印, 健康运行中一次都不会出现; +# 2026-10-05 的三次空队伍卡死里它分别刷了 242/306/24 次。 +STALL_MARKERS = {'empty_team': '配队人数OCR得到'} +STALL_THRESHOLD = 10 + +# 计数法抓不到"界面误判"型卡死: AALC 把别的界面认成目标界面, 对着误匹配的 +# 模板反复盲点, 日志照样疯涨, 只是再没有任何流程进展。2026-10-13 实测在镜牢 +# 入口把 home/luxcavation_assets.png 匹配到 0.836, 连点 18 分钟不停。 +# 所以再加一条与内容无关的判据: 里程碑(开始执行/结束执行)多久没前进了。 +STALL_NO_PROGRESS_S = int(os.environ.get('LCP_STALL_NO_PROGRESS_S', 10 * 60)) +# 里程碑可能离文件尾很远(卡死期间日志涨得很快), 回溯窗口给大一点 +PROGRESS_SCAN_BYTES = 8 * 1024 * 1024 +TIMESTAMP_RE = re.compile(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})') +PROGRESS_RE = re.compile(r'(开始执行|结束执行)\s') + + +def last_progress_epoch(path): + """日志里最后一条里程碑的时间戳(epoch 秒); 找不到返回 None。""" + try: + with open(path, 'rb') as f: + f.seek(0, os.SEEK_END) + f.seek(max(0, f.tell() - PROGRESS_SCAN_BYTES)) + blob = f.read().decode('utf-8', 'replace') + except OSError: + return None + last = None + for line in blob.splitlines(): + if not PROGRESS_RE.search(line): + continue + m = TIMESTAMP_RE.search(line) + if not m: + continue + try: + last = time.mktime(time.strptime(m.group(1), '%Y-%m-%d %H:%M:%S')) + except ValueError: + continue + return last + + +def log_stalls(path, now=None): + """统计日志尾部的卡死信号, 达到阈值的返回 {名称: 次数}。""" + lines = tail(path, ERROR_SCAN_LINES) + counts = {name: sum(marker in line for line in lines) for name, marker in STALL_MARKERS.items()} + stalls = {name: n for name, n in counts.items() if n >= STALL_THRESHOLD} + + # 必须随真实时间推进: 进程卡住不再写日志时, mtime 也会冻结。 + # 离线复核历史日志时可显式传入当时的 now。 + progress = last_progress_epoch(path) + if progress is not None: + idle = (time.time() if now is None else now) - progress + if idle >= STALL_NO_PROGRESS_S: + stalls['no_progress'] = int(idle) + return stalls class TaskRunner: @@ -122,13 +187,21 @@ class TaskRunner: state = 'running' else: self.info.setdefault('ended', time.time()) - state = 'stopped' if self.info['stopped_by_user'] else 'succeeded' if code == 0 else 'failed' + state = ('stopped' if self.info['stopped_by_user'] or code == USER_ABORT_EXIT + else 'succeeded' if code == 0 else 'failed') r = {'ok': True, 'state': state, 'task': self.info['task'], 'params': self.info['params'], 'elapsed_s': int((self.info.get('ended') or time.time()) - self.info['started']), 'log': self.info['log'], 'log_tail': tail(self.info['log'], max(1, min(int(lines), 200)))} - if code is not None: + if code is None: + stalls = log_stalls(self.info['log']) + if stalls: + r['stall'] = stalls + else: r['exit_code'] = code - errors = log_errors(self.info['log']) + # 子进程退出后日志已写完; 结果只计算一次, 避免轮询反复扫描大文件。 + if 'errors' not in self.info: + self.info['errors'] = log_errors(self.info['log']) + errors = self.info['errors'] if errors: r['errors'] = errors pending = self._pending_restores() diff --git a/scripts/audit_runs.py b/scripts/audit_runs.py new file mode 100644 index 0000000..b16d25c --- /dev/null +++ b/scripts/audit_runs.py @@ -0,0 +1,235 @@ +# -*- coding: utf-8 -*- +"""值守体检: 日志与报告交叉核对, 并挑出可疑记录。 + +用法: python audit_runs.py [--dir DIR] [--json] +退出码: 0 一切吻合 / 1 发现不一致 + +为什么需要这个脚本: + 上一轮我照着自己写在 docs/WATCH.md 里的办法做核对, 结果 6 条全部报"对不上" —— + 但数据其实是吻合的。坑在于: **日志的结论行写在一轮结束时, 报告的 started 是 + 开始时**, 两者天然差一个 elapsed_s。拿两个时间戳直接比必然全部失败。 + + 正确关系是: 报告.started + elapsed ≈ 日志结论时刻。 + + 代码里的时间关系比人记的可靠, 所以把核对做成脚本而不是让人照着文档敲 + PowerShell —— 我手敲那次就误判了。 + +检查三件事: + 1. 每份报告都能在日志里找到对应结论(时间对得上, 耗时和结果文本一致) + 2. 日志里每条结论都有对应报告(没有"跑了但没留报告"的运行) + 3. 疑似 mock 残留: 同一秒扎堆、或内容自相矛盾的结论行 +""" +import argparse +import glob +import json +import os +import re +import sys +from collections import defaultdict +from datetime import datetime, timedelta + +DIR = os.path.expanduser(os.path.join('~', 'lc_mcp', 'modules')) +LOG_NAME = 'convert.log' +# 报告.started 与日志结论时刻的允许偏差(两边各写一次时间戳) +TOL_S = 5 + +CONCLUSION_RE = re.compile( + r'^\[(?P\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\]\s*===\s*(?P.+?)\s*' + r'\((?P\w+)\), 耗时 (?P\d+)s ===') +START_RE = re.compile( + r'^\[(?P\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\]\s*===\s*开始: 体力换模块\s*===') +# 明显不可能出现在真实运行里的说法 +IMPOSSIBLE = ('powershell not found', 'not found', 'No such file') + + +def parse_runs(path): + """把日志解析成一轮一轮的 (开始, 结束, 结果, 耗时)。 + + ⛔ 为什么要配对而不是只取结论行: 第一版只用结论行, 拿"报告.started + elapsed" + 去和结论时刻比 —— 能对上就说明 elapsed 一致, 所以"耗时不符"那个分支永远不可能 + 触发, 是死代码。看起来在查、实际查不到的东西比没有更糟。 + 改成按日志里的"=== 开始: 体力换模块 ===" 配对, 报告的 started 才能和**开始**时刻 + 真正对照, 耗时也能独立核对。 + """ + out = [] + if not os.path.exists(path): + return out + pending = [] + with open(path, encoding='utf-8') as f: + for line in f: + line = line.strip() + ms = START_RE.match(line) + if ms: + pending.append(datetime.strptime(ms.group('t'), '%Y-%m-%d %H:%M:%S')) + continue + mc = CONCLUSION_RE.match(line) + if mc: + start = pending.pop(0) if pending else None + out.append({'start': start, + 'end': datetime.strptime(mc.group('t'), '%Y-%m-%d %H:%M:%S'), + 'result': mc.group('result'), 'ok': mc.group('ok'), + 'secs': int(mc.group('secs')), 'line': line}) + return out + + +# 兼容旧名字: 只要结论行 +def parse_log(path): + return parse_runs(path) + + +def load_reports(d): + out = [] + for p in sorted(glob.glob(os.path.join(d, 'convert_*.json'))): + try: + with open(p, encoding='utf-8') as f: + r = json.load(f) + except (OSError, ValueError): + continue + out.append({'file': os.path.basename(p), + 'start': datetime.strptime(r['started'], '%Y-%m-%d %H:%M:%S'), + 'secs': r.get('elapsed_s'), 'result': r.get('result', ''), + 'ok': bool(r.get('ok')), + # ⛔ steps / converted 也得留着: 第一版只挑了 5 个字段, 结果 + # "跨轮检查模组数"拿不到数据, 又是个查不出东西的检查。 + 'steps': r.get('steps') or [], + 'converted': r.get('converted')}) + out.sort(key=lambda r: r['start']) + return out + + +def same_second_clusters(conclusions): + """同一秒里出现多行结论 = 几乎必然是测试批量产生的。""" + bysec = defaultdict(list) + for c in conclusions: + bysec[c['end']].append(c) + return {k: v for k, v in bysec.items() if len(v) > 1} + + +def impossible_claims(conclusions): + """内容自相矛盾的结论(比如 powershell 明明在却说找不到)。""" + out = [] + for c in conclusions: + low = c['result'] + if any(k.lower() in low.lower() for k in IMPOSSIBLE): + out.append(c) + return out + + +OWNED_RE = re.compile(r'模组\s*(\d+)\s*->\s*(\d+)') + + +def module_trajectory(reports): + """跨轮检查模组数有没有减少。 + + ⛔ 2026-10-17 遇到一次: 22:05 合成后是 35, 而 06:04 那轮读到的合成前是 33。 + 当时怀疑是强制关游戏丢了未保存状态, 追查了一轮 —— **结果是人自己升阶用掉了**。 + (所以现在 close_game 仍是优雅关闭: 那是独立的健壮性改进, 和这件事无关。) + + 教训: 这类"数字对不上"的现象, **默认解释可能是人手动操作**, 而不是 bug。 + 所以这里的措辞是"需要确认", 不是"出问题了" —— 唯一的例外是它能反过来证明 + 某件自动化的事: 如果模组数**自己变多了**, 那才是真异常(自动化之外的来源)。 + + 自己从 steps[0].info 里解出模组数(不依赖调用方预先算好)。只比较**接连两轮都 + 成功合成**的情况, 免得把"跳过轮次"误判成倒退。 + """ + seq = [r for r in reports if r.get('converted')] + seq.sort(key=lambda r: r['start']) + owned = [] + for r in seq: + step = (r.get('steps') or [{}])[0] + m = OWNED_RE.search(step.get('info', '') or '') + owned.append((r, (int(m.group(1)), int(m.group(2))) if m else None)) + + out = [] + for (prev, pa), (cur, ca) in zip(owned, owned[1:]): + if pa is None or ca is None: + continue + if ca[0] < pa[1]: + out.append('模组数比上一轮少: %s 合成后是 %s, 而 %s 读到合成前只有 %s ' + '—— 若是人工升阶用掉的属正常; 否则要查' + % (prev['start'].strftime('%m-%d %H:%M'), pa[1], + cur['start'].strftime('%m-%d %H:%M'), ca[0])) + elif ca[0] > pa[1]: + # 自动化只会按合成前后的差值增加, 无端变多说明有别的来源 + out.append('模组数无端变多: %s 合成后是 %s, 而 %s 读到合成前有 %s ' + '—— 自动化之外还有别的来源, 值得看一眼' + % (prev['start'].strftime('%m-%d %H:%M'), pa[1], + cur['start'].strftime('%m-%d %H:%M'), ca[0])) + return out + + +def audit(d): + runs = parse_runs(os.path.join(d, LOG_NAME)) + reports = load_reports(d) + problems = [] + + # 0. 跨轮: 模组数不该倒退 + problems.extend(module_trajectory(reports)) + + # 1. 每份报告都要有对应的一轮 + for r in reports: + hit = [c for c in runs if c['start'] is not None + and abs((c['start'] - r['start']).total_seconds()) <= TOL_S] + if not hit: + problems.append('报告 %s (started %s) 在日志里找不到对应的开始行' + % (r['file'], r['start'])) + continue + c = hit[0] + # 结论时刻应当 = 开始 + 耗时 + expect_end = c['start'] + timedelta(seconds=r['secs'] or 0) + if abs((c['end'] - expect_end).total_seconds()) > TOL_S: + problems.append('%s 时间对不上: 开始 %s + 报告耗时 %ss 应为 %s, 日志结论在 %s' + % (r['file'], c['start'].strftime('%H:%M:%S'), r['secs'], + expect_end.strftime('%H:%M:%S'), c['end'].strftime('%H:%M:%S'))) + if c['secs'] != r['secs']: + problems.append('%s 耗时不符: 日志 %ss vs 报告 %ss' + % (r['file'], c['secs'], r['secs'])) + if c['result'] != r['result']: + problems.append('%s 结果文本不符:\n 日志 %s\n 报告 %s' + % (r['file'], c['result'], r['result'])) + + # 2. 每一轮都要有对应报告 + for c in runs: + hit = [r for r in reports + if c['start'] is not None + and abs((r['start'] - c['start']).total_seconds()) <= TOL_S] + if not hit: + problems.append('日志 %s 那轮没有对应报告: %s' + % (c['end'].strftime('%H:%M:%S'), c['result'][:50])) + + # 3. mock 残留 + for sec, group in same_second_clusters(runs).items(): + problems.append('同一秒(%s)出现 %d 行结论, 疑似测试残留' + % (sec.strftime('%H:%M:%S'), len(group))) + for c in impossible_claims(runs): + problems.append('可疑内容(%s): %s' + % (c['end'].strftime('%H:%M:%S'), c['result'][:60])) + + return {'runs': len(runs), 'reports': len(reports), 'problems': problems} + + +def main(argv=None): + ap = argparse.ArgumentParser(description='值守体检: 日志与报告交叉核对') + ap.add_argument('--dir', default=DIR) + ap.add_argument('--json', action='store_true') + args = ap.parse_args(argv) + + r = audit(args.dir) + if args.json: + json.dump(r, sys.stdout, ensure_ascii=False, indent=2) + print() + return 1 if r['problems'] else 0 + + print('日志 %d 轮 / 报告 %d 份' % (r['runs'], r['reports'])) + if not r['problems']: + print('✅ 全部吻合, 没有可疑记录') + return 0 + # 不叫"问题" —— 有些只是"需要确认"(比如人手动升阶用掉了模块) + print('⚠️ 有 %d 处需要确认:' % len(r['problems'])) + for p in r['problems']: + print(' - %s' % p) + return 1 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/auto_cycle.py b/scripts/auto_cycle.py new file mode 100644 index 0000000..11e5636 --- /dev/null +++ b/scripts/auto_cycle.py @@ -0,0 +1,416 @@ +# -*- coding: utf-8 -*- +"""一轮自动推进: 刷材料 -> (镜牢) -> 升级最弱人格 -> 同步 -> 报告。 + +用法: python auto_cycle.py [--mirror N] [--target LV] [--retries N] [--report-dir DIR] +退出码: 0 正常完成一轮 / 1 失败 + +每轮在 report-dir(默认 ~/lc_mcp/cycles)写一份 cycle_<时间>.log 与同名 .json 报告, +计划任务无人值守跑完后据此核对。 + +设计: 只做"一轮",不做无限循环——由外层(goal 轮次)负责重复与判断, +避免无人监督地长时间空转。每轮输出结构化报告供上层核对。 +""" +import argparse +import json +import os +import subprocess +import time + +from lc_ui import HERE, PY, click, drag, items, keypress, probe, run + +LEVELUP = os.path.join(HERE, 'levelup.py') +# 手动抽卡花掉狂气后, 删掉这个文件重新记基线, 否则每轮都会中止 +LUNACY_BASELINE = os.path.expanduser(os.path.join('~', 'lc_mcp', 'lunacy_baseline.txt')) + +# 导航 +BACK = (85, 75) # 只在 Sinners 内部退层用, 主界面上按它会进剧情 +BTN_SINNERS = (1130, 805) # 主界面底部 Sinners +TAB_ALL_IDENTITIES = (1472, 245) # TEAMS 页 -> All Identities + +# AALC 任务轮询上限 +DAILY_TIMEOUT_S = 45 * 60 +# 每局镜牢。10-04 首次 39 分钟、10-13 两局分别 59 与 >70 分钟(19 场战斗仍未结束), +# 所以 70 分钟不够用 —— 实测撞过超时, 强杀后游戏停在副本里, 连升级都进不去。 +MIRROR_TIMEOUT_S = 100 * 60 +POLL_S = 60 +# task_status 连续几次报 stall 就判定卡死并停任务 +STALL_POLLS = 2 +# 卡死后重跑次数。AALC 任务开头会自己回主界面, 重跑通常就能脱困 +STALL_RETRIES = 1 +DEFAULT_REPORT_DIR = os.path.expanduser(os.path.join('~', 'lc_mcp', 'cycles')) + +_log_file = None + + +class UserAborted(RuntimeError): + """用户主动停止, 结束整轮, 不执行后续导航、升级或重试。""" + + +def log(msg): + line = '[%s] %s' % (time.strftime('%H:%M:%S'), msg) + print(line, flush=True) + if _log_file: + with open(_log_file, 'a', encoding='utf-8') as f: + f.write(line + '\n') + + +def goto_identities(): + """从任意位置尽力走到 罪人 -> Identities 网格。 + + 只点 Sinners 按钮, 绝不点左上返回键——主界面上的返回键会进入剧情(Drive), + 实测会掉进过场动画, 需要额外恢复。 + """ + for attempt in range(5): + its = items() + txt = ' | '.join(i.get('text', '') for i in its) + if 'IDENTITIES' in txt and 'Facades' in txt: + return True + if 'TEAMS #1' in txt or 'SIN COST' in txt or 'All Idensities' in txt: + click(*TAB_ALL_IDENTITIES) + time.sleep(3) + continue + if 'LUXCAVATION' in txt.upper() or 'MIRROR' in txt.upper(): + # 在副本/关卡菜单里, 先回主界面 + keypress('esc') + time.sleep(2) + continue + click(*BTN_SINNERS) + time.sleep(3.5) + its = items() + txt = ' | '.join(i.get('text', '') for i in its) + return 'IDENTITIES' in txt and 'Facades' in txt + + +def on_teams_screen(txt): + """TEAMS 界面的判定。 + + 实测 OCR 会把 "SIN COST" 输出成 "SINICOST"(无空格), 直接匹配 'SIN COST' + 会漏判 —— 于是 ensure_team1() 以为不在 TEAMS 页, 去点 Sinners 按钮空转, + 最后报 "未能确认选中 TEAMS #1"。所以先去空格再比。 + """ + t = txt.replace(' ', '').upper() + return ('SINCOST' in t or 'SINICOST' in t + or 'ALLIDENTITIES' in t or 'ALLE.G.0' in t or 'ALLE.G.O' in t) + + +def on_grid(txt): + return 'IDENTITIES' in txt and 'Facades' in txt + + +def ensure_team1(): + """进 TEAMS 界面, 把预设列表滚到顶并选中 TEAMS #1。 + + 实测坑: 这个账号有 40 个队伍预设, 而 AALC 的选队搜索只朝列表下方扫 + (dy 为负), 列表一旦停在底部就永远找不到 TEAMS #1, 日志表现为 + "找不到队伍 # 1" 然后整轮空转。所以每轮开跑前先把列表拉回顶部。 + """ + for _ in range(5): + its = items() + txt = ' | '.join(i.get('text', '') for i in its) + if on_teams_screen(txt): + break + if on_grid(txt): + click(*BACK) # 网格 -> TEAMS, 仍在 Sinners 内, 安全 + time.sleep(3) + continue + click(*BTN_SINNERS) + time.sleep(3.5) + + for _ in range(10): + its = items() + cand = [i for i in its + if i.get('text', '').strip().replace(' ', '') in + ('TEAMS#1', 'TFAMS#1') and i.get('x', 999) < 320] + if cand: + top = min(cand, key=lambda i: i.get('y', 0)) + click(top['x'], top['y']) + time.sleep(2.5) + return True + # 向下拖拽 = 列表内容下移 = 露出更靠前的预设 + drag(190, 400, 190, 700) + time.sleep(2) + return False + + +def blocking_module_modal(): + """只读识别缺模组弹窗, 返回 Cancel 中心。AALC 运行期间不发送输入。""" + its = items() + txt = ''.join(''.join(i.get('text', '').split()) for i in its).lower() + if 'enoughenkephalinmodules' not in txt: + return None + for it in its: + if 'cancel' in it.get('text', '').lower(): + w = it.get('w') or 0 + h = it.get('h') or 0 + return it['x'] + w / 2.0, it['y'] + h / 2.0 + return None + + +def clear_blocking_modal(): + """任务停止后重新识别并取消缺模组弹窗; 点击被拒绝时不能报成功。""" + pos = blocking_module_modal() + if pos is None: + return None + result = click(*pos) + if not result.get('ok'): + raise RuntimeError('取消缺模组弹窗失败: %s' % result.get('error', result)) + return 'Enkephalin Modules 不足 -> 已发送 Cancel' + + +def stop_running_task(): + result = probe('stop_task') + if not result.get('ok'): + raise RuntimeError('停止 AALC 任务失败: %s' % result.get('error', result)) + + +# 同一轮里连着这么多次看到"模组不足", 就不是偶发了, 是资源真的见底 +RESOURCE_OUT_LIMIT = 3 + + +def poll_task(task, timeout_s, sleep=time.sleep): + """轮询到任务结束。返回 (ok, 说明, 是否因卡死被停)。""" + t0 = time.time() + stalled = 0 + resource_polls = 0 + while time.time() - t0 < timeout_s: + sleep(POLL_S) + st = probe('task_status', {'lines': 1}) + if st.get('ok') is False or not st.get('state'): + stop_running_task() + raise RuntimeError('无法读取任务状态: %s' % st.get('error', st)) + s = st.get('state') + el = int(time.time() - t0) + if s == 'stopped' or st.get('exit_code') == 130: + raise UserAborted('%s 已被用户停止' % task) + if s != 'running': + log('%s 结束: state=%s elapsed=%ds exit=%s' % (task, s, el, st.get('exit_code'))) + # AALC 单次战斗失败后仍会 exit 0, succeeded 还要看 errors + if st.get('errors'): + return False, '%s: %s' % (s, st['errors'][-1]), False + return s == 'succeeded', 'state=%s elapsed=%ds' % (s, el), False + try: + modal = blocking_module_modal() + except Exception as e: # 清道夫不该拖垮轮询 + modal = None + log(' [warn] 读取缺模组弹窗时出错: %s' % e) + resource_polls = resource_polls + 1 if modal is not None else 0 + if resource_polls: + log(' 缺模组弹窗连续出现 (%d/%d)' % (resource_polls, RESOURCE_OUT_LIMIT)) + if resource_polls >= RESOURCE_OUT_LIMIT: + # 反复缺模组 = 体力/模组真的见底了。继续点下去只是空转到超时, + # 浪费掉这一轮的时间(实测每次都烧满 10 分钟)。直接收工, 等下一轮。 + stop_running_task() + msg = clear_blocking_modal() + if msg: + log(' [fix] %s' % msg) + return False, 'RESOURCE_OUT', False + stalled = stalled + 1 if st.get('stall') else 0 + if stalled >= STALL_POLLS: + stop_running_task() + return False, '卡死(%s), 已停止任务 elapsed=%ds' % (st['stall'], el), True + if el % 600 < POLL_S: + log(' ...%s running %ds' % (task, el)) + stop_running_task() + return False, '超时 %ds' % timeout_s, False + + +def run_aalc(task, params, timeout_s, retries=STALL_RETRIES, sleep=time.sleep): + """跑一个 AALC 任务; 卡死时停掉重跑, 最多 retries 次。返回 (ok, 说明)。""" + info = '' + for attempt in range(retries + 1): + if attempt: + log('%s 卡死后重跑 (%d/%d)' % (task, attempt, retries)) + sleep(10) + r = probe('run_task', dict(params, task=task)) + if not r.get('ok'): + return False, 'run_task 失败: %s' % r.get('error', r) + log('%s 已启动 %s, 开始轮询' % (task, params or '')) + ok, info, stalled = poll_task(task, timeout_s, sleep=sleep) + if ok or not stalled: + return ok, info + return False, info + + +def report_grid(): + out = run([PY, '-X', 'utf8', LEVELUP, 'list'], check=True) + return out.strip() + + +MAIN_MENU_MARKERS = ('SINNERS', 'WINDOW', 'DISPENSE', 'THEATER', 'EXTRACT') + + +def read_lunacy(reads=5, pause=1.0): + """读狂气余额。取多次读数的**众数**, 读不到返回 None。 + + 两个实测坑(2026-10-13): + 1. OCR 偶尔漏掉 LUNACY 标签, 所以多读几次。 + 2. **同一个画面上数字本身就会抖**: 放大 6 倍肉眼确认余额是 6388, 而 OCR 在 + 同一画面连读 5 次得到 6388 四次、8859 一次。8859 被当成基线后, 之后正确 + 的 6388 反而被判成"已消耗"并中止整轮 —— 一次误读就能造成一次误报。 + 所以读完所有帧再取唯一众数(至少出现 2 次才采信), 平票返回 None。 + + 曾经试过"只在主界面取数", 但那样几乎总是读不到(轮次开始/结束时常停在副本、 + 网格、结算页), 守卫直接跳过。多帧投票只能减少偶发误读, 无法证明消费。 + """ + votes = {} + for attempt in range(reads): + its = items() + lab = None + for it in its: + if 'NACY' in it.get('text', '').upper(): + lab = it + break + if lab: + best = None + for it in its: + t = it.get('text', '').strip() + if t.isdigit(): + dy = it.get('y', 0) - lab.get('y', 0) + dx = abs(it.get('x', 0) - lab.get('x', 0)) + if 0 < dy < 70 and dx < 130: + best = int(t) + if best is not None: + votes[best] = votes.get(best, 0) + 1 + if attempt < reads - 1: + time.sleep(pause) + ranked = sorted(votes, key=votes.get, reverse=True) + if ranked and votes[ranked[0]] >= 2: + if len(ranked) == 1 or votes[ranked[0]] > votes[ranked[1]]: + return ranked[0] + return None + + +def lunacy_guard(): + """狂气只许不降。用户明确要求狂气只能用于抽卡。 + + 返回 (ok, 说明)。首次运行写入基线。 + """ + cur = read_lunacy() + if cur is None: + return True, '读不到狂气余额, 跳过校验' + base = None + if os.path.exists(LUNACY_BASELINE): + try: + base = int(open(LUNACY_BASELINE, encoding='utf-8').read().strip()) + except ValueError: + base = None + if base is None: + with open(LUNACY_BASELINE, 'w', encoding='utf-8') as f: + f.write(str(cur)) + return True, '记录狂气基线 %d' % cur + if cur < base: + return False, '狂气读数从 %d 降到 %d, 需人工核查(OCR 也可能误读), 本轮暂停' % (base, cur) + if cur > base: + with open(LUNACY_BASELINE, 'w', encoding='utf-8') as f: + f.write(str(cur)) + return True, '狂气 %d -> %d (增加, 更新基线)' % (base, cur) + return True, '狂气 %d 未变' % cur + + +def main(argv=None): + global _log_file + ap = argparse.ArgumentParser(description='一轮: 刷材料 -> 镜牢 -> 升级/同步') + ap.add_argument('--mirror', type=int, default=0, help='本轮镜牢局数, 默认 0') + ap.add_argument('--target', type=int, default=34, help='把队内人格升到的等级') + ap.add_argument('--retries', type=int, default=STALL_RETRIES, help='AALC 卡死后重跑次数') + ap.add_argument('--report-dir', default=DEFAULT_REPORT_DIR) + args = ap.parse_args(argv) + + os.makedirs(args.report_dir, exist_ok=True) + base = os.path.join(args.report_dir, 'cycle_' + time.strftime('%Y%m%d_%H%M%S')) + _log_file = base + '.log' + t_start = time.time() + steps = [] + + def step(name, ok, info): + steps.append({'step': name, 'ok': ok, 'info': info, 'at': time.strftime('%H:%M:%S')}) + log('%s: %s (%s)' % (name, 'OK' if ok else 'FAIL', info)) + return ok + + def finish(code, why): + log('=== %s, 耗时 %ds ===' % (why, int(time.time() - t_start))) + report = {'ok': code == 0, 'result': why, 'started': time.strftime( + '%Y-%m-%d %H:%M:%S', time.localtime(t_start)), 'elapsed_s': int(time.time() - t_start), + 'args': vars(args), 'steps': steps, 'log': _log_file} + with open(base + '.json', 'w', encoding='utf-8') as f: + json.dump(report, f, ensure_ascii=False, indent=2) + return code + + try: + return run_cycle(args, step, finish) + except UserAborted as e: + step('用户停止', False, str(e)) + return finish(130, '本轮已由用户停止') + except (OSError, RuntimeError, subprocess.SubprocessError) as e: + if isinstance(e, subprocess.CalledProcessError): + output = (e.stdout or '') + (e.stderr or '') + for line in output.splitlines(): + log(' ' + line) + step('执行异常', False, '%s: %s' % (type(e).__name__, e)) + return finish(1, '本轮失败: 执行异常') + finally: + _log_file = None + + +def run_cycle(args, step, finish): + log('=== 一轮开始 ===') + if not step('狂气校验', *lunacy_guard()): + return finish(1, '中止: 狂气读数下降, 需人工核查') + + # 先把预设列表拉回顶部并选中 TEAMS #1——AALC 只朝列表下方找, 停在底部会找不到 + if not ensure_team1(): + log('[warn] 未能确认选中 TEAMS #1, 继续尝试') + + ok, info = run_aalc('daily', {}, DAILY_TIMEOUT_S, args.retries) + if info == 'RESOURCE_OUT': + # 体力/模组见底, Luxcavation 打不了。这不是故障, 是资源周期 —— 体力和燃料 + # 都会自然恢复, 下一轮(计划任务 2.5 小时后再来)通常就能继续。空转没有意义。 + step('刷材料', False, '体力/模组不足, 本轮跳过') + log('[warn] 体力或模组见底, 本轮不再刷材料; 等自然恢复后下一轮继续') + return finish(0, '一轮结束(资源不足, 跳过刷取)') + if not step('刷材料', ok, info): + return finish(1, '本轮失败: 刷材料未成功') + + if args.mirror > 0: + # 镜牢掉落自我碎片, 同步到 IV 阶要用 + ok, info = run_aalc('mirror', {'count': args.mirror}, + MIRROR_TIMEOUT_S * args.mirror, args.retries) + if not step('镜牢 x%d' % args.mirror, ok, info): + log('[warn] 镜牢未完成, 继续升级') + + # AALC 任务结束后在主界面, 这里才是能读到 LUNACY 的时机 + time.sleep(8) + if not step('狂气校验(刷后)', *lunacy_guard()): + return finish(1, '中止: 狂气读数下降, 需人工核查') + + if not goto_identities(): + # 镜牢超时被强杀时游戏还停在副本里, 这时进不去网格是正常的, 不是缺陷。 + # 刷取本身已经发生, 不该因为附加的升级环节把整轮判死 —— 下一轮 AALC + # 的 back_init_menu 会自行把游戏带回主界面。 + step('进入 Identities 网格', False, '找不到网格(可能仍停在镜牢内), 跳过升级') + log('[warn] 进不去网格, 跳过升级; 下一轮的 AALC 会自行回到主界面') + return finish(0, '一轮结束(跳过升级)') + log('升级前:\n' + report_grid()) + + log('对队内低于 Lv.%d 的人格升级 + 同步' % args.target) + # 用 progress 而非 weakest: 网格 OCR 会把 LV14 读成 Lv.1, + # progress 会逐个打开详情页以真实等级判断目标。 + out = run([PY, '-X', 'utf8', LEVELUP, 'progress', str(args.target), '--uptie'], check=True) + lines = out.strip().splitlines() + for line in lines: + log(' ' + line) + step('升级/同步', not any('FAIL' in l for l in lines), + '; '.join(l.strip() for l in lines if '升级:' in l or '同步:' in l) or '无需升级') + + time.sleep(5) + if not goto_identities(): + # 同上: 升级结果已经拿到, 回不到网格只影响下一轮的起点 + step('回到网格', False, '升级后无法回到网格, 不影响本轮产出') + log('[warn] 升级后回不到网格') + else: + log('升级后:\n' + report_grid()) + return finish(0, '一轮结束') + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/convert_modules.py b/scripts/convert_modules.py new file mode 100644 index 0000000..eb576cd --- /dev/null +++ b/scripts/convert_modules.py @@ -0,0 +1,863 @@ +# -*- coding: utf-8 -*- +"""到点启动游戏 -> 把体力合成成模块 -> 关掉游戏。不跑任何战斗任务。 + +用法: python convert_modules.py [--keep-game] [--start-timeout S] +退出码: 0 完成(含"体力不够, 无需合成") / 1 失败 + +为什么要单独一个脚本: + 用户要的是"挂机等体力恢复, 攒模块", 但**不要打任何关卡**。AALC 的 + make_enkephalin_module 是挂在 Luxcavation 流程里的(打完一次才顺手换一次), + 没有独立的入口, 所以这里直接用界面操作, 不经过 AALC 的任务系统。 + +界面流程(1600x900 基准坐标, lc_ui 负责换算到实际客户区): + 主界面 -> 点模组图标 -> 弹出 Charge Enkephalin + -> 页签 [Modules] / [Use Lunacy] / [Use Boxes] + -> 停在 Modules(免费合成) -> 点 » 取最大 -> Confirm + -> 体力 -20 换 1 模块 + +硬规则(用户明确要求): + 1. **绝不消费狂气**。Use Lunacy 页签的坐标 USE_LUNACY_TAB 在代码里只用于 + "确认自己没点到它", 任何点击路径都不会碰它。 + 2. **不打任何关卡**。全程只碰底栏模组图标和合成面板。 + 3. 记录合成前后狂气读数; 已知 OCR 抖动以外的变化需要人工核查。 +""" +import argparse +import json +import os +import subprocess +import sys +import time + +from lc_ui import HERE, click, items, keypress, probe, screen_text + +GAME_EXE = r'D:\SteamLibrary\steamapps\common\Limbus Company\LimbusCompany.exe' +GAME_PROC = 'LimbusCompany' +REPO = os.path.dirname(HERE) if os.path.basename(HERE) == 'scripts' else HERE +PYW = os.path.join(REPO, 'vendor', 'aalc', '.venv', 'Scripts', 'pythonw.exe') +SERVER_PORT = 8765 + +# --- 坐标(1600x900 基准; lc_ui 会换算到真实客户区) --- +# 合成面板有三个页签, 从左到右: Modules / Use Lunacy / Use Boxes +# Modules (619,283) 免费合成, 本项目只走这条 +# Use Lunacy(797,283) ⛔ 花狂气, 绝对不许点 +# Use Boxes (957,283) 用体力箱, 本项目不用 —— 不定义常量: 定义了却没人用 +# 会让人以为某条路径处理了它, 死代码比没有更糟 +MODULE_ICON = (390, 805) # 主界面底栏, 绿胶囊图标(点开合成面板) +TAB_MODULES = (619, 283) # 免费合成页签 +USE_LUNACY_TAB = (797, 283) # ⛔ 绝对不许点 +BTN_MAX = (1019, 413) # »: 取当前能合成的最大数量 +BTN_CONFIRM = (943, 671) # 确认合成 +BTN_CANCEL = (656, 670) # 取消 / 关闭面板 + +MAIN_MENU_MARKERS = ('Window', 'Sinners', 'Drive', 'Theater', 'Extract', 'Dispense') +PANEL_MARKER = 'Charge Enkephalin' + +LOG_DIR = os.path.expanduser(os.path.join('~', 'lc_mcp', 'modules')) +LOG_FILE = os.path.join(LOG_DIR, 'convert.log') +_result = {} + + +def log(msg): + line = '[%s] %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), msg) + print(line, flush=True) + try: + os.makedirs(LOG_DIR, exist_ok=True) + with open(LOG_FILE, 'a', encoding='utf-8') as f: + f.write(line + '\n') + except OSError: + pass + + +# ---------------------------------------------------------------- MCP 服务 + +def server_listening(host='127.0.0.1', port=SERVER_PORT, timeout=1.0): + import socket + s = socket.socket() + s.settimeout(timeout) + try: + s.connect((host, port)) + return True + except OSError: + return False + finally: + s.close() + + +def ensure_server(timeout_s=90): + """确保 lc-mcp 的 TCP 服务在监听, 不在就拉起来。 + + 值守场景下没人手动救它。虽然计划任务 LcMCPServer 配了 RestartCount=3, + 但那只在进程"崩溃"时生效; 服务没起来(或重启后没登录)时, 这边的合成会 + 直接因为连不上而失败。自己拉一把最省事。 + """ + if server_listening(): + return True + log('MCP 服务(%d)未监听, 尝试拉起' % SERVER_PORT) + try: + subprocess.Popen([PYW, '-m', 'lc_mcp.server'], cwd=REPO, close_fds=True) + except OSError as e: + log('拉起服务失败: %s' % e) + return False + t0 = time.time() + while time.time() - t0 < timeout_s: + time.sleep(2) + if server_listening(): + log('服务已就绪 (%.0fs)' % (time.time() - t0)) + return True + log('等服务就绪超时(%ds)' % timeout_s) + return False + + +# ---------------------------------------------------------------- 桌面渲染 + +def _blit_ok(hdc, hwnd=None): + """探测采集 API, 窗口走 AALC 的 PrintWindow(flags=3)。不验证画面内容。""" + if not hdc: + return False + import ctypes + from ctypes import wintypes + import win32gui + import win32ui + + source = target = bitmap = old = bitmap_handle = None + try: + width, height = 64, 64 + if hwnd: + left, top, right, bottom = win32gui.GetClientRect(hwnd) + width, height = right - left, bottom - top + if width <= 0 or height <= 0: + return False + source = win32ui.CreateDCFromHandle(hdc) + target = source.CreateCompatibleDC() + bitmap = win32ui.CreateBitmap() + bitmap.CreateCompatibleBitmap(source, width, height) + bitmap_handle = bitmap.GetHandle() + old = target.SelectObject(bitmap) + if hwnd: + capture = ctypes.windll.user32.PrintWindow + capture.argtypes = [wintypes.HWND, wintypes.HDC, wintypes.UINT] + capture.restype = wintypes.BOOL + return bool(capture(hwnd, target.GetSafeHdc(), 3)) + target.BitBlt((0, 0), (width, height), source, (0, 0), 0x00CC0020) + return True + except Exception: + return False + finally: + try: + if old is not None: + target.SelectObject(old) + finally: + try: + if target is not None: + target.DeleteDC() + finally: + if bitmap_handle is not None: + win32gui.DeleteObject(bitmap_handle) + # source 只包装调用者的 DC, 由调用者 ReleaseDC, 不能 DeleteDC。 + + +def screen_blit_ok(): + import win32gui + hdc = None + try: + hdc = win32gui.GetDC(0) + return _blit_ok(hdc) + except Exception: + return False + finally: + if hdc: + win32gui.ReleaseDC(0, hdc) + + +def window_blit_ok(hwnd): + import win32gui + hdc = None + try: + if win32gui.IsIconic(hwnd): + return False + hdc = win32gui.GetWindowDC(hwnd) + return _blit_ok(hdc, hwnd=hwnd) + except Exception: + return False + finally: + if hdc: + win32gui.ReleaseDC(hwnd, hdc) + + +def render_ok(): + """游戏画面是否可采集。 + + ⛔ 原来只测屏幕 BitBlt(GetDC(0))。2026-10-22 实测它在 RDP 会话下会瞬时失败, + 而 AALC 走的是 background_screenshot(窗口 DC + PrintWindow), 那条路照样能截到图 + —— 结果是我的自检把本来能干活的轮次判成"截不到图"给跳过了(10-17 02:23 就这样 + 白丢过一轮)。 + + 现在优先按 AALC 的方式测**窗口**能否采集, 窗口不在或不可采时才回退到屏幕。 + """ + hwnd = _find_hwnd() + if hwnd and window_blit_ok(hwnd): + return True + return screen_blit_ok() + + +def parse_session_table(text): + """解析 `query session` 的输出。 + + 实测格式(注意: 成功时返回码也是 1, 不能拿返回码判断成败): + SESSIONNAME USERNAME ID STATE TYPE DEVICE + services 0 Disc + >console YWS-HHH 1 Active + 31c5ce94259d4... 65536 Listen + rdp-tcp 65537 Listen + + 行首的 '>' 标出**当前**会话。用户从 RDP 连进来时会变成: + >rdp-tcp#70 YWS-HHH 1 Active + console 3 Conn + 这时物理 console 的画面是空的, BitBlt 采集不到东西。 + """ + current = rdp_active = console = None + for line in text.splitlines(): + raw = line.rstrip() + stripped = raw.strip() + if not stripped or stripped.lower().startswith('sessionname'): + continue + is_current = raw.lstrip().startswith('>') + parts = stripped.lstrip('>').split() + if len(parts) < 3: + continue + name = parts[0] + # ID 列: 从后往前找第一个纯数字, 比按固定列切更耐得住用户名带空格 + sid = None + for tok in parts[1:]: + if tok.isdigit(): + sid = tok + break + state = 'Active' if 'active' in stripped.lower() else ( + 'Disc' if 'disc' in stripped.lower() else '') + if is_current: + current = name + if name.startswith('rdp-tcp#') and state == 'Active': + rdp_active = name + if name == 'console': + console = sid + return {'current': current, 'rdp_active': rdp_active, 'console': console} + + +def session_state(): + """查当前会话归属, 用于把"截不到图"的原因说清楚。 + + 实测两种都会让 BitBlt 失败, 但性质完全不同: + * 会话掉到 Disc -> 看门狗能把它挂回 console, 自愈 + * RDP 会话 Active 占着显示 -> console 画面是空的, 看门狗**不会动**(它只看 Disc) + 不区分的话日志里只会留一句"会话被断开", 排查时会被带偏。 + """ + try: + out = subprocess.run(['query', 'session'], capture_output=True, text=True, + errors='ignore', timeout=20).stdout + except (OSError, subprocess.SubprocessError): + return None + if not isinstance(out, str): + # 拿到的不是文本就别硬解析 —— 这只是诊断信息, 不值得为它炸掉整轮 + return None + st = parse_session_table(out) + return st if any(st.values()) else None + + +def ensure_display(timeout_s=90): + """确认桌面在出图, 不在就先跑看门狗把它挂回来。 + + 为什么这轮必须自己做: RDP 断开时 Windows 会把显示表面拆掉, 截图全黑, + 之后所有模板匹配和 OCR 都是瞎的。看门狗 LcKeepDisplay 每分钟修一次, 但 + 整轮合成只跑 3 分钟左右 —— 断线正好落在这 3 分钟里的话, 这一轮必然失败, + 而下一轮要等 4 小时。实测 2026-10-16 一天内会话掉了两次, 不是小概率。 + """ + if render_ok(): + return True + st = session_state() + if st and st.get('rdp_active'): + # RDP 会话 Active 时 console 画面是空的, 看门狗按设计不会动它(它只处理 Disc)。 + # 硬把它踢到 console 会把正在用的人踢下线, 所以这里只报告, 不擅自动手。 + log('桌面未在出图, 而 RDP 会话 %s 处于 Active(占着显示) —— ' + '看门狗只处理 Disc, 这种情况要人工把 RDP 断开; 本轮跳过' % st['rdp_active']) + return False + log('桌面未在出图(BitBlt 失败), 跑看门狗把显示挂回 console' + + ('(会话状态: %s)' % st if st else '')) + watchdog = os.path.join(HERE, 'keep_display.ps1') + try: + subprocess.run(['powershell.exe', '-NoProfile', '-ExecutionPolicy', 'Bypass', + '-File', watchdog], capture_output=True, text=True, + errors='ignore', timeout=120) + except (OSError, subprocess.SubprocessError) as e: + log('看门狗执行失败: %s' % e) + t0 = time.time() + while time.time() - t0 < timeout_s: + time.sleep(3) + if render_ok(): + log('显示已恢复 (%.0fs)' % (time.time() - t0)) + return True + log('显示仍未恢复, 这轮大概会失败') + return False + + +# ---------------------------------------------------------------- 屏幕判定 + +def screen(): + return screen_text(items()) + + +def on_main_menu(txt): + return sum(1 for m in MAIN_MENU_MARKERS if m in txt) >= 4 + + +def panel_open(txt): + return PANEL_MARKER in txt + + +# ---------------------------------------------------------------- 狂气 + +LABEL_KEY = 'NACY' # 见下: LUNACY 的首字母常被 OCR 吃掉, 只认后半段 + + +def find_lunacy_label(its=None): + """找狂气标签所在的那个 OCR 元素。 + + ⛔ 实测坑(2026-10-16 11:11): OCR 把 "LUNACY" 读成了 **"UNACY"** —— 首字母 L + 被吃掉了。而代码原本写的是 `'LUNACY' in text`, "UNACY" 不含 "LUNACY", + 于是每次都被判成"读不到", 狂气校验直接退化成 None -> 跳过比对, 防线形同虚设。 + (同一块底栏的体力却一直读得到, 所以只看日志很难发现。) + + 改成认后半段 "NACY": LUNACY / UNACY / 甚至 NACY 都能命中, 而这个词根 + 在游戏界面里不会出现在别处。 + """ + if its is None: + its = items() + for it in its: + if LABEL_KEY in it.get('text', '').upper(): + return it + # 再退一步: 底栏那一带最靠左的短文本元素(标签位置很固定) + near = [it for it in its + if 775 < it.get('y', 0) < 815 and it.get('x', 0) < 700 + and (it.get('w') or 0) < 100] + if near: + return sorted(near, key=lambda it: it.get('x', 0))[-1] + return None + + +def read_lunacy(reads=5, pause=1.0): + """读狂气余额, 取多次读数的众数。 + + 两个实测坑: + 1. 标签首字母会被 OCR 吃掉(LUNACY -> UNACY), 所以不能整词匹配, 见 find_lunacy_label。 + 2. 读完所有帧再取唯一众数(至少出现两次), 平票返回 None。标签和数字必须来自 + 同一帧。OCR 的系统性误读仍可能存在, 前后不同不能直接证明消费。 + """ + votes = {} + for i in range(reads): + its = items() + lab = find_lunacy_label(its) + if lab: + best = None + for it in its: + t = it.get('text', '').strip() + if t.isdigit(): + dy = it.get('y', 0) - lab.get('y', 0) + dx = abs(it.get('x', 0) - lab.get('x', 0)) + if 0 < dy < 70 and dx < 130: + best = int(t) + if best is not None: + votes[best] = votes.get(best, 0) + 1 + if i < reads - 1: + time.sleep(pause) + ranked = sorted(votes, key=votes.get, reverse=True) + if ranked and votes[ranked[0]] >= 2: + if len(ranked) == 1 or votes[ranked[0]] > votes[ranked[1]]: + return ranked[0] + return None + + +# 狂气那个数字的 OCR 读法**不稳定**: 同一个真值(6636)实测被读成过 +# 6636 / 9699 / 6388 / 8859 —— 艺术字加抗锯齿, 同一画面连读几次都可能不一样。 +# +# ⛔ 所以最初那套"前后读数不同 = 真的变了"是错的(2026-10-16 22:03 误报过一次: +# 前 6636 后 9699, 复读仍是 9699, 于是报了"狂气读数发生变化" —— 但那一轮脚本 +# 只点了模组图标和面板内的 » / 确认, 根本没碰 Use Lunacy 页签, 没有任何消费)。 +# +# 能站得住的判断只有两种: +# * 前后读数都落在"已知读法"集合里 -> 可能只是换了个误读法 +# * 变化涉及集合以外的读数 -> 需要人工核查 +# 真正的防线是结构性的(只点 Modules 页签, 且 Use Lunacy 坐标被测试盯着), +# 这里只是补一层"数字有没有变成陌生值"的旁证。 +LUNACY_KNOWN_READINGS = (6636, 9699, 6388, 8859) + + +def lunacy_verdict(before, after): + """返回 (是否可疑, 说明)。宁可说"不确定", 也不要把误读当消费。""" + if before is None or after is None: + return False, '读数不完整(%s -> %s), 本次未做比对' % (before, after) + if before == after: + return False, '前后读数一致 %s' % after + if before in LUNACY_KNOWN_READINGS and after in LUNACY_KNOWN_READINGS: + return False, ('前后均为已知读法(%s -> %s), 可能为 OCR 抖动, 不单凭此判定消费' + % (before, after)) + return True, ('读数 %s -> %s, 前后至少一项不在已知读法 %s 里, 需人工核查' + % (before, after, list(LUNACY_KNOWN_READINGS))) + + +def read_owned(retries=3, pause=2.0): + """从合成面板上读 'Owned NN'(当前模组数量)。读不到返回 None。 + + 这个读数是判断"到底换到没有"的依据, 所以第一次没读到要再试几次 —— + 面板刚打开时数字还在刷新, 单次读容易拿到 None。 + """ + for i in range(retries): + v = _read_owned_once() + if v is not None: + return v + if i < retries - 1: + time.sleep(pause) + return None + + +def _read_owned_once(): + import re + its = items() + for it in its: + m = re.search(r'Owned\s*(\d+)', it.get('text', ''), re.I) + if m: + return int(m.group(1)) + # OCR 有可能会把 'Owned 23' 拆开, 退一步找面板里的裸数字 + for it in its: + t = it.get('text', '').strip() + if t.isdigit() and 300 < it.get('y', 0) < 360: + return int(t) + return None + + +ENKEPHALIN_PER_MODULE = 20 + + +def read_enkephalin(): + """读主界面底栏的体力 'x/126'。读不到返回 None。 + + 只认 y>700 的读数 —— 合成面板里也有一个 x/126(那是"合成后"的预览值), + 用高度把它排除掉, 免得把预览当余额。 + """ + import re + for it in items(): + t = it.get('text', '').replace(' ', '') + m = re.search(r'(\d{1,4})/126', t) + if m and it.get('y', 0) > 700: + return int(m.group(1)) + return None + + +# ---------------------------------------------------------------- 游戏进程 + +def game_running(): + out = subprocess.run(['tasklist', '/FI', 'IMAGENAME eq %s.exe' % GAME_PROC], + capture_output=True, text=True, errors='ignore') + return GAME_PROC.lower() in (out.stdout or '').lower() + + +# ---------------------------------------------------------------- 窗口尺寸 + +def _find_hwnd(): + from ctypes import windll + return windll.user32.FindWindowW(None, 'LimbusCompany') + + +def _client_size(hwnd): + from ctypes import windll, wintypes + r = wintypes.RECT() + windll.user32.GetClientRect(hwnd, __import__('ctypes').byref(r)) + return r.right - r.left, r.bottom - r.top + + +def _move_window(hwnd, width, height, cur): + """把窗口调到客户区正好 width x height。""" + from ctypes import windll, wintypes, byref + wr = wintypes.RECT() + windll.user32.GetWindowRect(hwnd, byref(wr)) + # 边框/标题栏占掉的差值 = 窗口尺寸 - 客户区尺寸 + frame_w = (wr.right - wr.left) - cur[0] + frame_h = (wr.bottom - wr.top) - cur[1] + windll.user32.MoveWindow(hwnd, wr.left, wr.top, + width + frame_w, height + frame_h, True) + + +def ensure_window_size(width, height, find=None, client=None, resize=None): + """把游戏客户区调成 width x height, 返回调完后的 (w, h)。 + + 为什么要管这个: RDP 断线重连会把窗口改小(实测 1600x900 -> 1278x719), 之后 + OCR 质量明显下降 —— 连底栏的 LUNACY 标签都读不出来, 狂气校验直接变成 + "读不到, 跳过"。AALC 自己的 WindowGuard 只在跑任务时才生效, 而这个脚本 + 不跑任务, 所以得自己调。 + + find/client/resize 可注入, 便于测试 —— 默认走 ctypes 真实实现。 + """ + find = find or _find_hwnd + client = client or _client_size + resize = resize or _move_window + hwnd = find() + if not hwnd: + return None + cur = client(hwnd) + if cur == (width, height): + return cur # 已经对了就别动它 + resize(hwnd, width, height, cur) + time.sleep(2) + after = client(hwnd) + log('窗口客户区 %sx%s -> %sx%s (目标 %sx%s)' % (cur + after + (width, height))) + return after + + +def launch_game(timeout_s=240, tries=3): + """启动游戏, 分几次尝试。 + + ⛔ 2026-10-17 02:03 实测: 那一轮 exe 起来就退了 —— Steam 的 content_log 里 + 02:0x 毫无记录(上一轮 22:03:43 有 "App Running"), 应用事件日志也没有报错, + 游戏进程始终没出现。而 13 分钟后我手动启动, 5 秒就起来了。 + 时间线上, 01:49 刚发生过一次会话断开重连, Steam 的 webhelper 直到 02:16 才恢复活动。 + + 原来的写法是"点一次火, 干等 240 秒", 碰上一次静默失败就白丢一整轮(这轮体力白攒)。 + 改成多次尝试 —— 中间隔一会儿再来一次, 大多数瞬时故障都能靠这个救回来。 + """ + if game_running(): + log('游戏已在运行') + return True + log('Steam 进程数: %d' % len([p for p in _popen_psutil('steam')])) + each = max(40, timeout_s // max(1, tries)) + for i in range(tries): + log('启动游戏(第 %d/%d 次, 每次等 %ds): %s' % (i + 1, tries, each, GAME_EXE)) + subprocess.Popen([GAME_EXE], close_fds=True) + t0 = time.time() + while time.time() - t0 < each: + time.sleep(5) + if game_running(): + log('游戏进程已出现 (%.0fs)' % (time.time() - t0)) + return True + log(' 这一次没等到游戏进程') + log('游戏启动超时(试了 %d 次)' % tries) + return False + + +def _popen_psutil(name): + """按进程名查进程(只用于日志, 失败返回空)。""" + try: + out = subprocess.run(['tasklist', '/FI', 'IMAGENAME eq %s.exe' % name], + capture_output=True, text=True, errors='ignore').stdout + return [l for l in out.splitlines() if l.lower().startswith(name.lower())] + except OSError: + return [] + + +def close_game(graceful_s=20): + """关游戏。先好好关, 关不掉再强杀。 + + ⛔ 原来是一上来就 taskkill /F。2026-10-17 发现一次可疑的"换到的模块没保留": + 18:10 合成后 31 -> 33 + 22:05 合成前 33, 合成后 33 -> 35 (消耗了 40 点体力) + 06:04 合成前 **33** <- 22:05 那两个模块不见了 + 原因没查明(也可能是人手动用掉了), 但强制结束本来就有丢未保存状态的风险, + 换成优雅关闭成本很低, 顺手把这条路堵上。 + + 步骤: 先只发关闭请求(taskkill 不带 /F), 等它自己退; 超时再强杀。 + """ + if not game_running(): + log('游戏未在运行') + return + subprocess.run(['taskkill', '/IM', '%s.exe' % GAME_PROC], + capture_output=True, text=True, errors='ignore') + t0 = time.time() + while time.time() - t0 < graceful_s: + time.sleep(2) + if not game_running(): + log('游戏已正常关闭 (%.0fs)' % (time.time() - t0)) + return + log(' 优雅关闭没成功, 改用强制结束') + subprocess.run(['taskkill', '/IM', '%s.exe' % GAME_PROC, '/F'], + capture_output=True, text=True, errors='ignore') + time.sleep(3) + log('游戏已关闭' if not game_running() else '游戏仍在运行(关闭失败)') + + +def wait_main_menu(timeout_s=300): + """等游戏进到主界面。中途用 Enter/点击推进标题、剧情、公告。""" + t0 = time.time() + last = '' + while time.time() - t0 < timeout_s: + try: + txt = screen() + except Exception as e: + log(' 读取画面失败(%s), 稍后再试' % type(e).__name__) + time.sleep(8) + continue + if on_main_menu(txt): + log('已进入主界面') + return True + if txt != last: + log(' 等待中: %s' % txt[:90]) + last = txt + if 'DOWNLOADING' in txt.upper(): + time.sleep(10) + continue + # 标题/剧情/公告: 先点一下再按 Enter, 覆盖两种推进方式。 + # ⛔ 位置选屏幕中央而不是下方: 底栏 (800,830) 正好落在 Inventory 按钮里 + # (实测 OCR: Inventory @(759,834) w=91, 跨度 759~850)。上面虽然每轮都先 + # 查过"是不是主界面", 但画面恰在这一瞬切过去的话, 这一下就点在 Inventory + # 上了 —— 后果不重(只是开个背包), 却会让循环卡在一个预期之外的界面上。 + click(800, 450) + time.sleep(1.2) + keypress('enter') + time.sleep(2.0) + log('等待主界面超时') + return False + + +# ---------------------------------------------------------------- 合成 + +def open_panel(tries=4): + """点开合成面板。成功返回 True。 + + 点击后要等 UI 真的出来再截图判定 —— 实测立刻截图会拿到点击前的旧帧, + 于是误判成"点了没反应", 白折腾很多轮。 + """ + for i in range(tries): + txt = screen() + if panel_open(txt): + return True + log(' 点模组图标 %s (第 %d 次)' % (MODULE_ICON, i + 1)) + click(*MODULE_ICON) + time.sleep(3.5) + return panel_open(screen()) + + +# 免费合成页签独有的问句 —— 这句话在别的页签上不会出现 +MODULES_QUESTION = 'assemble Enkephalin Modules' + + +def on_modules_tab(): + """确认停在 Modules(免费合成)页签。 + + ⛔ 实测坑(2026-10-16 18:03): 原来只看"兑换区显示体力条 x/126", 但 OCR 会把相邻 + 几行合并成一个元素(那次 "Enkephalin Module Owned 31" 的框高 38、宽 351, 把下面 + 的 x/126 一起吞了), 于是判定失败 —— 整轮拒绝合成, 一个模块没换到。 + + 现在认面板自己的问句 "Would you like to assemble Enkephalin Modules?": + 它只在免费页签出现, 而且实测单独成行、不会被合并吃掉。 + 体力条那条留着当备用信号(两条任一成立即可)。 + + 判不出来时返回 False, 调用方拒绝合成 —— 宁可漏一轮, 也不在不知道哪个页签上点确认。 + """ + its = items() + flat = ' '.join(it.get('text', '') for it in its).replace(' ', '') + if MODULES_QUESTION.replace(' ', '') in flat: + return True + for it in its: + if 470 < it.get('y', 0) < 560 and '/126' in it.get('text', '').replace(' ', ''): + return True + return False + + +def convert_once(tries=2): + """打开面板 -> 取最大 -> 合成。返回 (ok, 说明, 合成数量)。 + + 为什么默认重试一次: "点了确认但模组没变"有两种完全不同的原因 —— + 1. 游戏限制了本轮/本日能换的数量(正常) + 2. 界面这一次没响应(偶发, 重开面板通常就好了) + 只做一次的话分不清这两者, 而它们该有不同的处置。重试第二次仍然不变, + 就按"换不了"如实报告。 + """ + last = '未尝试' + for attempt in range(tries): + if attempt: + log(' 第一次没换到, 关掉面板重开再试一次') + close_panel() + time.sleep(3) + ok, info, got = _convert_attempt() + if ok: + return ok, info, got + last = info + return False, last, 0 + + +def _convert_attempt(): + """一次合成尝试。返回 (ok, 说明, 合成数量)。""" + if not open_panel(): + return False, '打不开合成面板', 0 + + # 显式回到 Modules 页签。即使上一轮停在别处, 这一步也把它拨回来。 + click(*TAB_MODULES) + time.sleep(2.0) + if not on_modules_tab(): + return False, '确认不在 Modules(免费合成)页签, 为安全起见不合成', 0 + + before = read_owned() + log(' 合成前模组: %s' % before) + if before is None: + # 读不到起点就无从判断有没有换到。这里**不能报成功** —— 那是假装验证过, + # 和"狂气读不到就静默跳过"是同一类毛病。宁可不合成, 下一轮再来。 + return False, '读不到合成前的模组数, 无法确认结果, 本轮不合成', 0 + + click(*BTN_MAX) + time.sleep(2.5) + click(*BTN_CONFIRM) + + # 面板会自己刷新 Owned。等它变大, 最多等 20 秒。 + t0 = time.time() + while time.time() - t0 < 20: + time.sleep(2.5) + now = read_owned() + if now is not None and now > before: + return True, '模组 %d -> %d (+%d)' % (before, now, now - before), now - before + + after = read_owned() + if after is None: + return False, '合成后读不到模组数, 无法确认结果(合成前为 %d)' % before, 0 + if after < before: + return False, '模组读数下降(%d -> %d), 无法确认合成结果' % (before, after), 0 + if after == before: + # 走到这里时调用方已经确认体力 >= 20, 所以"体力不足"不是可能的原因, + # 写进去只会把排查方向带偏。真实原因只有这两种。 + return False, ('点了确认但模组没变(%s): 可能已达兑换上限, 或界面没响应' + % after), 0 + return True, '模组 %d -> %d (+%d)' % (before, after, after - before), after - before + + +def close_panel(): + for _ in range(4): + if not panel_open(screen()): + return True + click(*BTN_CANCEL) + time.sleep(2.0) + return not panel_open(screen()) + + +# ---------------------------------------------------------------- 主流程 + +def main(argv=None): + ap = argparse.ArgumentParser(description='启动游戏 -> 体力合成模块 -> 关掉游戏') + ap.add_argument('--keep-game', action='store_true', help='合成完不关游戏(调试用)') + ap.add_argument('--start-timeout', type=int, default=300, help='等主界面的秒数') + ap.add_argument('--report-dir', default=LOG_DIR) + args = ap.parse_args(argv) + + t_start = time.time() + _result.clear() + _result.update({'started': time.strftime('%Y-%m-%d %H:%M:%S'), 'steps': []}) + + def done(code, why): + _result['ok'] = code == 0 + _result['result'] = why + _result['elapsed_s'] = int(time.time() - t_start) + os.makedirs(args.report_dir, exist_ok=True) + p = os.path.join(args.report_dir, 'convert_%s.json' % time.strftime('%Y%m%d_%H%M%S')) + with open(p, 'w', encoding='utf-8') as f: + json.dump(_result, f, ensure_ascii=False, indent=2) + log('=== %s (%s), 耗时 %ds ===' % (why, 'OK' if code == 0 else 'FAIL', + int(time.time() - t_start))) + return code + + log('=== 开始: 体力换模块 ===') + + if not ensure_server(): + return done(1, 'MCP 服务连不上, 也没能拉起来') + # 断线会让截图全黑, 那之后什么都做不了 —— 先确认桌面在出图再动游戏 + if not ensure_display(): + return done(1, '桌面不在出图(会话被断开), 本轮跳过') + if not launch_game(): + return done(1, '游戏启动失败') + if not wait_main_menu(args.start_timeout): + if not args.keep_game: + close_game() + return done(1, '等不到主界面') + + # 窗口被 RDP 改小过的话先调回去, 否则底栏 OCR 会读不出来 + got_size = ensure_window_size(1600, 900) + if got_size != (1600, 900): + log('[warn] 客户区没能调到 1600x900(现为 %s), OCR 可能不稳定' % (got_size,)) + + time.sleep(3) + # 刚进主界面时底栏还在淡入, 单次读常常是 None(实测 11:01 那次), 那样 + # 合成前后的相对比对就白做了。这里也重试几次。 + lunacy_before = None + for _ in range(4): + lunacy_before = read_lunacy() + if lunacy_before is not None: + break + time.sleep(3) + log('合成前狂气(OCR, 作相对比对用): %s' % lunacy_before) + # 读到就记进报告 —— 后面可能因为体力不足提前收工, 那时这条读数不该丢。 + _result['lunacy_before'] = lunacy_before + _result['converted'] = False + + # 体力读数也要重试。单次读成 None 的话, 下面"体力不足就收工"这层判断会被 + # 整个跳过, 于是明明只是体力不够, 却要去点合成、最后报成 FAIL(退出码 1) —— + # 给值守留下一条误导性的失败记录。 + enk = None + for _ in range(4): + enk = read_enkephalin() + if enk is not None: + break + time.sleep(3) + log('当前体力: %s/126 (合成 1 个模块需要 %d)' % (enk, ENKEPHALIN_PER_MODULE)) + if enk is None: + log('[warn] 体力读数没拿到, 这轮按"不确定"处理, 不主动点合成') + close_panel() + if not args.keep_game: + close_game() + return done(0, '读不到体力读数, 本轮跳过(下一轮再试)') + if enk < ENKEPHALIN_PER_MODULE: + # 体力不够换一个模块 —— 这是正常情况(挂机等恢复), 不是失败。 + # 直接收工, 免得每轮都在计划任务里报错。 + close_panel() + if not args.keep_game: + close_game() + return done(0, '体力不足(%s<%d), 本轮无需合成' % (enk, ENKEPHALIN_PER_MODULE)) + + ok, info, got = convert_once() + _result['steps'].append({'step': '合成', 'ok': ok, 'info': info}) + _result['converted'] = bool(got) + log('合成: %s (%s)' % ('OK' if ok else 'FAIL', info)) + + time.sleep(2) + close_panel() + # 关面板后画面要缓一下才稳定, 立刻读会得到 None(实测), 那样相对比对就白做了 + lunacy_after = None + for _ in range(4): + time.sleep(3) + lunacy_after = read_lunacy() + if lunacy_after is not None: + break + log('合成后狂气(OCR): %s' % lunacy_after) + + # ⛔ 先记进报告再判 —— 22:03 那次是在判断之后才记, 结果告警分支提前 return, + # 报告里 lunacy_after 留了个 None, 事后想复核这次读数都无从下手。 + # (和第 10 轮修过的"提前收工导致读数丢失"是同一个毛病, 这次犯在告警分支上。) + _result['lunacy_before'] = lunacy_before + _result['lunacy_after'] = lunacy_after + _result['lunacy_checked'] = (lunacy_before is not None and lunacy_after is not None) + + # ⛔ 这里原来是"前后读数不同就报违规", 已证明是错的(2026-10-16 22:03 误报): + # 同一个真值 6636 的 OCR 读法本身就不固定(6636/9699/6388/8859 都出现过), + # 所以"不同"完全可能只是换了个误读法。判据换成 lunacy_verdict(): + # 只有读到**从没见过的值**才算可疑, 已知读法之间的抖动不算。 + suspicious, why = lunacy_verdict(lunacy_before, lunacy_after) + if suspicious: + log(' [warn] %s' % why) + if not args.keep_game: + close_game() + return done(1, '⚠️ %s' % why) + log('狂气校验: %s' % why) + if not args.keep_game: + close_game() + + if not ok: + return done(1, '合成未成功: %s' % info) + if got == 0: + return done(0, '本轮无需合成(体力不足或已达上限): %s' % info) + return done(0, '合成完成: %s' % info) + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/farm_status.py b/scripts/farm_status.py new file mode 100644 index 0000000..2d02223 --- /dev/null +++ b/scripts/farm_status.py @@ -0,0 +1,147 @@ +# -*- coding: utf-8 -*- +"""汇总 ~/lc_mcp/cycles 下的轮次报告, 用于持续运行时的定期上报。 + +用法: + python scripts/farm_status.py # 全部轮次 + python scripts/farm_status.py --last 10 # 只看最近 10 轮 + python scripts/farm_status.py --json # 机器可读 + +读的是 auto_cycle.py 写的 cycle_*.json, 不碰游戏, 可在任何时候运行。 +""" +import argparse +import glob +import json +import os +import re +import sys +import time + +DEFAULT_DIR = os.path.expanduser(os.path.join('~', 'lc_mcp', 'cycles')) +RUNS_DIR = os.path.expanduser(os.path.join('~', 'lc_mcp', 'runs')) +BASELINE = os.path.expanduser(os.path.join('~', 'lc_mcp', 'lunacy_baseline.txt')) + + +def load_reports(report_dir): + out = [] + for p in sorted(glob.glob(os.path.join(report_dir, 'cycle_*.json'))): + try: + with open(p, encoding='utf-8') as f: + r = json.load(f) + except (OSError, ValueError): + continue + r['_path'] = p + r['_mtime'] = os.path.getmtime(p) + out.append(r) + return sorted(out, key=lambda r: r.get('started') or '', reverse=True) + + +def step_of(report, name): + for s in report.get('steps', []): + if s.get('step') == name: + return s + return None + + +def task_stats_for(report): + """从 cycle 的 log 找同期的 daily 任务日志, 统计选队/卡死/错误。 + + cycle_*.log 里有 "daily 已启动" 的时间, 但精确对上 task 日志更麻烦; + 这里按 cycle 结束时间往前找最近一份 daily 日志。 + """ + if not os.path.isdir(RUNS_DIR): + return None + logs = [p for p in glob.glob(os.path.join(RUNS_DIR, 'task_*_daily.log'))] + logs = [p for p in logs if os.path.getmtime(p) <= report.get('_mtime', time.time()) + 60] + if not logs: + return None + p = max(logs, key=os.path.getmtime) + try: + with open(p, encoding='utf-8', errors='replace') as f: + txt = f.read() + except OSError: + return None + txt = re.sub(r'\x1b\[[0-9;]*m', '', txt) + return { + 'log': os.path.basename(p), + 'team_ok': len(re.findall(r'成功找到队伍', txt)), + 'team_fail': len(re.findall(r'找不到队伍', txt)), + 'exp': len(re.findall(r'结束执行 一次经验本', txt)), + 'thread': len(re.findall(r'结束执行 一次纽本', txt)), + 'empty_team_stall': len(re.findall(r'配队人数OCR得到:\D*0\s*/\s*5', txt)), + 'errors': len(re.findall(r'\[ERROR\]', txt)), + } + + +def fmt_mins(sec): + if not sec: + return '-' + return '%d:%02d' % (sec // 60, sec % 60) + + +def summarize(reports): + rows = [] + for r in reports: + lum = [s for s in r.get('steps', []) if '狂气' in s.get('step', '')] + lum_info = lum[-1]['info'] if lum else '-' + failed = [s['step'] for s in r.get('steps', []) if not s.get('ok')] + rows.append({ + 'started': (r.get('started') or '')[:16], + 'ok': r.get('ok'), + 'result': r.get('result'), + 'elapsed_s': r.get('elapsed_s'), + 'failed_steps': failed, + 'lunacy': lum_info, + 'tasks': task_stats_for(r), + }) + return rows + + +def main(argv=None): + ap = argparse.ArgumentParser(description='汇总持续刷取进度') + ap.add_argument('--report-dir', default=DEFAULT_DIR) + ap.add_argument('--last', type=int, default=0, help='只看最近 N 轮, 0=全部') + ap.add_argument('--json', action='store_true') + args = ap.parse_args(argv) + + reports = load_reports(args.report_dir) + if args.last: + reports = reports[:args.last] + rows = summarize(reports) + + base = None + if os.path.exists(BASELINE): + try: + base = int(open(BASELINE, encoding='utf-8').read().strip()) + except ValueError: + base = None + + if args.json: + print(json.dumps({'rows': rows, 'lunacy_baseline': base}, ensure_ascii=False, indent=2)) + return 0 + + if not rows: + print('还没有轮次报告 (%s)' % args.report_dir) + return 1 + + print('狂气基线: %s' % ('%d' % base if base is not None else '(无)')) + print() + print('%-17s %-5s %-7s %-30s %s' % ('开始', 'OK', '耗时', '失败步骤', '任务日志(选队/经验/纽本/卡死/错误)')) + print('-' * 104) + for r in rows: + t = r['tasks'] + tinfo = ('%s %d/%d/%d/%d/%d' % (t['log'][-24:], t['team_ok'], t['exp'], t['thread'], + t['empty_team_stall'], t['errors'])) if t else '-' + print('%-17s %-5s %-7s %-30s %s' % ( + r['started'], '✅' if r['ok'] else '❌', fmt_mins(r['elapsed_s']), + ','.join(r['failed_steps']) or '-', tinfo)) + print() + tot = len(rows) + good = sum(1 for r in rows if r['ok']) + print('共 %d 轮, 成功 %d, 失败 %d' % (tot, good, tot - good)) + if base is not None: + print('狂气基线 %d —— 只增不减才算没消费' % base) + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/scripts/install_convert_task.ps1 b/scripts/install_convert_task.ps1 new file mode 100644 index 0000000..b2e4a73 --- /dev/null +++ b/scripts/install_convert_task.ps1 @@ -0,0 +1,62 @@ +# 注册"到点启动游戏 -> 合成模块 -> 关掉游戏"的计划任务。 +# +# 用法: +# powershell -ExecutionPolicy Bypass -File scripts\install_convert_task.ps1 +# powershell -ExecutionPolicy Bypass -File scripts\install_convert_task.ps1 -EveryHours 6 +# powershell -ExecutionPolicy Bypass -File scripts\install_convert_task.ps1 -Uninstall +# +# 默认每 4 小时检查一次; 是否合成以本轮实际体力读数为准, 不按固定恢复速率推算。 +# 合成 1 个模块需要 20 点体力。 +# +# 这个任务和 LcMCPDailyCycle 是分开的: 用户明确要求这次不打任何关卡, +# 只挂机攒模块, 所以不能把刷取任务一起打开。 +param( + [double]$EveryHours = 4, + [string]$Python = "", + [switch]$Uninstall +) +$ErrorActionPreference = "Stop" +$Repo = Split-Path -Parent $PSScriptRoot +$TaskName = "LcMCPConvertModules" + +if ($Uninstall) { + Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue + Write-Output "uninstalled $TaskName" + exit 0 +} + +if (-not $Python) { + $Python = Join-Path $Repo "vendor\aalc\.venv\Scripts\pythonw.exe" +} +if (-not (Test-Path $Python)) { + throw "找不到 python: $Python" +} +$script = Join-Path $PSScriptRoot "convert_modules.py" +if (-not (Test-Path $script)) { + throw "找不到脚本: $script" +} + +# 以当前用户的交互会话运行, 必须保持登录; 注销后没有可供截图/点击的游戏桌面。 +$principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\$env:USERNAME" ` + -LogonType Interactive -RunLevel Limited + +$action = New-ScheduledTaskAction -Execute $Python -WorkingDirectory $Repo ` + -Argument "-X utf8 `"$script`"" + +# 一次跑 5 分钟足够: 启动游戏 + 进主界面 + 合成 + 关掉。给宽一点防止启动慢。 +$limit = New-TimeSpan -Minutes 15 + +# -Once + 长周期重复, 这样才能设成"每 N 小时" +$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(2) ` + -RepetitionInterval (New-TimeSpan -Minutes ($EveryHours * 60)) ` + -RepetitionDuration (New-TimeSpan -Days 3650) + +$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries ` + -StartWhenAvailable -ExecutionTimeLimit $limit -MultipleInstances IgnoreNew + +Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger ` + -Principal $principal -Settings $settings -Force | Out-Null + +Write-Output "registered $TaskName (every $EveryHours h, limit=$limit)" +Write-Output "reports -> $env:USERPROFILE\lc_mcp\modules\convert_*.json" +Write-Output "log -> $env:USERPROFILE\lc_mcp\modules\convert.log" diff --git a/scripts/install_logon_task.ps1 b/scripts/install_logon_task.ps1 index 2749fff..3ac41e7 100644 --- a/scripts/install_logon_task.ps1 +++ b/scripts/install_logon_task.ps1 @@ -1,4 +1,4 @@ -# 注册登录时启动的 lc-mcp 常驻服务 (交互会话, 能看到游戏窗口)。 +# 注册登录时启动的 lc-mcp 常驻服务 (交互会话, 能看到游戏窗口)。 # 用法 (在要跑游戏的那个账号下, 普通 PowerShell 即可): # powershell -ExecutionPolicy Bypass -File scripts\install_logon_task.ps1 # 可选: -Python 默认用 vendor\aalc\.venv (uv sync 生成) diff --git a/scripts/install_unattended.ps1 b/scripts/install_unattended.ps1 new file mode 100644 index 0000000..9076d5e --- /dev/null +++ b/scripts/install_unattended.ps1 @@ -0,0 +1,92 @@ +# 注册无人值守用的两个计划任务 (在跑游戏的那个账号下, 普通 PowerShell 即可): +# LcMCPKeepDisplay 每 1 分钟跑 keep_display.ps1: 会话掉到 Disc 时重挂 console, 防止截图全黑 +# LcMCPDailyCycle 定时跑 auto_cycle.py: 刷材料 -> 镜牢 -> 升级/同步, 报告写到 ~\lc_mcp\cycles +# +# 用法: +# powershell -ExecutionPolicy Bypass -File scripts\install_unattended.ps1 +# 可选: -At 05:30 每日运行时间。游戏每日重置为 06:00 (KST), 即北京时间 05:00 +# -EveryHours 2.5 改成"每 N 小时重复一轮"以持续刷取; 0 = 只按 -At 每天一次 +# 任务时限包含 daily 45 分钟、每局镜牢 100 分钟、各一次重试及 30 分钟收尾 +# -Mirror 1 每轮镜牢局数, 0 = 不打镜牢 +# -Target 34 把队内人格升到的等级 +# -Python <路径> 默认 vendor\aalc\.venv\Scripts\pythonw.exe (无窗口, 不抢游戏焦点) +# -NoWatchdog 只装每日任务 +# -Uninstall +# +# 前提: LcMCPServer 已用 install_logon_task.ps1 装好并在运行。 +# 先手动跑一轮确认无误再装: python scripts\auto_cycle.py --mirror 1 +param( + [string]$At = "05:30", + [double]$EveryHours = 0, + [int]$Mirror = 1, + [int]$Target = 34, + [string]$Python = "", + [switch]$NoWatchdog, + [switch]$Uninstall +) +$ErrorActionPreference = "Stop" +$Repo = Split-Path -Parent $PSScriptRoot +$Watchdog = "LcMCPKeepDisplay" +$Daily = "LcMCPDailyCycle" + +if ($Uninstall) { + foreach ($name in @($Watchdog, $Daily)) { + Unregister-ScheduledTask -TaskName $name -Confirm:$false -ErrorAction SilentlyContinue + Write-Output "removed $name" + } + exit 0 +} + +if (-not $Python) { $Python = Join-Path $Repo "vendor\aalc\.venv\Scripts\pythonw.exe" } +if (-not (Test-Path $Python)) { + throw "找不到 Python: $Python`n先在 vendor\aalc 里执行 uv sync, 或用 -Python 指定" +} +if (-not (Get-ScheduledTask -TaskName "LcMCPServer" -ErrorAction SilentlyContinue)) { + Write-Warning "没有找到 LcMCPServer 计划任务, 每日任务需要它: 先运行 scripts\install_logon_task.ps1" +} + +$user = "$env:USERDOMAIN\$env:USERNAME" +# Limited: keep_display.ps1 自己用 RunAs 静默提权跑 tscon (需要 ConsentPromptBehaviorAdmin=0) +$principal = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited + +if (-not $NoWatchdog) { + $ps = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" + $script = Join-Path $PSScriptRoot "keep_display.ps1" + $action = New-ScheduledTaskAction -Execute $ps -WorkingDirectory $Repo ` + -Argument "-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$script`"" + $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) ` + -RepetitionInterval (New-TimeSpan -Minutes 1) -RepetitionDuration (New-TimeSpan -Days 3650) + $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries ` + -ExecutionTimeLimit (New-TimeSpan -Minutes 3) -MultipleInstances IgnoreNew + Register-ScheduledTask -TaskName $Watchdog -Action $action -Trigger $trigger -Principal $principal ` + -Settings $settings -Force | Out-Null + Write-Output "registered $Watchdog (every 1 min) -> $script" +} + +$cycle = Join-Path $PSScriptRoot "auto_cycle.py" +$action = New-ScheduledTaskAction -Execute $Python -WorkingDirectory $Repo ` + -Argument "-X utf8 `"$cycle`" --mirror $Mirror --target $Target" +# 与 auto_cycle.py 的 DAILY_TIMEOUT_S / MIRROR_TIMEOUT_S / STALL_RETRIES 对齐。 +# 每个任务最多两次尝试, 另留 30 分钟给启动、轮询和升级; 避免外层先杀掉报告进程。 +$limit = New-TimeSpan -Minutes (30 + 2 * (45 + 100 * [Math]::Max($Mirror, 0))) +if ($EveryHours -gt 0) { + # 持续刷取: 每 N 小时重复一轮。开始时间取"现在", 装完即进入节奏。 + # 注意 New-TimeSpan -Hours 的参数是 [int], 传 2.5 会被截断成 2 小时, 所以用 -Minutes。 + $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) ` + -RepetitionInterval (New-TimeSpan -Minutes ($EveryHours * 60)) ` + -RepetitionDuration (New-TimeSpan -Days 3650) + $desc = "every $EveryHours h" + # 重复周期必须大于单轮上限, 否则会在上一轮还没结束时又起一轮 + if (($EveryHours * 60) -lt $limit.TotalMinutes) { + Write-Warning "EveryHours=$EveryHours ($($EveryHours * 60) 分钟) 短于单轮上限 $limit, 可能重叠; MultipleInstances=IgnoreNew 会跳过, 但建议调大" + } +} else { + $trigger = New-ScheduledTaskTrigger -Daily -At $At + $desc = "daily at $At" +} +$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries ` + -StartWhenAvailable -ExecutionTimeLimit $limit -MultipleInstances IgnoreNew +Register-ScheduledTask -TaskName $Daily -Action $action -Trigger $trigger -Principal $principal ` + -Settings $settings -Force | Out-Null +Write-Output "registered $Daily ($desc, mirror=$Mirror, target=Lv.$Target, limit=$limit)" +Write-Output "reports -> $env:USERPROFILE\lc_mcp\cycles\cycle_*.json" diff --git a/scripts/keep_display.ps1 b/scripts/keep_display.ps1 new file mode 100644 index 0000000..3503a89 --- /dev/null +++ b/scripts/keep_display.ps1 @@ -0,0 +1,98 @@ +# 看门狗: 会话掉回 "Disc" 时重新挂到物理控制台, 恢复桌面渲染。 +# +# 背景: DSH / lc-mcp 常驻服务跑在会话 2。RDP 断开后 Windows 会拆掉该会话的 +# 显示表面, 截图变全黑, AALC 直接失明。把会话挂到 console 后即使无人连接 +# 也持续渲染。 +# +# 只在会话状态为 Disc(无人连接) 时动作; 用户正通过 RDP/ToDesk 连着 +# (Active/Conn) 时绝不插手, 否则会把用户挤下线。 +# +# tscon 需要 SeTcbPrivilege, 普通令牌拿不到, 所以用 -Verb RunAs 提权。 +# 本机 ConsentPromptBehaviorAdmin=0(从不通知), 提权静默通过, 不会弹框。 +# +# 会话号默认取游戏进程所在会话, 找不到游戏时取本脚本所在会话(计划任务以 +# 登录用户身份运行, 与桌面同一会话)。重启或重新登录后会话号会变, 不要写死。 + +param( + [int]$SessionId = -1, + [string]$Python = "", + [string]$LogPath = "$env:USERPROFILE\lc_mcp\keep_display.log", + [switch]$Verbose, + [switch]$ForceDisc +) + +function Write-Log([string]$msg) { + $dir = Split-Path -Parent $LogPath + if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null } + Add-Content -Path $LogPath -Value ("[{0}] {1}" -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $msg) -Encoding UTF8 + $all = @(Get-Content $LogPath -ErrorAction SilentlyContinue) + if ($all.Count -gt 400) { $all | Select-Object -Last 400 | Set-Content $LogPath -Encoding UTF8 } +} + +# 会话状态: 用 WTS API (qwinsta 在计划任务上下文里拿不到输出) +$py = if ($Python) { $Python } else { Join-Path $PSScriptRoot '..\vendor\aalc\.venv\Scripts\python.exe' } +if ($SessionId -lt 0) { + $game = Get-Process -Name LimbusCompany -ErrorAction SilentlyContinue | Select-Object -First 1 + $SessionId = if ($game) { $game.SessionId } else { (Get-Process -Id $PID).SessionId } +} +$statePy = Join-Path $PSScriptRoot 'session_state.py' +if (-not (Test-Path $py) -or -not (Test-Path $statePy)) { + Write-Log "missing python ($py) or session_state.py ($statePy); abort" + exit 1 +} +$state = (& $py -X utf8 $statePy $SessionId 2>&1 | Out-String).Trim() +if ($state -notin @('Active', 'Connected', 'Disc', 'Idle')) { + Write-Log "session $SessionId state unreadable ('$state'); abort" + exit 1 +} + +if ($ForceDisc) { + Write-Log "ForceDisc: skipping state check (real state was '$state')" + $state = 'Disc' +} elseif ($state -ne 'Disc') { + if ($Verbose) { Write-Log "session $SessionId is $state; nothing to do" } + exit 0 +} + +Write-Log "session $SessionId is Disc -> re-attaching to console via elevated tscon" +$out = Join-Path (Split-Path -Parent $LogPath) 'tscon_last.txt' +Remove-Item $out -ErrorAction SilentlyContinue +# 之前的版本把命令拼成 -Command 字符串交给 Start-Process, 10-05 的 41 次失败 +# 全部只留下 "(no output file)", 连 tscon 有没有跑都看不出(多半是引号在 +# 命令行拼接时被吃掉, 重定向没生效)。改用 -EncodedCommand 原样传递, +# 并用 -PassThru 拿提权进程的退出码(= tscon 的退出码)。 +# 32 位宿主里 System32 会被重定向到 SysWOW64, 那里没有 tscon.exe, 用 Sysnative 绕过。 +$sysDir = if (Test-Path "$env:SystemRoot\Sysnative") { "$env:SystemRoot\Sysnative" } else { "$env:SystemRoot\System32" } +$inner = "& '$sysDir\tscon.exe' $SessionId /dest:console *> '$out'; exit `$LASTEXITCODE" +$encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($inner)) +try { + $proc = Start-Process -FilePath "$sysDir\WindowsPowerShell\v1.0\powershell.exe" ` + -ArgumentList @('-NoProfile', '-NonInteractive', '-EncodedCommand', $encoded) ` + -Verb RunAs -WindowStyle Hidden -Wait -PassThru -ErrorAction Stop +} catch { + Write-Log "elevated tscon launch FAILED: $($_.Exception.Message)" + exit 1 +} +Start-Sleep -Seconds 2 +# Get-Content -Raw 一般返回单个字符串, 但文件为空或 $out 被当成通配时可能返回数组, +# 那时 .Trim() 会报 "does not contain a method named 'Trim'"。先拼接成字符串再用。 +$tsconOut = '' +if (Test-Path $out) { + $raw = @(Get-Content $out -ErrorAction SilentlyContinue) -join ' ' + $tsconOut = ($raw -replace '\s+', ' ').Trim() +} +if (-not $tsconOut) { $tsconOut = '(no output)' } +$after = (& $py -X utf8 $statePy $SessionId 2>&1 | Out-String).Trim() +Write-Log "tscon exit=$($proc.ExitCode) said: $tsconOut | session $SessionId now: $after" + +# 渲染自检: BitBlt 屏幕 DC 成功 = 桌面在出图 +$renderPy = Join-Path $PSScriptRoot 'render_check.py' +if (Test-Path $renderPy) { + $rc = (& $py -X utf8 $renderPy 2>&1 | Out-String).Trim() + Write-Log "render check: $rc" +} + +if ($after -ne 'Active' -and $after -ne 'Connected') { + Write-Log "WARN: session $SessionId still '$after' after tscon" + exit 1 +} diff --git a/scripts/lc_ui.py b/scripts/lc_ui.py new file mode 100644 index 0000000..12d0fff --- /dev/null +++ b/scripts/lc_ui.py @@ -0,0 +1,137 @@ +# -*- coding: utf-8 -*- +"""levelup.py / auto_cycle.py 共用的 MCP 调用与坐标换算。 + +脚本里的坐标都是在 1600x900 客户区上实测的。实际客户区随 set_win_size +和桌面分辨率变化(720/900/1080 都出现过), 所以: + - get_state 返回的 OCR 坐标先换算到 1600x900 再交给脚本逻辑; + - click/drag 的坐标从 1600x900 换算回当前客户区再发出。 +脚本内部因此只需要面对一套坐标。 +""" +import json +import os +import subprocess +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) + + +def _console_python(exe): + """计划任务用 pythonw 启动(不弹窗、不抢游戏焦点), 但子进程要读 stdout, 换成同目录的 python。""" + head, name = os.path.split(exe) + if name.lower() == 'pythonw.exe' and os.path.exists(os.path.join(head, 'python.exe')): + return os.path.join(head, 'python.exe') + return exe + + +# 默认用运行本脚本的解释器(AALC 的 venv); 需要时用 LC_PY 指定 +PY = os.environ.get('LC_PY') or _console_python(sys.executable) +PROBE = os.path.join(HERE, 'mcp_probe.py') +# Windows 上不给子进程弹控制台窗口(从 pythonw 启动时每次调用都会闪一下) +NO_WINDOW = {'creationflags': 0x08000000} if os.name == 'nt' else {} + +BASE_W, BASE_H = 1600, 900 +_scale = None + + +def run(cmd, *, check=False): + r = subprocess.run(cmd, capture_output=True, text=True, + encoding='utf-8', errors='replace', check=check, **NO_WINDOW) + return (r.stdout or '') + (r.stderr or '') + + +def probe(tool, args=None, quiet=True): + cmd = [PY, '-X', 'utf8', PROBE, tool] + if args is not None: + cmd.append(json.dumps(args, ensure_ascii=False)) + out = run(cmd).strip() + for line in reversed(out.splitlines()): + line = line.strip() + if line.startswith('{'): + try: + return json.loads(line) + except json.JSONDecodeError: + continue + if not quiet: + print('[warn] probe %s 无 JSON 输出: %r' % (tool, out[:200])) + return {} + + +def state(): + """get_state, 并把 OCR 坐标换算到 1600x900。""" + global _scale + r = probe('get_state', quiet=False) + screen = r.get('screen') or {} + if screen.get('w') and screen.get('h'): + if abs(screen['w'] / screen['h'] - BASE_W / BASE_H) > 0.02: + print('[warn] 客户区 %sx%s 不是 16:9, 坐标会偏' % (screen['w'], screen['h'])) + _scale = screen['w'] / BASE_W + s = _scale or 1.0 + for it in r.get('items', []): + for k in ('x', 'y', 'w', 'h'): + if k in it: + it[k] = round(it[k] / s) + return r + + +def items(): + return state().get('items', []) + + +def screen_text(its): + return ' | '.join(i.get('text', '') for i in its) + + +def _to_client(x, y): + if _scale is None: + state() + s = _scale or 1.0 + return int(round(x * s)), int(round(y * s)) + + +def click(x, y, times=1): + cx, cy = _to_client(x, y) + return probe('click', {'x': cx, 'y': cy, 'times': times}) + + +def find_text(needle, contains=True): + """按文本找画面元素; 返回元素本身(含 x/y/w/h)或 None。 + + 默认子串匹配、忽略大小写。OCR 结果里 w/h 可能缺失, 调用方要能容忍。 + """ + needle = needle.lower() + for it in items(): + t = it.get('text', '').lower() + if (needle in t) if contains else (needle == t): + return it + return None + + +def click_text(needle, contains=True): + """按文本点击元素, 点的是识别框的**中心**。 + + 实测坑: 直接点 OCR 返回的 (x, y) 是文本框左上角, 按下去常常落空 + (2026-10-13 Uptie 弹窗的 Cancel: 文本在 (346,660), 实际可点区域中心在 + (380,675), 点前者毫无反应, 弹窗一直卡着挡住后续所有输入)。 + """ + it = find_text(needle, contains=contains) + if not it: + return False + w = it.get('w') or 0 + h = it.get('h') or 0 + click(it['x'] + w / 2.0, it['y'] + h / 2.0) + return True + + +def drag(from_x, from_y, to_x, to_y): + fx, fy = _to_client(from_x, from_y) + tx, ty = _to_client(to_x, to_y) + return probe('drag', {'from_x': fx, 'from_y': fy, 'to_x': tx, 'to_y': ty}) + + +def long_press(x, y): + """drag 起点==终点 即长按(实测可打开人格详情)。""" + return drag(x, y, x, y) + + +def keypress(key): + return probe('keypress', {'key': key}) diff --git a/scripts/levelup.py b/scripts/levelup.py new file mode 100644 index 0000000..77f554d --- /dev/null +++ b/scripts/levelup.py @@ -0,0 +1,508 @@ +# -*- coding: utf-8 -*- +"""人格升级/同步自动化。 + +流程(全部基于实测坐标,1600x900 客户区): + 罪人界面 IDENTITIES 网格 + -> 长按卡片(drag 起终点相同) 打开人格详情 + -> 点 Level Up + -> 对每种训练券点 »(全部投入) + -> Confirm + -> 关窗 + -> (可选) 点 Uptie -> Uptie -> Confirm -> 关窗 + -> 返回网格 + +用法: + python levelup.py list 列出网格里队内(SELECTED)人格及等级 + python levelup.py weakest [--uptie] 对队内等级最低者执行升级(可选同步) + python levelup.py card [--uptie] + python levelup.py back 返回网格 + +退出码: 0 成功 / 1 失败 +""" +import sys +import time + +from lc_ui import click, click_text, keypress, long_press, screen_text, state + +# 网格布局(1600x900 坐标, 由 lc_ui 换算到实际客户区)。 +# 第 4 行在 y=942, 超出客户区, 需要滚动才能看到, 这里不处理。 +COLS = [335, 508, 681, 853, 1026, 1198] +ROWS = [260, 487, 715] + +# 固定控件坐标 +BACK = (85, 75) +BTN_LEVEL_UP = (1164, 235) +BTN_UPTIE = (1367, 235) +TICKET_MAX_X = 1133 +TICKET_ROWS = [383, 490, 598] # IV / III / II +POWERUP_CONFIRM = (1030, 670) +POWERUP_CANCEL = (603, 670) +UPTIE_CONFIRM = (1085, 580) +UPTIE_DONE_CONFIRM = (772, 661) +UPTIE_CANCEL = (526, 660) + + +def near(items, cx, cy, dx=100, dy=115): + return [i for i in items + if abs(i.get('x', 0) - cx) < dx and abs(i.get('y', 0) - cy) < dy] + + +def parse_level(text): + """'LV36' / 'Lv.04' / 'Lv-30' -> int;失败返回 None""" + digits = ''.join(ch for ch in str(text) if ch.isdigit()) + return int(digits) if digits else None + + +def scan_grid(items): + """返回 [(col, row, x, y, level, selected, name)]""" + cards = [] + for ri, ry in enumerate(ROWS): + for ci, cx in enumerate(COLS): + ins = near(items, cx, ry) + if not ins: + continue + lvl = None + for it in ins: + t = it.get('text', '') + if t[:2].lower() == 'lv' and parse_level(t) is not None: + lvl = parse_level(t) + break + if lvl is None: + continue + sel = any('SELECTED' in it.get('text', '') for it in ins) + name = ' '.join(it.get('text', '') for it in ins + if it.get('y', 0) > ry + and not it.get('text', '')[:2].lower() == 'lv' + and 'SELECTED' not in it.get('text', '')) + cards.append((ci, ri, cx, ry, lvl, sel, name.strip())) + return cards + + +def cmd_list(): + items = state().get('items', []) + cards = scan_grid(items) + if not cards: + print('网格为空或不在 IDENTITIES 界面') + print('当前画面: ' + screen_text(items)[:200]) + return 1 + print('%-4s %-4s %-6s %-9s %s' % ('col', 'row', 'lv', 'inTeam', 'name')) + for ci, ri, cx, ry, lvl, sel, name in cards: + print('%-4d %-4d %-6d %-9s %s' % (ci, ri, lvl, 'Y' if sel else '-', name)) + return 0 + + +def ticket_balance(): + """当前 Power-up 界面上的券余额 -> {tier: owned} + + 不靠券名文字判定档位(OCR 会把 III 认成 lll),改用行的 y 坐标: + 三行固定为 IV / III / II。'Owned:o' 里的 o/O 视作 0。 + """ + items = state().get('items', []) + bal = {} + for it in items: + t = it.get('text', '') + if 'Owned' not in t: + continue + tail = t.split('Owned')[-1] + digits = ''.join(ch for ch in tail if ch.isdigit()) + val = int(digits) if digits else 0 + y = it.get('y', 0) + tier = 'IV' if y < 390 else ('III' if y < 500 else 'II') + bal[tier] = val + return bal + + +def do_level_up(hint=None): + """在已打开的人格详情页执行升级。返回 (ok, 描述), ok 为 None 表示没有券可用。 + + 成败看详情页的等级/经验条在升级前后是否变化。不能看 'Level Up'/'Uptie' + 字样: 详情页上它们一直都在, 升级失败也会被判成成功。 + """ + lvl0, _, bar0 = read_detail(hint) + click(*BTN_LEVEL_UP) + time.sleep(3.5) + items = state().get('items', []) + txt = screen_text(items) + # Power-up 弹窗独有 'Items' 分页与 'Owned' 字样 + if 'Owned' not in txt or 'Cancel' not in txt: + return False, '未打开 Power-up 界面: ' + txt[:160] + before = ticket_balance() + if not any(v > 0 for v in before.values()): + click(*POWERUP_CANCEL) + time.sleep(2) + return None, '没有可用训练券(余额=%s), 跳过升级' % before + for y in TICKET_ROWS: + click(TICKET_MAX_X, y) + time.sleep(1.2) + items = state().get('items', []) + txt = screen_text(items) + target = None + for it in items: + t = it.get('text', '') + if '▶' in t: + nums = [parse_level(p) for p in t.split('▶')] + nums = [n for n in nums if n is not None] + if len(nums) >= 2: + target = nums[-1] + if target is None: + # OCR 常把 ▶ 认成 · 或丢失, 退而求其次看是否有两段等级 + for it in items: + t = it.get('text', '') + nums = [parse_level(p) for p in t.replace('·', '▶').split('▶')] + nums = [n for n in nums if n is not None] + if len(nums) >= 2 and nums[-1] > nums[0]: + target = nums[-1] + click(*POWERUP_CONFIRM) + time.sleep(4.5) + txt = screen_text(state().get('items', [])) + # 弹窗"还在"不代表升级没生效。2026-10-13 实测: Zwei 从 Lv.33 一路升到 Lv.40(MAX), + # 券也确实扣了, 但 Confirm 后弹窗仍在, 旧代码据此直接判 FAIL —— 假阴性。 + # 详情页的等级/经验条才是事实来源, 所以先关弹窗再读, 用同一个判据下结论。 + lingering = 'Owned' in txt and 'Cancel' in txt + if lingering: + click(*POWERUP_CANCEL) + time.sleep(2) + lvl1, _, bar1 = read_detail(hint=target or lvl0 or hint) + desc = '券=%s 目标=%s 等级 %s->%s 经验 %s->%s%s' % ( + before, target, lvl0, lvl1, bar0, bar1, + ' (弹窗未关, 已按详情页判定)' if lingering else '') + if lvl0 is not None and lvl1 is not None and lvl1 > lvl0: + return True, desc + if bar0 is not None and bar1 is not None and bar1 != bar0: + return True, desc + if lingering: + return False, 'Confirm 后 Power-up 窗口仍在且等级未变: ' + desc + return False, '升级未确认: ' + desc + + +def skip_cutscene(press_esc=True): + """同步到三阶会解锁人格剧情并自动播放。ESC 会弹"是否跳过", 点 Confirm。 + + press_esc=False 时只处理已经弹出的跳过框, 不主动按 ESC——没有过场时按 ESC + 会关掉当前弹窗或退出详情页。返回 True 表示确实跳过一个过场。 + """ + items = state().get('items', []) + txt = screen_text(items) + if 'skip' not in txt.lower() and press_esc: + keypress('esc') + time.sleep(2) + items = state().get('items', []) + txt = screen_text(items) + if 'skip' in txt.lower(): + conf = None + for it in items: + if it.get('text', '').strip().startswith('Confirm'): + conf = it + if conf: + click(conf['x'], conf['y']) + time.sleep(4) + return True + return False + + +def dismiss_modal(): + """关掉可能残留的 Uptie / Power-up 弹窗, 返回 True 表示画面已干净。 + + 实测坑(2026-10-13): Tier IV 同步弹窗的 Cancel 按钮, 旧代码写死坐标 + (526,660), 而那一版弹窗多了 Shard::Thread Exchange 一排, 实际 Cancel + 在 (380,675) —— 点空处毫无反应, 弹窗一直卡着挡住后续所有输入, 结果 + 六张卡的长按全部失效, 升级环节空跑还报"无需升级"。 + 所以这里: (1) 按文本点识别框中心, 找不到才退回固定坐标; + (2) 每次长按前先清一遍, 比事后补救可靠。 + """ + for _ in range(3): + its = state().get('items', []) + txt = screen_text(its) + if 'Currency Req' in txt or 'Skills Upgraded' in txt: + if not click_text('Cancel'): + click(*UPTIE_CANCEL) + time.sleep(2.5) + continue + if 'Owned' in txt and 'Cancel' in txt: # Power-up 弹窗 + if not click_text('Cancel'): + click(*POWERUP_CANCEL) + time.sleep(2.5) + continue + return True + return False + + +def detail_page_open(txt): + """人格详情页是否已打开。 + + 不能只看 'Level Up': 满级(Lv.40)时那个按钮显示的是 **MAX** —— + 2026-10-13 实测 Zwei 满级后长按成功, 却因 'Level Up' 不在画面里被判成 + "长按未打开详情"而跳过。详情页独有的还有 Uptie 按钮与 Summary/Sanity 区块, + 网格上都不会出现。 + """ + return ('Level Up' in txt) or ('Uptie' in txt) or ('Summary' in txt and 'Sanity' in txt) + + +def do_uptie(): + """在人格详情页执行同步。返回 (ok, 描述) + + 注意: 同步成功会解锁并自动播放"人格剧情", 此时界面既没有 Uptied 字样 + 也不是失败——必须先跳过过场再判定, 否则会误报 FAIL。 + """ + for attempt in range(2): + click(*BTN_UPTIE) + time.sleep(4) + items = state().get('items', []) + txt = screen_text(items) + if ('Currency Req' in txt or 'Stats Increased' in txt + or 'Skills Gained' in txt or 'Skills Upgraded' in txt): + break + else: + return False, '未打开 Uptie 弹窗: ' + txt[:160] + click(*UPTIE_CONFIRM) + time.sleep(4.5) + + txt = screen_text(state().get('items', [])) + # 弹窗还在(仍显示材料需求)说明没同步成。必须先判断这个: 弹窗里本身就有 + # 'Skills Gained', 放在成功判定后面会把失败认成成功。 + if 'Currency Req' in txt or 'Egoshard' in txt: + if not click_text('Cancel'): + click(*UPTIE_CANCEL) + time.sleep(2) + return False, '同步未生效(通常缺自我碎片): ' + txt[:160] + if skip_cutscene(press_esc=False): + time.sleep(3) + return True, '同步成功(并跳过了解锁的人格剧情)' + if 'Uptied' in txt or 'Enhanced' in txt or 'Gained' in txt: + click(*UPTIE_DONE_CONFIRM) + time.sleep(2.5) + return True, '同步成功' + # 什么都没认出: 可能是剧情已经在播但还没出跳过提示, 这时才按 ESC + if skip_cutscene(press_esc=True): + time.sleep(3) + return True, '同步成功(并跳过了解锁的人格剧情)' + # 画面未知时不盲点坐标, 交给调用方按网格判断退回 + return False, '同步结果未知: ' + txt[:160] + + +def cmd_card(ci, ri, uptie=False): + if not (0 <= ci < len(COLS) and 0 <= ri < len(ROWS)): + print('坐标越界') + return 1 + cx, cy = COLS[ci], ROWS[ri] + print('长按卡片 col=%d row=%d @(%d,%d)' % (ci, ri, cx, cy)) + dismiss_modal() + long_press(cx, cy) + time.sleep(4) + items = state().get('items', []) + txt = screen_text(items) + if not detail_page_open(txt): + print('长按未打开详情页: ' + txt[:200]) + return 1 + print('详情页已打开') + ok, desc = do_level_up() + print('升级: %s (%s)' % ('OK' if ok else 'FAIL', desc)) + if uptie: + ok2, desc2 = do_uptie() + print('同步: %s (%s)' % ('OK' if ok2 else 'FAIL', desc2)) + click(*BACK) + time.sleep(2.5) + items = state().get('items', []) + txt = screen_text(items) + # 同步解锁的人格剧情可能在返回途中才弹出, 先跳过再判断 + if 'skip' in txt.lower() or 'LOADING' in txt.upper(): + skip_cutscene() + time.sleep(3) + items = state().get('items', []) + txt = screen_text(items) + # 只在还不在网格时再退一层——避免多余返回键落到主界面上(那里会进剧情) + if not ('IDENTITIES' in txt and 'Facades' in txt): + click(*BACK) + time.sleep(2.5) + items = state().get('items', []) + txt = screen_text(items) + if not ('IDENTITIES' in txt and 'Facades' in txt): + print('[warn] 未能回到 Identities 网格, 当前: ' + txt[:160]) + return 0 if ok else 1 + + +# 每级升级所需经验(来源 wiki "EXP per Level" 表)。 +# EXP_NEED[L] = 从 L-1 级升到 L 级所需经验。 +EXP_NEED = { + 2: 10, 3: 12, 4: 15, 5: 20, 6: 27, 7: 40, 8: 59, 9: 88, 10: 125, 11: 168, + 12: 227, 13: 298, 14: 381, 15: 482, 16: 591, 17: 728, 18: 885, 19: 1064, + 20: 1261, 21: 1488, 22: 1739, 23: 2016, 24: 2327, 25: 2674, 26: 3047, + 27: 3456, 28: 3899, 29: 4378, 30: 4899, 31: 3899, 32: 4378, 33: 4899, + 34: 5468, 35: 6075, 36: 4899, 37: 5468, 38: 6075, 39: 6722, 40: 7413, + 41: 6075, 42: 6722, 43: 7413, 44: 8156, 45: 8953, 46: 7413, 47: 7413, + 48: 7413, 49: 7413, 50: 7413, 51: 8156, 52: 8156, 53: 8156, 54: 8156, + 55: 8156, 56: 8953, 57: 8953, 58: 8953, 59: 8953, 60: 8953, 61: 9792, + 62: 9792, 63: 9792, 64: 9792, 65: 9792, +} + + +def level_from_bar(cur, need, hint=None): + """由详情页 EXP 进度条 "cur/need" 反推等级。 + + 进度条分母 = 当前等级升下一级所需经验 = EXP_NEED[L+1]。 + 表里数值有重复(如 4899 对应 30/33/36), 用网格读到的等级作 tiebreak。 + """ + cands = [lv - 1 for lv, v in EXP_NEED.items() if v == need and lv - 1 >= 1] + if not cands: + return None + if hint: + return min(cands, key=lambda c: abs(c - hint)) + return cands[0] + + +def read_detail(hint=None): + """从已打开的人格详情页读 (真实等级, 名字, 经验条 (cur, need))。 + + 网格里的小号艺术字 OCR 极不可靠(实测 LV14->'Lv.1', LV24->'LV2H'); + 详情页的大号等级也常被漏认(实测 LCB 罪人页只认出 '547/885')。 + 所以以 EXP 进度条反推为主, 直接读到的 LV 值为辅。 + """ + items = state().get('items', []) + lv_cands = [] + name = '' + bar = None + for it in items: + t = it.get('text', '').strip() + y = it.get('y', 0) + up = t.upper().replace(' ', '') + if up.startswith('LV') and 140 < y < 340: + v = parse_level(t) + if v: + lv_cands.append(v) + if 120 < y < 195 and len(t) > 6 and not up.startswith('LV'): + if not name: + name = t + if bar is None and 195 < y < 300 and '/' in t: + parts = [p for p in t.split('/') if p.strip().isdigit()] + if len(parts) == 2: + bar = (int(parts[0]), int(parts[1])) + + direct = min(lv_cands) if lv_cands else None + from_bar = level_from_bar(bar[0], bar[1], hint=hint) if bar else None + + # 满级时进度条反推必然偏低: 分母是"下一级"的需求, 而等级已经封顶。 + # 2026-10-13 实测 Zwei 满级(LV40/MAX, 进度条 0/6075), 反推成 Lv.34, + # 还顺带报了一句"与直读不符"。满级时直接读到的 LV 才是对的。 + maxed = any('MAX' in it.get('text', '').upper() for it in items) + if maxed: + direct_max = max(lv_cands) if lv_cands else None + if direct_max is not None: + return direct_max, name, bar + + if from_bar is not None and direct is not None: + # 两者都有时以进度条为准(数字识别比艺术字可靠), 但差异过大时告警 + if abs(from_bar - direct) > 2: + print(' [warn] 进度条推算 Lv.%d 与直读 Lv.%d 不符, 取进度条' + % (from_bar, direct)) + return from_bar, name, bar + if from_bar is not None: + return from_bar, name, bar + return direct, name, bar + + +def cmd_progress(target=34, uptie=True, max_try=6): + """按网格等级升序依次打开详情, 以详情页真实等级判断, 升级第一个低于 target 的。 + + 网格 OCR 会误读等级, 所以不能只信它——必须逐个打开核实。 + """ + items = state().get('items', []) + cards = scan_grid(items) + team = sorted([c for c in cards if c[5]], key=lambda c: c[4]) + if not team: + print('未找到队内(SELECTED)人格') + return 1 + unreadable = 0 + for ci, ri, cx, ry, ocr_lvl, sel, nm in team[:max_try]: + print('--- 候选 col=%d row=%d (网格读作 Lv.%s %s)' % (ci, ri, ocr_lvl, nm)) + # 长按前先清残留弹窗: 一张卡没关干净, 后面每张都会被挡住 + if not dismiss_modal(): + print(' [warn] 有弹窗关不掉, 长按可能无效') + long_press(cx, ry) + time.sleep(4) + items = state().get('items', []) + txt = screen_text(items) + if not detail_page_open(txt): + print(' 长按未打开详情, 跳过') + unreadable += 1 + continue + true_lvl, true_name, _ = read_detail(hint=ocr_lvl) + print(' 详情页: %s 真实等级=%s' % (true_name, true_lvl)) + if true_lvl is None: + print(' 详情页读不到等级, 无法确认是否需要升级, 跳过') + unreadable += 1 + click(*BACK) + time.sleep(2.5) + continue + if true_lvl >= target: + print(' 已达目标 Lv.%d, 跳过' % target) + click(*BACK) + time.sleep(2.5) + continue + ok, desc = do_level_up(hint=true_lvl) + print(' 升级: %s (%s)' % ('OK' if ok else ('SKIP' if ok is None else 'FAIL'), desc)) + ok2 = True + if uptie: + ok2, desc2 = do_uptie() + print(' 同步: %s (%s)' % ('OK' if ok2 else 'FAIL', desc2)) + click(*BACK) + time.sleep(2.5) + items = state().get('items', []) + txt = screen_text(items) + if not ('IDENTITIES' in txt and 'Facades' in txt): + click(*BACK) + time.sleep(2.5) + return 0 if ok and ok2 else 1 + if unreadable: + print('FAIL: %d 个候选未能核实详情等级, 不能判定为无需升级' % unreadable) + return 1 + print('已核实的 %d 个候选均达到目标等级, 无需升级' % len(team[:max_try])) + return 0 + + +def cmd_weakest(uptie=False): + items = state().get('items', []) + cards = scan_grid(items) + team = [c for c in cards if c[5]] + if not team: + print('未找到队内(SELECTED)人格') + return 1 + team.sort(key=lambda c: c[4]) + ci, ri, cx, ry, lvl, sel, name = team[0] + print('队内最低: Lv.%d %s (col=%d row=%d)' % (lvl, name, ci, ri)) + return cmd_card(ci, ri, uptie=uptie) + + +def cmd_back(): + click(*BACK) + time.sleep(2.5) + click(*BACK) + time.sleep(2.5) + print('已返回') + return 0 + + +def main(): + args = sys.argv[1:] + if not args: + print(__doc__) + return 2 + if args[0] == 'list': + return cmd_list() + if args[0] == 'back': + return cmd_back() + if args[0] == 'weakest': + return cmd_weakest(uptie='--uptie' in args) + if args[0] == 'progress': + tgt = 34 + for a in args[1:]: + if a.isdigit(): + tgt = int(a) + return cmd_progress(target=tgt, uptie='--uptie' in args) + if args[0] == 'card' and len(args) >= 3: + return cmd_card(int(args[1]), int(args[2]), uptie='--uptie' in args) + print(__doc__) + return 2 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/modules_status.py b/scripts/modules_status.py new file mode 100644 index 0000000..0cdd4ff --- /dev/null +++ b/scripts/modules_status.py @@ -0,0 +1,174 @@ +# -*- coding: utf-8 -*- +"""汇总模块合成的历史, 供值守时快速核对。 + +用法: python modules_status.py [--last N] [--json] + +读 ~/lc_mcp/modules/convert_*.json(每轮一份报告)与 convert.log, 输出: + 时间 / 结果 / 耗时 / 模组变化 / 体力 / 狂气读数 + +值守时关心三件事, 所以这三件排在最前面: + 1. 有没有真的换到模块(而不是一直"体力不足") + 2. 有没有哪次报"狂气读数发生变化"(那要立刻人工核查) + 3. 有没有连着失败(说明流程坏了, 不是资源问题) +""" +import argparse +import glob +import json +import os +import sys + +DIR = os.path.expanduser(os.path.join('~', 'lc_mcp', 'modules')) + + +def load_reports(d): + rows = [] + for p in sorted(glob.glob(os.path.join(d, 'convert_*.json'))): + try: + with open(p, encoding='utf-8') as f: + r = json.load(f) + except (OSError, ValueError): + continue # 写了一半的报告不该拖垮汇总 + r['_file'] = os.path.basename(p) + rows.append(r) + rows.sort(key=lambda r: r.get('started', ''), reverse=True) + return rows + + +def recheck_alarm(lb, la, result): + """用**当前**判据重新复核老报告里的狂气告警。 + + ⛔ 为什么需要这个: 2026-10-16 22:03 那份报告按当时的判据写了 + "⚠️ 狂气读数发生变化 6636 -> 9699", 而事后查明那是**误报** —— + 6636 和 9699 都是真值 6636 的已知 OCR 读法。 + + 报告是历史记录, 不该改写; 但汇总工具不能继续拿旧判据吓人。 + 这里重新判一遍, 并把"当时报了、现在看是误报"明说出来。 + """ + if '狂气读数发生变化' not in (result or ''): + return False, False # (是否告警, 是否新版判据认定是误报) + if lb is None or la is None: + return True, False + try: + import convert_modules as cm + suspicious, _ = cm.lunacy_verdict(lb, la) + except Exception: + return True, False + return True, (not suspicious) + + +def summarize(rows): + out = [] + for r in rows: + steps = r.get('steps') or [] + conv = steps[0] if steps else {} + lb, la = r.get('lunacy_before'), r.get('lunacy_after') + checked = r.get('lunacy_checked') + if checked is None: # 老报告没这个字段 + checked = lb is not None and la is not None + converted = r.get('converted') + if converted is None: + # 老报告没有 converted, 按结果文本推断 + converted = '合成完成' in (r.get('result') or '') + alarmed, now_false_alarm = recheck_alarm(lb, la, r.get('result')) + out.append({ + 'started': r.get('started', '?'), + 'ok': bool(r.get('ok')), + 'result': r.get('result', ''), + 'elapsed_s': r.get('elapsed_s'), + 'info': conv.get('info', ''), + 'converted': bool(converted), + 'lunacy_before': lb, + 'lunacy_after': la, + 'lunacy_checked': bool(checked), + 'lunacy_alarm': alarmed, + 'lunacy_false_alarm': now_false_alarm, + }) + return out + + +def lunacy_cell(r): + """狂气那格的显示。没比对上时明说, 不装作校过了。""" + if r['lunacy_alarm']: + if r.get('lunacy_false_alarm'): + # 报告里那句话是按旧判据写的, 但按现在的证据看是误报 —— 别继续吓人 + return '误报(%s/%s 都是已知读法)' % (r['lunacy_before'], r['lunacy_after']) + return '⚠️ %s -> %s' % (r['lunacy_before'], r['lunacy_after']) + if not r['converted']: + # 这轮压根没合成, 没什么可比 —— 和"合成过但没读到"是两回事 + n = r['lunacy_before'] + return '未合成(读到 %s)' % n if n is not None else '未合成' + if not r['lunacy_checked']: + return '未比对' + return '%s 前后一致' % r['lunacy_after'] + + +def fmt_secs(s): + if s is None: + return '-' + if s < 60: + return '%ds' % s + return '%d:%02d' % (s // 60, s % 60) + + +def main(argv=None): + ap = argparse.ArgumentParser(description='模块合成历史汇总') + ap.add_argument('--last', type=int, default=0, help='只看最近 N 条(0=全部)') + ap.add_argument('--json', action='store_true') + ap.add_argument('--dir', default=DIR) + args = ap.parse_args(argv) + + rows = summarize(load_reports(args.dir)) + if args.last: + rows = rows[:args.last] + + if args.json: + json.dump(rows, sys.stdout, ensure_ascii=False, indent=2) + print() + return 0 + + if not rows: + print('还没有合成记录(%s)' % args.dir) + return 0 + + got = sum(1 for r in rows if r['converted']) + fails = [r for r in rows if not r['ok']] + # 告警里要排掉"按现在的判据看是误报"的那些 —— 否则表头会一直喊狼来了 + alarms = [r for r in rows if r['lunacy_alarm'] and not r.get('lunacy_false_alarm')] + false_alarms = [r for r in rows if r.get('lunacy_false_alarm')] + # 只统计"真的合成过却没能比对"的 —— 没合成的轮次没什么可比, 混进来会虚高 + unchecked = [r for r in rows if r['converted'] and not r['lunacy_checked']] + + print('共 %d 轮: 换到模块 %d 轮, 失败 %d 轮, 狂气告警 %d 轮, 该比对却没比对 %d 轮' + % (len(rows), got, len(fails), len(alarms), len(unchecked))) + if false_alarms: + print(' (另有 %d 轮当时报过狂气告警, 但按现在的判据是误报, 见下表)' + % len(false_alarms)) + if alarms: + print('⚠️ 有狂气告警, 需要人工核查:') + for r in alarms: + print(' %s %s' % (r['started'], r['result'])) + if unchecked: + print('⚠️ 这些轮次合成过但狂气没读全, 等于没校过:') + for r in unchecked: + print(' %s %s' % (r['started'], r['result'])) + # 连着失败(最新几条都不是好结果)要醒目 —— 那说明流程坏了 + streak = 0 + for r in rows: + if r['ok']: + break + streak += 1 + if streak >= 3: + print('⚠️ 连续 %d 轮不成功, 可能是流程问题而不是资源不足' % streak) + + print() + print('%-19s %-4s %-7s %-18s %s' % ('时间', 'OK', '耗时', '狂气', '结果')) + print('-' * 110) + for r in rows: + print('%-19s %-4s %-7s %-18s %s' + % (r['started'], '✅' if r['ok'] else '❌', fmt_secs(r['elapsed_s']), + lunacy_cell(r), (r['result'] or r['info'])[:56])) + return 0 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/render_check.py b/scripts/render_check.py new file mode 100644 index 0000000..6e70e68 --- /dev/null +++ b/scripts/render_check.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +"""桌面渲染自检: 从屏幕 DC 做一次 BitBlt。 + +成功 = 桌面正在出图(会话处于渲染状态); +失败(err 6 ERROR_INVALID_HANDLE) = 会话被断开, Windows 拆掉了显示表面, +此时游戏截图会全黑, AALC 会失明。 + +退出码: 0 渲染正常, 1 渲染不可用 +""" +import ctypes + +SRCCOPY = 0x00CC0020 + + +def main(): + u = ctypes.windll.user32 + g = ctypes.windll.gdi32 + hdc = u.GetDC(0) + mem = g.CreateCompatibleDC(hdc) + bmp = g.CreateCompatibleBitmap(hdc, 64, 64) + g.SelectObject(mem, bmp) + r = g.BitBlt(mem, 0, 0, 64, 64, hdc, 0, 0, SRCCOPY) + g.DeleteObject(bmp) + g.DeleteDC(mem) + u.ReleaseDC(0, hdc) + print('BitBlt=%d desktop=%dx%d' % (r, u.GetSystemMetrics(0), u.GetSystemMetrics(1))) + return 0 if r else 1 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/session_state.py b/scripts/session_state.py new file mode 100644 index 0000000..194b97f --- /dev/null +++ b/scripts/session_state.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +"""打印指定 Windows 终端服务会话的连接状态。 + +qwinsta 在计划任务/隐藏窗口上下文里拿不到输出, 所以用 WTS API。 + +用法: python session_state.py [session_id] +输出: Active / Connected / Disc / Idle / Listen / ... 或 UNKNOWN +退出码: 0 成功, 1 查询失败 +""" +import ctypes +import sys +from ctypes import wintypes + +WTS_CURRENT_SERVER_HANDLE = 0 +WTS_CONNECT_STATE = 8 + +WTS_STATES = { + 0: 'Active', + 1: 'Connected', + 2: 'ConnectQuery', + 3: 'Shadow', + 4: 'Disc', + 5: 'Idle', + 6: 'Listen', + 7: 'Reset', + 8: 'Down', + 9: 'Init', +} + + +def main(argv): + session_id = int(argv[1]) if len(argv) > 1 else 2 + wts = ctypes.WinDLL('wtsapi32') + wts.WTSQuerySessionInformationW.argtypes = [ + wintypes.HANDLE, wintypes.DWORD, ctypes.c_int, + ctypes.POINTER(ctypes.c_void_p), ctypes.POINTER(wintypes.DWORD), + ] + wts.WTSQuerySessionInformationW.restype = wintypes.BOOL + wts.WTSFreeMemory.argtypes = [ctypes.c_void_p] + + buf = ctypes.c_void_p() + size = wintypes.DWORD() + ok = wts.WTSQuerySessionInformationW( + WTS_CURRENT_SERVER_HANDLE, session_id, WTS_CONNECT_STATE, + ctypes.byref(buf), ctypes.byref(size)) + if not ok or not buf: + print('UNKNOWN') + return 1 + try: + state = ctypes.cast(buf, ctypes.POINTER(ctypes.c_uint)).contents.value + finally: + wts.WTSFreeMemory(buf) + print(WTS_STATES.get(state, 'Unknown%d' % state)) + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/tests/test_audit_runs.py b/tests/test_audit_runs.py new file mode 100644 index 0000000..a22e606 --- /dev/null +++ b/tests/test_audit_runs.py @@ -0,0 +1,213 @@ +# -*- coding: utf-8 -*- +"""audit_runs 的核对逻辑。 + +这个工具的职责是"把日志和报告对起来", 所以测试重点不是它能通过, 而是 +**它能不能抓到问题** —— 一个什么都不报的体检工具等于没有。 + +⛔ 第一版就踩过这个坑: 它拿"报告.started + elapsed"去找日志结论行, 能对上就说明 +elapsed 一致, 于是"耗时不符"那个分支永远不可能触发 —— 是死代码。现在改成按日志里 +的"=== 开始: 体力换模块 ===" 配对, 时间关系和耗时才能各自独立核对。 +""" +import json +import os +import shutil +import sys +import tempfile +import unittest +from datetime import datetime +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts')) +import audit_runs as ar # noqa: E402 + +START = '=== 开始: 体力换模块 ===' + + +def start_line(t): + return '[%s] %s' % (t, START) + + +def conclusion(t, result, secs, ok='OK'): + return '[%s] === %s (%s), 耗时 %ds ===' % (t, result, ok, secs) + + +def report(start, secs, result, ok=True): + return json.dumps({'started': start, 'elapsed_s': secs, 'ok': ok, + 'result': result, 'steps': []}, ensure_ascii=False) + + +class AuditTest(unittest.TestCase): + + def setUp(self): + self.d = tempfile.mkdtemp() + + def write_log(self, lines): + with open(os.path.join(self.d, 'convert.log'), 'w', encoding='utf-8') as f: + f.write('\n'.join(lines) + '\n') + + def write_report(self, name, content): + with open(os.path.join(self.d, name), 'w', encoding='utf-8') as f: + f.write(content) + + def problems(self): + return ar.audit(self.d)['problems'] + + # ---------------------------------------------------------- 正常情况 + + def test_matching_run_is_clean(self): + self.write_log([start_line('2026-01-01 10:00:00'), + conclusion('2026-01-01 10:00:30', '合成完成: 模组 1 -> 2 (+1)', 30)]) + self.write_report('convert_20260101_100000.json', + report('2026-01-01 10:00:00', 30, '合成完成: 模组 1 -> 2 (+1)')) + self.assertEqual(self.problems(), []) + + def test_empty_dir_is_clean(self): + self.assertEqual(self.problems(), []) + + # ---------------------------------------------------------- 抓问题 + + def test_report_without_run_is_flagged(self): + self.write_report('convert_20260101_110000.json', + report('2026-01-01 11:00:00', 40, '体力不足(3<20), 本轮无需合成')) + self.assertTrue(any('找不到对应的开始行' in p for p in self.problems())) + + def test_run_without_report_is_flagged(self): + self.write_log([start_line('2026-01-01 12:00:00'), + conclusion('2026-01-01 12:00:10', '跑了但没留报告', 10)]) + self.assertTrue(any('没有对应报告' in p for p in self.problems())) + + def test_elapsed_mismatch_is_flagged(self): + """日志说耗时 30s, 报告说 99s —— 必须能发现。 + + 老版本这里永远查不出来(死代码), 所以这条用例是专门守它的。 + """ + self.write_log([start_line('2026-01-01 10:00:00'), + conclusion('2026-01-01 10:00:30', '合成完成', 30)]) + self.write_report('convert_20260101_100000.json', + report('2026-01-01 10:00:00', 99, '合成完成')) + got = self.problems() + self.assertTrue(any('耗时不符' in p for p in got), got) + + def test_end_time_mismatch_is_flagged(self): + # 开始和耗时都对得上, 但结论时刻对不上 -> 时间关系有问题 + self.write_log([start_line('2026-01-01 10:00:00'), + conclusion('2026-01-01 10:05:00', '合成完成', 30)]) + self.write_report('convert_20260101_100000.json', + report('2026-01-01 10:00:00', 30, '合成完成')) + self.assertTrue(any('时间对不上' in p for p in self.problems())) + + def test_result_text_mismatch_is_flagged(self): + self.write_log([start_line('2026-01-01 10:00:00'), + conclusion('2026-01-01 10:00:30', '合成完成: 模组 1 -> 2 (+1)', 30)]) + self.write_report('convert_20260101_100000.json', + report('2026-01-01 10:00:00', 30, '合成完成: 模组 5 -> 9 (+4)')) + self.assertTrue(any('结果文本不符' in p for p in self.problems())) + + def test_same_second_cluster_is_flagged(self): + """同一秒多行结论 = 测试批量产生的典型特征。""" + self.write_log([conclusion('2026-01-01 12:00:00', '第一条', 0), + conclusion('2026-01-01 12:00:00', '第二条', 0)]) + self.assertTrue(any('同一秒' in p for p in self.problems())) + + def test_impossible_content_is_flagged(self): + self.write_log([start_line('2026-01-01 12:00:00'), + conclusion('2026-01-01 12:00:05', '看门狗执行失败: powershell not found', 5)]) + self.assertTrue(any('可疑内容' in p for p in self.problems())) + + # ---------------------------------------------------------- 解析 + + def test_parse_pairs_start_with_conclusion(self): + self.write_log([ + '[2026-01-01 09:00:00] === 开始: 体力换模块 ===', + '[2026-01-01 09:00:05] 游戏已在运行', + conclusion('2026-01-01 09:01:00', '合成完成', 60), + ]) + runs = ar.parse_runs(os.path.join(self.d, 'convert.log')) + self.assertEqual(len(runs), 1) + self.assertEqual(runs[0]['secs'], 60) + self.assertEqual(runs[0]['start'].strftime('%H:%M:%S'), '09:00:00') + + def test_parse_handles_missing_file(self): + self.assertEqual(ar.parse_runs(os.path.join(self.d, 'nope.log')), []) + + def test_conclusion_without_start_line_still_listed(self): + # 没有开始行的结论不该被丢掉(要能报"没有对应报告") + self.write_log([conclusion('2026-01-01 12:00:00', '独苗', 10)]) + runs = ar.parse_runs(os.path.join(self.d, 'convert.log')) + self.assertEqual(len(runs), 1) + self.assertIsNone(runs[0]['start']) + + def test_skip_broken_report_json(self): + with open(os.path.join(self.d, 'convert_20260101_100000.json'), 'w', encoding='utf-8') as f: + f.write('{ 半截') + self.assertEqual(ar.load_reports(self.d), []) + + +class ModuleTrajectoryTest(unittest.TestCase): + """跨轮检查模组数。 + + ⛔ 2026-10-17 实测: 22:05 合成后是 35, 06:04 那轮读到的合成前只有 33。 + 追查了一轮, 最后**是用户自己升阶用掉的** —— 不是 bug。 + + 教训: 这类"数字对不上"的现象, 默认解释可能是人手动操作。所以措辞是"需要确认", + 不是"出问题了"。真正反常的是反过来: 模组数**自己变多**(自动化之外的来源)。 + """ + + def _rep(self, started, info, converted=True): + return {'start': datetime.strptime(started, '%Y-%m-%d %H:%M:%S'), + 'steps': [{'step': '合成', 'ok': True, 'info': info}], + 'converted': converted} + + def test_normal_progress_is_clean(self): + reps = [self._rep('2026-01-01 10:00:00', '模组 29 -> 30 (+1)'), + self._rep('2026-01-01 14:00:00', '模组 30 -> 31 (+1)')] + self.assertEqual(ar.module_trajectory(reps), []) + + def test_decrease_is_reported_but_not_as_a_failure_claim(self): + reps = [self._rep('2026-10-16 22:03:42', '模组 33 -> 35 (+2)'), + self._rep('2026-10-17 06:03:42', '模组 33 -> 35 (+2)')] + got = ar.module_trajectory(reps) + self.assertEqual(len(got), 1) + self.assertIn('比上一轮少', got[0]) + self.assertIn('人工升阶', got[0]) # 默认解释要摆出来, 别一口咬定是故障 + self.assertIn('35', got[0]) + self.assertIn('33', got[0]) + + def test_unexplained_increase_is_flagged(self): + """模组自己变多才是真反常 —— 自动化之外的来源。""" + reps = [self._rep('2026-01-01 10:00:00', '模组 29 -> 30 (+1)'), + self._rep('2026-01-01 14:00:00', '模组 33 -> 35 (+2)')] + got = ar.module_trajectory(reps) + self.assertEqual(len(got), 1) + self.assertIn('无端变多', got[0]) + + def test_skipped_runs_do_not_count(self): + """中间那些"体力不足没合成"的轮次不该被当成链条上的一环。""" + reps = [self._rep('2026-01-01 10:00:00', '模组 29 -> 30 (+1)'), + self._rep('2026-01-01 14:00:00', '', converted=False), + self._rep('2026-01-01 18:00:00', '模组 30 -> 31 (+1)')] + self.assertEqual(ar.module_trajectory(reps), []) + + def test_missing_numbers_are_skipped(self): + reps = [self._rep('2026-01-01 10:00:00', '合成完成'), + self._rep('2026-01-01 14:00:00', '模组 30 -> 31 (+1)')] + self.assertEqual(ar.module_trajectory(reps), []) + + def test_audit_includes_trajectory_problems(self): + """端到端: 报告目录里的减少要被 audit() 报出来。""" + d = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, d, True) + for name, started, secs, info in ( + ('convert_a.json', '2026-01-01 10:00:00', 30, '模组 29 -> 31 (+2)'), + ('convert_b.json', '2026-01-01 14:00:00', 30, '模组 29 -> 31 (+2)')): + with open(os.path.join(d, name), 'w', encoding='utf-8') as f: + f.write(json.dumps({'started': started, 'elapsed_s': secs, 'ok': True, + 'result': '合成完成', 'steps': [ + {'step': '合成', 'ok': True, 'info': info}], + 'converted': True}, ensure_ascii=False)) + problems = ar.audit(d)['problems'] + self.assertTrue(any('比上一轮少' in p for p in problems), problems) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_auto_cycle.py b/tests/test_auto_cycle.py new file mode 100644 index 0000000..08c2e3a --- /dev/null +++ b/tests/test_auto_cycle.py @@ -0,0 +1,421 @@ +from pathlib import Path +import json +import sys +import tempfile +import unittest +from unittest import mock + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts')) +import auto_cycle # noqa: E402 + + +class FakeMcp: + """按脚本返回 task_status, 记录 run_task / stop_task 调用。""" + + def __init__(self, *runs): + self.runs = [list(r) for r in runs] # 每次 run_task 后依次返回的状态 + self.calls = [] + + def probe(self, tool, args=None, quiet=True): + self.calls.append((tool, args)) + if tool == 'run_task': + self.current = self.runs.pop(0) + return {'ok': True} + if tool == 'task_status': + return self.current.pop(0) if len(self.current) > 1 else self.current[0] + return {'ok': True} + + +RUNNING = {'state': 'running'} +STALL = {'state': 'running', 'stall': {'empty_team': 30}} +DONE = {'state': 'succeeded', 'exit_code': 0} + + +class FakeTime: + """快进时钟。 + + poll_task 的循环上限是按**墙钟**判断的 (time.time() - t0 < timeout_s), + 而测试里 sleep 被换成了空函数 —— 只换 sleep 不换时钟的话, 那个循环会真的 + 空转满 timeout_s 秒, 每圈还往 mcp.calls 里塞一条记录。实测这样跑会把内存 + 吃爆, 让整个测试进程以 0xC0000005 退出。 + """ + + def __init__(self, step=1.0): + self.t = 0.0 + self.step = step + + def time(self): + self.t += self.step + return self.t + + def sleep(self, _s): + pass + + +class RunAalcTest(unittest.TestCase): + + def run_aalc(self, mcp, **kw): + with mock.patch.object(auto_cycle, 'probe', mcp.probe), \ + mock.patch.object(auto_cycle, 'blocking_module_modal', return_value=None), \ + mock.patch.object(auto_cycle, 'log', lambda m: None): + return auto_cycle.run_aalc('daily', {}, 3600, sleep=lambda s: None, **kw) + + def poll(self, mcp, timeout_s, clear=None, step=60.0): + """跑 poll_task, 用快进时钟, 绝不真的等。""" + clock = FakeTime(step) + patches = [mock.patch.object(auto_cycle, 'probe', mcp.probe), + mock.patch.object(auto_cycle, 'log', lambda m: None), + mock.patch.object(auto_cycle.time, 'time', clock.time), + mock.patch.object(auto_cycle, 'clear_blocking_modal', return_value='已发送 Cancel')] + if clear is not None: + patches.append(mock.patch.object(auto_cycle, 'blocking_module_modal', clear)) + else: + patches.append(mock.patch.object(auto_cycle, 'blocking_module_modal', return_value=None)) + for p in patches: + p.start() + try: + return auto_cycle.poll_task('daily', timeout_s, sleep=lambda s: None) + finally: + for p in patches: + p.stop() + + def tools(self, mcp): + return [t for t, _ in mcp.calls if t != 'task_status'] + + def test_stall_is_stopped_and_rerun_once(self): + mcp = FakeMcp([RUNNING, STALL, STALL], [RUNNING, DONE]) + ok, info = self.run_aalc(mcp) + self.assertTrue(ok, info) + self.assertEqual(self.tools(mcp), ['run_task', 'stop_task', 'run_task']) + + def test_single_stall_poll_is_not_enough(self): + mcp = FakeMcp([STALL, RUNNING, DONE]) + ok, info = self.run_aalc(mcp) + self.assertTrue(ok, info) + self.assertEqual(self.tools(mcp), ['run_task']) + + def test_gives_up_after_retries(self): + mcp = FakeMcp([STALL, STALL], [STALL, STALL]) + ok, info = self.run_aalc(mcp, retries=1) + self.assertFalse(ok) + self.assertIn('卡死', info) + self.assertEqual(self.tools(mcp), ['run_task', 'stop_task', 'run_task', 'stop_task']) + + def test_resource_out_stops_without_rerun(self): + """反复缺模组 = 资源见底, 直接收工, 不要重跑也不要等超时。 + + 实测(2026-10-13): 体力只剩 3/126、模组不足时, AALC 的 Luxcavation 流程 + 会一直在"not enough Enkephalin Modules"模态框后面点被挡住的 Enter 按钮。 + 每次都要烧满 10 分钟才被 no_progress 判据救回, 重跑还是同样的结果。 + """ + mcp = FakeMcp() + mcp.current = [RUNNING] * 40 + ok, info, stalled = self.poll(mcp, 3600, clear=lambda: '缺模组 -> 点 Cancel') + self.assertFalse(ok) + self.assertEqual(info, 'RESOURCE_OUT') + self.assertFalse(stalled) + # 连续观察到 RESOURCE_OUT_LIMIT 次就停, 不在任务运行时点击 + self.assertIn('stop_task', self.tools(mcp)) + + def test_occasional_modal_does_not_end_the_task(self): + """偶发一次模态框不该收工, 继续观察任务。""" + seq = ['x'] + mcp = FakeMcp() + mcp.current = [RUNNING] + ok, info, stalled = self.poll( + mcp, 600, clear=lambda: seq.pop(0) if seq else None) + self.assertNotEqual(info, 'RESOURCE_OUT') + # 跑到超时收工, 而不是被当成资源耗尽 + self.assertIn('超时', info) + + def test_separate_shortage_sightings_are_not_consecutive(self): + seq = iter(['x', None, 'x', None, 'x', None]) + mcp = FakeMcp() + mcp.current = [RUNNING] * 6 + [DONE] + ok, info, _ = self.poll(mcp, 3600, clear=lambda: next(seq)) + self.assertTrue(ok, info) + self.assertNotIn('stop_task', self.tools(mcp)) + + def test_failed_stop_prevents_retry(self): + mcp = FakeMcp([STALL, STALL], [DONE]) + original = mcp.probe + + def probe(tool, args=None): + result = original(tool, args) + return {'ok': False, 'error': '进程未退出'} if tool == 'stop_task' else result + + mcp.probe = probe + with self.assertRaisesRegex(RuntimeError, '停止 AALC 任务失败'): + self.run_aalc(mcp) + self.assertEqual(self.tools(mcp), ['run_task', 'stop_task']) + + def test_status_error_stops_the_task_before_reporting_failure(self): + mcp = FakeMcp([{'ok': False, 'error': '连接中断'}]) + with self.assertRaisesRegex(RuntimeError, '无法读取任务状态'): + self.run_aalc(mcp) + self.assertEqual(self.tools(mcp), ['run_task', 'stop_task']) + + def test_preflight_failure_is_not_retried(self): + failed = {'state': 'failed', 'exit_code': 3, + 'errors': ['[ERROR] [lc_mcp] preflight: 队伍 1 的 sinner_order 没有罪人']} + mcp = FakeMcp([failed]) + ok, info = self.run_aalc(mcp) + self.assertFalse(ok) + self.assertIn('preflight', info) + self.assertEqual(self.tools(mcp), ['run_task']) + + def test_user_stop_never_retries(self): + for status in ({'state': 'stopped', 'exit_code': 130}, + {'state': 'stopped'}, {'state': 'failed', 'exit_code': 130}): + mcp = FakeMcp([status], [DONE]) + with self.subTest(status=status), self.assertRaises(auto_cycle.UserAborted): + self.run_aalc(mcp) + self.assertEqual(self.tools(mcp), ['run_task']) + + def test_mirror_emergency_stop_ends_cycle_before_upgrade_or_navigation(self): + mcp = FakeMcp([DONE], [{'state': 'stopped', 'exit_code': 130}]) + poll = auto_cycle.poll_task + with tempfile.TemporaryDirectory() as tmp: + with mock.patch.object(auto_cycle, 'probe', mcp.probe), \ + mock.patch.object(auto_cycle, 'poll_task', + side_effect=lambda t, s, **kw: poll(t, s, sleep=lambda _: None)), \ + mock.patch.object(auto_cycle, 'lunacy_guard', return_value=(True, 'ok')), \ + mock.patch.object(auto_cycle, 'ensure_team1', return_value=True), \ + mock.patch.object(auto_cycle, 'goto_identities') as navigate, \ + mock.patch.object(auto_cycle, 'run') as upgrade, \ + mock.patch('builtins.print'): + code = auto_cycle.main(['--mirror', '1', '--report-dir', tmp]) + report = json.loads(next(Path(tmp).glob('cycle_*.json')).read_text(encoding='utf-8')) + self.assertEqual(code, 130) + self.assertFalse(report['ok']) + self.assertIn('用户停止', report['result']) + navigate.assert_not_called() + upgrade.assert_not_called() + self.assertEqual(self.tools(mcp), ['run_task', 'run_task']) + + def test_exit_zero_with_errors_is_failure(self): + mcp = FakeMcp([dict(DONE, errors=['[ERROR] 超出最大尝试次数,未能进入战斗'])]) + ok, info = self.run_aalc(mcp) + self.assertFalse(ok) + + def test_mirror_params_are_passed_with_task(self): + mcp = FakeMcp([DONE]) + with mock.patch.object(auto_cycle, 'probe', mcp.probe), \ + mock.patch.object(auto_cycle, 'log', lambda m: None): + auto_cycle.run_aalc('mirror', {'count': 2}, 3600, sleep=lambda s: None) + self.assertEqual(mcp.calls[0], ('run_task', {'count': 2, 'task': 'mirror'})) + + +class ScreenDetectTest(unittest.TestCase): + """TEAMS / 网格的界面判定。 + + 2026-10-13 实机: OCR 把 "SIN COST" 输出成 "SINICOST"(无空格), 而判定写死了 + 带空格的 'SIN COST', 于是 ensure_team1() 以为不在 TEAMS 页, 去点 Sinners + 按钮空转, 每轮都报 "未能确认选中 TEAMS #1"。判定必须容忍空格。 + """ + + def test_teams_screen_without_space_is_recognised(self): + # 这是本机 OCR 的真实输出 + self.assertTrue(auto_cycle.on_teams_screen( + 'TEAMS#1 | Details | SINICOST | 000 | Dante | All Idensities')) + + def test_teams_screen_with_space_still_recognised(self): + self.assertTrue(auto_cycle.on_teams_screen( + 'TEAMS #1 | Details | SIN COST | 000 | Dante | All E.G.O')) + + def test_grid_is_not_teams_screen(self): + t = 'TEAMS#1 | IDENTITIES | E.G.O | Facades | Details' + self.assertFalse(auto_cycle.on_teams_screen(t)) + self.assertTrue(auto_cycle.on_grid(t)) + + def test_main_menu_is_neither(self): + t = 'Inferno | MIRROROF | Window | Sinners | Drive | Extract' + self.assertFalse(auto_cycle.on_teams_screen(t)) + self.assertFalse(auto_cycle.on_grid(t)) + + +class BlockingModalTest(unittest.TestCase): + """挡路模态框清道夫。 + + 2026-10-13 实测: 模组不足时游戏弹 + "You don't have enough Enkephalin Modules. / Would you like to go assemble some?" + AALC 的 Luxcavation 流程不认它, 一直在后面点被挡住的 Enter 按钮。 + 连续观察到缺资源后先停止任务, 再重新识别并点 Cancel。 + """ + + MODAL = [{'text': "You don't have enough Enkephalin Modules.", 'x': 554, 'y': 404, 'w': 460, 'h': 24}, + {'text': 'Would you like to go assemble some?', 'x': 593, 'y': 439, 'w': 380, 'h': 24}, + {'text': 'X Cancel', 'x': 592, 'y': 599, 'w': 90, 'h': 26}, + {'text': 'Confirm', 'x': 924, 'y': 599, 'w': 100, 'h': 26}] + + def test_clicks_cancel_centre(self): + clicked = [] + with mock.patch.object(auto_cycle, 'items', lambda: list(self.MODAL)), \ + mock.patch.object(auto_cycle, 'click', + lambda x, y: (clicked.append((x, y)) or {'ok': True})): + msg = auto_cycle.clear_blocking_modal() + self.assertIn('Cancel', msg) + # 点的是识别框中心, 不是左上角 —— 实测点左上角常常落空 + self.assertEqual(clicked, [(592 + 45, 599 + 13)]) + + def test_other_screens_are_left_alone(self): + clicked = [] + grid = [{'text': 'TEAMS#1', 'x': 100, 'y': 300}, + {'text': 'IDENTITIES', 'x': 200, 'y': 300}] + with mock.patch.object(auto_cycle, 'items', lambda: grid), \ + mock.patch.object(auto_cycle, 'click', + lambda x, y: (clicked.append((x, y)) or {'ok': True})): + self.assertIsNone(auto_cycle.clear_blocking_modal()) + self.assertEqual(clicked, []) + + def test_spaces_in_ocr_text_still_match(self): + # OCR 常把词粘在一起或拆开, 所以标记比对前先去空格 + modal = [{'text': "You don'thave enough EnkephalinModules", 'x': 10, 'y': 20, 'w': 10, 'h': 10}, + {'text': 'Cancel', 'x': 30, 'y': 40, 'w': 10, 'h': 10}] + clicked = [] + with mock.patch.object(auto_cycle, 'items', lambda: modal), \ + mock.patch.object(auto_cycle, 'click', + lambda x, y: (clicked.append((x, y)) or {'ok': True})): + self.assertIsNotNone(auto_cycle.clear_blocking_modal()) + self.assertEqual(clicked, [(35, 45)]) + + def test_rejected_click_is_not_reported_as_cleared(self): + with mock.patch.object(auto_cycle, 'items', return_value=self.MODAL), \ + mock.patch.object(auto_cycle, 'click', return_value={'ok': False, 'error': '先 stop_task'}): + with self.assertRaisesRegex(RuntimeError, '先 stop_task'): + auto_cycle.clear_blocking_modal() + + def test_real_protocol_receives_cancel_only_after_task_stops(self): + # 使用真实 Server 的输入互斥逻辑, 避免假 click 掩盖“运行中点击被拒绝”。 + from lc_mcp.fake_engine import FakeEngine + from lc_mcp.protocol import Server + runner = mock.Mock() + runner.info = {'task': 'daily'} + runner.running.return_value = True + runner.status.return_value = {'ok': True, 'state': 'running'} + + def stop(): + runner.running.return_value = False + return {'ok': True, 'state': 'stopped'} + + runner.stop.side_effect = stop + engine = FakeEngine(frames=[self.MODAL]) + server = Server(engine, runner) + click_states = [] + + def click(x, y): + click_states.append(runner.running()) + return server.call_tool('click', {'x': x, 'y': y}) + + with mock.patch.object(auto_cycle, 'probe', lambda tool, args=None: server.call_tool(tool, args or {})), \ + mock.patch.object(auto_cycle, 'items', lambda: server.call_tool('get_state', {})['items']), \ + mock.patch.object(auto_cycle, 'click', click), \ + mock.patch.object(auto_cycle, 'log'), \ + mock.patch.object(auto_cycle.time, 'time', FakeTime().time): + ok, info, stalled = auto_cycle.poll_task('daily', 3600, sleep=lambda s: None) + self.assertEqual((ok, info, stalled), (False, 'RESOURCE_OUT', False)) + self.assertEqual(click_states, [False]) + self.assertEqual(engine.actions, [('click', 637, 612, 1)]) + runner.stop.assert_called_once() + + +class CycleReportTest(unittest.TestCase): + + def test_crashed_levelup_is_a_failed_report_with_diagnostics(self): + with tempfile.TemporaryDirectory() as tmp: + script = Path(tmp, 'broken_levelup.py') + script.write_text('raise RuntimeError("levelup crashed")\n', encoding='utf-8') + with mock.patch.multiple(auto_cycle, PY=sys.executable, LEVELUP=str(script)), \ + mock.patch.object(auto_cycle, 'lunacy_guard', return_value=(True, '读数一致')), \ + mock.patch.object(auto_cycle, 'ensure_team1', return_value=True), \ + mock.patch.object(auto_cycle, 'run_aalc', return_value=(True, '已完成')), \ + mock.patch.object(auto_cycle, 'goto_identities', return_value=True), \ + mock.patch.object(auto_cycle, 'report_grid', return_value='grid'), \ + mock.patch.object(auto_cycle.time, 'sleep'), \ + mock.patch('builtins.print'): + code = auto_cycle.main(['--report-dir', tmp]) + report = json.loads(next(Path(tmp).glob('cycle_*.json')).read_text(encoding='utf-8')) + output = next(Path(tmp).glob('cycle_*.log')).read_text(encoding='utf-8') + self.assertEqual(code, 1) + self.assertFalse(report['ok']) + self.assertIn('levelup crashed', output) + self.assertNotIn('无需升级', output) + self.assertIsNone(auto_cycle._log_file) + + +class LunacyReadTest(unittest.TestCase): + """狂气 OCR 是辅助核查, 读不到就是没校验, 所以要重试。 + + 2026-10-13 实测更麻烦的一种情况: 同一个画面上 OCR 会给出**两个不同的值** + (放大 6 倍肉眼确认余额是 6388, 而连读 5 次得到 6388 四次、8859 一次)。 + 8859 被当成基线后, 之后正确的 6388 反而被判成"已消耗"并中止整轮。 + 所以要取众数, 不是"最后读到什么就是什么"。 + """ + + MAIN = [{'text': 'Window', 'x': 993, 'y': 804}, + {'text': 'Sinners', 'x': 1093, 'y': 811}, + {'text': 'Drive', 'x': 1201, 'y': 808}, + {'text': 'Extract', 'x': 1389, 'y': 809}, + {'text': 'Dispense', 'x': 1486, 'y': 810}] + + def _frames(self, values): + """按顺序返回若干帧; 每帧都是主界面 + LUNACY + 该帧的值。""" + seq = list(values) + + def fake_items(): + v = seq.pop(0) if len(seq) > 1 else seq[0] + if v is None: + return list(self.MAIN) + return list(self.MAIN) + [{'text': 'LUNACY', 'x': 671, 'y': 795}, + {'text': str(v), 'x': 664, 'y': 823}] + + return fake_items + + def test_outlier_does_not_win(self): + # 5 次里 4 次 6388、1 次 8859 -> 取 6388 + with mock.patch.object(auto_cycle, 'items', self._frames([6388, 8859, 6388, 6388, 6388])), \ + mock.patch.object(auto_cycle.time, 'sleep', lambda s: None): + self.assertEqual(auto_cycle.read_lunacy(), 6388) + + def test_first_pair_does_not_override_later_majority(self): + with mock.patch.object(auto_cycle, 'items', self._frames([8859, 8859, 6388, 6388, 6388])), \ + mock.patch.object(auto_cycle.time, 'sleep'): + self.assertEqual(auto_cycle.read_lunacy(), 6388) + + def test_tied_readings_are_unknown(self): + with mock.patch.object(auto_cycle, 'items', self._frames([8859, 8859, 6388, 6388, None])), \ + mock.patch.object(auto_cycle.time, 'sleep'): + self.assertIsNone(auto_cycle.read_lunacy()) + + def test_truncated_label_and_low_balance_are_read(self): + frame = [{'text': 'UNACY', 'x': 671, 'y': 795}, + {'text': '0', 'x': 664, 'y': 823}] + with mock.patch.object(auto_cycle, 'items', return_value=frame), \ + mock.patch.object(auto_cycle.time, 'sleep'): + self.assertEqual(auto_cycle.read_lunacy(), 0) + + def test_retries_until_the_label_shows_up(self): + with mock.patch.object(auto_cycle, 'items', self._frames([None, None, 5864, 5864, 5864])), \ + mock.patch.object(auto_cycle.time, 'sleep', lambda s: None): + self.assertEqual(auto_cycle.read_lunacy(), 5864) + + def test_gives_up_when_never_agreeing(self): + # 每个值都只出现一次 -> 不采信, 宁可返回 None 也不要拿错值当基线 + with mock.patch.object(auto_cycle, 'items', self._frames([1000, 2000, 3000, 4000, 5000])), \ + mock.patch.object(auto_cycle.time, 'sleep', lambda s: None): + self.assertIsNone(auto_cycle.read_lunacy()) + + def test_reads_on_any_screen_not_just_main_menu(self): + # 曾经加过"只在主界面取数"的限制, 结果几乎总是读不到(轮次起止常停在副本/ + # 网格/结算页), 守卫直接跳过 —— 防线等于没有。众数投票已经能压住误读, + # 所以非主界面也读。 + fake = [{'text': 'LUNACY', 'x': 671, 'y': 795}, + {'text': '6388', 'x': 664, 'y': 823}, + {'text': 'Mirror Dungeon Result', 'x': 700, 'y': 400}] + with mock.patch.object(auto_cycle, 'items', lambda: fake), \ + mock.patch.object(auto_cycle.time, 'sleep', lambda s: None): + self.assertEqual(auto_cycle.read_lunacy(), 6388) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_background_window.py b/tests/test_background_window.py index 2ad4912..431d44b 100644 --- a/tests/test_background_window.py +++ b/tests/test_background_window.py @@ -48,7 +48,109 @@ class BackgroundRestoreTest(unittest.TestCase): engine.click(100, 200) engine._restore_background_position.assert_called_once_with((20, 30)) engine.auto.input_handler.set_mouse_pos.assert_not_called() - engine.screen.handle.set_window_transparent.assert_called_once_with(True) + + def test_click_restores_transparency_within_the_same_click(self): + """⛔ 透明度必须在本次点击内还原, 不能留给下一次截图。 + + 以前只在 background_screenshot 里恢复, 于是"点击 -> 截图 -> 点击 -> 截图" + 的高频交替会让游戏窗口在不可见/可见之间反复切换 —— 肉眼看就是画面一直抽搐。 + AALC 自己的 WindowMoveInput.mouse_click 根本不碰透明度, 所以它只"跳一下"。 + """ + engine = AalcEngine.__new__(AalcEngine) + engine.cfg = SimpleNamespace(simulator=False, win_input_type='window_move') + engine.auto = mock.Mock() + engine.screen = mock.Mock() + engine.auto.input_handler._set_window_pos.return_value = (20, 30) + engine._background_mouse = mock.Mock() + engine._restore_background_position = mock.Mock() + engine._prepare_input = mock.Mock() + constants = SimpleNamespace(WM_MOUSEMOVE=512, WM_LBUTTONDOWN=513, WM_LBUTTONUP=514) + with mock.patch.dict(sys.modules, win32con=constants), \ + mock.patch('lc_mcp.aalc_engine.time.sleep'): + engine.click(100, 200) + calls = [c.args[0] for c in engine.screen.handle.set_window_transparent.call_args_list] + self.assertEqual(calls, [True, False], '应当先设透明再立刻还原, 实际: %s' % calls) + + def test_click_leaves_no_transparency_when_it_raises(self): + """中途抛异常也必须把透明度还原, 否则窗口会一直隐形。""" + engine = AalcEngine.__new__(AalcEngine) + engine.cfg = SimpleNamespace(simulator=False, win_input_type='window_move') + engine.auto = mock.Mock() + engine.screen = mock.Mock() + engine.auto.input_handler._set_window_pos.return_value = (20, 30) + engine._background_mouse = mock.Mock() + engine._restore_background_position = mock.Mock() + engine._prepare_input = mock.Mock() + constants = SimpleNamespace(WM_MOUSEMOVE=512, WM_LBUTTONDOWN=513, WM_LBUTTONUP=514) + + # 第二次 sleep 时抛错 —— 那一步在按下之后的 try 里, finally 必须照常还原 + calls = {'n': 0} + + def sleep_then_fail(_): + calls['n'] += 1 + if calls['n'] >= 2: + raise RuntimeError('stopped') + + with mock.patch.dict(sys.modules, win32con=constants), \ + mock.patch('lc_mcp.aalc_engine.time.sleep', sleep_then_fail): + with self.assertRaises(RuntimeError): + engine.click(100, 200) + seen = [c.args[0] for c in engine.screen.handle.set_window_transparent.call_args_list] + self.assertIn(True, seen, '点击前应当设过透明') + self.assertEqual(seen[-1], False, '异常路径也要还原透明度, 实际: %s' % seen) + + def test_foreground_mode_never_touches_transparency(self): + """前台模式不需要搬窗口, 也就不该动透明度。""" + engine = AalcEngine.__new__(AalcEngine) + engine.cfg = SimpleNamespace(simulator=False, win_input_type='foreground') + engine.auto = mock.Mock() + engine.screen = mock.Mock() + engine.auto.input_handler.pos_offset.return_value = (100, 200) + engine._prepare_input = mock.Mock() + with mock.patch.dict(sys.modules, pyautogui=mock.Mock()), \ + mock.patch('lc_mcp.aalc_engine.time.sleep'): + engine.click(100, 200) + engine.screen.handle.set_window_transparent.assert_not_called() + + def test_window_cleanup_covers_setup_release_and_restore_failures(self): + constants = SimpleNamespace(WM_MOUSEMOVE=512, WM_LBUTTONDOWN=513, WM_LBUTTONUP=514) + for action in ('click', 'drag'): + for stage in ('move_window', 'activate', 'move_message', 'pre_press_sleep', + 'release', 'restore'): + with self.subTest(action=action, stage=stage): + engine = AalcEngine.__new__(AalcEngine) + engine.cfg = SimpleNamespace(simulator=False, win_input_type='window_move') + engine.auto, engine.screen = mock.Mock(), mock.Mock() + engine.auto.input_handler._set_window_pos.return_value = (20, 30) + engine._grab = mock.Mock(return_value=SimpleNamespace(width=800, height=600)) + engine._background_mouse = mock.Mock() + engine._restore_background_position = mock.Mock() + failure = RuntimeError(stage) + if stage == 'move_window': + engine.auto.input_handler._set_window_pos.side_effect = failure + elif stage == 'activate': + engine.auto.input_handler.set_active.side_effect = failure + elif stage == 'restore': + engine._restore_background_position.side_effect = failure + elif stage in ('move_message', 'release'): + message = 512 if stage == 'move_message' else 514 + def send(kind, *args, **kwargs): + if kind == message: + raise failure + engine._background_mouse.side_effect = send + with mock.patch.dict(sys.modules, win32con=constants), \ + mock.patch('lc_mcp.aalc_engine.time.sleep') as sleep: + if stage == 'pre_press_sleep': + sleep.side_effect = failure + with self.assertRaises(RuntimeError): + if action == 'click': + engine.click(100, 200) + else: + engine.drag(100, 100, 100, 300) + self.assertEqual(engine.screen.handle.set_window_transparent.call_args_list, + [mock.call(True), mock.call(False)]) + if stage != 'move_window': + engine._restore_background_position.assert_called_once_with((20, 30)) def test_restore_uses_noactivate_and_preserves_foreground(self): gui = mock.Mock() diff --git a/tests/test_convert_modules.py b/tests/test_convert_modules.py new file mode 100644 index 0000000..1787b4a --- /dev/null +++ b/tests/test_convert_modules.py @@ -0,0 +1,1133 @@ +# -*- coding: utf-8 -*- +"""convert_modules 的纯逻辑测试。 + +这个脚本会操作真实游戏, 所以这里只测不碰硬件的部分: 屏幕判定、资源读数、 +狂气相对比对用的解析。合成动作本身靠实机验证。 +""" +import os +import shutil +import sys +import tempfile +import unittest +from pathlib import Path +from unittest import mock + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts')) +import convert_modules as cm # noqa: E402 + + +class QuietLogMixin: + """把脚本的 log() 静音。 + + cm.log 会同时写 stdout 和 ~/lc_mcp/modules/convert.log —— 那是值守时要看的 + 真实运行记录, 不能被测试噪音污染(实测跑一次测试就往里塞了"服务未监听" + 和"等服务就绪超时"两条, 看起来像是真出事了)。 + """ + + def setUp(self): + patcher = mock.patch.object(cm, 'log', lambda m: None) + patcher.start() + self.addCleanup(patcher.stop) + + +class ScreenDetectTest(QuietLogMixin, unittest.TestCase): + + def test_main_menu_needs_enough_markers(self): + good = 'Window | Sinners | Drive | Theater | Extract | Dispense' + self.assertTrue(cm.on_main_menu(good)) + + def test_partial_screen_is_not_main_menu(self): + # 标题页只有一两个词, 不能当成主界面 —— 否则会在标题页上找模组图标 + self.assertFalse(cm.on_main_menu('TOUCH TO START | Clear all caches')) + self.assertFalse(cm.on_main_menu('Window | Sinners')) + + def test_panel_marker(self): + self.assertTrue(cm.panel_open('Charge Enkephalin | Modules | Use Lunacy')) + self.assertFalse(cm.panel_open('Window | Sinners | Drive')) + + +class LunacyLabelTest(QuietLogMixin, unittest.TestCase): + """⛔ 实测坑: OCR 会把 "LUNACY" 读成 "UNACY"(首字母 L 被吃掉)。 + + 原来写的是 `'LUNACY' in text`, 而 "UNACY" 不含 "LUNACY" —— 于是每次都被判成 + "读不到", 狂气校验退化成 None -> 跳过比对, 第三道防线形同虚设。同一块底栏的 + 体力却一直读得到, 所以只看日志很难发现, 是 dump 了底栏 OCR 才抓到的。 + """ + + def _with(self, its): + with mock.patch.object(cm, 'items', lambda: its): + return cm.find_lunacy_label() + + def test_matches_truncated_label(self): + lab = self._with([{'text': 'UNACY', 'x': 674, 'y': 795, 'w': 44, 'h': 22}]) + self.assertIsNotNone(lab) + self.assertEqual(lab['text'], 'UNACY') + + def test_matches_full_label(self): + self.assertIsNotNone(self._with([{'text': 'LUNACY', 'x': 670, 'y': 795}])) + + def test_full_read_works_with_truncated_label(self): + its = [{'text': 'UNACY', 'x': 674, 'y': 795, 'w': 44, 'h': 22}, + {'text': '9699', 'x': 664, 'y': 823, 'w': 70, 'h': 37}] + with mock.patch.object(cm, 'items', lambda: its), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + self.assertEqual(cm.read_lunacy(), 9699) + + def test_falls_back_to_position_when_label_unreadable(self): + # 标签整个读不出来时, 按位置兜底: 底栏那一带最靠左的短文本 + its = [{'text': '???', 'x': 674, 'y': 795, 'w': 44, 'h': 22}, + {'text': '9699', 'x': 664, 'y': 823, 'w': 70, 'h': 37}] + lab = self._with(its) + self.assertIsNotNone(lab) + with mock.patch.object(cm, 'items', lambda: its), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + self.assertEqual(cm.read_lunacy(), 9699) + + def test_no_label_at_all_returns_none(self): + its = [{'text': 'Window', 'x': 994, 'y': 809}] + self.assertIsNone(self._with(its)) + + +class ReadOwnedTest(QuietLogMixin, unittest.TestCase): + + def test_reads_owned(self): + its = [{'text': 'Enkephalin Module Owned 29', 'x': 820, 'y': 334}] + with mock.patch.object(cm, 'items', lambda: its): + self.assertEqual(cm.read_owned(), 29) + + def test_falls_back_to_bare_number(self): + its = [{'text': 'Owned', 'x': 820, 'y': 334}, + {'text': '29', 'x': 900, 'y': 334}] + with mock.patch.object(cm, 'items', lambda: its): + self.assertEqual(cm.read_owned(), 29) + + def test_none_when_absent(self): + with mock.patch.object(cm, 'items', lambda: [{'text': 'Window', 'x': 1, 'y': 800}]): + self.assertIsNone(cm.read_owned()) + + +class ReadEnkephalinTest(QuietLogMixin, unittest.TestCase): + """只认主界面底栏的 x/126。 + + 合成面板里也有一个 x/126, 但那是"合成后"的预览值 —— 拿它当余额会把 + "体力不足"误判成"还有体力", 于是每轮都去点确认。 + """ + + def test_reads_bottom_bar(self): + its = [{'text': '13/126', 'x': 451, 'y': 827}] + with mock.patch.object(cm, 'items', lambda: its): + self.assertEqual(cm.read_enkephalin(), 13) + + def test_ignores_panel_preview(self): + # y≈508 是合成面板里的预览, 不是余额 + its = [{'text': '132/126', 'x': 709, 'y': 508}] + with mock.patch.object(cm, 'items', lambda: its): + self.assertIsNone(cm.read_enkephalin()) + + def test_handles_spaces_and_garbage(self): + its = [{'text': '13 / 126', 'x': 451, 'y': 827}] + with mock.patch.object(cm, 'items', lambda: its): + self.assertEqual(cm.read_enkephalin(), 13) + + +class LunacyReadTest(QuietLogMixin, unittest.TestCase): + """狂气数字会有多种 OCR 误读; 同帧取数、多帧投票仍只提供核查线索。""" + + def _frames(self, values): + seq = list(values) + + def fake(): + v = seq.pop(0) if len(seq) > 1 else seq[0] + return [{'text': 'LUNACY', 'x': 670, 'y': 795}, + {'text': str(v), 'x': 664, 'y': 823}] + return fake + + def test_majority_wins_over_outlier(self): + with mock.patch.object(cm, 'items', self._frames([9699, 6636, 9699, 9699, 9699])), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + self.assertEqual(cm.read_lunacy(), 9699) + + def test_none_when_no_label(self): + with mock.patch.object(cm, 'items', lambda: [{'text': 'Window', 'x': 1, 'y': 800}]), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + self.assertIsNone(cm.read_lunacy()) + + def test_first_pair_does_not_override_later_majority(self): + with mock.patch.object(cm, 'items', self._frames([8859, 8859, 6388, 6388, 6388])), \ + mock.patch.object(cm.time, 'sleep'): + self.assertEqual(cm.read_lunacy(), 6388) + + def test_label_and_balance_must_come_from_the_same_frame(self): + # 数字和标签从未同时出现, 跨帧拼接会伪造一个有效读数。 + frames = [[{'text': '9999', 'x': 664, 'y': 823}], + [{'text': 'LUNACY', 'x': 670, 'y': 795}]] * 5 + with mock.patch.object(cm, 'items', side_effect=frames) as sample, \ + mock.patch.object(cm.time, 'sleep'): + self.assertIsNone(cm.read_lunacy()) + self.assertEqual(sample.call_count, 5) + + def test_tied_readings_are_unknown(self): + with mock.patch.object(cm, 'items', self._frames([8859, 8859, 6388, 6388, 1000])), \ + mock.patch.object(cm.time, 'sleep'): + self.assertIsNone(cm.read_lunacy()) + + +class EnkephalinGateTest(QuietLogMixin, unittest.TestCase): + """体力读数是"要不要合成"的闸门, 读不到时不能贸然去点合成。 + + 单次读成 None 的话, 原来那层"体力不足就收工"的判断会被整个跳过 —— 于是明明 + 只是体力不够, 却要去点合成、最后报成 FAIL(退出码 1), 给值守留下一条误导性 + 的失败记录。底栏淡入时读不到是实测发生过的(2026-10-16 11:01 的狂气读数)。 + + ⛔ main() 会把报告写进 ~/lc_mcp/modules/convert_*.json —— 那是值守要看的历史。 + 调用时必须把 --report-dir 指到临时目录, 否则测试会伪造出一批 + "读不到体力读数" 的假记录(实测已经产生过 7 条)。 + """ + + def _main(self, enk_seq): + seq = list(enk_seq) + called = [] + tmp = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, tmp, True) + with mock.patch.object(cm, 'read_enkephalin', lambda: seq.pop(0) if seq else None), \ + mock.patch.object(cm, 'read_lunacy', lambda **k: 9699), \ + mock.patch.object(cm, 'ensure_server', lambda *a: True), \ + mock.patch.object(cm, 'ensure_display', lambda *a: True), \ + mock.patch.object(cm, 'launch_game', lambda *a: True), \ + mock.patch.object(cm, 'wait_main_menu', lambda *a: True), \ + mock.patch.object(cm, 'ensure_window_size', lambda *a: (1600, 900)), \ + mock.patch.object(cm, 'close_panel', lambda: True), \ + mock.patch.object(cm, 'close_game', lambda: None), \ + mock.patch.object(cm, 'convert_once', + lambda tries=2: (called.append(1), + (True, '模组 29 -> 30 (+1)', 1))[1]), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + code = cm.main(['--report-dir', tmp]) + return code, bool(called) + + def test_enough_enkephalin_goes_ahead(self): + code, called = self._main([25]) + self.assertEqual(code, 0) + self.assertTrue(called) + + def test_not_enough_skips_without_touching_confirm(self): + code, called = self._main([4]) + self.assertEqual(code, 0, '体力不足是正常情况, 不该报失败') + self.assertFalse(called, '体力不足时绝不该去点合成') + + def test_unreadable_enkephalin_skips_instead_of_failing(self): + code, called = self._main([None, None, None, None]) + self.assertEqual(code, 0, '读不到就跳过, 不要报成 FAIL') + self.assertFalse(called) + + def test_read_is_retried(self): + """前几次读不到要接着读, 不能一次读不到就放弃。""" + code, called = self._main([None, None, 25]) + self.assertEqual(code, 0) + self.assertTrue(called, '重试后读到了就该正常合成') + + +class WindowSizeTest(QuietLogMixin, unittest.TestCase): + """RDP 断线重连会把客户区改小(实测 1600x900 -> 1278x719), 之后 OCR 明显变差。 + + AALC 自己的 WindowGuard 只在跑任务时才生效, 而这个脚本不跑任务, 所以要自己调。 + """ + + def test_missing_window_returns_none(self): + self.assertIsNone(cm.ensure_window_size(1600, 900, find=lambda: 0)) + + def test_correct_size_is_left_alone(self): + moved = [] + r = cm.ensure_window_size( + 1600, 900, + find=lambda: 123, + client=lambda h: (1600, 900), + resize=lambda *a: moved.append(a)) + self.assertEqual(r, (1600, 900)) + self.assertEqual(moved, [], '尺寸已经对了就不该去动窗口') + + def test_wrong_size_is_fixed(self): + sizes = iter([(1278, 719), (1600, 900)]) + moved = [] + r = cm.ensure_window_size( + 1600, 900, + find=lambda: 123, + client=lambda h: next(sizes), + resize=lambda *a: moved.append(a)) + self.assertEqual(r, (1600, 900)) + self.assertEqual(len(moved), 1, '尺寸不对时应该调一次') + # 传下去的是目标客户区尺寸和"调整前"的客户区 + self.assertEqual(moved[0][1:], (1600, 900, (1278, 719))) + + def test_reports_actual_size_even_if_resize_fails(self): + """调不动时返回真实值, 让调用方自己能告警 —— 不要假装调好了。""" + r = cm.ensure_window_size( + 1600, 900, + find=lambda: 123, + client=lambda h: (1278, 719), + resize=lambda *a: None) + self.assertEqual(r, (1278, 719)) + + +class LunacyVerdictTest(unittest.TestCase): + """⛔ 狂气那个数字的判据 —— 曾被"相对比对"的错假设坑过两次。 + + 2026-10-16 22:03 实测: 合成前读到 6636、合成后读到 9699, 复读仍是 9699, + 于是报了"狂气读数发生变化"并让整轮 FAIL。但那一轮脚本只点了模组图标和面板内的 + » / 确认, 从没碰 Use Lunacy 页签 —— **是误报**。 + + 根因: 我以为"同一画面的误读方式一致", 实际上真值 6636 被读过 6636 / 9699 / + 6388 / 8859 四种样子, 误读根本不固定。所以"前后不同"区分不了 + "真变了" 和 "换了个误读法"。 + + 现在只有一种情况算可疑: 读到从没见过的值。 + """ + + KNOWN = cm.LUNACY_KNOWN_READINGS + + def test_same_reading_is_clean(self): + suspicious, why = cm.lunacy_verdict(9699, 9699) + self.assertFalse(suspicious) + self.assertIn('一致', why) + + def test_the_real_false_alarm_is_now_clean(self): + """22:03 那次的真实读数 —— 必须不再被当成消费。""" + suspicious, why = cm.lunacy_verdict(6636, 9699) + self.assertFalse(suspicious, '6636 -> 9699 是已知的两种读法, 不是消费') + self.assertIn('已知读法', why) + + def test_jitter_between_known_readings_is_clean(self): + for a in self.KNOWN: + for b in self.KNOWN: + suspicious, why = cm.lunacy_verdict(a, b) + self.assertFalse(suspicious, '%s -> %s 都属已知读法, 不该报' % (a, b)) + + def test_unreadable_is_not_a_verdict(self): + suspicious, why = cm.lunacy_verdict(9699, None) + self.assertFalse(suspicious, '读不到不等于变了') + self.assertIn('未做比对', why) + + def test_unknown_value_is_suspicious(self): + """真的被消费(或获得)狂气时会读到陌生值, 那种要报出来。""" + suspicious, why = cm.lunacy_verdict(6636, 3000) + self.assertTrue(suspicious) + self.assertIn('不在已知读法', why) + + def test_unknown_value_on_the_before_side_also_alerts(self): + # 合成前就读到陌生值 -> 说明基线本身变了, 同样值得看 + suspicious, why = cm.lunacy_verdict(4000, 4000) + self.assertFalse(suspicious) # 前后一致就不管(可能只是 OCR 一直这么读) + suspicious2, _ = cm.lunacy_verdict(4000, 3000) + self.assertTrue(suspicious2) + + def test_new_balance_must_not_be_silently_folded_into_old_readings(self): + suspicious, _ = cm.lunacy_verdict(10000, 6636) + self.assertTrue(suspicious) + + +class LunacyFalseAlarmTest(QuietLogMixin, unittest.TestCase): + """整轮跑下来: 已知读法抖动不该让这一轮 FAIL。""" + + def _run(self, lunacy_seq): + s = list(lunacy_seq) + with mock.patch.object(cm, 'read_enkephalin', lambda: 25), \ + mock.patch.object(cm, 'ensure_server', lambda *a: True), \ + mock.patch.object(cm, 'ensure_display', lambda *a: True), \ + mock.patch.object(cm, 'launch_game', lambda *a: True), \ + mock.patch.object(cm, 'wait_main_menu', lambda *a: True), \ + mock.patch.object(cm, 'ensure_window_size', lambda *a: (1600, 900)), \ + mock.patch.object(cm, 'close_panel', lambda: True), \ + mock.patch.object(cm, 'close_game', lambda: None), \ + mock.patch.object(cm, 'convert_once', + lambda tries=2: (True, '模组 29 -> 30 (+1)', 1)), \ + mock.patch.object(cm.time, 'sleep', lambda s: None), \ + mock.patch.object(cm, 'read_lunacy', + lambda **k: s.pop(0) if s else None): + tmp = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, tmp, True) + return cm.main(['--report-dir', tmp]) + + def test_consistent_reading_passes(self): + self.assertEqual(self._run([9699, 9699]), 0) + + def test_real_false_alarm_case_now_passes(self): + """22:03 那次: 6636 -> 9699 -> 复读 9699。修好后这轮必须算成功。""" + self.assertEqual(self._run([6636, 9699, 9699]), 0, + '已知读法之间的抖动不该让整轮 FAIL') + + def test_unknown_value_still_fails_the_run(self): + self.assertEqual(self._run([6636, 3000, 3000]), 1, + '读到陌生值必须报出来') + + def test_unreadable_after_is_not_a_failure(self): + self.assertEqual(self._run([9699, None, None, None, None]), 0) + + +class ConvertAttemptVerifiedTest(QuietLogMixin, unittest.TestCase): + """⛔ 每一层"读不到"都不能被当成成功。 + + 原来这段有两个假成功分支: + if now is not None and before is None: return True, '模组现为 %d' + return True, '模组 %s -> %s' % (before, after) # 两边都可能是 None + 读不到起点就无从判断有没有换到, 却报了成功 —— 和"狂气读不到就静默跳过" + 是同一类毛病: 降级路径看起来没事, 实际什么都没验证。 + """ + + def _clock(self): + c = {'t': 0.0} + + def ft(): + c['t'] += 3.0 + return c['t'] + return ft + + def _attempt(self, owned_fn, on_tab=True): + with mock.patch.object(cm, 'open_panel', lambda *a, **k: True), \ + mock.patch.object(cm, 'on_modules_tab', lambda: on_tab), \ + mock.patch.object(cm, '_read_owned_once', owned_fn), \ + mock.patch.object(cm, 'click', lambda *a, **k: None), \ + mock.patch.object(cm.time, 'sleep', lambda s: None), \ + mock.patch.object(cm.time, 'time', self._clock()): + return cm._convert_attempt() + + def test_unreadable_start_is_not_success(self): + ok, info, got = self._attempt(lambda: None) + self.assertFalse(ok, '读不到起点绝不能报成功') + self.assertIn('读不到合成前', info) + + def test_increase_is_success(self): + seq = [29, 29, 30] + ok, info, got = self._attempt(lambda: seq.pop(0) if seq else 30) + self.assertTrue(ok) + self.assertEqual(got, 1) + self.assertIn('29 -> 30', info) + + def test_unchanged_is_failure(self): + ok, info, got = self._attempt(lambda: 29) + self.assertFalse(ok) + self.assertIn('没变', info) + + def test_decrease_is_not_a_successful_negative_conversion(self): + seq = [35] + ok, info, got = self._attempt(lambda: seq.pop(0) if seq else 33) + self.assertFalse(ok) + self.assertEqual(got, 0) + self.assertIn('读数下降', info) + + def test_unchanged_message_does_not_blame_enkephalin(self): + """走到这一步时体力 >= 20 已经确认过, 所以"体力不足"不可能是原因。 + + 文案里带上它只会把排查方向带偏 —— 上限和界面没响应才是真实可能。 + """ + ok, info, got = self._attempt(lambda: 29) + self.assertNotIn('体力不足', info) + self.assertIn('上限', info) + + def test_unreadable_after_is_not_success(self): + seq = [29] + [None] * 60 + ok, info, got = self._attempt(lambda: seq.pop(0) if seq else None) + self.assertFalse(ok, '合成后读不到也不能报成功') + self.assertIn('无法确认结果', info) + + def test_wrong_tab_refuses(self): + ok, info, got = self._attempt(lambda: 29, on_tab=False) + self.assertFalse(ok) + self.assertIn('Modules', info) + + +class ConvertRetryTest(QuietLogMixin, unittest.TestCase): + """"点了确认但模组没变"有两种原因, 该有不同的处置。 + + 1. 游戏限制了本轮/本日能换的数量 —— 正常, 重试也没用 + 2. 界面这一次没响应 —— 偶发, 重开面板通常就好 + 只做一次分不清这两者, 所以默认重试一次。 + """ + + def _run(self, attempts): + seq = list(attempts) + with mock.patch.object(cm, '_convert_attempt', lambda: seq.pop(0)), \ + mock.patch.object(cm, 'close_panel', lambda: True), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + return cm.convert_once() + + def test_retries_once_then_succeeds(self): + ok, info, got = self._run([(False, '点了确认但模组没变(29)', 0), + (True, '模组 29 -> 30 (+1)', 1)]) + self.assertTrue(ok) + self.assertEqual(got, 1) + self.assertIn('29 -> 30', info) + + def test_both_attempts_fail_reports_the_reason(self): + ok, info, got = self._run([(False, '点了确认但模组没变(29)', 0), + (False, '点了确认但模组没变(29)', 0)]) + self.assertFalse(ok) + self.assertIn('没变', info) + + def test_no_retry_when_first_succeeds(self): + calls = [] + + def once(): + calls.append(1) + return True, '模组 29 -> 30 (+1)', 1 + + with mock.patch.object(cm, '_convert_attempt', once): + cm.convert_once() + self.assertEqual(len(calls), 1, '成功了就不该再试') + + def test_retry_closes_the_panel_first(self): + """重试前必须把面板关掉重开 —— 不关的话还是那个没响应的界面。""" + closed = [] + seq = [(False, 'no', 0), (True, 'ok', 1)] + with mock.patch.object(cm, '_convert_attempt', lambda: seq.pop(0)), \ + mock.patch.object(cm, 'close_panel', lambda: closed.append(1) or True), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + cm.convert_once() + self.assertEqual(len(closed), 1) + + +class DisplayRecoveryTest(QuietLogMixin, unittest.TestCase): + """断线时桌面被拆掉, 截图全黑 —— 先修显示再动游戏。 + + 看门狗每分钟修一次, 但整轮合成只跑 3 分钟; 断线正好落在这 3 分钟里的话, + 这轮必然失败而下一轮要等 4 小时。实测 2026-10-16 一天内会话掉了两次。 + """ + + def test_ok_when_rendering(self): + with mock.patch.object(cm, 'render_ok', lambda: True), \ + mock.patch.object(cm.subprocess, 'run') as run: + self.assertTrue(cm.ensure_display()) + run.assert_not_called() # 正常时不该去折腾看门狗 + + def test_runs_watchdog_then_rechecks(self): + seq = [False, False, True] # 先挂两次, 第三次恢复 + calls = [] + + def fake_run(cmd, **kw): + calls.append(cmd) + return mock.Mock(returncode=0) + + # session_state 固定成 None: 否则诊断用的 `query session` 也走 subprocess, + # 会混进 calls 里把"看门狗跑了几次"数错 + with mock.patch.object(cm, 'render_ok', lambda: seq.pop(0)), \ + mock.patch.object(cm, 'session_state', lambda: None), \ + mock.patch.object(cm.subprocess, 'run', fake_run), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + self.assertTrue(cm.ensure_display(timeout_s=10)) + self.assertEqual(len(calls), 1, '应该跑一次看门狗') + self.assertIn('keep_display.ps1', ' '.join(calls[0])) + + def test_reports_failure_when_never_recovers(self): + with mock.patch.object(cm, 'render_ok', lambda: False), \ + mock.patch.object(cm, 'session_state', lambda: None), \ + mock.patch.object(cm.subprocess, 'run', lambda *a, **k: mock.Mock()), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + self.assertFalse(cm.ensure_display(timeout_s=0)) + + def test_watchdog_launch_failure_does_not_crash(self): + # 看门狗自己起不来时也要给出结论, 而不是抛异常 + def boom(*a, **k): + raise OSError('powershell not found') + + with mock.patch.object(cm, 'render_ok', lambda: False), \ + mock.patch.object(cm, 'session_state', lambda: None), \ + mock.patch.object(cm.subprocess, 'run', boom), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + self.assertFalse(cm.ensure_display(timeout_s=0)) + + +class ServerBootstrapTest(QuietLogMixin, unittest.TestCase): + """值守时没人手动救服务, 所以脚本要能自己确认/拉起 lc-mcp 的 TCP 服务。 + + 计划任务 LcMCPServer 配了 RestartCount=3, 但那只在进程"崩溃"时生效; + 服务压根没起来(或重启后还没登录)时, 合成会因为连不上而失败。 + """ + + def test_listening_returns_bool(self): + self.assertIsInstance(cm.server_listening(timeout=0.5), bool) + + def test_ensure_server_short_circuits_when_listening(self): + with mock.patch.object(cm, 'server_listening', lambda **kw: True): + self.assertTrue(cm.ensure_server(timeout_s=1)) + + def test_ensure_server_gives_up_when_never_listening(self): + calls = [] + with mock.patch.object(cm, 'server_listening', lambda **kw: False), \ + mock.patch.object(cm.subprocess, 'Popen', + lambda *a, **k: calls.append(a)), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + self.assertFalse(cm.ensure_server(timeout_s=0)) + self.assertEqual(len(calls), 1, '应该尝试拉起服务一次') + + def test_server_port_matches_the_project_default(self): + # 服务端 lc_mcp/server.py 用的就是 8765, 改这里要同步改 + self.assertEqual(cm.SERVER_PORT, 8765) + + +class NoRealReportPollutionTest(unittest.TestCase): + """测试不许往真实报告目录里写东西。 + + ⛔ 实测: EnkephalinGateTest 调 main() 时没指 --report-dir, 于是往 + ~/lc_mcp/modules/convert_*.json 里写了一批 elapsed_s=0 的假记录 + (内容是"读不到体力读数"), 一共 7 条。值守看报告时会以为真出过这些事。 + 日志那边已经用 QuietLogMixin 堵住了, 报告这边靠这条 AST 检查兜住。 + """ + + def test_every_main_call_passes_report_dir(self): + import ast + src = Path(__file__).read_text(encoding='utf-8') + tree = ast.parse(src) + offenders = [] + for node in ast.walk(tree): + if not isinstance(node, ast.Call): + continue + f = node.func + if (getattr(f, 'attr', None) != 'main' or + getattr(getattr(f, 'value', None), 'id', None) != 'cm'): + continue + flat = ast.dump(node) + if 'report-dir' not in flat: + offenders.append('line %d' % node.lineno) + self.assertFalse(offenders, + 'cm.main() 没带 --report-dir, 会写进真实报告目录: ' + + ', '.join(offenders)) + + +class CliRoutingTest(QuietLogMixin, unittest.TestCase): + """命令行参数的路由 —— main() 改了很多轮, 参数别在改动里被弄丢。 + + --report-dir 由 EnkephalinGateTest 间接覆盖(它每次都传), 这里补 --keep-game。 + """ + + def _main(self, argv): + closed = [] + done = [] + tmp = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, tmp, True) + with mock.patch.object(cm, 'read_enkephalin', lambda: 4), \ + mock.patch.object(cm, 'read_lunacy', lambda **k: 9699), \ + mock.patch.object(cm, 'ensure_server', lambda *a: True), \ + mock.patch.object(cm, 'ensure_display', lambda *a: True), \ + mock.patch.object(cm, 'launch_game', lambda *a: True), \ + mock.patch.object(cm, 'wait_main_menu', lambda *a: True), \ + mock.patch.object(cm, 'ensure_window_size', lambda *a: (1600, 900)), \ + mock.patch.object(cm, 'close_panel', lambda: True), \ + mock.patch.object(cm, 'close_game', lambda: closed.append(1)), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + code = cm.main(argv + ['--report-dir', tmp]) + done.append(os.listdir(tmp)) + return code, closed, done[0] + + def test_default_closes_the_game(self): + code, closed, reports = self._main([]) + self.assertEqual(code, 0) + self.assertEqual(len(closed), 1, '默认应该把游戏关掉') + + def test_keep_game_skips_closing(self): + code, closed, reports = self._main(['--keep-game']) + self.assertEqual(code, 0) + self.assertEqual(closed, [], '--keep-game 时不该关游戏') + + def test_a_skipped_run_does_not_reuse_previous_lunacy_result(self): + cm._result.update(lunacy_after=9699, lunacy_checked=True, converted=True) + code, _, _ = self._main([]) # 体力不足, 不合成也不做后读。 + self.assertEqual(code, 0) + self.assertNotIn('lunacy_after', cm._result) + self.assertNotIn('lunacy_checked', cm._result) + self.assertFalse(cm._result['converted']) + + def test_report_is_written_with_the_expected_fields(self): + """报告字段要齐全 —— 值守就靠 lunacy_* 和 converted 那几项下结论。""" + import json + closed = [] + tmp = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, tmp, True) + with mock.patch.object(cm, 'read_enkephalin', lambda: 25), \ + mock.patch.object(cm, 'read_lunacy', lambda **k: 9699), \ + mock.patch.object(cm, 'ensure_server', lambda *a: True), \ + mock.patch.object(cm, 'ensure_display', lambda *a: True), \ + mock.patch.object(cm, 'launch_game', lambda *a: True), \ + mock.patch.object(cm, 'wait_main_menu', lambda *a: True), \ + mock.patch.object(cm, 'ensure_window_size', lambda *a: (1600, 900)), \ + mock.patch.object(cm, 'close_panel', lambda: True), \ + mock.patch.object(cm, 'close_game', lambda: closed.append(1)), \ + mock.patch.object(cm, 'convert_once', + lambda tries=2: (True, '模组 1 -> 2 (+1)', 1)), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + cm.main(['--report-dir', tmp]) + name = os.listdir(tmp)[0] + self.assertRegex(name, r'^convert_\d{8}_\d{6}\.json$') + with open(os.path.join(tmp, name), encoding='utf-8') as fh: + r = json.load(fh) + for k in ('started', 'result', 'ok', 'elapsed_s', 'steps', + 'lunacy_before', 'lunacy_after', 'lunacy_checked', 'converted'): + self.assertIn(k, r, '报告缺字段 %s' % k) + self.assertTrue(r['converted']) + self.assertTrue(r['lunacy_checked']) + + def test_start_timeout_is_accepted(self): + code, closed, reports = self._main(['--start-timeout', '60']) + self.assertEqual(code, 0) + + +class RenderCheckTest(QuietLogMixin, unittest.TestCase): + """⛔ render_ok() 必须测 AALC 真正走的那条采集路径。 + + 原来只测屏幕 BitBlt(GetDC(0))。2026-10-22 实测它在 RDP 会话下会瞬时失败, 而 + AALC 走的是 background_screenshot(窗口 DC + PrintWindow), 那条路照样能截到图 —— + 结果是我的自检把本来能干活的轮次判成"截不到图"跳过了。 + """ + + def test_window_capture_alone_is_enough(self): + """窗口能采到就算能干活 —— 不该再去看屏幕那一路。""" + with mock.patch.object(cm, '_find_hwnd', lambda: 123), \ + mock.patch.object(cm, 'window_blit_ok', lambda hwnd: True), \ + mock.patch.object(cm, 'screen_blit_ok', + lambda: self.fail('窗口能采就不该再测屏幕')): + self.assertTrue(cm.render_ok()) + + def test_falls_back_to_screen_when_window_is_missing(self): + with mock.patch.object(cm, '_find_hwnd', lambda: 0), \ + mock.patch.object(cm, 'screen_blit_ok', lambda: True): + self.assertTrue(cm.render_ok()) + + def test_falls_back_to_screen_when_window_blit_fails(self): + with mock.patch.object(cm, '_find_hwnd', lambda: 123), \ + mock.patch.object(cm, 'window_blit_ok', lambda hwnd: False), \ + mock.patch.object(cm, 'screen_blit_ok', lambda: True): + self.assertTrue(cm.render_ok()) + + def test_reports_false_only_when_both_paths_fail(self): + with mock.patch.object(cm, '_find_hwnd', lambda: 123), \ + mock.patch.object(cm, 'window_blit_ok', lambda hwnd: False), \ + mock.patch.object(cm, 'screen_blit_ok', lambda: False): + self.assertFalse(cm.render_ok()) + + +class CaptureApiTest(QuietLogMixin, unittest.TestCase): + def test_window_capture_uses_printwindow_and_releases_gdi_objects(self): + import ctypes + for outcome in (1, 0, OSError('capture failed')): + with self.subTest(outcome=outcome): + api, gui, ui = mock.Mock(), mock.Mock(), mock.Mock() + gui.GetClientRect.return_value = (0, 0, 1280, 720) + gui.IsIconic.return_value = False + source = ui.CreateDCFromHandle.return_value + target = source.CreateCompatibleDC.return_value + bitmap = ui.CreateBitmap.return_value + previous = target.SelectObject.return_value + if isinstance(outcome, Exception): + api.user32.PrintWindow.side_effect = outcome + else: + api.user32.PrintWindow.return_value = outcome + with mock.patch.dict(sys.modules, win32gui=gui, win32ui=ui), \ + mock.patch.object(ctypes, 'windll', api, create=True): + self.assertEqual(cm.window_blit_ok(123), outcome == 1) + api.user32.PrintWindow.assert_called_once_with(123, target.GetSafeHdc(), 3) + target.BitBlt.assert_not_called() + bitmap.CreateCompatibleBitmap.assert_called_once_with(source, 1280, 720) + self.assertEqual(target.SelectObject.call_args_list, + [mock.call(bitmap), mock.call(previous)]) + target.DeleteDC.assert_called_once() + gui.DeleteObject.assert_called_once_with(bitmap.GetHandle()) + source.DeleteDC.assert_not_called() + gui.ReleaseDC.assert_called_once_with(123, gui.GetWindowDC()) + + def test_missing_dc_and_minimized_window_cannot_pass_capture(self): + gui = mock.Mock() + gui.IsIconic.return_value = True + with mock.patch.dict(sys.modules, win32gui=gui): + self.assertFalse(cm.window_blit_ok(123)) + gui.GetWindowDC.assert_not_called() + self.assertFalse(cm._blit_ok(0)) + + def test_screen_fallback_uses_bitblt(self): + gui, ui = mock.Mock(), mock.Mock() + source = ui.CreateDCFromHandle.return_value + target = source.CreateCompatibleDC.return_value + with mock.patch.dict(sys.modules, win32gui=gui, win32ui=ui): + self.assertTrue(cm.screen_blit_ok()) + target.BitBlt.assert_called_once_with((0, 0), (64, 64), source, (0, 0), 0x00CC0020) + gui.ReleaseDC.assert_called_once_with(0, gui.GetDC()) + + +class SessionTableTest(QuietLogMixin, unittest.TestCase): + """解析 `query session` —— 用来区分"截不到图"到底是哪种情况。 + + 两段输入都是**实测原样**(2026-10-17)。注意成功时返回码也是 1, 所以只能看输出。 + + ⛔ 必须继承 QuietLogMixin: 这里会调 ensure_display(), 它一 log 就写进真实的 + convert.log —— 又一次让值守日志里出现"看着像真出事"的行(这是第三次了)。 + """ + + # 用户从 RDP 连进来: console 画面是空的 -> BitBlt 失败, 看门狗按设计不会动 + RDP_IN = ( + ' SESSIONNAME USERNAME ID STATE TYPE DEVICE \n' + ' services 0 Disc \n' + '>rdp-tcp#70 YWS-HHH 1 Active \n' + ' console 3 Conn \n' + ' 31c5ce94259d4... 65536 Listen \n' + ' rdp-tcp 65537 Listen \n') + + # 已挂回 console: 显示正常 + CONSOLE = ( + ' SESSIONNAME USERNAME ID STATE TYPE DEVICE \n' + ' services 0 Disc \n' + '>console YWS-HHH 1 Active \n' + ' 31c5ce94259d4... 65536 Listen \n' + ' rdp-tcp 65537 Listen \n') + + def test_detects_active_rdp(self): + st = cm.parse_session_table(self.RDP_IN) + self.assertEqual(st['rdp_active'], 'rdp-tcp#70') + self.assertEqual(st['console'], '3') + self.assertEqual(st['current'], 'rdp-tcp#70') + + def test_console_only_has_no_active_rdp(self): + st = cm.parse_session_table(self.CONSOLE) + self.assertIsNone(st['rdp_active'], '没有 RDP 会话时不该报有') + self.assertEqual(st['console'], '1') + self.assertEqual(st['current'], 'console') + + def test_empty_or_garbage_is_safe(self): + for text in ('', 'garbage\n', 'only one\n'): + st = cm.parse_session_table(text) + self.assertIsNone(st['rdp_active']) + + def test_non_text_output_is_tolerated(self): + """query session 万一没给出文本, 也不能把整轮炸掉 —— 那只是诊断信息。""" + with mock.patch.object(cm.subprocess, 'run', + lambda *a, **k: mock.Mock(stdout=object())): + self.assertIsNone(cm.session_state()) + + def test_display_refuses_to_fight_an_active_rdp(self): + """RDP Active 时不能去跑看门狗(它不会动), 也不能硬踢人家下线。""" + ran = [] + with mock.patch.object(cm, 'render_ok', lambda: False), \ + mock.patch.object(cm, 'session_state', + lambda: {'current': 'rdp-tcp#70', + 'rdp_active': 'rdp-tcp#70', + 'console': '3'}), \ + mock.patch.object(cm.subprocess, 'run', + lambda *a, **k: ran.append(a)): + self.assertFalse(cm.ensure_display(timeout_s=1)) + self.assertEqual(ran, [], '不该去跑看门狗, 更不该踢人下线') + + +class LaunchGameRetryTest(QuietLogMixin, unittest.TestCase): + """⛔ 2026-10-17 02:03 实测: exe 起来就退了。 + + Steam 的 content_log 里 02:0x 毫无记录(上一轮 22:03:43 还有 "App Running"), + 应用事件日志也没报错, 游戏进程始终没出现; 而 13 分钟后手动启动 5 秒就起来了。 + 原来"点一次火干等 240 秒"的写法碰上一次静默失败就白丢一整轮。 + + 这里的时钟是假的 —— sleep 打桩成空函数后墙钟几乎不走, 内层循环会狂转, + 不控时钟就测不出"一次尝试等满 40 秒"这件事。 + """ + + class FakeTime: + def __init__(self): + self.t = 1000.0 + + def time(self): + return self.t + + def sleep(self, s): + self.t += s + + def _run(self, appear_after_call, tries=3, each=40): + """appear_after_call: 第几次 game_running 调用开始返回 True(None=永不)。""" + clock = self.FakeTime() + calls = {'n': 0} + pops = [] + + def running(): + calls['n'] += 1 + return appear_after_call is not None and calls['n'] >= appear_after_call + + with mock.patch.object(cm, 'game_running', running), \ + mock.patch.object(cm, '_popen_psutil', lambda n: []), \ + mock.patch.object(cm.subprocess, 'Popen', + lambda *a, **k: pops.append(a)), \ + mock.patch.object(cm.time, 'time', clock.time), \ + mock.patch.object(cm.time, 'sleep', clock.sleep): + ok = cm.launch_game(timeout_s=tries * each, tries=tries) + return ok, len(pops), clock.t + + def test_first_attempt_success_is_enough(self): + # 第 1 次调用是进入函数时的"已经在运行吗"检查(返回 False), + # 之后循环里的调用才代表"点火后进程出现了" —— 所以用 3。 + ok, pops, _ = self._run(appear_after_call=3) + self.assertTrue(ok) + self.assertEqual(pops, 1, '第一次就成功, 不该重复点火') + + def test_silent_failure_is_retried_and_can_recover(self): + """第一次点火后进程没出现 -> 必须再试, 第二次才出现。""" + ok, pops, _ = self._run(appear_after_call=None if False else 10) + self.assertTrue(ok, '重试之后应该成功') + self.assertGreater(pops, 1, '进程没出现时应该重新点火') + + def test_already_running_never_launches(self): + # 第 1 次检查就为真 -> 直接返回, 不点火 + ok, pops, _ = self._run(appear_after_call=1) + self.assertTrue(ok) + self.assertEqual(pops, 0, '已经在运行就不该点火') + + def test_gives_up_after_all_tries(self): + ok, pops, _ = self._run(appear_after_call=None) + self.assertFalse(ok) + self.assertEqual(pops, 3, '试满 3 次就放弃') + + def test_each_attempt_waits_its_share(self): + """总等待要摊到每次尝试上, 不能把 240 秒全花在第一次。""" + ok, pops, elapsed = self._run(appear_after_call=None, tries=3, each=40) + self.assertAlmostEqual(elapsed - 1000.0, 120.0, delta=1.0, + msg='3 次 x 40 秒 = 120 秒总等待') + + def test_already_running_does_not_relaunch(self): + with mock.patch.object(cm, 'game_running', lambda: True), \ + mock.patch.object(cm, '_popen_psutil', lambda n: []), \ + mock.patch.object(cm.subprocess, 'Popen', + lambda *a, **k: self.fail('已在运行还去点火')): + self.assertTrue(cm.launch_game()) + + +class OnModulesTabTest(QuietLogMixin, unittest.TestCase): + """确认停在免费合成页签 —— 判错的代价是整轮拒绝合成。 + + ⛔ 2026-10-16 18:03 真出过事: 原来只看"兑换区显示体力条 x/126", 而 OCR 会把相邻 + 几行合并成一个元素(那次 "Enkephalin Module Owned 31" 的框高 38、宽 351, 把下面 + 的 x/126 一起吞了), 判定失败 -> 拒绝合成 -> 那轮一个模块没换到。 + + 下面的元素是那次面板上**真实的 OCR 输出**, 不是我编的。 + """ + + # 18:03 那轮真实 dump(体力条被合并吞掉, 但问句完整成行) + REAL_FAILED_DUMP = [ + {'text': 'Modules', 'x': 589, 'y': 269, 'w': 85, 'h': 27}, + {'text': 'Use Lunacy', 'x': 749, 'y': 269, 'w': 101, 'h': 25}, + {'text': 'Use Boxes', 'x': 921, 'y': 271, 'w': 100, 'h': 24}, + {'text': 'Enkephalin Module Owned 31', 'x': 681, 'y': 331, 'w': 351, 'h': 38}, + {'text': '1 Enkephalin recovered inD2:50', 'x': 658, 'y': 462, 'w': 278, 'h': 26}, + {'text': 'Would you like to assemble Enkephalin Modules?', + 'x': 564, 'y': 598, 'w': 472, 'h': 27}, + {'text': 'X Cancel', 'x': 593, 'y': 652, 'w': 118, 'h': 31}, + {'text': 'Confirm', 'x': 926, 'y': 653, 'w': 92, 'h': 30}, + ] + + def _items(self, items): + return mock.patch.object(cm, 'items', lambda: items) + + def test_recognises_the_frame_that_used_to_fail(self): + with self._items(self.REAL_FAILED_DUMP): + self.assertTrue(cm.on_modules_tab(), + '这批元素曾让判定失败, 现在必须认得出来') + + def test_question_phrase_alone_is_enough(self): + with self._items([{'text': 'Would you like to assemble Enkephalin Modules?', + 'x': 564, 'y': 598, 'w': 472, 'h': 27}]): + self.assertTrue(cm.on_modules_tab()) + + def test_question_phrase_survives_ocr_space_noise(self): + # OCR 常在词间丢空格/加空格 + with self._items([{'text': 'WouldyouliketoassembleEnkephalinModules?', + 'x': 564, 'y': 598, 'w': 472, 'h': 27}]): + self.assertTrue(cm.on_modules_tab()) + + def test_gauge_is_still_a_valid_fallback(self): + with self._items([{'text': '132/26112/126', 'x': 709, 'y': 508, + 'w': 200, 'h': 30}]): + self.assertTrue(cm.on_modules_tab()) + + def test_unknown_screen_is_refused(self): + """两条信号都没有时必须拒绝 —— 宁可漏一轮, 也不在不知道哪个页签上点确认。""" + with self._items([{'text': 'Window', 'x': 994, 'y': 809}, + {'text': 'Inventory', 'x': 759, 'y': 834}]): + self.assertFalse(cm.on_modules_tab()) + + def test_tab_labels_alone_are_not_enough(self): + """只有三个页签名(面板刚开、还没点页签)时不能算数。 + + 页签名一直显示, 分不出当前选中哪个, 所以不能当依据。 + """ + with self._items([{'text': 'Modules', 'x': 589, 'y': 269}, + {'text': 'Use Lunacy', 'x': 749, 'y': 269}, + {'text': 'Use Boxes', 'x': 921, 'y': 271}]): + self.assertFalse(cm.on_modules_tab()) + + def test_refusal_prevents_clicking_confirm(self): + """面板开着但认不出页签时, 绝不点确认。 + + 夹具要含面板标记(Charge Enkephalin), 否则走的是"打不开面板"那条更早的路径, + 测不到这里真正想守的东西。 + """ + clicked = [] + panel_but_no_tab_info = [ + {'text': 'Charge Enkephalin', 'x': 700, 'y': 180, 'w': 200, 'h': 30}, + {'text': 'Modules', 'x': 589, 'y': 269, 'w': 85, 'h': 27}, + {'text': 'Use Lunacy', 'x': 749, 'y': 269, 'w': 101, 'h': 25}, + {'text': 'Confirm', 'x': 926, 'y': 653, 'w': 92, 'h': 30}, + ] + with self._items(panel_but_no_tab_info), \ + mock.patch.object(cm, 'click', lambda *a: clicked.append(a)), \ + mock.patch.object(cm, 'read_owned', lambda: 31), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + ok, info, got = cm._convert_attempt() + self.assertFalse(ok) + self.assertEqual(got, 0) + self.assertIn('页签', info, '应该报"认不出页签", 实际: %s' % info) + self.assertFalse(any(cm.BTN_CONFIRM == tuple(a) for a in clicked), + '判不出页签还点了确认: %s' % clicked) + + +class SafeClickTargetsTest(QuietLogMixin, unittest.TestCase): + """脚本能点到的地方必须逐个安全 —— 用户的两条硬约束就靠这几个坐标。 + + 整个脚本只有 7 处输入调用(其余全在合成面板内部或底栏模组图标上), 所以这个 + 审查面很小, 值得把它钉死: 任何新增的裸坐标点击都要有明确的理由。 + """ + + SAFE_LITERALS = { + (800, 450): '屏幕中央, 推进标题/剧情/公告 —— 任何界面上都无害', + (656, 670): 'BTN_CANCEL, 只关面板', + } + + def _calls(self): + import ast + src = (Path(__file__).resolve().parents[1] / 'scripts' / 'convert_modules.py') \ + .read_text(encoding='utf-8') + out = [] + for node in ast.walk(ast.parse(src)): + if isinstance(node, ast.Call): + name = getattr(node.func, 'id', None) or getattr(node.func, 'attr', None) + if name in ('click', 'long_press'): + out.append(node) + return out + + def test_literal_click_coordinates_are_whitelisted(self): + import ast + bad = [] + for node in self._calls(): + if len(node.args) != 2: + continue # click(*CONST) 形式, 由常量保证 + vals = [] + for a in node.args: + if isinstance(a, ast.Constant) and isinstance(a.value, int): + vals.append(a.value) + else: + vals = None + break + if not vals: + continue + if tuple(vals) not in self.SAFE_LITERALS: + bad.append('line %d: click(%d, %d)' % (node.lineno, *vals)) + self.assertFalse(bad, + '出现了未经审查的裸坐标点击, 请先确认它不会误触:\n ' + + '\n '.join(bad)) + + def test_advance_click_is_not_on_the_bottom_bar(self): + """推进用的点击不能落在底栏 —— 那里有 Inventory 等按钮。 + + ⛔ 曾经用 (800,830), 而 Inventory 按钮实测是 @(759,834) w=91(跨度 759~850), + 正好把它包住。画面恰在检查与点击之间切到主界面时就会误触。 + """ + import ast + for node in self._calls(): + if len(node.args) != 2: + continue + try: + x = node.args[0].value + y = node.args[1].value + except AttributeError: + continue + self.assertLess(y, 780, + 'line %d 的点击在 y=%d, 落在底栏区(>=780)' % (node.lineno, y)) + + +class NoDeadConstantsTest(unittest.TestCase): + """顶层的全大写常量必须真的被用到。 + + 删过一个 TAB_USE_BOXES(界面上的第三个页签, 本项目不用) —— 它从来没被引用过。 + 留着它的坏处不是占地方, 而是**会让人以为某条代码路径处理了它**。 + 死代码比没有更糟, 这条测试把口子堵上。 + + 统计范围包含测试文件: 有些常量(比如 USE_LUNACY_TAB)只被测试引用, 那是有意的 + —— 它的存在就是为了让"绝不许点"这件事有个可断言的锚点。 + """ + + def test_every_module_level_constant_is_referenced(self): + import ast + root = Path(__file__).resolve().parents[1] + src = (root / 'scripts' / 'convert_modules.py').read_text(encoding='utf-8') + tree = ast.parse(src) + + names = [] + for node in tree.body: + if isinstance(node, ast.Assign): + for t in node.targets: + if isinstance(t, ast.Name) and t.id.isupper(): + names.append(t.id) + + others = ((root / 'scripts' / 'convert_modules.py').read_text(encoding='utf-8'), + (root / 'tests' / 'test_convert_modules.py').read_text(encoding='utf-8')) + dead = [] + for n in names: + uses = 0 + for text in others: + for line in text.splitlines(): + s = line.strip() + if s.startswith(n + ' =') or s.startswith(n + '='): + continue # 定义行本身不算 + if n in line: + uses += 1 + if uses == 0: + dead.append(n) + self.assertFalse(dead, '这些常量从没被引用过, 请删掉或说明理由: ' + ', '.join(dead)) + + +class ForbiddenCoordinateTest(QuietLogMixin, unittest.TestCase): + """Use Lunacy 页签的坐标只能用于"确认没点到它", 不能出现在任何点击路径上。 + + 这条做成测试, 是因为以后改动布局时很容易顺手把它接进某个分支 —— + 那是一步就能花掉狂气的操作。用 AST 查实参, 而不是查文本: 文本里 + 文档说明本来就会提到这个常量名。 + """ + + def _source(self): + return (Path(__file__).resolve().parents[1] / 'scripts' / 'convert_modules.py') \ + .read_text(encoding='utf-8') + + def test_no_click_call_passes_the_use_lunacy_tab(self): + import ast + tree = ast.parse(self._source()) + offenders = [] + for node in ast.walk(tree): + if not isinstance(node, ast.Call): + continue + f = node.func + name = getattr(f, 'id', None) or getattr(f, 'attr', None) + if name != 'click': + continue + for arg in list(node.args): + # click(*USE_LUNACY_TAB) 或 click(USE_LUNACY_TAB[0], ...) + if isinstance(arg, ast.Starred): + arg = arg.value + if isinstance(arg, ast.Name) and arg.id == 'USE_LUNACY_TAB': + offenders.append('line %d' % node.lineno) + if isinstance(arg, ast.Subscript) and \ + getattr(arg.value, 'id', None) == 'USE_LUNACY_TAB': + offenders.append('line %d' % node.lineno) + self.assertFalse(offenders, 'click() 用到了 Use Lunacy 页签坐标: ' + ', '.join(offenders)) + + def test_the_constant_still_exists_and_is_where_we_think(self): + """万一布局变了, 这条会提醒重新量坐标, 而不是让上面那条静静地失效。 + + 只锁"我们会点的那个"和"绝不能点的那个"。Use Boxes 的坐标只写在源码注释里 + —— 本项目不用它, 所以不定义常量(定义了却没人用, 会让人以为某条路径处理了它)。 + """ + self.assertEqual(cm.USE_LUNACY_TAB, (797, 283)) + self.assertLess(cm.TAB_MODULES[0], cm.USE_LUNACY_TAB[0]) # Modules 在左 + self.assertAlmostEqual(cm.TAB_MODULES[1], cm.USE_LUNACY_TAB[1], delta=5) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_doc_refs.py b/tests/test_doc_refs.py new file mode 100644 index 0000000..9e03fda --- /dev/null +++ b/tests/test_doc_refs.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +"""文档里引用的脚本/文件必须真实存在。 + +文档漂移是最难发现的一类问题: README 说"跑 install_xxx.ps1",而那个脚本早改名了 —— +读到的人会直接卡住, 而代码测试全绿。这个仓库的 README 就曾经写着 +"每 5 分钟的会话看门狗 + 每天 05:30 一轮", 而实际早改成了 1 分钟 + 每 N 小时一轮。 + +这里只做机械检查: 文档中形如 scripts/xxx 或 docs/xxx.md 的路径必须存在。 +判断"描述是否过时"做不到, 但"引用的东西还在不在"是能查的。 +""" +import re +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +DOCS = ['README.md', 'docs/WATCH.md'] +# 只认仓库内的 scripts/ 与 docs/ 路径。 +# 不要收 lc_mcp/ —— 文档里的 ~/lc_mcp/modules/convert.log 之类是**运行期产物**, +# 在用户主目录下, 本来就不该出现在仓库里(第一版这么写导致误报)。 +PATH_RE = re.compile(r'\b((?:scripts|docs)/[A-Za-z0-9_./-]+\.\w+)\b') + + +class DocReferenceTest(unittest.TestCase): + + def refs(self, path): + text = (ROOT / path).read_text(encoding='utf-8') + return sorted(set(PATH_RE.findall(text))) + + def test_docs_exist(self): + for d in DOCS: + self.assertTrue((ROOT / d).exists(), '%s 不见了' % d) + + def test_referenced_files_exist(self): + missing = [] + for d in DOCS: + for ref in self.refs(d): + if not (ROOT / ref).exists(): + missing.append('%s -> %s' % (d, ref)) + self.assertFalse(missing, + '文档引用了不存在的文件:\n ' + '\n '.join(missing)) + + def test_readme_points_at_the_watch_guide(self): + """值守手册必须能从入口找到, 否则写了等于没写。""" + text = (ROOT / 'README.md').read_text(encoding='utf-8') + self.assertIn('docs/WATCH.md', text) + + def test_watch_guide_mentions_both_tasks(self): + text = (ROOT / 'docs/WATCH.md').read_text(encoding='utf-8') + for name in ('LcMCPConvertModules', 'LcKeepDisplay', 'LcMCPServer', 'LcMCPDailyCycle'): + self.assertIn(name, text, '值守手册没提到 %s' % name) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_driver_input.py b/tests/test_driver_input.py new file mode 100644 index 0000000..c79afe1 --- /dev/null +++ b/tests/test_driver_input.py @@ -0,0 +1,459 @@ +# -*- coding: utf-8 -*- +"""驱动级输入接管。 + +⛔ 这个模块的每一条"拒绝"都比"接管"更重要: 接管错了会让任务点错地方, +而拒绝只是继续用原来的注入方式。所以测试重点放在 preflight 的各种拒绝条件上。 + +背景(2026-10-22 实测): + * RDP 独立会话不能靠前台窗口判定, 必须核对进程与 console 会话 ID。 + * 指针加速开着时 counts 和像素不成比例(+100/+200/+400 -> -45/-3/-3 像素), + 关掉后严格 1:1。所以加速没关时不该给出"差不多"的位置。 +""" +import sys +import os +import ast +import inspect +import threading +import unittest +from pathlib import Path +from types import SimpleNamespace +from unittest import mock + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +from lc_mcp import driver_input as di # noqa: E402 +from lc_mcp import aalc_patches as ap # noqa: E402 + + +class PreflightTest(unittest.TestCase): + """能不能用, 必须说得清楚; 不能用时一条都不能含糊。""" + + def _drv(self, dll_ok=True, fg=True, accel=False, console=True): + d = di.DriverInput(dll_path='X.dll', log=lambda m: None) + d._dll = mock.Mock() + d._open = dll_ok + with mock.patch.object(di, 'has_foreground', lambda: fg), \ + mock.patch.object(di, 'is_console_session', lambda: console), \ + mock.patch.object(di, 'acceleration_on', lambda: accel): + return d.preflight() + + def test_ok_when_everything_is_right(self): + ok, why = self._drv() + self.assertTrue(ok) + self.assertEqual(why, 'ok') + + def test_refuses_without_driver(self): + ok, why = self._drv(dll_ok=False) + self.assertFalse(ok) + self.assertIn('device_open', why) + + def test_refuses_in_a_session_without_foreground(self): + """RDP 独立会话的典型特征 —— 这种会话里驱动级输入无效。""" + ok, why = self._drv(fg=False) + self.assertFalse(ok) + self.assertIn('前台窗口', why) + + def test_remote_session_is_rejected_even_with_foreground(self): + ok, why = self._drv(console=False, fg=True) + self.assertFalse(ok) + self.assertIn('console', why) + + def test_refuses_when_acceleration_is_on(self): + ok, why = self._drv(accel=True) + self.assertFalse(ok) + self.assertIn('加速', why) + + def test_refuses_missing_dll_file(self): + d = di.DriverInput(dll_path=r'Z:\nope\nope.dll', log=lambda m: None) + self.assertFalse(d.open()) + self.assertFalse(d.ready) + + +class MoveToTest(unittest.TestCase): + """定位必须是闭环: 发位移 -> 读回 -> 不够再发。不依赖标定常数。""" + + def test_converges_when_moves_are_exact(self): + pos = {'v': (0, 0)} + d = di.DriverInput(dll_path='X.dll', log=lambda m: None) + d._dll = mock.Mock() + d._open = True + + def moveR(dx, dy, _): + pos['v'] = (pos['v'][0] + dx, pos['v'][1] + dy) + + d._dll.moveR.side_effect = moveR + with mock.patch.object(di, 'get_cursor', lambda: pos['v']), \ + mock.patch.object(di.time, 'sleep', lambda s: None): + self.assertTrue(d.move_to(300, 200)) + self.assertEqual(pos['v'], (300, 200)) + + def test_gives_up_when_moves_do_nothing(self): + """驱动不理人时不能假称到位 —— 那样会点错地方。""" + d = di.DriverInput(dll_path='X.dll', log=lambda m: None) + d._dll = mock.Mock() + d._open = True + with mock.patch.object(di, 'get_cursor', lambda: (0, 0)), \ + mock.patch.object(di.time, 'sleep', lambda s: None): + self.assertFalse(d.move_to(300, 200, iters=4)) + + def test_tolerance_is_respected(self): + """已经在容差内就不该再发位移 —— 白折腾还容易引入抖动。""" + d = di.DriverInput(dll_path='X.dll', log=lambda m: None) + d._dll = mock.Mock() + d._open = True + with mock.patch.object(di, 'get_cursor', lambda: (100, 100)), \ + mock.patch.object(di.time, 'sleep', lambda s: None): + self.assertTrue(d.move_to(101, 101, tol=1)) + self.assertEqual(d._dll.moveR.call_count, 0, '容差内不该发位移') + + def test_out_of_tolerance_does_move(self): + """超出容差就必须尝试移动, 只是驱动不动时要如实返回失败。""" + d = di.DriverInput(dll_path='X.dll', log=lambda m: None) + d._dll = mock.Mock() + d._open = True + with mock.patch.object(di, 'get_cursor', lambda: (100, 100)), \ + mock.patch.object(di.time, 'sleep', lambda s: None): + self.assertFalse(d.move_to(105, 105, tol=1, iters=3)) + self.assertGreater(d._dll.moveR.call_count, 0) + + +class ClickTest(unittest.TestCase): + """没到位置就绝不点。""" + + def _drv(self, reachable): + d = di.DriverInput(dll_path='X.dll', log=lambda m: None) + d._dll = mock.Mock() + d._open = True + return d + + def test_clicks_only_after_positioning(self): + pos = {'v': (0, 0)} + d = self._drv(True) + d._dll.moveR.side_effect = lambda dx, dy, _: pos.update( + {'v': (pos['v'][0] + dx, pos['v'][1] + dy)}) + with mock.patch.object(di, 'get_cursor', lambda: pos['v']), \ + mock.patch.object(di.time, 'sleep', lambda s: None): + self.assertTrue(d.click(500, 400)) + self.assertEqual(pos['v'], (500, 400)) + d._dll.mouse_down.assert_called_once_with(1) + d._dll.mouse_up.assert_called_once_with(1) + + def test_never_clicks_when_positioning_fails(self): + d = self._drv(False) + with mock.patch.object(di, 'get_cursor', lambda: (0, 0)), \ + mock.patch.object(di.time, 'sleep', lambda s: None): + self.assertFalse(d.click(500, 400)) + d._dll.mouse_down.assert_not_called() + d._dll.mouse_up.assert_not_called() + + +class InstallTest(unittest.TestCase): + """接管 AALC 的点击: 条件不满足时**一个都不许改**。""" + + def _auto(self): + auto = SimpleNamespace() + auto.input_handler = mock.Mock() + auto.mouse_click = auto.input_handler.mouse_click + return auto + + def test_refuses_quietly_when_preflight_fails(self): + auto = self._auto() + before = auto.input_handler + drv = mock.Mock() + drv.preflight.return_value = (False, '不是物理会话') + got = ap.install_driver_click(auto, mock.Mock(), driver=drv, log=lambda m: None) + self.assertIsNone(got) + self.assertIs(auto.input_handler, before, '条件不满足就不该换 handler') + + def test_rebinds_the_aliases_captured_at_init(self): + """automation.py 初始化时把方法绑成了别名, 光换 handler 影响不到那些别名。""" + auto = self._auto() + old_click = auto.mouse_click + drv = mock.Mock() + drv.preflight.return_value = (True, 'ok') + got = ap.install_driver_click(auto, mock.Mock(), driver=drv, log=lambda m: None) + self.assertIs(got, drv) + self.assertIsNot(auto.mouse_click, old_click, '别名必须重绑') + + def test_proxy_other_methods_fall_through(self): + """拖拽/滑动/滚轮等仍走 AALC 原逻辑, 不能被吞掉。""" + handler = mock.Mock() + proxy = ap.DriverClickProxy(handler, mock.Mock(), mock.Mock(), log=lambda m: None) + proxy.mouse_drag(10, 20, 0.5, 0, 100, True) + handler.mouse_drag.assert_called_once() + proxy.wait_pause() + handler.wait_pause.assert_called_once() + + +class ClientToScreenTest(unittest.TestCase): + + def test_uses_client_to_screen(self): + def fake(hwnd, byref_pt): + ptr = byref_pt._obj + ptr.x, ptr.y = ptr.x + 100, ptr.y + 50 + return 1 + + api = mock.Mock() + api.user32.ClientToScreen.side_effect = fake + with mock.patch.object(di, '_win_library', side_effect=lambda name: getattr(api, name)): + self.assertEqual(di.client_to_screen(123, 7, 9), (107, 59)) + + +def vendor_auto(): + """执行 vendor 的真实接线与交互门方法, 只隔离 Windows 输入后端。""" + root = Path(__file__).resolve().parents[1] / 'vendor/aalc/module/automation' + abstract = ast.parse((root / 'input_handlers/__init__.py').read_text()) + abstract.body = [n for n in abstract.body if isinstance(n, ast.ClassDef)] + namespace = {'log': mock.Mock(), 'sleep': lambda _: None, 'time': lambda: 0} + exec(compile(abstract, str(root / 'input_handlers/__init__.py'), 'exec'), namespace) + base = namespace['AbstractInput'] + + class Handler(base): + def mouse_click(self, *args, **kwargs): + raise AssertionError('旧点击后端不应被调用') + + def mouse_click_blank(self, *args, **kwargs): + raise AssertionError('空白点击不应回落到旧后端') + + source = ast.parse((root / 'automation.py').read_text()) + cls = next(n for n in source.body if isinstance(n, ast.ClassDef) and n.name == 'Automation') + keep = {'init_input', '_run_business_interaction', 'monitor_mouse_click', + 'suspend_interactions', 'resume_interactions'} + cls.body = [n for n in cls.body if isinstance(n, ast.FunctionDef) and n.name in keep] + cls.keywords = [] + namespace = {'__name__': 'module.automation.automation', '__package__': 'module.automation', + 'inspect': inspect, 'AbstractInput': base, 'log': mock.Mock(), + 'cfg': SimpleNamespace(simulator=False, win_input_type='foreground', + memory_protection=False), 'GATE_WAIT_TIMEOUT': 30} + exec(compile(ast.Module(body=[cls], type_ignores=[]), str(root / 'automation.py'), 'exec'), namespace) + auto = namespace['Automation']() + auto.input_handler = None + auto._input_lock = threading.RLock() + auto._interaction_gate = threading.Event() + auto._interaction_gate.set() + with mock.patch.dict(sys.modules, {'module.automation.input_handlers.input': + SimpleNamespace(Input=Handler)}): + auto.init_input() + return auto, Handler + + +class DriverWiringTest(unittest.TestCase): + def test_real_business_gate_and_monitor_share_the_input_lock(self): + auto, _ = vendor_auto() + drv = mock.Mock() + drv.preflight.return_value = (True, 'ok') + locked = [] + drv.click.side_effect = lambda *a, **k: locked.append(auto._input_lock._is_owned()) or True + ap.install_driver_click(auto, mock.Mock(), driver=drv, log=lambda _: None) + auto.suspend_interactions() + entered = threading.Event() + wait = auto._interaction_gate.wait + def waiting(*args, **kwargs): + entered.set() + return wait(*args, **kwargs) + with mock.patch.object(auto.input_handler, '_screen_pos', return_value=(10, 20)), \ + mock.patch.object(auto._interaction_gate, 'wait', side_effect=waiting): + worker = threading.Thread(target=auto.mouse_click, args=(10, 20), daemon=True) + worker.start() + try: + self.assertTrue(entered.wait(1), '业务点击必须等待交互门') + drv.click.assert_not_called() + # 监控点击允许绕过门, 但仍必须持有同一把锁。 + auto.monitor_mouse_click(10, 20) + finally: + auto.resume_interactions() + worker.join(2) + self.assertFalse(worker.is_alive()) + self.assertEqual(locked, [True, True]) + + def test_blank_click_uses_driver_and_move_back_is_honored(self): + auto, _ = vendor_auto() + drv = mock.Mock() + drv.preflight.return_value = (True, 'ok') + ap.install_driver_click(auto, mock.Mock(), driver=drv, log=lambda _: None) + with mock.patch.object(auto.input_handler, '_screen_pos', return_value=(10, 20)), \ + mock.patch.object(di, 'get_cursor', return_value=(90, 80)): + self.assertTrue(auto.mouse_click_blank((1, 2), times=2, move_back=True)) + drv.click.assert_called_once_with(10, 20, times=2) + drv.move_to.assert_called_once_with(90, 80) + + def test_all_task_and_reinitialization_reinstall_after_init(self): + auto, handler_type = vendor_auto() + scheme = SimpleNamespace(init_game=auto.init_input) + scheme.script_task = lambda: (scheme.init_game(), auto.mouse_click_blank()) + original = scheme.init_game + drv = mock.Mock() + drv.preflight.return_value = (True, 'ok') + with mock.patch.dict(os.environ, LCP_DRIVER_INPUT='1'), \ + mock.patch.dict(sys.modules, {'module.automation.input_handlers.input': + SimpleNamespace(Input=handler_type)}), \ + mock.patch.object(di, 'DriverInput', return_value=drv), \ + mock.patch.object(ap.DriverClickProxy, '_screen_pos', return_value=(10, 20)): + with ap.driver_click_tasks(scheme, auto, mock.Mock(), + SimpleNamespace(simulator=False), log=lambda _: None): + scheme.script_task() + first = auto.input_handler + scheme.script_task() + self.assertIsNot(auto.input_handler, first) + self.assertIsInstance(auto.input_handler, ap.DriverClickProxy) + self.assertEqual(drv.click.call_count, 2) + self.assertIs(scheme.init_game, original) + + def test_actual_task_entry_enables_driver_for_all_and_daily(self): + from lc_mcp import aalc_task + for task, problems in [('all', []), ('daily', []), ('all', ['invalid config'])]: + with self.subTest(task=task, problems=problems): + auto, handler_type = vendor_auto() + auto.clear_img_cache = mock.Mock() + auto.click_element = mock.Mock(return_value=False) + cfg = SimpleNamespace(simulator=False) + scheme = SimpleNamespace(init_game=auto.init_input) + scheme.script_task = lambda: (scheme.init_game(), auto.mouse_click(10, 20)) + scheme.Daily_task_wrapper = lambda **kw: lambda: auto.mouse_click(10, 20) + scheme.to_get_reward = scheme.Buy_enkephalin = scheme.Mirror_task = mock.Mock() + drv = mock.Mock() + drv.preflight.return_value = (True, 'ok') + modules = { + 'module.automation': SimpleNamespace(auto=auto), + 'module.automation.input_handlers.input': SimpleNamespace(Input=handler_type), + 'module.config': SimpleNamespace(cfg=cfg), + 'module.game_and_screen': SimpleNamespace(screen=mock.Mock()), + 'tasks.base': SimpleNamespace(script_task_scheme=scheme), + 'tasks.base.retry_monitor': SimpleNamespace(retry_monitor=mock.Mock()), + 'tasks.battle': SimpleNamespace(battle=mock.Mock()), + 'utils.path_manager': SimpleNamespace(path_manager=mock.Mock()), + } + with mock.patch.dict(sys.modules, modules), \ + mock.patch.dict(os.environ, LCP_DRIVER_INPUT='1', LCP_RESTORE_FILE=''), \ + mock.patch.object(aalc_task, 'bootstrap'), \ + mock.patch.object(aalc_task, 'install_exact_team_match'), \ + mock.patch.object(aalc_task, 'install_robust_set_foreground'), \ + mock.patch.object(aalc_task, 'WindowGuard'), \ + mock.patch.object(aalc_task.killswitch, 'install') as install_hotkey, \ + mock.patch.object(aalc_task, 'log'), \ + mock.patch.object(aalc_task.preflight, 'collect', return_value={}), \ + mock.patch.object(aalc_task.preflight, 'desktop_size', return_value=(1920, 1080)), \ + mock.patch.object(aalc_task.preflight, 'check', return_value=problems), \ + mock.patch.object(di, 'DriverInput', return_value=drv), \ + mock.patch.object(ap.DriverClickProxy, '_screen_pos', return_value=(10, 20)): + self.assertEqual(aalc_task.run(task, {}), 3 if problems else 0) + install_hotkey.return_value.stop.assert_called_once() + if problems: + drv.click.assert_not_called() + else: + drv.click.assert_called_once_with(10, 20, times=1) + install_hotkey.call_args.kwargs['on_stop']() + drv.emergency_stop.assert_called_once() + + def test_disabled_and_simulator_leave_initialization_unchanged(self): + for enabled, simulator in [('0', False), ('1', True)]: + with self.subTest(enabled=enabled, simulator=simulator): + scheme = SimpleNamespace(init_game=mock.Mock()) + original = scheme.init_game + with mock.patch.dict(os.environ, LCP_DRIVER_INPUT=enabled): + with ap.driver_click_tasks(scheme, mock.Mock(), mock.Mock(), + SimpleNamespace(simulator=simulator)): + self.assertIs(scheme.init_game, original) + + +class DriverFailureTest(unittest.TestCase): + def test_emergency_stop_releases_press_and_blocks_subsequent_clicks(self): + drv = di.DriverInput() + drv._open, drv._dll = True, mock.Mock() + with mock.patch.object(drv, 'move_to', return_value=True), \ + mock.patch.object(di.time, 'sleep', side_effect=lambda _: drv.emergency_stop()): + self.assertFalse(drv.click(10, 20, times=3)) + drv._dll.mouse_down.assert_called_once_with(1) + drv._dll.mouse_up.assert_called_with(1) + self.assertFalse(drv.ready) + self.assertFalse(drv.click(30, 40)) + self.assertFalse(drv.move_relative(20, 30)) + self.assertFalse(drv.down()) + drv._dll.moveR.assert_not_called() + self.assertEqual(drv._pressed, set()) + + def test_release_even_if_sleep_is_interrupted(self): + drv = di.DriverInput() + drv._open, drv._dll = True, mock.Mock() + with mock.patch.object(drv, 'move_to', return_value=True), \ + mock.patch.object(di.time, 'sleep', side_effect=InterruptedError): + with self.assertRaises(InterruptedError): + drv.click(1, 2) + drv._dll.mouse_up.assert_called_once_with(1) + + def test_release_even_if_coordinate_lookup_fails(self): + drv = mock.Mock() + proxy = ap.DriverClickProxy(mock.Mock(), drv, mock.Mock()) + with mock.patch.object(proxy, '_screen_pos', side_effect=OSError('closed')): + with self.assertRaises(OSError): + proxy.mouse_up(1, 2) + drv.up.assert_called_once_with(1) + + def test_no_physical_click_if_game_cannot_get_foreground(self): + drv = mock.Mock() + handle = SimpleNamespace(hwnd=123, isMinimized=False, setForeground=mock.Mock()) + proxy = ap.DriverClickProxy(mock.Mock(), drv, SimpleNamespace(handle=handle), log=lambda _: None) + with mock.patch.object(di, 'is_console_session', return_value=True), \ + mock.patch.object(di, 'foreground_window', return_value=999): + self.assertFalse(proxy.mouse_click(1, 2)) + drv.click.assert_not_called() + handle.setForeground.assert_called_once() + + def test_failed_windows_reads_do_not_become_zero_coordinates(self): + api = mock.Mock() + api.user32.ClientToScreen.return_value = 0 + api.user32.GetCursorPos.return_value = 0 + api.user32.SystemParametersInfoA.return_value = 0 + with mock.patch.object(di, '_win_library', side_effect=lambda name: getattr(api, name)): + for fn, args in [(di.client_to_screen, (123, 1, 2)), (di.get_cursor, ()), + (di.acceleration_on, ())]: + with self.subTest(function=fn.__name__), self.assertRaises(OSError): + fn(*args) + + def test_failed_environment_query_refuses_installation(self): + drv = di.DriverInput() + drv._open, drv._dll = True, mock.Mock() + with mock.patch.object(di, 'is_console_session', side_effect=OSError('session query failed')): + ok, reason = drv.preflight() + self.assertFalse(ok) + self.assertIn('session query failed', reason) + + def test_dll_without_mouse_exports_is_rejected(self): + drv = di.DriverInput() + with mock.patch.object(di.os.path, 'exists', return_value=True), \ + mock.patch.object(di.ctypes, 'CDLL', return_value=SimpleNamespace(device_open=lambda: 1)): + self.assertFalse(drv.open()) + self.assertFalse(drv.ready) + + def test_console_session_ids_are_compared(self): + api = mock.Mock() + def query(pid, sid): + sid._obj.value = 2 + return 1 + api.kernel32.ProcessIdToSessionId.side_effect = query + with mock.patch.object(di, '_win_library', side_effect=lambda name: getattr(api, name)): + for console, expected in [(2, True), (3, False), (0xFFFFFFFF, False)]: + api.kernel32.WTSGetActiveConsoleSessionId.return_value = console + self.assertEqual(di.is_console_session(), expected) + + +class ForegroundFallbackTest(unittest.TestCase): + def test_none_on_success_still_detaches_after_success_or_failure(self): + for failed in (False, True): + with self.subTest(failed=failed): + handle = SimpleNamespace(hwnd=123, setForeground=mock.Mock(side_effect=OSError)) + gui = mock.Mock() + gui.GetForegroundWindow.return_value = 456 + gui.SetForegroundWindow.side_effect = OSError if failed else None + process = mock.Mock() + process.GetWindowThreadProcessId.return_value = (11, 22) + process.AttachThreadInput.return_value = None + api = SimpleNamespace(GetCurrentThreadId=lambda: 33) + with mock.patch.dict(sys.modules, win32api=api, win32gui=gui, win32process=process): + ap.install_robust_set_foreground(SimpleNamespace(handle=handle), log=lambda _: None) + handle.setForeground() + self.assertEqual(process.AttachThreadInput.call_args_list, + [mock.call(33, 11, True), mock.call(33, 11, False)]) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_farm_status.py b/tests/test_farm_status.py new file mode 100644 index 0000000..877014e --- /dev/null +++ b/tests/test_farm_status.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +"""farm_status 的解析与汇总。 + +它只是读报告文件做统计, 不碰游戏, 所以用临时目录造几份 cycle_*.json 就能测。 +""" +import json +import os +import sys +import tempfile +import unittest +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts')) +import farm_status # noqa: E402 + + +def _report(ok, started, steps, elapsed=100): + return {'ok': ok, 'result': '一轮结束' if ok else '本轮失败', 'started': started, + 'elapsed_s': elapsed, 'steps': steps} + + +class SummarizeTest(unittest.TestCase): + + def setUp(self): + self.dir = tempfile.mkdtemp() + + def write(self, name, obj): + p = os.path.join(self.dir, name) + with open(p, 'w', encoding='utf-8') as f: + json.dump(obj, f, ensure_ascii=False) + return p + + def test_reads_and_orders_newest_first(self): + self.write('cycle_20260101_010101.json', _report(True, '2026-01-01 01:01:01', [])) + self.write('cycle_20260102_010101.json', _report(True, '2026-01-02 01:01:01', [])) + rows = farm_status.load_reports(self.dir) + self.assertEqual([r['started'] for r in rows], + ['2026-01-02 01:01:01', '2026-01-01 01:01:01']) + + def test_broken_json_is_skipped_not_fatal(self): + self.write('cycle_20260101_010101.json', _report(True, '2026-01-01 01:01:01', [])) + with open(os.path.join(self.dir, 'cycle_20260103_010101.json'), 'w', encoding='utf-8') as f: + f.write('{ this is not json') + rows = farm_status.load_reports(self.dir) + self.assertEqual(len(rows), 1) + + def test_failed_steps_are_collected(self): + steps = [{'step': '狂气校验', 'ok': True, 'info': '狂气 5864 未变', 'at': '00:00:01'}, + {'step': '刷材料', 'ok': True, 'info': 'succeeded', 'at': '00:22:00'}, + {'step': '升级/同步', 'ok': False, 'info': '升级: FAIL', 'at': '00:23:00'}] + self.write('cycle_20260101_010101.json', + _report(True, '2026-01-01 01:01:01', steps, elapsed=1400)) + rows = farm_status.summarize(farm_status.load_reports(self.dir)) + self.assertEqual(rows[0]['failed_steps'], ['升级/同步']) + self.assertEqual(rows[0]['lunacy'], '狂气 5864 未变') + # 单步失败不影响整轮, 这点在 2026-10-13 的实机里验证过 + self.assertTrue(rows[0]['ok']) + + def test_mins_formatting(self): + self.assertEqual(farm_status.fmt_mins(5038), '83:58') + self.assertEqual(farm_status.fmt_mins(0), '-') + self.assertEqual(farm_status.fmt_mins(None), '-') + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_killswitch.py b/tests/test_killswitch.py new file mode 100644 index 0000000..d7a0bb1 --- /dev/null +++ b/tests/test_killswitch.py @@ -0,0 +1,195 @@ +# -*- coding: utf-8 -*- +"""急停热键。 + +背景(2026-10-22, 用户提问"你执行脚本的时候我鼠标没法动,我怎么停止呢"): + +驱动级点击是闭环定位 —— 手一动, 下一次点击前会读到新位置、算出偏差、再把你推回 +目标点。所以任务跑起来时鼠标是"拔河"状态, 用户没法用鼠标去点停止按钮。键盘不受 +影响, 所以急停必须走键盘。 + +AALC 自带的 pause_hotkey 帮不上忙: 那个配置项只在 GUI(app/farming_interface.py) +里注册, lc_mcp 走命令行子进程, 那条路径上没有热键监听。这是本模块存在的原因。 +""" +import os +import sys +import threading +import tempfile +import time +import unittest +from pathlib import Path +from unittest import mock + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +from lc_mcp import killswitch # noqa: E402 + + +class KeySpecTest(unittest.TestCase): + + def test_wraps_plain_name(self): + self.assertEqual(killswitch._key_spec('f12'), '') + + def test_keeps_already_wrapped(self): + self.assertEqual(killswitch._key_spec(''), '') + + def test_lowercases_and_trims(self): + self.assertEqual(killswitch._key_spec(' F12 '), '') + + def test_empty_falls_back_to_default(self): + self.assertEqual(killswitch._key_spec(''), '') + self.assertEqual(killswitch._key_spec(None), '') + self.assertEqual(killswitch._key_spec(' '), '') + + +class InstallTest(unittest.TestCase): + """装不上不能把任务带崩,但必须说清楚怎么应急。""" + + def test_reports_when_pynput_is_missing(self): + lines = [] + with mock.patch.dict(sys.modules, {'pynput': None}): + got = killswitch.install(log=lines.append, key='f12') + self.assertIsNone(got) + joined = '\n'.join(lines) + self.assertIn('急停热键不可用', joined) + self.assertIn('Ctrl+Alt+Del', joined, '必须给出应急手段') + + def test_registers_the_configured_key(self): + listener = mock.Mock() + listener.daemon = False + fake_keyboard = mock.Mock() + fake_keyboard.GlobalHotKeys.return_value = listener + with mock.patch.dict(sys.modules, {'pynput': mock.Mock(keyboard=fake_keyboard), + 'pynput.keyboard': fake_keyboard}): + got = killswitch.install(log=lambda m: None, key='f11') + self.assertIs(got, listener) + fake_keyboard.GlobalHotKeys.assert_called_once() + self.assertIn('', fake_keyboard.GlobalHotKeys.call_args[0][0]) + listener.start.assert_called_once() + self.assertTrue(listener.daemon) + + def test_env_var_overrides_default_key(self): + listener = mock.Mock() + fake_keyboard = mock.Mock() + fake_keyboard.GlobalHotKeys.return_value = listener + with mock.patch.dict(os.environ, {'LCP_KILL_KEY': 'pause'}), \ + mock.patch.dict(sys.modules, {'pynput': mock.Mock(keyboard=fake_keyboard), + 'pynput.keyboard': fake_keyboard}): + killswitch.install(log=lambda m: None) + self.assertIn('', fake_keyboard.GlobalHotKeys.call_args[0][0]) + + +class ActivateTest(unittest.TestCase): + def _grab_handler(self, log=lambda _: None, on_stop=None): + listener = mock.Mock() + keyboard = mock.Mock() + keyboard.GlobalHotKeys.return_value = listener + with mock.patch.dict(sys.modules, {'pynput': mock.Mock(keyboard=keyboard)}): + killswitch.install(log=log, on_stop=on_stop) + return next(iter(keyboard.GlobalHotKeys.call_args.args[0].values())), listener + + def fire(self, handler, listener): + handler() + listener._lc_state['worker'].join(2) + self.assertFalse(listener._lc_state['worker'].is_alive()) + + def test_exits_with_user_abort_code_and_only_fires_once(self): + handler, listener = self._grab_handler() + with mock.patch.object(killswitch.os, '_exit') as fake_exit: + self.fire(handler, listener) + handler() + fake_exit.assert_called_once_with(killswitch.EXIT_CODE) + + def test_broken_log_cannot_disable_the_hotkey(self): + log = mock.Mock() + handler, listener = self._grab_handler(log=log) + log.reset_mock() + log.side_effect = OSError('closed log') + with mock.patch.object(killswitch.os, '_exit') as fake_exit: + self.fire(handler, listener) + fake_exit.assert_called_once_with(130) + log.assert_not_called() + + def test_releases_input_before_exiting_even_when_cleanup_raises(self): + calls = [] + def cleanup(): + calls.append('release') + raise OSError('driver disconnected') + handler, listener = self._grab_handler(on_stop=cleanup) + # 不让测试线程输出预期的异常 traceback。 + with mock.patch.object(killswitch.os, '_exit', side_effect=lambda code: calls.append(code)), \ + mock.patch.object(threading, 'excepthook'): + self.fire(handler, listener) + self.assertEqual(calls, ['release', 130]) + + def test_hung_cleanup_cannot_block_exit_deadline(self): + release, exited = threading.Event(), threading.Event() + handler, listener = self._grab_handler(on_stop=release.wait) + with mock.patch.object(killswitch.os, '_exit', side_effect=lambda code: exited.set()): + handler() + try: + self.assertTrue(exited.wait(2), '清理卡住也必须触发强退') + finally: + release.set() + listener._lc_state['worker'].join(2) + + def test_startup_message_explains_game_is_kept(self): + lines = [] + self._grab_handler(log=lines.append) + self.assertIn('游戏窗口保留', '\n'.join(lines)) + + def test_real_emergency_exit_is_reported_as_stopped(self): + from lc_mcp.tasks import TaskRunner + child = """ +import json, os, sys, time +from types import SimpleNamespace +from lc_mcp import killswitch +from lc_mcp.aalc_task import RESTORE_ENV +class Listener: + def __init__(self, bindings): self.activate = next(iter(bindings.values())) + def start(self): pass +sys.modules['pynput'] = SimpleNamespace(keyboard=SimpleNamespace(GlobalHotKeys=Listener)) +listener = killswitch.install(log=lambda msg: None) +with open(os.environ[RESTORE_ENV], 'w') as f: json.dump({'set_mirror_count': 1}, f) +listener.activate() +time.sleep(10) +""" + with tempfile.TemporaryDirectory() as tmp: + runner = TaskRunner(tmp, argv_factory=lambda t, p: [sys.executable, '-c', child]) + self.assertTrue(runner.start('mirror', {'count': 2})['ok']) + self.addCleanup(runner.proc.kill) + runner.proc.wait(timeout=5) + status = runner.status() + self.assertEqual((status['state'], status['exit_code']), ('stopped', 130)) + self.assertTrue(status['pending_restore'], '强退保留配置恢复文件, 下次启动前由服务处理') + + +class StopTest(unittest.TestCase): + + def test_stop_is_safe_on_none(self): + killswitch.stop(None) # 不该抛 + + def test_stop_calls_listener(self): + listener = mock.Mock() + killswitch.stop(listener) + listener.stop.assert_called_once() + + def test_listening_stops_on_return_and_exception(self): + for failure in (False, True): + listener = mock.Mock() + with self.subTest(failure=failure), \ + mock.patch.object(killswitch, 'install', return_value=listener): + try: + with killswitch.listening(): + if failure: + raise RuntimeError('task failed') + except RuntimeError: + pass + listener.stop.assert_called_once() + + def test_stop_swallows_listener_errors(self): + listener = mock.Mock() + listener.stop.side_effect = RuntimeError('boom') + killswitch.stop(listener) # 不该抛 + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_lc_mcp.py b/tests/test_lc_mcp.py index e840a2d..fc50425 100644 --- a/tests/test_lc_mcp.py +++ b/tests/test_lc_mcp.py @@ -674,6 +674,85 @@ class TaskErrorSurfaceTest(unittest.TestCase): self.assertEqual(status['state'], 'succeeded') self.assertNotIn('errors', status) + def test_early_battle_error_survives_later_debug_output(self): + # AALC 会在一场战斗失败后继续执行, 报错可能已不在最后 400 行/64 KiB。 + child = ('print("[ERROR] 超出最大尝试次数,未能进入战斗")\n' + 'for _ in range(5000): print("[DEBUG] 后续正常输出")\n' + 'print("[lc_mcp] task daily done")\n') + with tempfile.TemporaryDirectory() as d: + runner = TaskRunner(d, argv_factory=lambda t, p: [sys.executable, '-c', child]) + self.addCleanup(runner.stop) + self.assertTrue(runner.start('daily', {})['ok']) + runner.proc.wait(timeout=15) + status = runner.status(lines=1) + self.assertGreater(os.path.getsize(status['log']), 64 * 1024) + self.assertEqual((status['state'], status['exit_code']), ('succeeded', 0)) + self.assertEqual(status['log_tail'], ['[lc_mcp] task daily done']) + self.assertIn('未能进入战斗', status.get('errors', [''])[-1]) + + def test_full_scan_keeps_only_last_three_errors(self): + from lc_mcp.tasks import log_errors + with tempfile.TemporaryDirectory() as d: + path = os.path.join(d, 'task.log') + with open(path, 'w', encoding='utf-8') as f: + for n in range(5): + f.write('[ERROR] problem %d\n' % n) + f.write('[DEBUG] running\n' * 500) + f.write('Traceback (most recent call last):\n') + f.write('[DEBUG] cleanup\n' * 500) + self.assertEqual(log_errors(path), ['[ERROR] problem 3', '[ERROR] problem 4', + 'Traceback (most recent call last):']) + + def test_finished_result_survives_log_removal_and_resets_for_next_run(self): + with tempfile.TemporaryDirectory() as d: + runner = TaskRunner(d, argv_factory=lambda t, p: [sys.executable, '-c', self.CHILD]) + self.addCleanup(runner.stop) + runner.start('daily', {}) + runner.proc.wait(timeout=15) + first = runner.status() + os.remove(first['log']) + self.assertEqual(runner.status()['errors'], first['errors']) + runner.argv_factory = lambda t, p: [sys.executable, '-c', 'print("clean run")'] + runner.start('reward', {}) + runner.proc.wait(timeout=15) + self.assertNotIn('errors', runner.status()) + + +class TaskStallSurfaceTest(unittest.TestCase): + """空队伍卡死时进程健在、日志无报错, 只有编队人数检查在刷屏。""" + + @staticmethod + def child(repeats): + return ('import sys, time\n' + 'for _ in range(%d):\n' + ' sys.stdout.write("[DEBUG] tasks\\\\teams\\\\team_formation.py:225: ' + '对于配队人数OCR得到:0/5\\n")\n' + 'sys.stdout.flush()\n' + 'time.sleep(30)\n' % repeats) + + def status_while_running(self, repeats): + with tempfile.TemporaryDirectory() as d: + runner = TaskRunner(d, argv_factory=lambda t, p: [sys.executable, '-c', self.child(repeats)]) + self.assertTrue(runner.start('daily', {})['ok']) + try: + deadline = time.time() + 15 + while time.time() < deadline and repeats and not os.path.getsize(runner.info['log']): + time.sleep(0.05) + time.sleep(0.2) + return runner.status() + finally: + runner.stop() + + def test_repeated_empty_team_check_is_reported(self): + status = self.status_while_running(12) + self.assertEqual(status['state'], 'running') + self.assertEqual(status['stall'], {'empty_team': 12}) + + def test_occasional_check_is_not_a_stall(self): + status = self.status_while_running(3) + self.assertEqual(status['state'], 'running') + self.assertNotIn('stall', status) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_levelup.py b/tests/test_levelup.py new file mode 100644 index 0000000..875aca4 --- /dev/null +++ b/tests/test_levelup.py @@ -0,0 +1,242 @@ +from pathlib import Path +import sys +import unittest +from unittest import mock + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts')) +import lc_ui # noqa: E402 +import levelup # noqa: E402 + + +def shot(w, h, items=()): + return {'ok': True, 'screen': {'path': 'x.png', 'w': w, 'h': h}, + 'items': [dict(i) for i in items]} + + +class ScaleTest(unittest.TestCase): + """脚本坐标按 1600x900 写, 实际客户区可能是 1280x720 或 1920x1080。""" + + def setUp(self): + lc_ui._scale = None + + def test_720p_items_and_clicks_use_base_coordinates(self): + calls = [] + + def probe(tool, args=None, quiet=True): + calls.append((tool, args)) + return shot(1280, 720, [{'text': 'Level Up', 'x': 800, 'y': 400, 'w': 80, 'h': 20}]) + + with mock.patch.object(lc_ui, 'probe', probe): + item = lc_ui.items()[0] + lc_ui.click(1600, 900) + lc_ui.long_press(800, 450) + self.assertEqual((item['x'], item['y'], item['w']), (1000, 500, 100)) + self.assertEqual(calls[1], ('click', {'x': 1280, 'y': 720, 'times': 1})) + self.assertEqual(calls[2], ('drag', {'from_x': 640, 'from_y': 360, 'to_x': 640, 'to_y': 360})) + + def test_click_before_any_state_reads_client_size_first(self): + calls = [] + + def probe(tool, args=None, quiet=True): + calls.append((tool, args)) + return shot(1920, 1080) + + with mock.patch.object(lc_ui, 'probe', probe): + lc_ui.click(100, 100) + self.assertEqual(calls, [('get_state', None), ('click', {'x': 120, 'y': 120, 'times': 1})]) + + +class ProgressResultTest(unittest.TestCase): + + def run_progress(self, detail=True, level=40, uptie=True): + card = (0, 0, 300, 400, 40, True, 'identity') + with mock.patch.object(levelup, 'state', return_value={'items': []}), \ + mock.patch.object(levelup, 'scan_grid', return_value=[card]), \ + mock.patch.object(levelup, 'dismiss_modal', return_value=True), \ + mock.patch.object(levelup, 'long_press'), \ + mock.patch.object(levelup, 'click'), \ + mock.patch.object(levelup, 'detail_page_open', return_value=detail), \ + mock.patch.object(levelup, 'read_detail', return_value=(level, 'identity', None)), \ + mock.patch.object(levelup, 'do_level_up', return_value=(True, '等级增加')) as upgrade, \ + mock.patch.object(levelup, 'do_uptie', return_value=(uptie, '同步结果')), \ + mock.patch.object(levelup.time, 'sleep'), \ + mock.patch('builtins.print'): + code = levelup.cmd_progress(target=34) + return code, upgrade.call_count + + def test_unopened_details_are_not_a_successful_noop(self): + self.assertEqual(self.run_progress(detail=False), (1, 0)) + + def test_unreadable_details_do_not_trust_grid_level(self): + self.assertEqual(self.run_progress(level=None), (1, 0)) + + def test_verified_max_level_is_a_successful_noop(self): + self.assertEqual(self.run_progress(level=40), (0, 0)) + + def test_failed_uptie_is_a_failed_command(self): + self.assertEqual(self.run_progress(level=30, uptie=False), (1, 1)) + + def test_successful_upgrade_and_uptie(self): + self.assertEqual(self.run_progress(level=30), (0, 1)) + + +class Screens: + """按顺序返回预设画面的假 state(), 记录点击。""" + + def __init__(self, *screens): + self.screens = list(screens) + self.clicks = [] + self.keys = [] + + def state(self): + texts = self.screens.pop(0) if len(self.screens) > 1 else self.screens[0] + return {'items': [{'text': t, 'x': x, 'y': y} for t, x, y in texts]} + + def patch(self): + return mock.patch.multiple(levelup, state=self.state, time=mock.Mock(), + click=lambda *a, **k: self.clicks.append(a), + keypress=lambda k: self.keys.append(k)) + + +DETAIL = [('Level Up', 1164, 235), ('Uptie', 1367, 235), ('547/885', 400, 250)] +POWERUP = [('Owned:3', 900, 380), ('Owned:0', 900, 485), ('Owned:7', 900, 595), ('Cancel', 603, 670)] + + +class LevelUpVerdictTest(unittest.TestCase): + + def test_detail_page_without_exp_change_is_not_success(self): + # 旧逻辑只要回到详情页(有 Level Up / Uptie)就算成功 + screens = Screens(DETAIL, POWERUP, POWERUP, DETAIL, DETAIL) + with screens.patch(): + ok, desc = levelup.do_level_up(hint=17) + self.assertFalse(ok, desc) + + def test_level_increase_is_success(self): + after = [('Level Up', 1164, 235), ('Uptie', 1367, 235), ('100/1261', 400, 250)] + screens = Screens(DETAIL, POWERUP, POWERUP, after, after) + with screens.patch(): + ok, desc = levelup.do_level_up(hint=17) + self.assertTrue(ok, desc) + self.assertIn('17->19', desc) + + def test_popup_still_open_after_confirm_is_cancelled(self): + screens = Screens(DETAIL, POWERUP, POWERUP, POWERUP) + with screens.patch(): + ok, desc = levelup.do_level_up(hint=17) + self.assertFalse(ok) + self.assertEqual(screens.clicks[-1], levelup.POWERUP_CANCEL) + + def test_popup_still_open_but_level_rose_is_still_success(self): + """2026-10-13 实机: Zwei Lv.33 -> Lv.40(MAX), 券也扣了, 但 Confirm 后弹窗仍在。 + + 旧逻辑据此直接判 FAIL, 是假阴性。详情页的等级才是事实来源。 + """ + after = [('Level Up', 1164, 235), ('Uptie', 1367, 235), ('0/6075', 400, 250)] + # 注意 state() 的消耗次数: 详情页 x1, 弹窗打开 x1, ticket_balance() x1, + # 点完 MAX 再读 x1, Confirm 之后再读 x1 —— 所以弹窗要连给 4 次。 + screens = Screens(DETAIL, POWERUP, POWERUP, POWERUP, POWERUP, after, after) + with screens.patch(): + ok, desc = levelup.do_level_up(hint=33) + self.assertTrue(ok, desc) + # 等级必须是从详情页读出来的(547/885 -> 17, 0/6075 -> 34), 不是从弹窗猜的 + self.assertIn('17->34', desc) + # 仍然要把残留弹窗关掉, 不能把它留给下一步 + self.assertIn(levelup.POWERUP_CANCEL, screens.clicks) + + +UPTIE_POPUP = [('Currency Req.', 700, 300), ('Skills Gained', 700, 400), + ('Owned:2', 900, 450), ('Uptie', 1085, 580)] + + +class UptieVerdictTest(unittest.TestCase): + + def test_popup_still_open_is_failure_even_with_skills_gained(self): + screens = Screens(UPTIE_POPUP, UPTIE_POPUP) + with screens.patch(): + ok, desc = levelup.do_uptie() + self.assertFalse(ok, desc) + self.assertEqual(screens.keys, []) + + def test_success_dialog_is_confirmed_without_esc(self): + done = [('Uptied!', 700, 300), ('Confirm', 772, 661)] + screens = Screens(UPTIE_POPUP, done, done) + with screens.patch(): + ok, desc = levelup.do_uptie() + self.assertTrue(ok, desc) + self.assertEqual(screens.keys, []) + self.assertEqual(screens.clicks[-1], levelup.UPTIE_DONE_CONFIRM) + + def test_unknown_screen_presses_esc_once_and_never_clicks_blind(self): + story = [("I swear to you! I will return this favor", 500, 700)] + screens = Screens(UPTIE_POPUP, story, story, story) + with screens.patch(): + ok, desc = levelup.do_uptie() + self.assertFalse(ok) + self.assertEqual(screens.keys, ['esc']) + self.assertNotIn(levelup.UPTIE_CANCEL, screens.clicks) + + def test_cutscene_skip_prompt_counts_as_success(self): + story = [("I swear to you!", 500, 700)] + skip = [('Skip this story?', 700, 400), ('Confirm', 900, 600)] + screens = Screens(UPTIE_POPUP, story, story, skip, skip) + with screens.patch(): + ok, desc = levelup.do_uptie() + self.assertTrue(ok, desc) + self.assertEqual(screens.clicks[-1], (900, 600)) + + +class DetailPageDetectTest(unittest.TestCase): + """详情页判定。 + + 2026-10-13 实机: Zwei 满级后详情页上的按钮是 MAX 而不是 Level Up, + 代码却用 'Level Up' not in txt 判断"长按有没有打开详情", 于是把成功的 + 长按判成失败, 六张卡全部跳过, 升级环节空跑还报"无需升级"。 + """ + + def test_normal_detail_page(self): + self.assertTrue(levelup.detail_page_open('Level Up | Uptie | 547/885')) + + def test_maxed_identity_without_level_up_label(self): + # 满级: 有 MAX 和 Uptie, 但没有 'Level Up' + t = 'Zwei Assoc. South Section 6 | LV40 | 0/6075 | MAX | Uptie++ | Summary | Sanity' + self.assertTrue(levelup.detail_page_open(t)) + + def test_sections_only(self): + self.assertTrue(levelup.detail_page_open('Summary | Skill | E.G.O | Sanity')) + + def test_grid_is_not_detail_page(self): + t = 'TEAMS#1 | IDENTITIES | E.G.O | Facades | Details | ALL | SELECTED' + self.assertFalse(levelup.detail_page_open(t)) + + +class MaxLevelReadTest(unittest.TestCase): + """满级时进度条反推会偏低, 要以直读为准。 + + 实测 Zwei LV40/MAX 的进度条是 0/6075, 而 6075 在表里对应 Lv.35, + 反推成 34 —— 比真实等级低了 6 级。 + """ + + def _read(self, items): + screens = Screens([(i['text'], i['x'], i['y']) for i in items]) + with screens.patch(): + return levelup.read_detail(hint=None) + + def test_maxed_uses_direct_level(self): + items = [{'text': 'Zwei Assoc. South Section 6', 'x': 1079, 'y': 155}, + {'text': 'LV40', 'x': 900, 'y': 218}, + {'text': '0/6075', 'x': 1000, 'y': 234}, + {'text': 'MAX', 'x': 700, 'y': 240}] + lvl, name, bar = self._read(items) + self.assertEqual(lvl, 40) + + def test_non_maxed_still_prefers_bar(self): + # 进度条 547/885 反推 Lv.17, 直读 LV17 一致 + items = [{'text': 'LCB Sinner', 'x': 900, 'y': 155}, + {'text': 'LV17', 'x': 900, 'y': 218}, + {'text': '547/885', 'x': 1000, 'y': 234}] + lvl, name, bar = self._read(items) + self.assertEqual(lvl, 17) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_modules_status.py b/tests/test_modules_status.py new file mode 100644 index 0000000..6739b61 --- /dev/null +++ b/tests/test_modules_status.py @@ -0,0 +1,174 @@ +# -*- coding: utf-8 -*- +"""modules_status 的汇总逻辑。 + +值守时要一眼看出三件事: 有没有真的换到模块、有没有狂气告警、有没有连着失败。 +""" +import json +import os +import sys +import tempfile +import unittest +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts')) +import modules_status as ms # noqa: E402 + + +def rep(started, ok, result, info='', elapsed=100): + return {'started': started, 'ok': ok, 'result': result, 'elapsed_s': elapsed, + 'steps': [{'step': '合成', 'ok': ok, 'info': info}]} + + +class SummarizeTest(unittest.TestCase): + + def setUp(self): + self.d = tempfile.mkdtemp() + + def write(self, name, obj): + with open(os.path.join(self.d, name), 'w', encoding='utf-8') as f: + json.dump(obj, f, ensure_ascii=False) + + def test_orders_newest_first(self): + self.write('convert_20260101_010101.json', rep('2026-01-01 01:01:01', True, 'a')) + self.write('convert_20260102_010101.json', rep('2026-01-02 01:01:01', True, 'b')) + rows = ms.summarize(ms.load_reports(self.d)) + self.assertEqual([r['started'] for r in rows], + ['2026-01-02 01:01:01', '2026-01-01 01:01:01']) + + def test_broken_json_skipped(self): + self.write('convert_20260101_010101.json', rep('2026-01-01 01:01:01', True, 'a')) + with open(os.path.join(self.d, 'convert_20260103_010101.json'), 'w', encoding='utf-8') as f: + f.write('{ not json') + self.assertEqual(len(ms.load_reports(self.d)), 1) + + def test_lunacy_alarm_is_flagged(self): + self.write('convert_20260101_010101.json', + rep('2026-01-01 01:01:01', False, '⚠️ 狂气读数发生变化 9699 -> 6300, 立即停止并人工核查')) + rows = ms.summarize(ms.load_reports(self.d)) + self.assertTrue(rows[0]['lunacy_alarm']) + + def test_normal_run_is_not_an_alarm(self): + self.write('convert_20260101_010101.json', + rep('2026-01-01 01:01:01', True, '合成完成: 模组 29 -> 30 (+1)', '模组 29 -> 30 (+1)')) + rows = ms.summarize(ms.load_reports(self.d)) + self.assertFalse(rows[0]['lunacy_alarm']) + + def test_time_formatting(self): + self.assertEqual(ms.fmt_secs(36), '36s') + self.assertEqual(ms.fmt_secs(180), '3:00') + self.assertEqual(ms.fmt_secs(None), '-') + + +class LunacyColumnTest(unittest.TestCase): + """狂气读数要进报告, 并在汇总里单列一栏。 + + JSON 里原先只有一句 result 文本, 狂气读数只留在 convert.log 里 —— 值守看的是 + 报告, 而"前后读数是否一致"恰恰是最该一眼看到的一项。 + """ + + def test_checked_run_shows_agreement(self): + r = ms.summarize([{'started': 'x', 'ok': True, + 'result': '合成完成: 模组 29 -> 30 (+1)', 'elapsed_s': 10, + 'converted': True, + 'lunacy_before': 9699, 'lunacy_after': 9699, + 'lunacy_checked': True}])[0] + self.assertTrue(r['lunacy_checked']) + self.assertIn('9699', ms.lunacy_cell(r)) + + def test_unchecked_run_says_so(self): + # 合成过但狂气没读全 -> 必须明说"未比对"(不能装作校过了) + r = ms.summarize([{'started': 'x', 'ok': True, + 'result': '合成完成: 模组 29 -> 30 (+1)', 'elapsed_s': 10, + 'converted': True, + 'lunacy_before': None, 'lunacy_after': 9699, + 'lunacy_checked': False}])[0] + self.assertFalse(r['lunacy_checked']) + self.assertEqual(ms.lunacy_cell(r), '未比对') + + def test_skipped_run_is_not_counted_as_unchecked(self): + """没合成的轮次没什么可比, 不该混进"该比对却没比对"。 + + 混进去会让这个数字虚高, 掩盖真正有问题的那几轮。 + """ + r = ms.summarize([{'started': 'x', 'ok': True, + 'result': '体力不足(4<20), 本轮无需合成', 'elapsed_s': 10, + 'converted': False, 'lunacy_before': 9699, + 'lunacy_checked': False}])[0] + self.assertFalse(r['converted']) + self.assertEqual(ms.lunacy_cell(r), '未合成(读到 9699)') + + def test_old_report_infers_converted_from_result_text(self): + # 老报告没有 converted 字段, 按结果文本推断 + r = ms.summarize([{'started': 'x', 'ok': True, + 'result': '合成完成: 模组 29 -> 30 (+1)', + 'elapsed_s': 10}])[0] + self.assertTrue(r['converted']) + r2 = ms.summarize([{'started': 'y', 'ok': True, + 'result': '体力不足(4<20), 本轮无需合成', + 'elapsed_s': 10}])[0] + self.assertFalse(r2['converted']) + + def test_alarm_is_visible_in_the_cell(self): + r = ms.summarize([{'started': 'x', 'ok': False, + 'result': '⚠️ 狂气读数发生变化 9699 -> 6300, 立即停止并人工核查', + 'elapsed_s': 10, 'converted': True, + 'lunacy_before': 9699, 'lunacy_after': 6300, + 'lunacy_checked': True}])[0] + self.assertTrue(r['lunacy_alarm']) + self.assertIn('⚠️', ms.lunacy_cell(r)) + + def test_old_reports_without_the_field_are_inferred(self): + # 老报告没有 lunacy_checked, 要按读数推 + r = ms.summarize([{'started': 'x', 'ok': True, 'result': 'r', 'elapsed_s': 10, + 'lunacy_before': 6636, 'lunacy_after': 6636}])[0] + self.assertTrue(r['lunacy_checked']) + r2 = ms.summarize([{'started': 'y', 'ok': True, 'result': 'r', + 'elapsed_s': 10}])[0] + self.assertFalse(r2['lunacy_checked']) + + +class RecheckAlarmTest(unittest.TestCase): + """老报告里的狂气告警要用**当前**判据重新复核。 + + ⛔ 2026-10-16 22:03 那份报告写的是"⚠️ 狂气读数发生变化 6636 -> 9699", 而事后 + 查明 6636 和 9699 都是真值 6636 的已知 OCR 读法 —— 是误报。报告是历史记录不该 + 改写, 但汇总工具不能继续拿旧判据吓人。 + """ + + ALARM = '⚠️ 狂气读数发生变化 6636 -> 9699 (复读仍为 9699), 立即停止并人工核查' + + def test_false_alarm_is_reclassified(self): + alarmed, false_alarm = ms.recheck_alarm(6636, 9699, self.ALARM) + self.assertTrue(alarmed, '当时确实报过告警') + self.assertTrue(false_alarm, '按现在的判据这是误报') + + def test_real_alarm_stays(self): + # 陌生值 -> 现在的判据也认为可疑 + alarmed, false_alarm = ms.recheck_alarm(6636, 3000, self.ALARM) + self.assertTrue(alarmed) + self.assertFalse(false_alarm) + + def test_non_alarm_report_is_untouched(self): + alarmed, false_alarm = ms.recheck_alarm(9699, 9699, '合成完成: 模组 1 -> 2 (+1)') + self.assertFalse(alarmed) + self.assertFalse(false_alarm) + + def test_missing_readings_cannot_be_rechecked(self): + """读数缺了就没法复核 —— 只能维持原判, 不能凭空洗白。""" + alarmed, false_alarm = ms.recheck_alarm(6636, None, self.ALARM) + self.assertTrue(alarmed) + self.assertFalse(false_alarm) + + def test_summary_excludes_false_alarms_from_the_header_count(self): + """表头那句"狂气告警 N 轮"不该再数误报, 否则一直喊狼来了。""" + rows = ms.summarize([ + {'started': 'a', 'ok': False, 'result': self.ALARM, 'elapsed_s': 10, + 'converted': True, 'lunacy_before': 6636, 'lunacy_after': 9699, + 'lunacy_checked': True}]) + self.assertTrue(rows[0]['lunacy_alarm']) + self.assertTrue(rows[0]['lunacy_false_alarm']) + self.assertIn('误报', ms.lunacy_cell(rows[0])) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_preflight_patches.py b/tests/test_preflight_patches.py new file mode 100644 index 0000000..c3e8b40 --- /dev/null +++ b/tests/test_preflight_patches.py @@ -0,0 +1,163 @@ +import os +import sys +import unittest +from unittest import mock + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from lc_mcp import aalc_patches, preflight # noqa: E402 + + +def values(**over): + v = {'simulator': False, 'mirror': True, 'set_win_size': 720, 'set_lunacy_to_enkephalin': 0, + 'teams_active_queue': [1], + 'teams': {'1': {'sinner_order': [1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0]}}} + v.update(over) + return v + + +class PreflightTest(unittest.TestCase): + + def test_healthy_config_passes(self): + self.assertEqual(preflight.check(values(), 'mirror', desktop=(1600, 900), env={}), []) + + def test_default_all_zero_sinner_order_is_rejected_for_mirror(self): + v = values(teams={'1': {'sinner_order': [0] * 12}}) + problems = preflight.check(v, 'mirror', env={}) + self.assertEqual(len(problems), 1) + self.assertIn('sinner_order', problems[0]) + # 日常本只按预设编号选队, 不用 sinner_order + self.assertEqual(preflight.check(v, 'daily', env={}), []) + # all 只在勾选了镜牢时检查 + self.assertEqual(preflight.check(dict(v, mirror=False), 'all', env={}), []) + self.assertEqual(len(preflight.check(v, 'all', env={})), 1) + + def test_missing_team_in_queue(self): + problems = preflight.check(values(teams_active_queue=[2]), 'mirror', env={}) + self.assertIn('队伍 2', problems[0]) + + def test_lunacy_spending_is_rejected_unless_explicit(self): + v = values(set_lunacy_to_enkephalin=2) + self.assertIn('狂气', preflight.check(v, 'daily', env={})[0]) + self.assertEqual(preflight.check(v, 'enkephalin', env={}), []) + self.assertEqual(preflight.check(v, 'daily', env={preflight.ALLOW_LUNACY_ENV: '1'}), []) + + def test_window_that_cannot_fit_desktop_is_rejected(self): + # 10-04 坑 4: 900 高的客户区加标题栏放不进 1600x900 桌面 + problems = preflight.check(values(set_win_size=900), 'daily', desktop=(1600, 900), env={}) + self.assertIn('1616x940', problems[0]) + self.assertEqual(preflight.check(values(set_win_size=900), 'daily', desktop=(1920, 1080), env={}), []) + self.assertEqual(preflight.check(values(set_win_size=900, simulator=True), 'daily', + desktop=(1600, 900), env={}), []) + + def test_collect_reads_pydantic_teams(self): + class Team: + def model_dump(self): + return {'sinner_order': [1]} + + class Cfg: + data = {'simulator': False, 'mirror': True, 'set_win_size': 720, + 'set_lunacy_to_enkephalin': None, 'teams_active_queue': [1], 'teams': {1: Team()}} + + def get_value(self, key): + return self.data[key] + + v = preflight.collect(Cfg()) + self.assertEqual(v['teams'], {'1': {'sinner_order': [1]}}) + self.assertEqual(v['set_lunacy_to_enkephalin'], 0) + + +class ExactTeamMatchTest(unittest.TestCase): + + class Auto: + def find_str_in_text(self, target, ocr_dict): + # AALC 原逻辑: 子串匹配 + for text, pos in ocr_dict.items(): + if target.replace(' ', '').lower() in text.replace(' ', '').lower(): + return pos + return False + + def setUp(self): + self.auto = self.Auto() + aalc_patches.install_exact_team_match(self.auto, log=lambda m: None) + + def test_team_1_does_not_match_team_10(self): + ocr = {'TEAMS #10': [10, 10], 'TEAMS #11': [10, 20], 'TEAMS #1': [10, 30]} + self.assertEqual(self.auto.find_str_in_text('TEAMS #1', ocr), [10, 30]) + self.assertFalse(self.auto.find_str_in_text('TEAMS #1', {'TEAMS #10': [1, 1]})) + + def test_ocr_variants_and_chinese(self): + self.assertEqual(self.auto.find_str_in_text('TFAMS#1', {'TEAMS # 1': [5, 5]}), [5, 5]) + self.assertEqual(self.auto.find_str_in_text('编队#1', {'编队#12': [1, 1], '编队#1': [2, 2]}), [2, 2]) + self.assertEqual(self.auto.find_str_in_text('TEAMS #12', {'TEAMS #12': [3, 3]}), [3, 3]) + + def test_other_targets_keep_aalc_substring_logic(self): + self.assertEqual(self.auto.find_str_in_text('Hong Lu', {'W HongLu': [7, 7]}), [7, 7]) + + +class FakeHandle: + def __init__(self, size): + self._hwnd = 1 + self.size = size + self.isMinimized = False + + def width(self, client=False): + return self.size[0] + + def height(self, client=False): + return self.size[1] + + +class FakeScreen: + def __init__(self, size, resizable=True): + self.handle = FakeHandle(size) + self.resizable = resizable + self.calls = [] + + def adjust_win_size(self, want): + self.calls.append(want) + if self.resizable: + self.handle.size = want + + +class Cfg: + simulator = False + set_windows = True + set_win_size = 720 + + +class WindowGuardTest(unittest.TestCase): + + def guard(self, screen, cfg=Cfg): + self.logs = [] + return aalc_patches.WindowGuard(screen, cfg, log=self.logs.append) + + def test_correct_size_is_left_alone(self): + screen = FakeScreen((1280, 720)) + self.assertEqual(self.guard(screen).check_once(), 'ok') + self.assertEqual(screen.calls, []) + + def test_stretched_window_is_restored(self): + # 10-04 坑 5: RDP 重连后被拉伸成 1872x898 + screen = FakeScreen((1872, 898)) + with mock.patch.object(aalc_patches.time, 'sleep'): + self.assertEqual(self.guard(screen).check_once(), 'fixed') + self.assertEqual(screen.calls, [(1280, 720)]) + + def test_unfixable_size_is_reported_once(self): + screen = FakeScreen((1600, 877), resizable=False) + guard = self.guard(screen) + with mock.patch.object(aalc_patches.time, 'sleep'): + self.assertEqual(guard.check_once(), 'failed') + self.assertEqual(guard.check_once(), 'failed') + self.assertEqual(len([m for m in self.logs if '[ERROR]' in m]), 1) + + def test_user_managed_window_is_not_touched(self): + class Manual(Cfg): + set_windows = False + screen = FakeScreen((1872, 898)) + self.assertIsNone(self.guard(screen, Manual).check_once()) + self.assertEqual(screen.calls, []) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_ps1_bom.py b/tests/test_ps1_bom.py new file mode 100644 index 0000000..758088b --- /dev/null +++ b/tests/test_ps1_bom.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +"""PowerShell 脚本必须带 UTF-8 BOM。 + +背景(10-04 坑 6, 10-13 又踩了一次): +`scripts/*.ps1` 里有中文注释和中文提示串。文件没有 BOM 时, Windows PowerShell +5.1 会按**系统 ANSI 代码页(GBK)** 解析, 中文被拆成乱码字节, 于是报出一堆 +"行号对不上"的语法错, 而且报的行号会指到别的语句上, 极难定位。 + +更坑的是: 用 pwsh 7 / PowerShell Core 做的"语法检查"能正确处理无 BOM 的 UTF-8, +会给出假的 ✅。所以必须用字节级检查, 不能靠解析器。 + +编辑器(包括各种自动改写工具)保存时常把 BOM 丢掉, 所以这里做成测试而不是一次性修复。 +""" +import os +import sys +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +SCRIPTS = ROOT / 'scripts' +BOM = b'\xef\xbb\xbf' + + +class Ps1BomTest(unittest.TestCase): + + def files(self): + return sorted(SCRIPTS.glob('*.ps1')) + + def test_there_are_ps1_files_to_check(self): + # 防止 glob 路径写错导致这个测试空转(空列表会让下面全部通过) + self.assertTrue(self.files(), '没找到 scripts/*.ps1, 测试本身失效了') + + def test_every_ps1_starts_with_utf8_bom(self): + bad = [] + for p in self.files(): + head = p.read_bytes()[:3] + if head != BOM: + bad.append('%s (前 3 字节: %s)' % (p.name, head.hex(' ').upper())) + self.assertFalse( + bad, + '这些 .ps1 缺 UTF-8 BOM, Windows PowerShell 5.1 会按 GBK 解析中文而报错:\n ' + + '\n '.join(bad) + + '\n修复: 读成 UTF-8 后以 utf-8-sig 写回。') + + def test_no_ps1_contains_gbk_decodable_mojibake(self): + """带 BOM 的文件读出来不应有乱码替换符。""" + for p in self.files(): + text = p.read_text(encoding='utf-8-sig') + self.assertNotIn('\ufffd', text, '%s 含替换符, 可能编码已损坏' % p.name) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_stall_no_progress.py b/tests/test_stall_no_progress.py new file mode 100644 index 0000000..8b27046 --- /dev/null +++ b/tests/test_stall_no_progress.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +"""卡死检测: 无进展判据。 + +背景 —— 2026-10-13 实机测试撞到的第二种卡死: +AALC 把镜牢入口误认成经验本界面, 把 home/luxcavation_assets.png 匹配到 0.836, +然后对着误匹配的位置连点了 18 分钟。日志一直在涨, 所以原有的计数法 +(STALL_MARKERS 只认 "配队人数OCR得到") 完全抓不到, 外层只能干等 45 分钟超时。 + +修法是加一条与日志内容无关的判据: 里程碑(开始执行/结束执行)多久没前进。 +""" +import os +import gzip +import tempfile +import time +import unittest +from pathlib import Path + +from lc_mcp import tasks + + +def _write(lines): + fd, path = tempfile.mkstemp(suffix='.log') + with os.fdopen(fd, 'w', encoding='utf-8') as f: + f.write('\n'.join(lines) + '\n') + return path + + +def _stamp(offset_s=0): + return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() - offset_s)) + + +class NoProgressStall(unittest.TestCase): + + def tearDown(self): + for p in getattr(self, '_paths', []): + try: + os.remove(p) + except OSError: + pass + + def _make(self, lines): + p = _write(lines) + self._paths = getattr(self, '_paths', []) + [p] + return p + + def test_stale_milestone_is_reported(self): + """里程碑停在阈值之前 -> 报 no_progress。""" + old = tasks.STALL_NO_PROGRESS_S + 120 + p = self._make([ + '[INFO] %s [AALC] tasks\\base\\script_task_scheme.py:262: 开始执行 一次纽本' % _stamp(old), + '[DEBUG] %s [AALC] tasks\\daily\\luxcavation.py:224: 目标图片:home/luxcavation_assets.png' + % _stamp(0), + ]) + stalls = tasks.log_stalls(p) + self.assertIn('no_progress', stalls) + self.assertGreaterEqual(stalls['no_progress'], tasks.STALL_NO_PROGRESS_S) + + def test_recent_milestone_is_not_reported(self): + """里程碑刚刚前进过 -> 不报。""" + p = self._make([ + '[INFO] %s [AALC] tasks\\daily\\luxcavation.py:9: 结束执行 一次纽本' % _stamp(5), + '[DEBUG] %s [AALC] tasks\\automation\\automation.py:152: 点击位置:(979,290)' % _stamp(0), + ]) + self.assertNotIn('no_progress', tasks.log_stalls(p)) + + def test_frozen_log_does_not_freeze_stall_clock(self): + old = tasks.STALL_NO_PROGRESS_S + 120 + p = self._make(['[INFO] %s [AALC] 开始执行 一次纽本' % _stamp(old)]) + frozen = time.time() - old + os.utime(p, (frozen, frozen)) + self.assertIn('no_progress', tasks.log_stalls(p)) + + def test_no_milestone_at_all_is_not_reported(self): + """一条里程碑都没有时不下结论(可能只是还没走到), 避免误杀启动阶段。""" + p = self._make([ + '[DEBUG] %s [AALC] module\\automation\\automation.py:93: 使用基于窗口移动的后台点击模块' + % _stamp(99999), + ]) + self.assertNotIn('no_progress', tasks.log_stalls(p)) + + def test_existing_empty_team_marker_still_works(self): + """原有判据不能被破坏。""" + p = self._make([ + '[DEBUG] %s [AALC] tasks\\teams\\team_formation.py:225: 对于配队人数OCR得到:0/5' % _stamp(1), + ] * 12) + self.assertIn('empty_team', tasks.log_stalls(p)) + + def test_stale_milestone_far_from_tail_is_still_found(self): + """卡死期间日志涨得很快, 里程碑可能离文件尾很远, 回溯窗口必须够大。""" + old = tasks.STALL_NO_PROGRESS_S + 60 + body = ['[INFO] %s [AALC] tasks\\base\\script_task_scheme.py:262: 开始执行 一次经验本' % _stamp(old)] + body += ['[DEBUG] %s [AALC] tasks\\daily\\luxcavation.py:224: 目标图片:home/luxcavation_assets.png' + ' 相似度:0.836' % _stamp(0)] * 6000 + p = self._make(body) + self.assertGreater(os.path.getsize(p), 64 * 1024) # 确定超出了 tail() 的 64KB 窗口 + self.assertIn('no_progress', tasks.log_stalls(p)) + + def test_archived_windows_runs_distinguish_stalled_and_healthy_tasks(self): + root = Path(__file__).resolve().parents[1] / 'docs/feedback/2026-10-13/results/runs' + for name, stalled in [('task_20261013_124337_daily.log.gz', True), + ('task_20261013_132845_daily.log.gz', False), + ('task_20261013_135050_mirror.log.gz', False)]: + with self.subTest(log=name): + with gzip.open(root / name, 'rt', encoding='utf-8') as f: + lines = f.read().splitlines() + stamp = next(tasks.TIMESTAMP_RE.search(line).group(1) + for line in reversed(lines) if tasks.TIMESTAMP_RE.search(line)) + observed_at = time.mktime(time.strptime(stamp, '%Y-%m-%d %H:%M:%S')) + path = self._make(lines) + self.assertEqual('no_progress' in tasks.log_stalls(path, now=observed_at), stalled) + + +if __name__ == '__main__': + unittest.main() diff --git a/vendor/aalc b/vendor/aalc index 7452fad..e1d1749 160000 --- a/vendor/aalc +++ b/vendor/aalc @@ -1 +1 @@ -Subproject commit 7452fad5a45a0fadb59a753fafbf40434d987c19 +Subproject commit e1d17499051c12d59985a333e0f7b5f5304d9b2d