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, + }