
    iA	                    F    d Z ddlmZ ddlZddlmZ ddlmZ ed   ZddZ	y)	u  utils/g3_fail_classifier.py — .g3-fail 자동 분류 룰.

reconcile 전용 분류기. fail_reasons 패턴과 report 파일 mtime 비교만 사용.
사람 판정 없이 룰 기반 fail-closed.

분류:
- false_alert_resolved_by_late_report: fail_reasons에 "report not found"만 있고
  report 파일이 g3-fail 발행 후 생성됨
- unresolved: 그 외 모든 케이스 (fail-closed)
    )annotationsN)Path)Literal)#false_alert_resolved_by_late_report
unresolvedc                   | j                         sy	 t        j                  | j                  d            }|j                  dg       }t        |t              r|syt        d |D              rM|j                         r=	 |j                         j                  }| j                         j                  }||kD  ry	 yy# t        j                  t
        f$ r Y yw xY w# t
        $ r Y yw xY w)uA  g3-fail을 자동 분류.

    Parameters
    ----------
    g3_fail_path : Path
        ``.g3-fail`` 파일 경로 (없으면 unresolved 반환).
    report_path : Path
        대응 report 파일 경로 (예: ``memory/reports/task-XXX.md``).

    Returns
    -------
    ClassificationResult
        ``"false_alert_resolved_by_late_report"`` (reconcile 허용) 또는
        ``"unresolved"`` (fail-closed, reconcile 차단).

    동작 원칙
    ---------
    - g3_fail_path 부재 → unresolved (파일 없으면 판정 불가)
    - JSON 파싱 실패 → unresolved (fail-closed)
    - fail_reasons 빈 리스트 → unresolved
    - 모든 fail_reason에 "report not found" 포함 AND report 파일이
      g3-fail 발행 이후 생성되었으면 → false_alert_resolved_by_late_report
    - 그 외 → unresolved
    r   zutf-8)encodingfail_reasonsc              3  H   K   | ]  }t        |t              xr d |v   yw)zreport not foundN)
isinstancestr).0rs     //home/jay/workspace/utils/g3_fail_classifier.py	<genexpr>z#classify_g3_fail.<locals>.<genexpr>;   s%     
Pa:a9"4"99
Ps    "r   )existsjsonloads	read_textJSONDecodeErrorOSErrorgetr   listallstatst_mtime)g3_fail_pathreport_pathpayloadr
   report_mtimeg3_mtimes         r   classify_g3_failr"      s    2  **\33W3EF ;;~r2LlD) 
P<
PP*//1::',,.77(*@ +
 %   '*   s#   %B=  9C =CC	C('C()r   r   r   r   returnClassificationResult)
__doc__
__future__r   r   pathlibr   typingr   r$   r"        r   <module>r+      s)   	 #   RS 0r*   