From 58f333956109caabf9452ada96ff34a6249161b3 Mon Sep 17 00:00:00 2001 From: OG T Date: Mon, 23 Mar 2026 22:15:16 +0800 Subject: [PATCH] =?UTF-8?q?chore(api):=20=E6=96=B0=E5=A2=9E=20debug=20endp?= =?UTF-8?q?oint=20=E6=B8=AC=E8=A9=A6=20incident=20resolve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 臨時測試端點,用於驗證 resolve_incident_after_approval 邏輯 Co-Authored-By: Claude Opus 4.5 --- apps/api/src/api/v1/incidents.py | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/apps/api/src/api/v1/incidents.py b/apps/api/src/api/v1/incidents.py index d679efbe0..6ed263ae5 100644 --- a/apps/api/src/api/v1/incidents.py +++ b/apps/api/src/api/v1/incidents.py @@ -338,3 +338,54 @@ async def generate_proposal(incident_id: str) -> ProposalGenerateResponse: proposal=ApprovalRequestResponse.from_approval(approval), incident_status=incident_status, ) + + +# ============================================================================= +# DEBUG: 測試 Incident 狀態更新 +# ============================================================================= + +@router.post( + "/{incident_id}/resolve", + summary="[DEBUG] 直接將 Incident 標記為 RESOLVED", + description="測試用端點,直接更新 Incident 狀態", +) +async def debug_resolve_incident(incident_id: str) -> dict[str, Any]: + """ + DEBUG: 直接更新 Incident 狀態為 RESOLVED + 用於測試 resolve_incident_after_approval 邏輯 + """ + service = get_proposal_service() + + # 先取得當前狀態 + redis_client = get_redis() + before_status = None + try: + data = await redis_client.get(f"incident:{incident_id}") + if data: + incident = Incident.model_validate_json(data) + before_status = incident.status.value + except Exception as e: + logger.warning("debug_resolve_get_failed", error=str(e)) + + # 呼叫 resolve + result = await service.resolve_incident_after_approval( + incident_id=incident_id, + approval_id="debug-test", + ) + + # 取得更新後狀態 + after_status = None + try: + data = await redis_client.get(f"incident:{incident_id}") + if data: + incident = Incident.model_validate_json(data) + after_status = incident.status.value + except Exception as e: + logger.warning("debug_resolve_get_after_failed", error=str(e)) + + return { + "success": result, + "incident_id": incident_id, + "before_status": before_status, + "after_status": after_status, + }