Skip to content

feat(mobile): 可观测性增强(结构化日志 + 失败工件) - #46

Merged
currycan merged 1 commit into
masterfrom
feat/observability-and-desktop-decision
May 6, 2026
Merged

feat(mobile): 可观测性增强(结构化日志 + 失败工件)#46
currycan merged 1 commit into
masterfrom
feat/observability-and-desktop-decision

Conversation

@currycan

@currycan currycan commented May 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • mobile/logger.py 新增 log_event(event, *, level, **fields):把热路径关键事件统一成 event=name k=v ... 形式,方便 grep/聚合。空格 / = / 引号 / None / bool 自动转义。
  • 关键热路径事件统一改为 log_event 输出
    • 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=N
    • select_session*Error 前:event=error type=SessionNotFoundError scene=... date=... city=...
  • 启动期环境快照mobile/env_snapshot.py + DamaiBot._emit_boot_snapshot):
    • adb shell pm dump cn.damaiversionName 解析
    • adb 不在 PATH / 超时 / 非零退出 / 无 versionName → 一律降级 damai_version=unknown
    • event=boot py_version=3.X damai_version=10.6.1 device=... rush_mode=true
  • 失败时自动 dump UI XML + 截图 + metadata 到 tmp/failures/mobile/damai_app/recovery_strategies.capture_failure_artifacts):
    • 文件名 <YYYYmmdd-HHMMSS-mmm>_<scene>.{xml,png,json}
    • metadata 含 device / damai_version / config_hash / error_type / error_message / screenshot_failed
    • 截图失败仅记 XML,标 screenshot_failed=True
    • 挂载点:run_ticket_grabbing 顶层 except Exception
  • D-002 desktop/ 处理决策已写入 reference/decisions/D-002-desktop-cleanup.md(gitignored,不入 PR),结论 = A 完全删除,等 W4-05 PM 月度评审后另开 PR 实施。

Test plan

  • poetry run pytest --cov=mobile --cov-fail-under=8081.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.py 16 例覆盖 adb 不在 PATH / 超时 / OSError / 非零退出 / 空 stdout / 多 versionName 等场景
  • tests/unit/test_mobile_logger.py +15 例覆盖 _format_event_valuelog_event 各路径
  • 真机 boot snapshot 验证(需要 Android 设备 + cn.damai 已安装;本地 mock 已绿)

关联

  • Refs reference/03-tech-assessment.md 可观测性建议
  • Note: desktop/ 处理决策记录在 reference/decisions/D-002-desktop-cleanup.md(gitignored),等 W4-05 评审决议

- 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
@currycan
currycan merged commit f604e2b into master May 6, 2026
5 checks passed
@currycan
currycan deleted the feat/observability-and-desktop-decision branch July 11, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant