feat(mobile): 可观测性增强(结构化日志 + 失败工件) - #46
Merged
Merged
Conversation
- mobile/logger.py 新增 log_event(event, *, level, **fields) helper
+ _format_event_value 处理空格 / "=" / 引号 / None / bool 转义
- 关键热路径事件改用 log_event:
+ sale_waiter.wait_for_sale_start 命中(带 cta_text/polls/duration_ms)
+ purchase_flow._submit_order_fast 完成(带 success/result/attempts/duration_ms)
+ event_navigator.select_session 命中(带 match=date+city|date|fallback_index)
+ select_session 抛 *Error 前发 event=error
- 启动期环境快照(mobile/env_snapshot.py + DamaiBot._emit_boot_snapshot):
+ adb shell pm dump cn.damai → versionName 解析
+ adb 不在 PATH / 进程超时 / 非零退出 / 无 versionName 全部降级到 None
+ log_event(boot, py_version, damai_version, device, rush_mode)
- mobile/damai_app/recovery_strategies.py 新增 capture_failure_artifacts:
+ tmp/failures/<ts>_<scene>.{xml,png,json}
+ 截图失败标 screenshot_failed=True;XML 失败仅记 metadata
+ metadata 含 device / damai_version / config_hash / error_type
- run_ticket_grabbing 顶层 except 自动调用 capture_failure_artifacts
- 测试:tests/unit/test_mobile_logger.py +15、test_env_snapshot.py、test_recovery_artifacts.py
覆盖率 81.47%(门槛 80%),1067 passed + 1 xfailed
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.
Summary
log_event(event, *, level, **fields):把热路径关键事件统一成event=name k=v ...形式,方便 grep/聚合。空格 /=/ 引号 / None / bool 自动转义。wait_for_sale_start命中:event=sale_ready source=poll_loop|buy_button_guard cta_text=... polls=N duration_ms=..._submit_order_fast完成:event=order_submitted success=true|false result=... attempts=N duration_ms=...select_session命中:event=session_selected match=date+city|date|fallback_index date=... city=... index=N total=Nselect_session抛*Error前:event=error type=SessionNotFoundError scene=... date=... city=...mobile/env_snapshot.py+DamaiBot._emit_boot_snapshot):adb shell pm dump cn.damai→versionName解析damai_version=unknownevent=boot py_version=3.X damai_version=10.6.1 device=... rush_mode=truetmp/failures/(mobile/damai_app/recovery_strategies.capture_failure_artifacts):<YYYYmmdd-HHMMSS-mmm>_<scene>.{xml,png,json}screenshot_failed=Truerun_ticket_grabbing顶层except Exceptionreference/decisions/D-002-desktop-cleanup.md(gitignored,不入 PR),结论 = A 完全删除,等 W4-05 PM 月度评审后另开 PR 实施。Test plan
poetry run pytest --cov=mobile --cov-fail-under=80→ 81.47% / 1067 passed + 1 xfailed(≥80% 门槛)tmp/failures/生成 ≥3 个文件(xml/png/json)— 由tests/unit/test_recovery_artifacts.py覆盖event=boot py_version=... damai_version=... device=... rush_mode=...tests/unit/test_env_snapshot.py16 例覆盖 adb 不在 PATH / 超时 / OSError / 非零退出 / 空 stdout / 多 versionName 等场景tests/unit/test_mobile_logger.py+15 例覆盖_format_event_value与log_event各路径关联
reference/03-tech-assessment.md可观测性建议reference/decisions/D-002-desktop-cleanup.md(gitignored),等 W4-05 评审决议