
    ۉ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
mZ ddlmZ ddlZddlmZmZ ddlmZmZmZmZmZ  ee      j3                         j4                  j4                  j4                  Zedz  d	z  d
z  ZdZddZddZddZ ddZ!ejD                  jG                  de      d        Z$y)u  tests.regression.test_ci_watch_handoff_runner_fixture_parametrized — task-2642.

회장 verbatim (2026-05-23 19:38 KST) 1:1 박제 — 6 시나리오 fixture parametrized
PASS 회귀.

Layer A / NO-CRON: subprocess / cokacdir / merge / cron / live gh 호출 0.
모든 시나리오는 fixtures/ci_watch_handoff_runner/<scenario>/evidence.json 의
ci_status_sequence + router_call_sequence + auto_remediation_outcome_sequence 로
runner 를 호출하고 expected.json 의 terminal_state / callback_fired /
audit_event_sequence 단언.
    )annotationsN)Path)Iterator)AUDIT_SCHEMACiWatchHandoffAudit)CALLBACK_ENVELOPE_BYTE_LIMITCANONICAL_ROOTCiWatchHandoffRunnerCIStatusSnapshotRouterCallResulttestsfixturesci_watch_handoff_runner)merge_ready_clean_gemini_fresh'gemini_stale_nudge_posted_re_poll_fresh gemini_stale_after_nudge_timeout&ci_failure_auto_remediation_medium_fix$forbidden_path_modification_detected!loop_boundary_three_high_attemptsscenarioc                    t         | z  }t        j                  |dz  j                  d            }t        j                  |dz  j                  d            }||fS )Nzevidence.jsonutf-8encodingzexpected.json)FIXTURE_ROOTjsonloads	read_text)r   fdirevidenceexpecteds       Y/home/jay/workspace/tests/regression/test_ci_watch_handoff_runner_fixture_parametrized.py_load_fixturer#   /   sY    ("Dzz4/1<<g<NOHzz4/1<<g<NOHX    c                2   g }| j                  dg       D ]m  }|j                  t        |d   t        |j                  dg             |j                  dd      |j                  dd      |j                  dd      	             o t	        |      dfd
}|S )Nci_status_sequencestatusfailing_checksseverity forbidden_path_touchedFsame_function_high_repeated)r'   r(   r)   r+   r,   c                    t              S Nnext_handoffits    r"   fnz_make_ci_fn.<locals>.fnD       Bxr$   )r2   dictreturnr   )getappendr   tupleiter)r    snapsrawr4   r3   s       @r"   _make_ci_fnr>   6   s    $&E||0"5 	
8}$SWW-=r%BCR0'*ww/G'O,/GG4QSX,Y	
	
 &*%[B Ir$   c                    g }| j                  dg       D ]B  }|j                  t        |d   |j                  dd      |j                  dd                   D t        |      d	fd}|S )
Nrouter_call_sequencefinal_statepermission_diagnostics_presentFreasonr*   )rA   rB   rC   c                    t              S r.   r/   r1   s    r"   r4   z_make_router_fn.<locals>.fnX   r5   r$   )r2   r6   r7   r   )r8   r9   r   r;   )r    callsr=   r4   r3   s       @r"   _make_router_fnrF   J   sw    $&E||2B7 	
./2ww4e0 wwx,	
	
 &*%[B Ir$   c                f    t        | j                  dg             }|sy t        |      dfd}|S )N!auto_remediation_outcome_sequencec                    t              S r.   r/   )r2   _ci_snapr3   s     r"   r4   z_make_remediate_fn.<locals>.fnd   r5   r$   )r2   r6   rJ   r   r7   str)listr8   r;   )r    outcomesr4   r3   s      @r"   _make_remediate_fnrN   ^   s4    HLL!DbIJH	hB Ir$   c                "  $ t        |      \  }}t        |       }g $d`$fd}t        | t        |      t	        |      t        |      ||dd      }|j                  |d   |j                  dd      d	      }|j                  }|j                  }	|d
   }
|	|
k(  }|st        j                  d|fd|	|
f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      t        j                  |
      dz  }t        j                   d| d|d
   d|j                  j                  d|j                  j"                        dz   d|iz  }t%        t        j&                  |            d x}x}	x}}
d|v r#|j                  }|j(                  }	|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                  |
      dz  }t        j                   d| d|d   d|j                  j(                        dz   d|iz  }t%        t        j&                  |            d x}x}	x}}
d|v r#|j                  }|j*                  }	|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                  |
      dz  }t        j                   d| d|d   d|j                  j*                        dz   d|iz  }t%        t        j&                  |            d x}x}	x}}
|j,                  }|d   }||k(  }	|	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|d    d|j,                         dz   d |iz  }t%        t        j&                  |            d x}x}	}|d   r|d!   }|d"   }|j.                  }||k  }||k  }|r|sJt        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t        j                  |      d&t        j                         v st        j                  |      rt        j                  |      nd&d'z  }t        j                   d| d(|j.                   d)| d*| d+	      d,z   d-|iz  }t%        t        j&                  |            d x}x}}|j.                  }|t0        k  }	|	st        j                  d.|	fd/|t0        f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      d0t        j                         v st        j                  t0              rt        j                  t0              nd0d1z  }d2d3|iz  }t%        t        j&                  |            d x}}	$d4   }|j2                  }	d5} |	|      }t5        |      }|j.                  }||k(  }|sFt        j                  d|fd6||f      d7t        j                         v st        j                  t4              rt        j                  t4              nd7t        j                  |      t        j                  |	      t        j                  |      t        j                  |      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      d8z  }d9d:|iz  }t%        t        j&                  |            d x}x}	x}x}x}x}}d;t6         }$d4   }	||	v }|slt        j                  d<|fd=||	f      t        j                  |      t        j                  |	      d>z  }d2d3|iz  }t%        t        j&                  |            d x}x}}	d?|d
    }$d4   }	||	v }|slt        j                  d<|fd=||	f      t        j                  |      t        j                  |	      d>z  }d2d3|iz  }t%        t        j&                  |            d x}x}}	d@|v r#|j                  }|j8                  }	|d@   }
|	|
k(  }|st        j                  d|fdA|	|
f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      t        j                  |
      dz  }t        j                   d| dB|d@    d|j                  j8                         dz   d|iz  }t%        t        j&                  |            d x}x}	x}}
dC|v r#|j                  }|j:                  }	|dC   }
|	|
k(  }|st        j                  d|fdD|	|
f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      t        j                  |
      dz  }t        j                   d| dE|dC    d|j                  j:                         dz   d|iz  }t%        t        j&                  |            d x}x}	x}}
|j<                  j?                  d5F      jA                         jC                         }|D cg c]  }tE        jF                  |      dG    }}|dH   }||k(  }|st        j                  d|fdI||f      dJt        j                         v st        j                  |      rt        j                  |      ndJt        j                  |      dKz  } t        j                   d| dL|dH    dM|       dNz   dO| iz  }t%        t        j&                  |            d x}}|D ]  }!tE        jF                  |!      }"|"dP   }|tH        k(  }|st        j                  d|fdQ|tH        f      t        j                  |      dRt        j                         v st        j                  tH              rt        j                  tH              ndRdSz  } dTdO| iz  }t%        t        j&                  |            d x}}dU}||"v}|st        j                  dV|fdW||"f      t        j                  |      dXt        j                         v st        j                  |"      rt        j                  |"      ndXdSz  } dTdO| iz  }t%        t        j&                  |            d x}}dY}||"v}|st        j                  dV|fdW||"f      t        j                  |      dXt        j                         v st        j                  |"      rt        j                  |"      ndXdSz  } dTdO| iz  }t%        t        j&                  |            d x}} |j                  dZg       D ]I  }#|j                  }	|	j"                  }|#|v }|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                  |      rt        j                  |      ndt        j                  |	      t        j                  |      d]z  }t        j                   d| d^|j                  j"                  d_|#      d,z   d-|iz  }t%        t        j&                  |            d x}x}	}L y c c}w )aNc                Z    j                  |        t        | j                  d            S )Nr   )r9   lenencode)envelopecaptures    r"   callback_send_fnzVtest_fixture_scenario_runs_runner_to_expected_terminal_state.<locals>.callback_send_fnq   s#    x 8??7+,,r$         )workspace_rootci_status_fngemini_router_call_fnauto_remediation_fnrU   audit	max_pollsloop_boundary_attemptshandofftask_idr*   zsched-fixture)r`   watcher_schedule_idterminal_state)==)zT%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.decision
}.terminal_state
} == %(py7)sresult)py0py2py4py7[z$] terminal_state mismatch: expected=z, got=z	; reason=z
>assert %(py9)spy9router_final_state)zX%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.decision
}.router_final_state
} == %(py7)sz(] router_final_state mismatch: expected=	ci_status)zO%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.decision
}.ci_status
} == %(py7)sz] ci_status mismatch: expected=callback_fired)z6%(py2)s
{%(py2)s = %(py0)s.callback_fired
} == %(py5)s)re   rf   py5z$] callback_fired mismatch: expected=z
>assert %(py7)srh   callback_prompt_bytes_mincallback_prompt_bytes_max)<=rq   )z=%(py0)s <= %(py5)s
{%(py5)s = %(py3)s.callback_prompt_bytes
}z=%(py5)s
{%(py5)s = %(py3)s.callback_prompt_bytes
} <= %(py6)sbminbmax)re   py3rn   py6z] callback_prompt_bytes=z	 out of [z, ]z
>assert %(py8)spy8)rq   )z=%(py2)s
{%(py2)s = %(py0)s.callback_prompt_bytes
} <= %(py4)sr   )re   rf   rg   zassert %(py6)sru   r   r   )z%(py10)s
{%(py10)s = %(py0)s(%(py8)s
{%(py8)s = %(py4)s
{%(py4)s = %(py2)s.encode
}(%(py6)s)
})
} == %(py14)s
{%(py14)s = %(py12)s.callback_prompt_bytes
}rQ   )re   rf   rg   ru   rw   py10py12py14zassert %(py16)spy16zcanonical_root=)in)z%(py1)s in %(py4)s)py1rg   zterminal_state=auto_remediation_attempts)z_%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.decision
}.auto_remediation_attempts
} == %(py7)sz/] auto_remediation_attempts mismatch: expected=loop_iterations)zU%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.decision
}.loop_iterations
} == %(py7)sz%] loop_iterations mismatch: expected=r   eventaudit_event_sequence)z%(py0)s == %(py3)sactual_events)re   rt   z-] audit event sequence mismatch:
  expected: z
  actual:   z
>assert %(py5)srn   schema)z%(py1)s == %(py3)sr   )r}   rt   zassert %(py5)stoken)not in)z%(py1)s not in %(py3)srecauthorizationreason_must_contain)zL%(py0)s in %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s.decision
}.reason
}needle)re   rf   rg   ru   z	] reason z missing needle )rS   rK   )%r#   r   r
   r>   rF   rN   runr8   decisionrb   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_saferepr_format_assertmsgrC   AssertionError_format_explanationrk   rl   rm   callback_prompt_bytesr   rR   rQ   r	   r~   r   pathr   strip
