fix(drift-card): 修 drift 卡片 2 bug — AI 研判 copy 樣式 + Diff 按鈕 AttributeError
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 13m8s

Bug 1: 按「🔍 查看 Diff」失敗
  錯誤: 'DriftReportRepository' object has no attribute 'get_by_id'
  根因: DriftReportRepository 方法叫 get(), 其他 repo 都叫 get_by_id()
  修法: 加 get_by_id() alias, 對齊 repo 介面慣例

Bug 2: AI 研判內容被渲染成 code block + copy 按鈕
  根因: telegram_gateway line 1962 用 <pre> 包 diff_summary
       但 diff_summary 是 AI 研判敘述 + emoji 清單, 非 code
  修法: 移除 <pre>, 改以分隔線 + html.escape 純文字顯示

驗收:
- 下次 drift 卡片: AI 研判段落純文字(無紫色 code block + copy)
- 按「🔍 查看 Diff」→ 送完整 diff 詳情(非 AttributeError)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
OG T
2026-04-19 11:27:13 +08:00
parent eab3f527cd
commit 2abc91e360
2 changed files with 9 additions and 1 deletions

View File

@@ -116,6 +116,11 @@ class DriftReportRepository:
row = result.fetchone()
return _row_to_report(row) if row else None
# 2026-04-19 Claude Opus 4.7 修 drift_view 按鈕 AttributeError
# 其他 repo 慣例皆 get_by_id對齊介面供 telegram_gateway 呼叫
async def get_by_id(self, report_id: str) -> DriftReport | None:
return await self.get(report_id)
async def list_recent(self, limit: int = 50) -> list[DriftReport]:
"""列出最近 N 筆(倒序)"""
async with get_db_context() as db:

View File

@@ -1957,9 +1957,12 @@ class TelegramGateway:
diff_summary: Diff 摘要文字
detected_at: 偵測時間
"""
# 2026-04-19 Claude Opus 4.7 修 diff_summary 被 <pre> 包成 code block (copy 按鈕 UI)
# 根因:<pre> 在 Telegram HTML mode 渲染為 code block但 diff_summary 是 AI
# 研判敘述 + emoji 清單(非 code應以純文字顯示
# Diff 長度處理 (ADR-071, Section 14.9.6)
if len(diff_summary) <= 500:
diff_block = f"\n<pre>{html.escape(diff_summary)}</pre>"
diff_block = f"\n━━━━━━━━━━━━━━━━━━━\n{html.escape(diff_summary)}"
else:
web_url = f"https://aiops.wooo.work/incidents/{incident_id}/drift-diff"
diff_block = f"\n⚠️ 差異過大({len(diff_summary)} 字)\n🔗 <a href='{web_url}'>查看完整 Diff</a>"