
    #Ij
                        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ZddlmZ  ee      j#                         j$                  d   ZddZd Zd Zd	 Zd
 Zd Zd Zd Zy)u  tests/regression/test_dashboard_report_hardening_2487.py — task-2487 회귀 (Group C, task-2547 corrected).

dashboard/helpers.py + report_parser.py 의 V2 + legacy dot-phase 호환 hardening 검증.

검증 대상:
- dashboard/helpers.py        : get_records_list 의 task-ID 접두사 제거 패턴 3개
- report_parser.py            : task_id 추출 + merge_branch 추출 패턴
    )annotationsN)Path   c                <   t         |z  }t        j                  j                  | t	        |            }||j
                  t        d|       t        j                  j                  |      }|t        j                  | <   |j
                  j                  |       |S )Nzcannot load spec for )	WORKSPACE	importlibutilspec_from_file_locationstrloaderImportErrormodule_from_specsysmodulesexec_module)mod_namefile_rel	file_pathspecmodules        L/home/jay/workspace/tests/regression/test_dashboard_report_hardening_2487.py_load_moduler      s    H$I>>11(C	NKD|t{{*1)=>>^^,,T2F"CKKKKF#M    c                    t         dz  dz  j                  d      } d}|| v }|st        j                  d|fd|| f      t        j                  |      dt        j                         v st        j                  |       rt        j                  |       ndd	z  }t        j                  d
      dz   d|iz  }t        t        j                  |            dx}}y)uZ   get_records_list 의 first_desc task-ID 접두사 제거 패턴이 V2 retry/_phase 인식.	dashboard
helpers.pyutf-8encodingz
(?:\+\d+)?inz%(py1)s in %(py3)ssrcpy1py3u2   dashboard/helpers.py V2 retry suffix 패턴 누락
>assert %(py5)spy5N)r   	read_text
@pytest_ar_call_reprcompare	_saferepr@py_builtinslocals_should_repr_global_name_format_assertmsgAssertionError_format_explanation)r#   @py_assert0@py_assert2@py_format4@py_format6s        r   /test_dashboard_helpers_v2_pattern_in_first_descr7   "   s    {"\1
<
<g
<
NCV>S VVV>SVVV>VVVVVVSVVVSVVVV"VVVVVVVr   c                 L   ddl } t        dz  dz  j                  d      }| j                  |      }d}| j	                  |      D ]8  }t        || j                  | j                  f      s&|j                  dk(  s6|} n d}||u}|st        j                  d|fd	||f      d
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |      dz  }t        j                  d      dz   d|iz  }t!        t        j"                  |            dx}}g }	| j	                  |      D ]k  }t        || j$                        s|j&                  }
t        |
| j(                        r|
j*                  nt-        |
dd      }|dk(  s[|	j/                  |       m |	s{t        j                  d      dz   ddt        j                         v st        j                  |	      rt        j                  |	      ndiz  }t!        t        j"                  |            |	D ]  }|j0                  D ci c]&  }|j2                  s|j2                  |j4                  ( }}d}||v }|st        j                  d|fd||f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }t        j                  d      dz   d|iz  }t!        t        j"                  |            dx}}|d   }t        || j6                        r|j4                  n|}d}||u }|st        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }t        j                  d|d       dz   d|iz  }t!        t        j"                  |            dx}} yc c}w )!u  task-2543 mtime fallback off 변경이 보존되어야 한다.

    invariant: dashboard.helpers.get_records_list 내부 모든 _resolve_end_time_priority
    호출이 fallback_to_mtime=False 키워드를 명시해야 한다. (task-2543 § 5/9 14:32
    working-tree 일괄 갱신 회귀 방지 — mtime fallback 사용 시 reconcile 결과 손상)
    AST 기반 검사로 vacuous assertion 회피.
    r   Nr   r   r   r   get_records_listis not)z%(py0)s is not %(py3)s	target_fn)py0r&   uC   get_records_list 함수를 dashboard/helpers.py에서 찾지 못함r'   r(   id_resolve_end_time_priorityu   task-2543 회귀: get_records_list 내부에서 _resolve_end_time_priority 호출이 사라짐 — end_time 우선순위 라우팅 손상 가능성z
