
    i<                       d Z ddlmZ ddlZddlmc mZ ddl	Z
ddlZddlZddlmZ ddlZ ee      j#                         j$                  d   Z ej(                  d      d        Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!y)u[  tests/lifecycle_guards/test_gemini_image_severity.py — task-2471 회귀 테스트.

토르가 commit 0750481e 에서 ``scripts/gemini_severity_parser.py`` 에 추가한
이미지 alt-text severity 패턴 (``![High](url)`` / ``![Critical](...)`` /
``![Blocking](...)``) 을 영구 차단한다.

- ``_HIGH_IMAGE_LABEL`` 정규식 노출
- ``count_severities`` 가 image hits 를 high 카운트에 반영
- 대소문자 무관 (``re.IGNORECASE``)
- code block 안의 ``![High]`` 는 strip (false positive 방지)
- ``match_high_severity`` 도 image label 인식

헤임달(개발2팀 테스터) 작성.
    )annotationsN)Path   module)scopec                    t         dz  dz  } | j                  } |       }|st        j                  d|        dz   dt	        j
                         v st        j                  |       rt        j                  |       ndt        j                  |      t        j                  |      dz  }t        t        j                  |            dx}}t        j                  j                  dt        |             }g }d}||u}|}|r|j                  }d}||u}	|	}|slt        j                  d	|fd
||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }
dd|
iz  }|j!                  |       |rt        j                  d		fdf      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }|j!                  |       t        j"                  |d      i z  }dd|iz  }t        t        j                  |            dx}x}x}x}x}x}	}t        j                  j%                  |      }|t&        j(                  |j*                  <   |j                  j-                  |       |S )u;   ``scripts/gemini_severity_parser.py`` 절대 경로 로드.scriptszgemini_severity_parser.pyz	missing: zC
>assert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}	file_pathpy0py2py4N!gemini_severity_parser_test_alias)is not)z%(py2)s is not %(py5)sspec)r   py5z%(py7)spy7)z5%(py11)s
{%(py11)s = %(py9)s.loader
} is not %(py14)s)py9py11py14z%(py16)spy16r   zassert %(py19)spy19)	WORKSPACEexists
@pytest_ar_format_assertmsg@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation	importlibutilspec_from_file_locationstrloader_call_reprcompareappend_format_boolopmodule_from_specsysmodulesnameexec_module)r
   @py_assert1@py_assert3@py_format5r   @py_assert4@py_assert0@py_assert10@py_assert13@py_assert12@py_format6@py_format8@py_format15@py_format17@py_format18@py_format20mods                    H/home/jay/workspace/tests/lifecycle_guards/test_gemini_image_severity.pygspr@      s    I%(CCI66669+666666696669666666666666>>11+S^D 8t74t77474 777774t77777747774777t77777774777777777777777477777777777777
..
)
)$
/C CKK		KKC J    c           	        d}t        | |      }|st        j                  d      dz   dt        j                         v st        j
                  t               rt        j                  t               nddt        j                         v st        j
                  |       rt        j                  |       ndt        j                  |      t        j                  |      dz  }t        t        j                  |            d x}}| j                  }t        j                  }t        ||      }|s3ddt        j                         v st        j
                  t              rt        j                  t              nddt        j                         v st        j
                  |       rt        j                  |       ndt        j                  |      d	t        j                         v st        j
                  t              rt        j                  t              nd	t        j                  |      t        j                  |      d