splitlinesr   r   r   )%tmp_pathr   r    r!   r\   rU   runnerrd   @py_assert1@py_assert3@py_assert6@py_assert5@py_format8@py_format10@py_assert4@py_format6rr   rs   @py_assert2@py_format7@py_format9@py_format5@py_assert7@py_assert9@py_assert13@py_assert11@py_format15@py_format17@py_assert0lineslr   @py_format4liner   r   rT   s%                                       @r"   <test_fixture_scenario_runs_runner_to_expected_terminal_stater   j   s   &x0Hh)EG- " *-h7.x8) 	F ZZY++  F ?? ?)) X6F-G )-GG   	)-G   	  	    	    	    	 *   	 .H    H: -.1 2--0	&//:P:P9S	U   	   x' 	
11 	
X>R5S 	
15SS 	
 		
15S 	
 	
 
6		
 	
 	  	
 	
 
		  	
 	
 
		  	
 	
 
		 2 	
 	
 
		 6T 	
 	
  z  !569 :??558:	
 	
 	
 		
 	
 	
 h 	
(( 	
H[,A 	
(,AA 	
 		
(,A 	
 	
 
6		
 	
 	  	
 	
 
		  	
 	
 
		  	
 	
 
		 ) 	
 	
 
		 -B 	
 	
  z  -0 1??,,/1	
 	
 	
 		
 	
 	
    H-=$>  $>>   $>              !    %?    H: -./vf6K6K5L	N      !343433 	
t3; 	
3t; 	
 	
 	
t3t 	
 	
 
6	
 	
   	
 	
 
	  	
 	
 
6	
 	
   	
 	
 
	  	
 	
 
	 4 	
 	
 
6	
 	
  8< 	
 	
 
	 8< 	
 	
  z1&2N2N1O PfBtfA'	
 	
 	
 	
 	

 ++K+/KKKKK+/KKKKKKKvKKKvKKK+KKKKKK/KKKK/KKKKKKKK1:N:$$NWN$W-Ns-.N&2N2NN.2NNNNN.2NNNNNNNsNNNsNNN:NNN$NNNWNNN-NNN.NNNNNN&NNN&NNN2NNNNNNNNN  01?WQZ?1Z????1Z???1???Z??????? *:!; <=KK=KKKK=KKK=KKKKKKKKKK #h. 	
88 	
H'=
 	
8 =
 
 	
 	
8 =
 	
 	
 
6	
 	
   	
 	
 
	  	
 	
 
	  	
 	
 
	 9 	
 	
 
	=
 	
 	
  z  !<=> ???<<=?	
 	
 	
 	
 	
 	
 H$ 	
.. 	
(;L2M 	
.2MM 	
 		
.2M 	
 	
 
6		
 	
 	  	
 	
 
		  	
 	
 
		  	
 	
 
		 / 	
 	
 
		 3N 	
 	
  z  !234 5??2235	
 	
 	
 		
 	
 	
 JJ  ' 288:EEGE5:;TZZ]7+;M;$%;< =<<  	=<   	  	    	    	 =    H:  678 9$o	'   	   *jj8},},,,,},,,},,,,,,,,,,,,,,,,!wc!!!!wc!!!w!!!!!!c!!!c!!!!!!!)c))))c)))))))))c)))c)))))))* ,,4b9 
 	
// 	
v// 	
 	
 	
v/ 	
 	
	6	
 	
   	
 	
 		  	
 	
	6	
 	
    	
 	
 		   	
 	
 		 ) 	
 	
 		 0 	
 	
  z6??#9#9"<<LVJW	
 	
 	
 	
 	
 	

! <s   AD)r   rK   r7   ztuple[dict, dict])r    r6   )%__doc__
__future__r   builtinsr   _pytest.assertion.rewrite	assertionrewriter   r   pathlibr   typingr   pytestutils.ci_watch_handoff_auditr   r   utils.ci_watch_handoff_runnerr   r	   r
   r   r   __file__resolveparent	WORKSPACEr   	SCENARIOSr#   r>   rF   rN   markparametrizer    r$   r"   <module>r      s   
 #        N""$++2299	7"Z/2KK	((	 Y/p
 0p
r$   