>assert %(py0)sr=   resolve_callsfallback_to_mtimer    r"   kwr$   u   task-2543 회귀 catch 불능: _resolve_end_time_priority 호출에 fallback_to_mtime 키워드가 명시되지 않음 (암묵 기본값 의존 금지)F)is)z%(py0)s is %(py3)sobservedu?   task-2543 회귀: _resolve_end_time_priority(fallback_to_mtime=uG   ) — False 강제 필요 (5/9 14:32 mtime 일괄 갱신 회귀 방지))astr   r)   parsewalk
isinstanceFunctionDefAsyncFunctionDefnamer*   r+   r-   r.   r/   r,   r0   r1   r2   Callfunc	AttributeattrgetattrappendkeywordsargvalueConstant)rE   r#   treer<   noder4   @py_assert1r5   r6   r@   rM   	call_name@py_format1callkrB   r3   val_noderD   s                      r   9test_dashboard_helpers_preserves_task_2543_mtime_fallbackr^   )   sg    {"\1
<
<g
<
NC99S>DI dS__c.B.BCDVhIhI !g9D ggg9Dgggggg9ggg9gggDggg"gggggggM# +dCHH%99D%/cmm%D		'RVX\^bJcI88$$T*+   	;              
  
&*mm=quuaeeQWWn==" 	
"b( 	
 	
"b 	
 	
 
	 # 	
 	
 
6	
 	
  ') 	
 	
 
	 ') 	
 	
 b	
 	
 	
 	
 	
 )*%/#,,%G8>>X  	
x5  	
 	
x5 	
 	
 
6	
 	
   	
 	
 
	  	
 	
 
	 ! 	
 	
  Nlac	
 	
 	
 	
 	

=s   P!P!c                 ~   t        dd      } t        j                  dddd      5 }|j                  d       |j                  }d	d	d	       	 | j                        }|d
   }d}||k(  }|st        j                  d|fd||f      t        j                  |      t        j                  |      dz  }t        j                  d|       dz   d|iz  }t        t        j                  |            d	x}x}}t        |      j                  d       y	# 1 sw Y   xY w# t              j                  d       w xY w)uV   report_parser.parse_report 가 # task-2487+1 헤더에서 V2 task_id 를 추출한다.rp_2487report_parser.pyw.mdFr   modesuffixdeleter   u5   # task-2487+1 — sample title

- **팀**: dev2-team
Ntask_idztask-2487+1==)z%(py1)s == %(py4)sr%   py4u   V2 retry suffix 추출 실패: z
>assert %(py6)spy6T
missing_ok)r   tempfileNamedTemporaryFilewriterK   parse_reportr*   r+   r,   r0   r1   r2   r   unlink)	rptftmp_pathoutr3   @py_assert3r4   @py_format5@py_format7s	            r   1test_report_parser_v2_pattern_in_title_extractionr|   X   s    	i!3	4B		$	$#eET[	\ `b
KL77/ooh'9~WW~.WWW~WWW~WWWWWW2QRUQV0WWWWWWWWX.  	X.s   DB*D DD<c                    t        dd      } t        j                  dddd      5 }|j                  d       |j                  }d	d	d	       	 | j                        }|d
   }d	}||u}|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}x}}|d
   }|j                  }d}	 ||	      }
|
st        j                  d|       dz   t        j                  |      t        j                  |      t        j                  |	      t        j                  |
      dz  }t        t        j                  |            d	x}x}x}	}
t        |      j                  d       y	# 1 sw Y   ixY w# t              j                  d       w xY w)u]   report_parser.parse_report 가 legacy # task-1234.5 헤더에서도 task_id 를 추출한다.rp_2487_legacyra   rb   rc   Fr   rd   u5   # task-1234.5 — legacy title

- **팀**: dev2-team
Nrh   r:   )z%(py1)s is not %(py4)srk   zassert %(py6)srm   z	task-1234u   legacy task_id 추출 실패: zN
>assert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.startswith
}(%(py5)s)
})r%   r&   r(   py7Trn   )r   rp   rq   rr   rK   rs   r*   r+   r,   r1   r2   
startswithr0   r   rt   )ru   rv   rw   rx   r3   ry   r4   rz   r{   @py_assert4@py_assert6@py_format8s               r   5test_report_parser_legacy_pattern_in_title_extractionr   e   s]   	&(:	;B		$	$#eET[	\ `b
KL77	/ooh'
 9~)T)~T))))~T)))~)))T)))))))9~]~((]](5]5]]9WX[W\7]]]]~]]](]]]]]]5]]]]]]X.  	X.s   F+EF8 +F58Gc                    t        dd      } t        j                  dddd      5 }|j                  d       |j                  }d	d	d	       	 | j                        }|j                  }d
} ||      }d}||k(  }|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  }	t        j                  d|j                  d
             dz   d|	iz  }
t        t        j                  |
            d	x}x}x}x}}t!        |      j#                  d       y	# 1 sw Y   ^xY w# t!              j#                  d       w xY w)uP   report_parser.parse_report 가 V2 branch task/task-2487+1-dev2 를 추출한다.rp_2487_branchra   rb   rc   Fr   rd   uj   # task-2487+1 — merge sample

- **머지 브랜치**: task/task-2487+1-dev2
- **상태**: 머지 필요
Nmerge_branchztask/task-2487+1-dev2ri   zI%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.get
}(%(py4)s)
} == %(py9)srx   r=   py2rl   rm   py9u&   V2 retry suffix branch 추출 실패: 
>assert %(py11)spy11Trn   r   rp   rq   rr   rK   rs   getr*   r+   r-   r.   r/   r,   r0   r1   r2   r   rt   ru   rv   rw   rx   rX   ry   @py_assert5@py_assert8@py_assert7@py_format10@py_format12s              r   *test_report_parser_merge_branch_v2_patternr   w   s   	&(:	;B		$	$#eET[	\ `b
,	

 77/ooh'ww 	
~ 	
w~& 	
*A 	
&*AA 	
 	
&*A 	
 	
	6	
 	
   	
 	
 		  	
 	
 		  	
 	
 		 & 	
 	
 		 ' 	
 	
 		 +B 	
 	
  5SWW^5L4MN	
 	
 	
 	
 	
 	
 	X.  	X.   F D7F-  F*-G
c                    t        dd      } t        j                  dddd      5 }|j                  d       |j                  }d	d	d	       	 | j                        }|j                  }d
} ||      }d}||k(  }|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  }	t        j                  d|j                  d
             dz   d|	iz  }
t        t        j                  |
            d	x}x}x}x}}t!        |      j#                  d       y	# 1 sw Y   ^xY w# t!              j#                  d       w xY w)uT   report_parser.parse_report 가 legacy task/task-1234.5-dev1 branch 도 추출한다.rp_2487_branch_legacyra   rb   rc   Fr   rd   uN   # task-1234.5 — legacy merge

- **머지 브랜치**: task/task-1234.5-dev1
Nr   ztask/task-1234.5-dev1ri   r   rx   r   u   legacy branch 추출 실패: r   r   Trn   r   r   s              r   .test_report_parser_merge_branch_legacy_patternr      s   	-/A	BB		$	$#eET[	\ `b
>	
 77/ooh'ww 	
~ 	
w~& 	
*A 	
&*AA 	
 	
&*A 	
 	
	6	
 	
   	
 	
 		  	
 	
 		  	
 	
 		 & 	
 	
 		 ' 	
 	
 		 +B 	
 	
  ,CGGN,C+DE	
 	
 	
 	
 	
 	
 	X.  	X.r   c                 
   t         dz  dz  j                  d      } d}d}g }|| v }|}|s|| v }|}|st        j                  d|fd|| f      d	t	        j
                         v st        j                  |      rt        j                  |      nd	d
