fix(emulator): MuMu 命令输出混有日志时仍能取到设备信息 - #621
Merged
ClozyA merged 3 commits intoSep 10, 2026
Merged
Conversation
get_device_info 用 if_merge_std=True 跑 MuMuManager,MuMu 自己的埋点
(add record:{...}) 与 C++ 日志 ([*** LOG ERROR ***] ... {bad_weak_ptr})
因此和设备 JSON 混在同一份 stdout 里。5 处 json.loads 都要求整段是纯 JSON,
多一行日志就整条失败——而那份设备 JSON 本身是完整可用的。
新增 _decode_polluted_json:扫出输出里所有顶层 JSON 值,由 prefer 判据挑出
期望的那一份。不能简单取第一个——埋点本身也是合法 JSON 且常排在设备 JSON 之前。
Closes AUTO-MAS-Project#620
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
审查者指南该 PR 通过提取所有顶层 JSON 值,并选择与每个调用方预期架构匹配的候选值,使 MuMu 命令解析能够适应 stdout 中包含多个无关日志或遥测片段的情况。该行为已应用于设备、ADB 和应用状态解析,并使用具有代表性的污染输出样本添加了回归测试。 受污染 MuMu JSON 解析的时序图sequenceDiagram
participant Caller
participant MumuManager
participant MuMu
Caller->>MumuManager: getInfo(idx)
MumuManager->>MuMu: get_device_info(idx)
MuMu-->>MumuManager: telemetry + device JSON + logs
MumuManager->>MumuManager: _decode_polluted_json(data, _has_device_entries)
MumuManager-->>Caller: device information
从受污染输出中选择 JSON 的流程图flowchart TD
A[MuMu stdout contains logs and JSON fragments] --> B[_decode_polluted_json]
B --> C[Scan top-level JSON values]
C --> D{prefer predicate matches?}
D -->|Yes| E[Return matching candidate]
D -->|No| F{Any candidate decoded?}
F -->|Yes| G[Return first candidate]
F -->|No| H[Raise JSONDecodeError]
E --> I[Caller-specific parsing]
G --> I
文件级变更
可能相关的问题
提示和命令与 Sourcery 交互
自定义使用体验访问你的控制面板以:
获取帮助Original review guide in EnglishReviewer's GuideThe PR makes MuMu command parsing resilient to stdout containing multiple unrelated log or telemetry fragments by extracting all top-level JSON values and selecting the candidate matching each caller’s expected schema. It applies this behavior across device, ADB, and app-state parsing and adds regression tests using representative polluted-output samples. Sequence diagram for polluted MuMu JSON parsingsequenceDiagram
participant Caller
participant MumuManager
participant MuMu
Caller->>MumuManager: getInfo(idx)
MumuManager->>MuMu: get_device_info(idx)
MuMu-->>MumuManager: telemetry + device JSON + logs
MumuManager->>MumuManager: _decode_polluted_json(data, _has_device_entries)
MumuManager-->>Caller: device information
Flow diagram for selecting JSON from polluted outputflowchart TD
A[MuMu stdout contains logs and JSON fragments] --> B[_decode_polluted_json]
B --> C[Scan top-level JSON values]
C --> D{prefer predicate matches?}
D -->|Yes| E[Return matching candidate]
D -->|No| F{Any candidate decoded?}
F -->|Yes| G[Return first candidate]
F -->|No| H[Raise JSONDecodeError]
E --> I[Caller-specific parsing]
G --> I
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
# Conflicts: # res/version.json
…260908 # Conflicts: # CHANGELOG.md # res/version.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #620
问题
get_device_info用if_merge_std=True跑MuMuManager info -v,MuMu 自己的埋点和 C++ 日志因此和设备 JSON 混在同一份 stdout 里。mumu.py里 5 处json.loads都要求整段是纯 JSON,多一行日志就整条失败——而那份设备 JSON 本身是完整可用的(6K的事件里is_android_started: true都在,只是尾部多了一行日志)。近一日:
1M1,943 条(自 08-20 累计 2,113)、6G1 条、6K1 条。1M是模拟器族里事件量最大的一条。需要说清楚这条和「模拟器自身故障」不是一回事:
WinError 5/WinError 2那批确实是用户侧环境问题,不该我们修;这批是我方解析口径过严。改动
新增
MumuManager._decode_polluted_json(text, prefer=None):扫出输出里所有顶层 JSON 值,由prefer判据挑出期望的那一份,都不命中时退回第一个,一个都解不出来才抛JSONDecodeError。不能简单取第一个 —— 埋点
add record:{"_track_id":...}本身也是合法 JSON,而且常常排在设备 JSON 之前,取第一个会把埋点当成设备信息。所以 5 个调用点各带自己的判据:getStatus/getInfo/list_devices_has_device_entries(有index+name)_get_adb_address_get_app_statestate是 str本地验证
新增
tests/tools/test_mumu_json_parse.py9 条(纯解析逻辑,按tests/AGENTS.md属于该提交的纯逻辑测试)。样本用的是 Sentry 事件里的真实污染形态:[*** LOG ERROR #0001 ***] ... {bad_weak_ptr}add record:{"_track_id":...,"event":"$SignUp",...}这些样本在改动前确实是炸的,且报错与 Sentry 上一字不差:
其中一条专门断言「埋点排在前面也不能被当成设备信息返回」。
没有做真机手测:本地这台 MuMu 不会往 stdout 写埋点,复现不了污染。解析是纯函数、由上面 9 条覆盖;但真机上
getInfo拿到的输出格式如果和我构造的样本有出入,欢迎指出。请审阅
@qiyinxi
app/utils/emulator是你维护的。确认后请你自行合并,我不代合。Sourcery 总结
允许 MuMu 命令解析从混入遥测数据和原生日志的标准输出中恢复有效的模拟器数据。
错误修复:
增强功能:
测试:
Original summary in English
Sourcery 总结
提高 MuMu 命令输出的解析容错性,确保混入日志时仍能读取模拟器信息。
Bug 修复:
增强功能:
测试:
Original summary in English
Summary by Sourcery
提高 MuMu 命令输出解析的容错性,确保混入日志时仍能恢复有效的模拟器信息。
Bug Fixes:
Enhancements:
Tests:
Original summary in English
Summary by Sourcery
提高 MuMu 命令输出解析的容错性,确保混入日志时仍能恢复有效的模拟器信息。
Bug Fixes:
Enhancements:
Tests: