
     j|                    h   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 ddlZ ee      j#                         j$                  j$                  j$                  Z ee      ej*                  v r!ej*                  j-                   ee             ej*                  j/                  d ee             ddlmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3 dd	l-m4Z4 dd
l5m6Z6 ddl7m8Z8  ee      j$                  dz  dz  Z9d.dZ:d/dZ;h dZ<d Z=d Z>d Z?d Z@d ZAd ZBd ZCd ZDd ZEd ZFd ZG ej                  d      d        ZId ZJd  ZKd! ZLd" ZMd# ZNd$ ZOd% ZPd& ZQd' ZRd( ZSd) ZTd* ZUd0d+ZVd, ZWeXd-k(  r ej                   eV              yy)1u   task-2515 e2e auto-merge replay harness — 9 PR × 12 verifications.
회장 명시: 본 task = end-to-end 검증 + replay harness (신규 기능 X).
    )annotationsN)Path)AUTO_MERGE_ALLOWEDAUTO_MERGE_SUCCESSBLOCKED_WITH_REASONDIFF_CONTAMINATION_REPLACEMENTGEMINI_UNRESOLVED_BLOCKCRITICAL_FORBIDDEN_PATH CRITICAL_DIFF_REPLACEMENT_FAILEDCRITICAL_GEMINI_SCOPE_EXPANSIONCRITICAL_BLOCK_OVERRIDECRITICAL_DEPENDENCY_CYCLECRITICAL_REPLACEMENT_FAILEDCRITICAL_POST_MERGE_SMOKEExecutorContextTaskSpecevaluate_prverify_head_lock_then_mergecompare_effective_diffdetect_forbidden_pathscheck_predecessor_mergedrecheck_following_prs)ReplacementResult)	triage_pr)PostMergeSmokeRunSmokeStatus)SmokeResult)process_eventReplacementPRRunnerfixtureszauto_merge_replay_2515.jsonc                 T    t        j                  t        j                  d            S )Nutf-8encoding)jsonloadsFIXTURE_PATH	read_text     @/home/jay/workspace/tests/e2e/test_auto_merge_e2e_replay_2515.py_load_fixturesr-   .   s    ::l,,g,>??r+   c                4    t        j                  g | ||      S )N)args
returncodestdoutstderr)
subprocessCompletedProcess)r0   r1   r2   s      r,   _cpr5   2   s    &&B:f]cddr+   >   -f--admin--force--no-verifycherry-pick--force-with-leasec                *     g d fd	}|_         |S )uZ   시나리오 fixture로부터 fake subprocess runner 합성. forbidden flag 호출 차단.c           	     0    j                  t               ||d       t        D ]  f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}x}} d v r!d	 v rt        j                  d
d      d      S j                  d      xs g }|r4t         fd|d d D              rt        j                  dd      d      S j                  d      xs g D ]  }t        |d         }	|	 v sd v s|j                  dd      |j                  dd      d|j                  dg       D 
cg c]  }
d|
i c}
d}t        dt!        j"                  |            c S  t               S c c}
w )N)r/   cwdtimeoutc              3  \   K   | ]#  }|k(  xs |j                  d d      d   k(   % yw)=   r   N)split).0argtoks     r,   	<genexpr>z4_make_fake_runner.<locals>.runner.<locals>.<genexpr>B   s:       s
9ciiQ/2c99s   ),zFORBIDDEN_TOKEN detected: z in z2
>assert not %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
}anypy0py2py4mergez--squashmerge_runner_returncoder   merged)r0   r1   smoke_commandc              3  &   K   | ]  }|v  
 y wNr*   )rD   tr/   s     r,   rG   z4_make_fake_runner.<locals>.runner.<locals>.<genexpr>K   s     0Aa4i0s   rB   smoke_runner_returncodezsmoke outputfollowing_queue	pr_numberz--jsonmergeStateStatusCLEAN
headRefOid maineffective_filespath)rW   rY   baseRefNamefiles)appendlistFORBIDDEN_TOKENSrH   
@pytest_ar_format_assertmsg@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationr5   getallstrr&   dumps)r/   r>   r?   @py_assert1@py_assert3@py_assert5@py_format6scfppnppayloadrF   callsscenarios   `           @r,   runnerz!_make_fake_runner.<locals>.runner>   s"   d4jIJ# 	<C <s   <   <  < +<*;+C5TF;< < 6<V< < $<#;  < < 3<)  < < 3<) < < 3<) < < < )<(;< < <	< d?zT1(,,/H!"LU]^^\\/*0b#0BQ00(,,/H!"LUcdd,,017R 		EBR_%BTzh$.(*/A7(K"$&&r":#)3566:KR3PQavqkQ	 a

70CDD		E u Rs   H)N<   )rx   )ry   rz   rx   s   ` @r,   _make_fake_runnerr|   :   s    E8 FLMr+   c                   t        | d   t        | d         dt        | j                  dg             | j                  dd      | j                  dd      | j                  d	d
      | j                  dd      | j                  d      	      S )Ntask_idexpected_filesauto_merge_e2e_replay
dependencyparallel_policyserial_onlymerge_queue_positionrB   stale_recheck_requiredTcherry_pick_allowedFrP   )	r~   r   	risk_arear   r   r   r   r   rP   )r   ra   rk   ss    r,   _make_task_specr   ^   s    )A./0)lB/0/?UU#91= uu%=tDEE"7?eeO,
 
r+   c                d      d   }|dk(  rt        |d      S |dk(  r G  fdd      } |       S y)	u6  시나리오 expected_replacement_used에 맞춰 ReplacementPRRunner 또는 fake runner 반환.
    PR57_contamination_replacement → ReplacementPRRunner(dry_run=True) (success=True 합성).
    critical_diff_contamination_replacement_failed → fake runner returning success=False.
    그 외 → None.
    idPR57_contamination_replacementT)rz   dry_run.critical_diff_contamination_replacement_failedc                      e Zd Zd fd	Zy)-_make_replacement_runner.<locals>._FailRunnerNc           
     p    t        |d d|rt        |j                        ng t        d         g dd      S )NTr\   F9REPLACEMENT_PR_AUTO_CREATION_FAILED_FOR_CONTAMINATED_DIFF)	source_prreplacement_proriginal_pr_preservedr   effective_diff_filesforbidden_pathssuccessfailure_reason)r   ra   r   )selfrV   	task_specr   s      r,   executez5_make_replacement_runner.<locals>._FailRunner.executew   sB    ('*.EN4	(@(@#ATV)-a0A.B)C$&!#^ r+   rR   )__name__
__module____qualname__r   r   s   r,   _FailRunnerr   v   s    	r+   r   Nr   )r   rz   sidr   s   `   r,   _make_replacement_runnerr   l   sD     D'C
.."&$??
>>
	 
	 }r+   c                      j                  dd       j                  d      xs g rdj                        nd fd}|S )u   task-2514 W1 circular import으로 run_pm_smoke_v2 가 None이라 직접 envelope 합성 fn 주입.

    fixture 의 smoke_runner_returncode 에 따라 PASS/FAIL envelope 반환.
    rT   r   rP    rZ   c                $   
dk(  rDt        	ddddd       }t        |xs dd   t        j                  |dt	              dd d|	
      S t        	d
dd
d
       }t        |xs dd   t        j
                  |dt	              dd d|	
      S )Nr   TrZ   )commandpassed	exit_codestdout_tailstderr_tailr   zfixture-merge-shar~   d   F)
merge_commitr~   statussmoke_resultduration_msrP   allow_continuation
escalationstaler   zsmoke fail simulatedEXIT_)r   r   r   PASSra   FAIL)	task_filer   r   rz   rV   skip_stale_check_kwsrcmdcmd_strrcry   s           r,   _envelope_fnz-_make_smoke_envelope_fn.<locals>._envelope_fn   s    7BtB %)@-@ +"''"3i#'  ER(>"2$<

 !%<)<Y'##s)$
 	
r+   )rk   join)ry   r   r   r   r   s   ` @@@r,   _make_smoke_envelope_fnr      sH    
 
/	3B
,,
'
-2C"chhsmG"
F r+   c                $    g fd}|_         |S )u   ctx.triage_fn 으로 주입할 spy. evaluate_pr W3 호출 여부를 외부에서 관찰 가능.

    실제 triage_pr 을 위임 호출. wiring 활성화 검증용.
    c           
     d    j                  | t        |      |d       t        | |||||||      S )N)rV   thread_countr~   )r`   lenr   )	rV   threadspr_head_shafix_commitsr   r   applyr~   observeds	           r,   spyz_make_triage_spy.<locals>.spy   sB    "L
 	
 w[OUG
 	
r+   r   ry   r   r   s     @r,   _make_triage_spyr      s    
 H

 CLJr+   c                (     g  fd}|_         |S )u   ctx.reporter_hook 으로 주입할 spy. evaluate_pr emit_critical_escalation 활성 검증.

    실제 process_event 호출 후 decision.escalations 에 결과를 직접 push.
    W1 circular import 으로 default report_critical_event=None 이지만, hook 명시 주입 시 작동.
    c                $   |j                   |j                  | t        d         d}t        d   d   | d|ddd      }j	                  | |d	       t        |d
      r|j                  g |_        |j                  j	                  |       y )Nr\   )decisionreasoncritical_coder\   r~   rV   e2e_reporter_hook_spyr~   rV   
event_typesourceevidenceTno_auditr   )coderesultescalations)r   r   ra   r   r`   hasattrr   )r   r   r   r   r   ry   s       r,   r   z$_make_reporter_hook_spy.<locals>.spy   s     ))oo!#H->$?@	
 #I.%k2"1$ 

 	89x/83G3G3O#%H ##F+r+   r   r   s   ` @r,   _make_reporter_hook_spyr      s     H,, CLJr+   c                b   | j                  d      rt        |       nd }| j                  d      dk(  rt        |       nd }| j                  d      rt        |       nd }t	        || j                  d      d| j                  dd      t        | |      || j                  d      xs d | j                  d      xs d | j                  d	      | j                  d
      rd nd ||      }|t        t              |_        | j                  d      rt        | d         |_
        ||_        ||_        |S )Ntriage_threadsexpected_classificationcriticalrP   Tfixture_main_shazfixture-main-shar   r   main_log_grep_returns_truec                     yNTr*   _ts    r,   <lambda>z(_make_executor_context.<locals>.<lambda>       r+   )rz   rP   r   r   replacement_runner	triage_fnr   triage_fix_commitstriage_pr_head_shamain_log_grepreporter_hooksmoke_envelope_fnrU   )rk   r   r   r   r   r   r   __file__r   ra   rU   
triage_spyreporter_spy)r   rz   r   r   smoke_env_fnctxs         r,   _make_executor_contextr      s   ().>(?!!$TJ127P1QU_1_*1-eiL121G*1-TL
eeO,13EF3Av>uu-.6$55/7455/+,551M+NTX"&C Xuu"1%6#78CN#CJr+   c                @    t         t        t        t        t        d|    S )Nr   r   r   r   r	   r   names    r,   _resolve_expected_decisionr   	  s%    002*H#:  r+   c                Z    | y t         t        t        t        t        t
        t        d|    S )Nr
   r   r   r   r   r   r   r   r   s    r,   _resolve_critical_coder     s3    |#:,L+J#:%>'B%>  r+   c           
     $    t               }t               }t         |      }t         d   | d   t	         d          d    d    d   |      } j                  d      r)|j                  t        k(  rt        | d   | fd	d
      }||||fS )u_   evaluate_pr → (필요 시) verify_head_lock_then_merge 호출 → final QueueDecision 반환.rV   r   r\   merge_stateci_stategemini_state)rV   r   r   r\   r  r  r  r   verify_mergec                    d   S )Nr   r*   )_nry   s    r,   r   z_run_pipeline.<locals>.<lambda>5  s    h}.E r+   F)r   rV   r   fetch_pr_head_at_merger   )	r|   r   r   r   ra   rk   r   r   r   )ry   rz   specr   r   s   `    r,   _run_pipeliner	  !  s    x(F8$D
 6
2C;']+X&789]+*%n-	H ||N#(9(9=O(O.{+#E
 S&$&&r+   c                2a   | d   }| j                  d      rd nd}t        | j                  d      xs g ||      \  }}g }	d}
||
u }|}|r	g }||k(  }|}|sst        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                  |      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}x}
x}}t        | d   | d         \  }}}| d   }t        |      }||k(  }	|	st        j                  d|	fd||f      dt	        j
                         v st        j                  |      rt        j                  |      nddt	        j
                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }t        j                  | d| d | d!| d"| d    	      d#z   d$|iz  }t        t        j                  |            dx}	x}}t        | d   | d         }t!        |      }| d%   }t#        |      }||k(  }
|
stt        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                  |      d)t	        j
                         v st        j                  t"              rt        j                  t"              nd)t        j                  |      t        j                  |      d*z  }t        j                  | d+| d,| d%          d-z   d.|iz  } t        t        j                  |             dx}x}
x}}|j$                  }	| d/   }t        |      }!|	|!k(  }|s5t        j                  d|fd0|	|!f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      dt	        j
                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |!      d2z  }t        j                  | d3|j$                   d4| d/          d5z   d6|iz  }"t        t        j                  |"            dx}	x}x}}!t'        |d7d      }#| j                  d8      rd}|#|u}	|	st        j                  d9|	fd:|#|f      d7t	        j
                         v st        j                  |#      rt        j                  |#      nd7t        j                  |      d;z  }$t        j                  | d<      d=z   d>|$iz  }t        t        j                  |            dx}	}|#j(                  }t!        |      }
d?}!|
|!k(  }|s8t        j                  d|fd@|
|!f      d't	        j
                         v st        j                  t               rt        j                  t               nd'd7t	        j
                         v st        j                  |#      rt        j                  |#      nd7t        j                  |      t        j                  |
      t        j                  |!      dAz  }t        j                  | dBt!        |#j(                               d5z   d6|iz  }"t        t        j                  |"            dx}x}
x}}!|#j(                  d   dC   }| dC   }||k(  }|st        j                  d|fdD||f      t        j                  |      t        j                  |      dEz  }%t        j                  | dF|#j(                         dGz   dH|%iz  }t        t        j                  |            dx}x}}nd}|#|u }	|	st        j                  d|	fdI|#|f      d7t	        j
                         v st        j                  |#      rt        j                  |#      nd7t        j                  |      d;z  }$t        j                  | dJ      d=z   d>|$iz  }t        t        j                  |            dx}	}| j                  dK      xs g }&|&r\t+        | dC   | d8   xs g | dL   | j                  dM      xs g t-        | d         g dN| dO   P      }'|'j.                  D (cg c]  }(|(j0                  j2                   })}(|)|&k(  }	|	st        j                  d|	fdQ|)|&f      dRt	        j
                         v st        j                  |)      rt        j                  |)      ndRdSt	        j
                         v st        j                  |&      rt        j                  |&      ndSdTz  }*t        j                  | dU|) d4|&       dVz   dW|*iz  }%t        t        j                  |%            d}	| j                  dX      }+| j                  dYdN      },| j                  dZdN      }-|+|j4                  xs |j6                  }.t        |+      }
|.|
k(  }	|	sXt        j                  d|	fd[|.|
f      d\t	        j
                         v st        j                  |.      rt        j                  |.      nd\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^z  }t        j                  | d_|j4                   d`|j6                   d4|+       daz   d|iz  }t        t        j                  |            dx}	}
|j8                  }	t        |,      }|	|k(  }|s_t        j                  d|fdb|	|f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      dt	        j
                         v st        j                  t              rt        j                  t              nddct	        j
                         v st        j                  |,      rt        j                  |,      ndct        j                  |      ddz  }t        j                  | de|j8                   d4|,       dfz   dg|iz  }t        t        j                  |            dx}	x}}|,r
|j6                  }	t        |-      }|	|k(  }|s_t        j                  d|fdh|	|f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      dt	        j
                         v st        j                  t              rt        j                  t              nddit	        j
                         v st        j                  |-      rt        j                  |-      ndit        j                  |      ddz  }t        j                  | dj|j6                   d4|-       dfz   dg|iz  }t        t        j                  |            dx}	x}}n|j8                  }	t        |,      }|	|k(  }|s_t        j                  d|fdb|	|f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      dt	        j
                         v st        j                  t              rt        j                  t              nddct	        j
                         v st        j                  |,      rt        j                  |,      ndct        j                  |      ddz  }t        j                  | dk|j8                   d4|,       dfz   dg|iz  }t        t        j                  |            dx}	x}}t;        | dl         }/|j<                  }	|	|/k(  }|st        j                  d|fdm|	|/f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      dnt	        j
                         v st        j                  |/      rt        j                  |/      ndndoz  }%t        j                  | dp|j<                   d4|/       dGz   dH|%iz  }t        t        j                  |            dx}	}t?        | j                  dq            }0|j@                  }	|	|0k(  }|st        j                  d|fdr|	|0f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      dst	        j
                         v st        j                  |0      rt        j                  |0      ndsdoz  }%t        j                  | dt|j@                   d4|0       dGz   dH|%iz  }t        t        j                  |            dx}	}| j                  du      }1|1|jB                  }	|	|1k(  }|st        j                  d|fdv|	|1f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      dwt	        j
                         v st        j                  |1      rt        j                  |1      ndwdoz  }%t        j                  | dx|jB                   d4|1       dGz   dH|%iz  }t        t        j                  |            dx}	}|jD                  }	d}
|	|
u}|st        j                  d9|fdy|	|
f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      t        j                  |
      dzz  }t        j                  | d{|jB                         daz   d|iz  }t        t        j                  |            dx}	x}}
|jD                  }	|	j                   }d|} ||      }!|!|1k(  }2|2sJt        j                  d|2fd}|!|1f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      t        j                  |      t        j                  |      t        j                  |!      dwt	        j
                         v st        j                  |1      rt        j                  |1      ndwd~z  }"t        j                  | d|jD                  j                  d|             dz   d|"iz  }t        t        j                  |            dx}	x}x}x}!}2|1dk(  }3|jD                  }	|	j                   }d} ||      }!|!|3u }2|2sMt        j                  d|2fd|!|3f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      t        j                  |      t        j                  |      t        j                  |!      dt	        j
                         v st        j                  |3      rt        j                  |3      ndd~z  }"t        j                  | d|jD                  j                  d       d4|3       dz   d|"iz  }t        t        j                  |            dx}	x}x}x}!}2ng }	|jB                  }d}||k(  }|}|s|jD                  }4d}5|4|5u }6|6}|st        j                  d|fd||f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |      t        j                  |      dz  }ddg|iz  }|	j                  |       |st        j                  d6fd45f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |4      t        j                  |5      dz  }7dd|7iz  }8|	j                  |8       t        j                  |	d?      i z  }9t        j                  | d|jD                         dz   d|9iz  }:t        t        j                  |:            dx}x}	x}x}x}x}4x}6}5| j                  d      xs g };| j                  d      xs g }<|<rtG        |<|      }=t!        |=      }t!        |;      }!||!k(  }