z  }t        t        j                  |            d x}x}}y )N_HIGH_IMAGE_LABELu   _HIGH_IMAGE_LABEL 미노출z7
>assert %(py5)s
{%(py5)s = %(py0)s(%(py1)s, %(py3)s)
}hasattrr@   )r   py1py3r   zyassert %(py8)s
{%(py8)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s._HIGH_IMAGE_LABEL
}, %(py6)s
{%(py6)s = %(py4)s.Pattern
})
}
isinstancere)r   rE   rF   r   py6py8)rD   r   r   r   r   r   r    r!   r"   rC   rH   PatternrG   )r@   @py_assert2r3   r8   @py_assert5@py_assert7@py_format9s          r?   %test_high_image_label_pattern_exposedrP   /   s=   +K73+,K,KK.KKKKKKK7KKK7KKKKKK3KKK3KKK+KKK,KKKKKK++8RZZ8:+Z88888888:888:888888c888c888+888888R888R888Z8888888888rA   c                &   | j                  d      }|d   }d}||k\  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t	        t        j
                  |            d	x}x}}y	)
u*   ``![High](url)`` 패턴 1건 -> high >= 1.z'Issue: ![High](https://x.com/badge.svg)high   >=z%(py1)s >= %(py4)srE   r   assert %(py6)srI   Ncount_severitiesr   r(   r    r!   r"   r@   outr4   r1   rL   r2   @py_format7s          r?    test_count_severities_image_highr^   9   sa    


H
ICv;!;!;!;!rA   c                &   | j                  d      }|d   }d}||k\  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t	        t        j
                  |            d x}x}}y )	Nz'Found: ![Critical](https://x.com/c.png)rR   rS   rT   rV   rW   rX   rI   rY   r[   s          r?   $test_count_severities_image_criticalr`   ?   sa    


H
ICv;!;!;!;!rA   c                &   | j                  d      }|d   }d}||k\  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t	        t        j
                  |            d x}x}}y )	Nz(Status: ![Blocking](https://x.com/b.png)rR   rS   rT   rV   rW   rX   rI   rY   r[   s          r?   $test_count_severities_image_blockingrb   D   sa    


I
JCv;!;!;!;!rA   c                &   | j                  d      }|d   }d}||k\  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t	        t        j
                  |            d	x}x}}y	)
u!   소문자 ``![high]`` 도 인식.z.![high](url) ![CRITICAL](url) ![blocking](url)rR      rT   rV   rW   rX   rI   NrY   r[   s          r?   ,test_count_severities_image_case_insensitivere   I   sa    


O
PCv;!;!;!;!rA   c                &   | j                  d      }|d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t	        t        j
                  |            d	x}x}}y	)
u3   이미지 패턴 없는 일반 텍스트는 high=0.z%Normal text with no severity markers.rR   r   ==z%(py1)s == %(py4)srW   rX   rI   NrY   r[   s          r?   &test_count_severities_normal_text_zerorj   O   sa    


F
GCv;!;!;!;!rA   c                b   d}| j                  |      }|d   }d}||k(  }|st        j                  d|fd||f      t        j                  |      t        j                  |      dz  }t        j                  d|d          d	z   d
|iz  }t        t        j                  |            dx}x}}y)u6   code block 안의 ``![High]`` 는 strip 되어 high=0.z:Here is example code:
```
![High](url)
```
End of example.rR   r   rg   ri   rW   uB   code block 내부 패턴이 false-positive 로 카운트됨: hits=	high_hitsz
>assert %(py6)srI   N)rZ   r   r(   r    r   r!   r"   r@   bodyr\   r4   r1   rL   r2   r]   s           r?   2test_count_severities_image_in_code_block_excludedro   U   s    	 	 

t
$Cv; ! ;!  ;!            MSQ\M]L^_     rA   c                *   d}| j                  |      }|d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t	        t        j
                  |            d	x}x}}y	)
u3   inline code (``...``) 안의 ``![High]`` 도 strip.z;Use the marker `![High](url)` in your text. Nothing severe.rR   r   rg   ri   rW   rX   rI   NrY   rm   s           r?   3test_count_severities_image_in_inline_code_excludedrq   d   se    HD


t
$Cv;!;!;!;!rA   c                   | j                  d      }d |d   D        }t        |      }|st        j                  d|d          dz   dt	        j
                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }t        t        j                  |            dx}}y)	u>   ``high_hits`` 리스트에 ``image:...`` 형식 항목 포함.z![High](https://x/a.png)c              3  >   K   | ]  }|j                  d         yw)image:N)
startswith.0hs     r?   	<genexpr>z7test_high_hits_contains_image_prefix.<locals>.<genexpr>s   s     @!q||H%@s   rl   u   image: prefix hit 없음: .
>assert %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
}anyr   N)
rZ   r{   r   r   r   r   r   r    r!   r"   )r@   r\   r0   r1   r2   s        r?   $test_high_hits_contains_image_prefixr|   p   s    


9
:C@s;/?@ 3@@ @   %S%5$67             A    A     rA   c                   | j                  d      }d |D        }t        |      }|st        j                  d|       dz   dt	        j
                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }t        t        j                  |            dx}}y)u>   기존 호환 함수 ``match_high_severity`` 도 image 인식.z![Critical](url)c              3  $   K   | ]  }d |v  
 yw)imageN rv   s     r?   ry   z>test_match_high_severity_includes_image_hit.<locals>.<genexpr>|   s     *w!|*s   u%   match_high_severity image 미포함: rz   r{   r   N)
match_high_severityr{   r   r   r   r   r   r    r!   r"   )r@   hitsr0   r1   r2   s        r?   +test_match_high_severity_includes_image_hitr   x   s    ""#56D*T*Z3**Z*ZZ.STXSY,ZZZZZZZ3ZZZ3ZZZ*ZZZ*ZZZZZZrA   c                   d}| j                  |      }|d   D cg c]  }|j                  d      s| }}t        |      }d}||k\  }|st        j                  d|fd||f      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      d	z  }t        j                  d
|       dz   d|iz  }	t        t        j                  |	            d x}x}}y c c}w )Nz@Three image badges:
![High](u1) ![Critical](u2) ![Blocking](u3)
rl   rt   rd   rT   )z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} >= %(py6)slen
image_hits)r   rE   rF   rI   u   image hits 부족: z
>assert %(py8)srJ   )rZ   ru   r   r   r(   r   r   r   r    r   r!   r"   )
r@   rn   r\   rx   r   rL   rM   r3   r]   rO   s
             r?   -test_multiple_image_labels_counted_separatelyr      s    	8 	 

t
$C -Hh1G!HJHz?CaC?aCCC?aCCCCCC3CCC3CCCCCCzCCCzCCC?CCCaCCC#6zl!CCCCCCCC Is
   E#E#c                   | j                   }d} ||      }d}||u }|st        j                  d|fd||f      dt        j                         v st        j
                  |       rt        j                  |       ndt        j                  |      t        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}x}x}x}}| j                   }d
} ||      }d}||u }|st        j                  d|fd||f      dt        j                         v st        j
                  |       rt        j                  |       ndt        j                  |      t        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}x}x}x}}y	)u8   ``has_high_severity`` 헬퍼도 image 패턴에서 True.z
![High](u)T)is)zW%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.has_high_severity
}(%(py4)s)
} is %(py9)sr@   )r   r   r   rI   r   zassert %(py11)sr   Nz
clean bodyF)	has_high_severityr   r(   r   r   r   r    r!   r"   )r@   r0   r1   rM   @py_assert8rN   @py_format10@py_format12s           r?   -test_has_high_severity_returns_true_for_imager      s7     66 .6$6.$6666.$66666636663666 666666.666$6666666  77 .7%7.%7777.%77777737773777 777777.777%77777777rA   )"__doc__
__future__r   builtinsr   _pytest.assertion.rewrite	assertionrewriter   importlib.utilr#   rH   r,   pathlibr   pytest__file__resolveparentsr   fixturer@   rP   r^   r`   rb   re   rj   ro   rq   r|   r   r   r   r   rA   r?   <module>r      s    #     	 
  N""$,,Q/	 h  &9

[D8rA   