t	        j
                         v st        j                  |       rt        j                  |       nd
dz  }dd|iz  }|j                  |       |st        j                  dfd|| f      dt	        j
                         v st        j                  |      rt        j                  |      ndd
t	        j
                         v st        j                  |       rt        j                  |       nd
dz  }	dd|	iz  }
|j                  |
       t        j                  |d      i z  }t        j                  d      dz   d|iz  }t        t        j                  |            dx}x}x}}d}t        j                  }d}d} ||||      }|j                  } |       }d}||k(  }|sZt        j                  d|fd||f      dt	        j
                         v st        j                  t              rt        j                  t              ndt        j                  |      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      d 	z  }d!d"|iz  }t        t        j                  |            dx}x}x}x}x}x}x}}t        j                  }d}d#} ||||      }|j                  } |       }d$}||k(  }|sZt        j                  d|fd||f      dt	        j
                         v st        j                  t              rt        j                  t              ndt        j                  |      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      d 	z  }d!d"|iz  }t        t        j                  |            dx}x}x}x}x}x}x}}y)%u_   dashboard/helpers.py 의 prefix-strip regex 가 task-2487+1: 를 제거하는지 직접 검증.r   r   r   r   z5task-\d+(?:\.\d+)?(?:_\d+\.\d+)?(?:_[a-z])?(?:\+\d+)?z5task-\d+(?:\.\d+)*(?:_\d+\.\d+)?(?:_[a-z])?(?:\+\d+)?r    )z%(py2)s in %(py4)spat_marker_qr#   )r   rl   z%(py6)srm   )z%(py8)s in %(py10)spat_marker_star)py8py10z%(py12)spy12   u4   dashboard/helpers.py V2 task-ID strip pattern 누락z
>assert %(py15)spy15NuY   ^(?:task-\d+(?:\.\d+)?(?:_\d+\.\d+)?(?:_[a-z])?(?:\+\d+)?|Task\s+\d+[\.\d]*)\s*[:：]?\s* ztask-2487+1: sample titlezsample titleri   )z%(py13)s
{%(py13)s = %(py11)s
{%(py11)s = %(py9)s
{%(py9)s = %(py2)s
{%(py2)s = %(py0)s.sub
}(%(py3)s, %(py5)s, %(py7)s)
}.strip
}()
} == %(py16)srepattern)	r=   r   r&   r(   r   r   r   py13py16zassert %(py18)spy18ztask-1234.5: legacy titlezlegacy title)r   r)   r*   r+   r-   r.   r/   r,   rQ   _format_boolopr0   r1   r2   r   substrip)r#   r   r   rX   ry   r3   @py_assert9rz   r{   @py_format11@py_format13@py_format14@py_format16r   r   r   r   @py_assert10@py_assert12@py_assert15@py_assert14@py_format17@py_format19s                          r   )test_dashboard_helpers_retry_suffix_stripr      s   {"\1
<
<g
<
NCRLUO<3 /S"8   <3                         /S      #2    #2      69    69        	?     
 kG66U2U:U6'2:;U;AAUACU~UC~UUUUC~UUUUUU2UUU2UUU6UUUUUU'UUU'UUU2UUU:UUU;UUUAUUUCUUU~UUUUUUUU66U2U:U6'2:;U;AAUACU~UC~UUUUC~UUUUUU2UUU2UUU6UUUUUU'UUU'UUU2UUU:UUU;UUUAUUUCUUU~UUUUUUUUr   )r   r   r   r   )__doc__
__future__r   builtinsr-   _pytest.assertion.rewrite	assertionrewriter*   importlib.utilr   r   r   rp   pathlibr   __file__resolveparentsr   r   r7   r^   r|   r   r   r   r    r   r   <module>r      sk    #     	 
  N""$,,Q/	W,
^
//$/&/$Vr   