|
st        j                  d|
fd||!f      d't	        j
                         v st        j                  t               rt        j                  t               nd'dt	        j
                         v st        j                  |=      rt        j                  |=      ndt        j                  |      d't	        j
                         v st        j                  t               rt        j                  t               nd'dt	        j
                         v st        j                  |;      rt        j                  |;      ndt        j                  |!      dz  }t        j                  | dt!        |=       d4t!        |;             d5z   d6|iz  }"t        t        j                  |"            dx}x}
}!tI        |=|;      D ]  \  }>}?|?jK                         D ]  \  }@}A|>j                   }	 |	|@      }
|
|Ak(  }|sqt        j                  d|fd|
Af      dt	        j
                         v st        j                  |>      rt        j                  |>      ndt        j                  |	      dt	        j
                         v st        j                  @      rt        j                  @      ndt        j                  |
      dt	        j
                         v st        j                  A      rt        j                  A      nddz  }t        j                  | d|>j                  dC       d@ d|>j                  |@       d4A 	      dfz   dg|iz  }t        t        j                  |            dx}	x}
}  | j                  d      r|j<                  tL        k(  r|jN                  }Bg }	|B}|Brt!        B      }d?}2||2k\  }|}|sdddt	        j
                         v st        j                  B      rt        j                  B      ndiz  }*|	j                  |*       Brt        j                  d|fd|2f      d't	        j
                         v st        j                  t               rt        j                  t               nd'dt	        j
                         v st        j                  B      rt        j                  B      ndt        j                  |      t        j                  |2      dz  }"dd|"iz  }|	j                  |       t        j                  |	d      i z  }Ct        j                  | dB       dz   d|Ciz  }t        t        j                  |            dx}x}	x}x}}2BD Dch c]  }D|Dj                  dC       }E}D|<D ]  }F|FdC   }|Ev }|st        j                  d|fd|Ef      t        j                  |      dt	        j
                         v st        j                  E      rt        j                  E      nddz  }$t        j                  | dFdC    d      d=z   d>|$iz  }t        t        j                  |            dx}} ng }	|jN                  }g }||k(  }|}|s|jN                  }4d}5|4|5u }6|6}|st        j                  d|fd||f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |      t        j                  |      dz  }ddg|iz  }|	j                  |       |st        j                  d6fd45f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |4      t        j                  |5      dz  }7dd|7iz  }8|	j                  |8       t        j                  |	d?      i z  }9t        j                  | d|jN                         dz   d|9iz  }:t        t        j                  |:            dx}x}	x}x}x}x}4x}6}5| j                  d      }G| d   }Ht'        |dd      }I|Hdk(  rPd}I|u}	|	st        j                  d9|	fd:I|f      dt	        j
                         v st        j                  I      rt        j                  I      ndt        j                  |      d;z  }$t        j                  | d      d=z   d>|$iz  }t        t        j                  |            dx}	}Ij(                  }t!        |      }
d?}!|
|!k\  }|s8t        j                  d|fd|
|!f      d't	        j
                         v st        j                  t               rt        j                  t               nd'dt	        j
                         v st        j                  I      rt        j                  I      ndt        j                  |      t        j                  |
      t        j                  |!      dAz  }t        j                  | dt!        Ij(                               d5z   d6|iz  }"t        t        j                  |"            dx}x}
x}}!Ij(                  d   }J|Jd   d   }d}||k(  }|st        j                  d|fdD||f      t        j                  |      t        j                  |      dEz  }%t        j                  | dJd   d          dGz   dH|%iz  }t        t        j                  |            dx}x}}Jd   d   }d}||u}|st        j                  d9|fd||f      t        j                  |      t        j                  |      dEz  }%t        j                  | d      dGz   dH|%iz  }t        t        j                  |            dx}x}}Jd   d   }|Gk(  }|st        j                  d|fd|Gf      t        j                  |      dt	        j
                         v st        j                  G      rt        j                  G      nddz  }$t        j                  | dJd   d    d4G       d=z   d>|$iz  }t        t        j                  |            dx}}g }	|jP                  }|}|r |jP                  }t!        |      }d?}K||Kk\  }4|4}|sdd1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |      dǜz  }%|	j                  |%       |rt        j                  d4fd|Kf      d't	        j
                         v st        j                  t               rt        j                  t               nd'd1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |      t        j                  |      t        j                  K      dɜz  }dd|iz  }7|	j                  |7       t        j                  |	d      i z  }t        j                  | d|jP                         dz   d|iz  }9t        t        j                  |9            dx}x}	x}x}x}x}4}KnIaIj(                  }t!        |      }
d}!|
|!k(  }|s8t        j                  d|fd@|
|!f      d't	        j
                         v st        j                  t               rt        j                  t               nd'dt	        j
                         v st        j                  I      rt        j                  I      ndt        j                  |      t        j                  |
      t        j                  |!      dAz  }t        j                  | dt!        Ij(                               d5z   d6|iz  }"t        t        j                  |"            dx}x}
x}}!tS        | dO   | dC   ddi dҜddӫ      }L|Ld   }d}||k(  }|st        j                  d|fdD||f      t        j                  |      t        j                  |      dEz  }%t        j                  | dLd          dGz   dH|%iz  }t        t        j                  |            dx}x}}Ld   }d}||u }|st        j                  d|fd||f      t        j                  |      t        j                  |      dEz  }%t        j                  | dם      dGz   dH|%iz  }t        t        j                  |            dx}x}}Hdk(  r|j@                  }	d}
|	|
u }|st        j                  d|fd|	|
f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      t        j                  |
      dzz  }t        j                  | d|j@                         daz   d|iz  }t        t        j                  |            dx}	x}}
|jT                  }	d}
|	|
u }|st        j                  d|fd|	|
f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |	      t        j                  |
      dzz  }t        j                  | d|jT                         daz   d|iz  }t        t        j                  |            dx}	x}}
yg }	|j@                  }d}||u}|}|s|jT                  }4d}5|4|5u}6|6}|st        j                  d9|fd||f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |      t        j                  |      dz  }ddg|iz  }|	j                  |       |st        j                  d96fd45f      d1t	        j
                         v st        j                  |      rt        j                  |      nd1t        j                  |4      t        j                  |5      dz  }7dd|7iz  }8|	j                  |8       t        j                  |	d?      i z  }9t        j                  | dޝ      dz   d|9iz  }:t        t        j                  |:            dx}x}	x}x}x}x}4x}6}5yc c}(w c c}Dw )u   12 항목을 순서대로 검증. 모든 assertion이 PASS여야 함.

    ctx 는 spy(triage_spy/reporter_spy) 관찰 + smoke_envelope_fn 활성화 검증 시 사용.
    _spec 은 호출 측 signature 호환 (직접 참조 X).
    r   r   c                     yr   r*   r   s    r,   r   z"_verify_12_items.<locals>.<lambda>D  r   r+   Nr   )r   Tis)z%(py2)s is %(py5)shead_ok)rK   py5z%(py7)spy7==)z%(py9)s == %(py12)spending)py9py12z%(py14)spy14r   u     §1 queue head failed: pending=z
>assert %(py17)spy17r\   r   expected_diff_equal)z0%(py0)s == %(py6)s
{%(py6)s = %(py2)s(%(py4)s)
}diff_okbool)rJ   rK   rL   py6u    §2 diff mismatch: diff_ok=z extra=z	 missing=z expected_equal=z
>assert %(py8)spy8expected_forbidden_count)zN%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py9)s
{%(py9)s = %(py5)s(%(py7)s)
}r   	forbiddenint)rJ   py1py3r  r  r  u    §3 forbidden mismatch: got=z expected_count=z
>assert %(py11)spy11expected_replacement_used)zV%(py2)s
{%(py2)s = %(py0)s.replacement_used
} == %(py8)s
{%(py8)s = %(py4)s(%(py6)s)
}r   )rJ   rK   rL   r  r  u$    §4 replacement_used mismatch: got=z
 expected=z
>assert %(py10)spy10r   r   is not)z%(py0)s is not %(py3)s)rJ   r!  u5    §5 triage_spy must be injected for triage scenariosz
>assert %(py5)sr  rB   )zN%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.observed
})
} == %(py8)s)rJ   r   r!  r  r  u1    §5 triage_fn must be invoked exactly once, got rV   z%(py1)s == %(py4)sr   rL   u#    §5 triage_fn pr_number mismatch: z
>assert %(py6)sr  )z%(py0)s is %(py3)su'    §5 no triage scenario but spy presentexpected_triage_verdictsr   r   Fr~   )rV   r   r   r   r   r   r   r~   )z%(py0)s == %(py2)sactualexpected_verdicts)rJ   rK   u    §6 verdict mismatch: actual=z
>assert %(py4)srL   expected_review_gate_passedfallback_review_used_expectedfallback_review_passed_expected)z0%(py0)s == %(py5)s
{%(py5)s = %(py2)s(%(py3)s)
}
actual_rgpexpected_rgp)rJ   rK   r!  r  u&    §7 review_gate_passed mismatch: got=z
 fallback=
>assert %(py7)s)zZ%(py2)s
{%(py2)s = %(py0)s.fallback_review_used
} == %(py7)s
{%(py7)s = %(py4)s(%(py5)s)
}expected_fb_used)rJ   rK   rL   r  r  u(    §7 fallback_review_used mismatch: got=z
>assert %(py9)sr  )z\%(py2)s
{%(py2)s = %(py0)s.fallback_review_passed
} == %(py7)s
{%(py7)s = %(py4)s(%(py5)s)
}expected_fb_passedu*    §7 fallback_review_passed mismatch: got=u*    §7 N/A path fallback_used mismatch: got=expected_decision)z0%(py2)s
{%(py2)s = %(py0)s.decision
} == %(py4)sexpected_decrI   u    §8 decision mismatch: got=expected_critical_code)z5%(py2)s
{%(py2)s = %(py0)s.critical_code
} == %(py4)sexpected_critu!    §8 critical_code mismatch: got=expected_smoke_status)z4%(py2)s
{%(py2)s = %(py0)s.smoke_status
} == %(py4)sexpected_smokeu     §9 smoke_status mismatch: got=)z:%(py2)s
{%(py2)s = %(py0)s.smoke_envelope
} is not %(py5)srJ   rK   r  uK    §9 smoke_envelope must be populated when verify_merge=true; smoke_status=r   )zn%(py8)s
{%(py8)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.smoke_envelope
}.get
}(%(py6)s)
} == %(py10)s)rJ   rK   rL   r  r  r$  u#    §9 envelope status mismatch: got=z
>assert %(py12)sr  r   r   )zn%(py8)s
{%(py8)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.smoke_envelope
}.get
}(%(py6)s)
} is %(py10)sexpected_allowu/    §9 envelope allow_continuation mismatch: got=rZ   )z4%(py4)s
{%(py4)s = %(py2)s.smoke_status
} == %(py7)s)rK   rL   r  z%(py9)s)z:%(py13)s
{%(py13)s = %(py11)s.smoke_envelope
} is %(py16)s)r"  py13py16z%(py18)spy18uK    §9 envelope must remain unpopulated for non-smoke scenario, got envelope=z
>assert %(py21)spy21expected_following_statesrU   )zN%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py8)s
{%(py8)s = %(py5)s(%(py6)s)
}statesexpected_states)rJ   r   r!  r  r  r  u$    §10 following count mismatch: got=)zI%(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.get
}(%(py3)s)
} == %(py7)ss_actualkv)rJ   rK   r!  r  r  u    §10 following PR#z field z: got=r  z%(py2)srK   replay_states)>=)z1%(py7)s
{%(py7)s = %(py4)s(%(py5)s)
} >= %(py10)s)rL   r  r  r$  z%(py12)suP    §10 verify_head_lock_then_merge must populate decision.fixture_pr_replay, got z
>assert %(py15)spy15)in)z%(py1)s in %(py3)srecorded_pr_numbers)r   r!  u	    §10 PR#z( missing from decision.fixture_pr_replay)z9%(py4)s
{%(py4)s = %(py2)s.fixture_pr_replay
} == %(py7)s)z=%(py13)s
{%(py13)s = %(py11)s.fixture_pr_replay
} is %(py16)su4    §10 N/A path expects empty fixture_pr_replay, got expected_escalation_typer   r   r   u(    §11 reporter_hook spy must be injected)zN%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.observed
})
} >= %(py8)su>    §11 reporter_hook must be called for critical scenario, got r   classificationu#    §11 spy classification mismatch: packet)z%(py1)s is not %(py4)su    §11 packet must be setescalation_type)z%(py1)s == %(py3)sexpected_escu$    §11 escalation_type mismatch: got=z(%(py4)s
{%(py4)s = %(py2)s.escalations
})rK   rL   )zT%(py11)s
{%(py11)s = %(py6)s(%(py9)s
{%(py9)s = %(py7)s.escalations
})
} >= %(py14)s)r  r  r  r"  r  z%(py16)sr=  u>    §11 decision.escalations must contain at least 1 entry, got z
>assert %(py19)spy19u?    §11 auto-handled scenario must not invoke reporter_hook, got AUTO_HANDLED_DUMMY_EVENT
e2e_replayr   r   auto-handledu!    §11 expected auto-handled, got z%(py1)s is %(py4)su*    §11 packet must be None for auto-handled)z5%(py2)s
{%(py2)s = %(py0)s.critical_code
} is %(py5)su7    §12 critical_code must be None for auto-handled, got )z;%(py2)s
{%(py2)s = %(py0)s.critical_escalation
} is %(py5)su=    §12 critical_escalation must be None for auto-handled, got )z9%(py4)s
{%(py4)s = %(py2)s.critical_code
} is not %(py7)s)zC%(py13)s
{%(py13)s = %(py11)s.critical_escalation
} is not %(py16)suE    §12 critical scenario must set critical_code or critical_escalation)+rk   r   rc   _call_reprcomparere   rf   rg   rh   r`   _format_booloprd   ri   rj   r   r  r   r   r  replacement_usedgetattrr   r   ra   r   verdictvaluereview_gate_passedfallback_review_passedfallback_review_usedr   r   r   r   smoke_statussmoke_enveloper   zipitemsr   fixture_pr_replayr   r   critical_escalation)Mry   r   r   rz   _specr   	main_grepr  r  ro   @py_assert4rp   @py_assert0@py_assert11@py_assert10rr   @py_format8@py_format13@py_format15@py_format16@py_format18r  extramissingrq   @py_format7@py_format9r  @py_assert2@py_assert6@py_assert8@py_format10@py_format12@py_assert7@py_format11r   @py_format4@py_format5r+  reportor*  @py_format3r0  r2  r3  r/  r5  r7  r9  @py_assert9r;  @py_assert12@py_assert15@py_assert14@py_format17@py_format19@py_format20@py_format22rB  fqrA  rC  
s_expectedrD  rE  rF  @py_format14r   rJ  efrO  expected_clsr   	first_obs@py_assert13r   sM                                                                                r,   _verify_12_itemsr  ;  sy+    4.C &.\\2N%OUYI/\"(b&	GW `d_7d?_"_w"}____7d______7___7___d_______w"______w___w___"__________5UV]U^.________ 5"#X.>%?GUG $$9: d:; 7;;   7;                        ;    <    %+G9GE7)G9Tdem  oD  fE  eF  	G    
 '"#X.>%?I y> *D!E S!EF >FF   >F                              !    !    "F    G    %,YK7GQkHlGmn     
 $$ X6Q-R -R(S $(SS   $(S              %      )-    )-    .S    )T    %3H4M4M3NjYab}Y~X  	A     
 lD1J||$%!%dz%dddzddddddzdddzdddddd#.c'ddddddd&& 	
s&' 	
1 	
'1, 	
 	
 	
'1 	
 	
	6	
 	
   	
 	
 		  	
 	
	6	
 	
   	
 	
 		  	
 	
 		 ' 	
 	
 		 ( 	
 	
 		 ,- 	
 	
  eDSI\I\E]D^_	
 	
 	
 	
 	
 	
 ""1%k2 	
h{6K 	
26KK 	
 	
26K 	
 	
 		 3 	
 	
 		 7L 	
 	
  e6z7J7J6KL	
 	
 	
 	
 	
 	

 " 	
zT! 	
 	
zT 	
 	
	6	
 	
   	
 	
 		  	
 	
 		 " 	
 	
  e:;	
 	
 	
 	
 	

 !%?@FB{+-.4" / ]39r)9 :;Y'	
 ,2>>:a!))//::** 	
 	
v* 	
 	
	6	
 	
   	
 	
 		  	
 	
	6	
 	
  + 	
 	
 		 + 	
 	
  e1&DUCVW	
 	
 	
 	
 	
 << =>L||$CUK!&GO00SH4S4S
!,/ 	
z// 	
 	
 	
z/ 	
 	
	6	
 	
   	
 	
 		  	
 	
	6	
 	
  " 	
 	
 		 " 	
 	
	6	
 	
  #/ 	
 	
 		 #/ 	
 	
 		 0 	
 	
  e9(:U:U9VV`ai  bA  bA  aB  BL  MY  LZ  [	
 	
 	
 	
 	
 ,, 	
5E0F 	
,0FF 	
 	
 	
,0F 	
 	
	6	
 	
   	
 	
 		  	
 	
 		 - 	
 	
	6	
 	
  15 	
 	
 		 15 	
 	
	6	
 	
  6F 	
 	
 		 6F 	
 	
 		 1G 	
 	
  e;H<Y<Y;ZZdeudvw	
 	
 	
 	
 	
 22 d;M6N 26NN   26N  v     I   I 3  v   7;  I 7;  v   <N  I <N  I 7O    %A(BaBaAbblm  mA  B      ,, 	
5E0F 	
,0FF 	
 	
 	
,0F 	
 	
	6	
 	
   	
 	
 		  	
 	
 		 - 	
 	
	6	
 	
  15 	
 	
 		 15 	
 	
	6	
 	
  6F 	
 	
 		 6F 	
 	
 		 1G 	
 	
  e=h>[>[=\\fgwfxy	
 	
 	
 	
 	

 .h7J.KLL ,                       !-    !-    %+H,=,=+>jW     +8<<8P+QRM!! !]2   !]              "      &3    &3    %01G1G0H
S`Rab    
 \\"9:N!$$ 	
$6 	
 	
 	
$ 	
 	
	6	
 	
   	
 	
 		  	
 	
 		 % 	
 	
	6	
 	
  )7 	
 	
 		 )7 	
 	
  e3H4I4I3J*UcTde	
 	
 	
 	
 	

 && 	
d 	
&d2 	
 	
&d 	
 	
 
6	
 	
   	
 	
 
	  	
 	
 
	 ' 	
 	
 
	 /3 	
 	
  e $1124	
 	
 	
 	
 	
 && 	
&** 	
8 	
*84 	
4F 	
 	
 	
4 	
 	
	6	
 	
   	
 	
 		  	
 	
 		 ' 	
 	
 		 + 	
 	
 		 ,4 	
 	
 		 5 	
 	
	6	
 	
  9G 	
 	
 		 9G 	
 	
  e6x7N7N7R7RS[7\6]^	
 	
 	
 	
 	
 	
 )F2&& 	
&** 	
+? 	
*+?@ 	
@NR 	
 	
 	
@N 	
 	
 
6	
 	
   	
 	
 
	  	
 	
 
	 ' 	
 	
 
	 + 	
 	
 
	 ,@ 	
 	
 
	 A 	
 	
 
6	
 	
  ES 	
 	
 
	 ES 	
 	
  e **../CDEZP^O_a	
 	
 	
 	
 	
 	
	
x$$ 	
 	
$* 	
h.E.E 	
 	
.E.M 	
 	
 	
$ 	
 	
	6	
 	
   	
 	
 		  	
 	
 		 % 	
 	
 		 )+ 	
 	
 	
	6	
		
 	
.E 	
 	
	6	
 	
  /7 	
 	
 		 /7 	
 	
 		 /F 	
 	
 		 JN 	
 	
 	
	6	
		
 	
 	
  e^_g_v_v^wx	
 	
 	
 	
 	
 	
 	

 ll#>?E2O	'	(	.BB	&r626{ 	
c/2 	
{22 	
 	
 	
{2 	
 	
	6	
 	
   	
 	
 		  	
 	
	6	
 	
   	
 	
 		  	
 	
 		  	
 	
	6	
 	
  " 	
 	
 		 " 	
 	
	6	
 	
  #2 	
 	
 		 #2 	
 	
 		 3 	
 	
  e7F}JsSbOcNde	
 	
 	
 	
 	
 %($@ 	 Hj"((* 1|| |A !+    !  6      	    	 $  6   %&  	 %&  	 '  6   +,  	 +,     e.x||K/H.IQRPSSYZbZfZfghZiYjjtuvtwx     	 <<'H,=,=AS,S$66M= =S%7 1 %71%<  v   !  I !  v !  %71  v   &)  I &)  v   *7  I *7  I &8  I <=   v    %ghugvw      @M"M!155#5"M"M + *==   *=  	 '  6   +>  	 +>     e9R_$55]^    	
x)) 	
R 	
)R/ 	
83M3M 	
QU 	
3MQU3U 	
 	
 	
)R 	
 	
	6	
 	
   	
 	
 		  	
 	
 		 * 	
 	
 		 .0 	
 	
 	
	6	
		
 	
3MQU 	
 	
	6	
 	
  4< 	
 	
 		 4< 	
 	
 		 4N 	
 	
 		 RV 	
 	
 	
	6	
		
 	
 	
  eGHbHbGcd	
 	
 	
 	
 	
 	
 	

 << :;L56L35Lz!#'Y|4'YYY|4YYYYYY|YYY|YYY4YYYC50X)YYYYYYY(( 	
s() 	
Q 	
)Q. 	
 	
 	
)Q 	
 	
	6	
 	
   	
 	
 		  	
 	
	6	
 	
    	
 	
 		   	
 	
 		 ) 	
 	
 		 * 	
 	
 		 ./ 	
 	
  eQRUVbVkVkRlQmn	
 	
 	
 	
 	
 	
 !))!,	"#34 	

 	
4
B 	
 	
4
 	
 	
 		 5 	
 	
 		 9C 	
 	
  e6y7JK[7\6]^	
 	
 	
 	
 	
 "8,ZDZ,D8ZZZ,DZZZ,ZZZDZZZSEAY:ZZZZZZZZ"#45 	
5E 	
 	
5 	
 	
 		 6 	
 	
	6	
 	
  :F 	
 	
 		 :F 	
 	
  e7	(8KL]8^7__ijviwx	
 	
 	
 	
 	
	
x## 	
# 	
#H,@,@ 	
,@(A 	
Q 	
(AQ(F 	
 	
	6	
 	
   	
 	
 		  	
 	
 		 $ 	
 	
	6	
	 $ 	
 	
(AQ 	
 	
	6	
 	
  ), 	
 	
 		 ), 	
 	
	6	
 	
  -5 	
 	
 		 -5 	
 	
 		 -A 	
 	
 		 )B 	
 	
 		 FG 	
 	
 	
	6	
		
 	
 	
  eQRZRfRfQgh	
 	
 	
 	
 	
 	
 	

 ##,, 3,-  -2   -  v     I   v   $  I $  I -  I .  I 23    %VWZ[g[p[pWqVrs       +(;:O5 4	
 &' 	
> 	
'>9 	
 	
'> 	
 	
 		 ( 	
 	
 		 ,: 	
 	
  e4V<L5M4NO	
 	
 	
 	
 	
 h[4[4'[[[4[[[[[[4[[[C50Z)[[[[[[[[ ~%%% 	
 	
%- 	
 	
% 	
 	
	6	
 	
   	
 	
 		  	
 	
 		 & 	
 	
 		 *. 	
 	
  eJ8KaKaJbc	
 	
 	
 	
 	
 ++ 	
t 	
+t3 	
 	
+t 	
 	
	6	
 	
   	
 	
 		  	
 	
 		 , 	
 	
 		 04 	
 	
  ePQYQmQmPno	
 	
 	
 	
 	
 	

	
x%% 	
T 	
%T1 	
X5Q5Q 	
Y] 	
5QY]5] 	
 	
 	
%T 	
 	
	6	
 	
   	
 	
 		  	
 	
 		 & 	
 	
 		 .2 	
 	
 	
	6	
		
 	
5QY] 	
 	
	6	
 	
  6> 	
 	
 		 6> 	
 	
 		 6R 	
 	
 		 Z^ 	
 	
 	
	6	
		
 	
 	
  eXY	
 	
 	
 	
 	
 	
 	
g ;l #Ns   CBCCBmodule)scopec                     t               S rR   )r-   r*   r+   r,   replayr    s    r+   c                D    | d   D ]  }|d   |k(  s|c S  t        |      )N	scenariosr   )KeyError)r  r   r   s      r,   _scenario_by_idr    s2    K  T7c>H 3-r+   c                Z    t        | d      }t        |      \  }}}}t        |||||       y )NPR55_clean_auto_merger  r	  r  r  r   r   r   rz   r  s         r,   test_e2e_pr55_clean_auto_merger  #  s2     78A"/"2Hc64Q#vt4r+   c                Z    t        | d      }t        |      \  }}}}t        |||||       y )NPR57_false_positive_triager  r  s         r,   #test_e2e_pr57_false_positive_triager  )  2     <=A"/"2Hc64Q#vt4r+   c                Z    t        | d      }t        |      \  }}}}t        |||||       y )NPR58_gemini_quota_fallbackr  r  s         r,   #test_e2e_pr58_gemini_quota_fallbackr  /  r  r+   c                Z    t        | d      }t        |      \  }}}}t        |||||       y )NPR64_smoke_passr  r  s         r,   test_e2e_pr64_smoke_passr  5  s2     12A"/"2Hc64Q#vt4r+   c                Z    t        | d      }t        |      \  }}}}t        |||||       y )Nr   r  r  s         r,   'test_e2e_pr57_contamination_replacementr  ;  s2     @AA"/"2Hc64Q#vt4r+   c                Z    t        | d      }t        |      \  }}}}t        |||||       y )NPR61_review_thread_blockerr  r  s         r,   #test_e2e_pr61_review_thread_blockerr  A  r  r+   c                Z    t        | d      }t        |      \  }}}}t        |||||       y )Ncritical_smoke_failurer  r  s         r,   test_e2e_critical_smoke_failurer  G  s2     89A"/"2Hc64Q#vt4r+   c                Z    t        | d      }t        |      \  }}}}t        |||||       y )Ncritical_forbidden_pathr  r  s         r,    test_e2e_critical_forbidden_pathr  M  s2     9:A"/"2Hc64Q#vt4r+   c                Z    t        | d      }t        |      \  }}}}t        |||||       y )Nr   r  r  s         r,   7test_e2e_critical_diff_contamination_replacement_failedr  S  s2     PQA"/"2Hc64Q#vt4r+   c                P   | }t        ddddddgid|d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}}|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z  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}	}|j                  d      j                         }
|
s{t        j                  d      d z   d!d"t        j                         v st        j                  |
      rt        j                  |
      nd"iz  }t	        t        j
                  |            t        j                  |
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}}|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}}|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_   Critical 시나리오에서 process_event(no_audit=False) 호출 시 audit JSONL 실재 박제.	task-2515i'  FORBIDDEN_PATH_INTRUSIONtest_audit_appendr\   z.github/workflows/foo.ymlr   FTworkspace_rootr   r   rL  r   r  r'  r(  assert %(py6)sr  Naudit_appendedr  rT  memoryorchestration-auditcritical-escalations.jsonlaudit JSONL must exist at C
>assert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}	audit_logrI   r#   r$   (audit JSONL must contain at least 1 line
>assert %(py0)srJ   rawr~   rN  r   rc   rU  rh   ri   rj   existsrd   re   rf   rg   r)   stripr&   r'   
splitlinestmp_path
audit_rootr   rg  rp   rs  r{  rq  r  ro   r  @py_format1lasts                r,   'test_audit_append_critical_writes_jsonlr  [  s   J"4)*-H,IJ	
 "F "#1z1#z1111#z111#111z1111111"#+t+#t++++#t+++#+++t+++++++X%(==@\\IGGGG!;I;GGGGGGG9GGG9GGGGGGGGGGGG


w

/
5
5
7C:::::::::3:::3:::::::cnn&r*+D	?)k)?k))))?k)))?)))k))))))) !/Z/!Z////!Z///!///Z///////!"@&@@"&@@@@@"&@@@@"@@@&@@@@@@@@r+   c                J   | }t        ddddi d|d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}}|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   }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z  dz  dz  }|j                  }	 |	       }|st        j                  d| 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}	}|j                  d      j                         }
|
s{t        j                  d      d z   d!d"t        j                         v st        j                  |
      rt        j                  |
      nd"iz  }t	        t        j
                  |            t        j                  |
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}}|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)%ua   auto-handled 시나리오에서 process_event(no_audit=False) 호출 시 audit-only JSONL 박제.r  i'  rQ  r  r   FTr  rL  rS  r  r'  r(  r  r  NrM  r  rT  r  r  r  r  r  z (auto-handled append)r  r  rI   r#   r$   r  r  rJ   r  r  r~   r  r  s                r,   +test_audit_append_auto_handled_writes_jsonlr  v  s   J"4)	
 "F "#5~5#~5555#~555#555~5555555(#t#t####t######t#######"#+t+#t++++#t+++#+++t+++++++X%(==@\\I]]]]!;I;F\]]]]]]]9]]]9]]]]]]]]]]]]


w

/
5
5
7C:::::::::3:::3:::::::cnn&r*+D	?)k)?k))))?k)))?)))k))))))) !3^3!^3333!^333!333^3333333r+   c                   t        j                  d      }|j                  dt        d       |j                  ddd	       |j	                  |       }t               }|j                  r0|d
   D ]'  }t        d|d   dd|d   dd|d    d|d           ) y|j                  r|d
   D ]{  }|d   |j                  k(  st        |      \  }}}}t        t        j                  |j                         ddt                     t        |||||       t        d|d    d        y t        d|j                   d       y|j                          y)Nztask-2515 e2e replay harness)descriptionz--pru   단일 PR 번호 replay)typehelpz--list
store_trueu   9 시나리오 목록)actionr  r  z  PR#rV   z>3z  r   z<55z  [categoryu   ]  → r4  r      F)indentensure_asciidefaultz
[PASS] u    — 12/12 verificationszPR #z not found in fixtures)argparseArgumentParseradd_argumentr  
parse_argsr-   ra   printprr	  r&   rn   to_dictrm   r  
print_help)	argvparserr/   r!   r   r   r   rz   r  s	            r,   	_cli_mainr    sc   $$1OPF
S/HI
<STT"DHyy+& 	oAE!K.,Bqwsm3q}oWUVWjUkTlmn	oww+& 	A~(.;A.>+#vtdjj!1!1!3AE[^_` Hc64@	!D'*BCD	 	TWWI345
r+   c                 v   ddl } dD ]&  }|t        j                  v st        j                  |= ( | j                  d      }|j                  }d}||u }|st        j                  d|fd||f      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}}|j                  }d}||u}|st        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  }t        t        j                  |            dx}x}}|j                  }d}||u}|st        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  }t        t        j                  |            dx}x}}|j                   }d}||u}|st        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  }t        t        j                  |            dx}x}}|j"                  }d}||u}|st        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  }t        t        j                  |            dx}x}}y)u   task-2516: ctx hook 미주입 상태에서 default runtime path가 W1 wiring chain
    (_WIRING_AVAILABLE=True 경로의 ReplacementPRRunner / triage_pr / run_pm_smoke_v2 등)을
    실제로 사용하는지 검증. circular import fix 회귀 방지.
    r   N)utils.merge_queue_executorzutils.replacement_pr_runnerr  Tr  )z9%(py2)s
{%(py2)s = %(py0)s._WIRING_AVAILABLE
} is %(py5)smqer:  u,   W1 wiring 비활성 — task-2516 fix 회귀r1  r  r%  )z?%(py2)s
{%(py2)s = %(py0)s.ReplacementPRRunner
} is not %(py5)szassert %(py7)s)z5%(py2)s
{%(py2)s = %(py0)s.triage_pr
} is not %(py5)s)z;%(py2)s
{%(py2)s = %(py0)s.run_pm_smoke_v2
} is not %(py5)s)zA%(py2)s
{%(py2)s = %(py0)s.report_critical_event
} is not %(py5)s)	importlibsysmodulesimport_module_WIRING_AVAILABLErc   rU  re   rf   rg   rh   rd   ri   rj   r    r   run_pm_smoke_v2report_critical_event)r  mod_namer  ro   rf  rp   rr   rj  s           r,   +test_default_runtime_path_no_ctx_hooks_2516r    s   
 Q &s{{"H%& 
!
!">
?C  XDX D(XXX DXXXXXX3XXX3XXX XXXDXXX*XXXXXXXX "".$."$...."$......3...3..."...$.......==$$=$$$$=$$$$$$3$$$3$$$=$$$$$$$$$$*d*d****d******3***3******d*******$$0D0$D0000$D00000030003000$000D0000000r+   __main__)returndict)r   rZ   rZ   rR   )Z__doc__
__future__r   builtinsre   _pytest.assertion.rewrite	assertionrewriterc   r  r&   r3   r  pathlibr   pytestr   resolveparent	WORKSPACErm   r]   removeinsertutils.merge_queue_executorr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   utils.automation_contractsr   utils.auto_gemini_triager   utils.post_merge_smoke_runnerr   r   r   "utils.critical_escalation_reporterr   utils.replacement_pr_runnerr    r(   r-   r5   rb   r|   r   r   r   r   r   r   r   r   r	  r  fixturer  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   exitr*   r+   r,   <module>r     s   #      
  N""$++2299	y>SXXHHOOC	N# 3y> "      9 = ;H~$$z14QQ@e
 d !H2,^,D:'4W
x h  555555555A64:01( zCHHY[ r+   