
    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
m
Z
 ddlmZ ddlmZmZ ddlZddlmZmZmZ ddlmZmZmZmZmZmZ  ee      j;                         j<                  j<                  d	z  d
z  ZdefdefdefdefdefdefgZ ddZ!ddZ"ddZ#ejH                  jK                  de       d        Z&d Z'd Z(d Z)y)u   tests.regression.test_real_merge_executor_no_op_paths — task-2637.

7 NO_OP fixture finalize_result 단언 + 실 subprocess 호출 0.

Spec: memory/specs/system_real_merge_executor_wiring_spec_260523.md §5 / §10
    )annotationsN)datetime)Path)AnyList)EXECUTION_RESULT_FILENAMEresolve_artifact_dirvalidate_post_smoke_payload)NO_OP_FLAG_DISABLEDNO_OP_GATE_FAILNO_OP_NO_AUTHORIZATIONNO_OP_RESULTSNO_OP_STALE_SNAPSHOTreal_merge_executefixturesreal_merge_wiringno_op_no_authorizationwould_merge_but_disabledstale_snapshotchair_auth_expiredadmin_override_requiredblocking_secret_detectedc                    t         | z  }t        j                  |dz  j                  d            }t        j                  |dz  j                  d            }||fS )Nzevidence.jsonzutf-8)encodingzexpected.json)FIXTURE_ROOTjsonloads	read_text)scenariobaseevidenceexpecteds       L/home/jay/workspace/tests/regression/test_real_merge_executor_no_op_paths.py_loadr$   -   sY    ("Dzz4/1<<g<NOHzz4/1<<g<NOHX    c                :    t        j                  | d      fdS )Nz%Y-%m-%dT%H:%M:%S%zc                      S )N )dts   r#   <lambda>z_kst_clock.<locals>.<lambda>6   s    2 r%   )r   strptime)textr)   s    @r#   
_kst_clockr-   4   s    			4!6	7Br%   c                     t        d      )NuY   subprocess_runner was invoked during a NO_OP path — task-2637 safety invariant violated)AssertionError)_args_kwargss     r#   _runner_must_never_runr2   9   s    
	. r%   zscenario,expected_enumc                   t        |       \  }}d|v rt        |d         nd }t        |      }t        |j	                  d      |d   |j	                  d      |j	                  d      |j	                  d      |j	                  d      t        |d         t        ||j	                  d	      |
      }|d   }||k(  }	|d   }
||
k(  }|	r|st        j                  d|	|fd|||
f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |
      dz  }dd|iz  }t        t        j                  |            d x}x}	x}}
|d   }|t        v }	|	st        j                  d|	fd|t        f      t        j                  |      dt        j                         v st        j                  t              rt        j                  t              nddz  }dd|iz  }t        t        j                  |            d x}}	|d   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!   }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"   }g }||k(  }	|	slt        j                  d#|	fd$||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}	}|j                  }	d%}d} |	||      }t        |      }|j                  }d%}d} |||      }t        |      }||k(  }|s t        j                  d#|fd&||f      d't        j                         v st        j                  t
              rt        j                  t
              nd'd(t        j                         v st        j                  |      rt        j                  |      nd(t        j                  |	      t        j                  |      t        j                  |      t        j                  |      t        j                  |      d't        j                         v st        j                  t
              rt        j                  t
              nd'd)t        j                         v st        j                  |      rt        j                  |      nd)t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      d*z  }d+d,|iz  }t        t        j                  |            d x}	x}x}x}x}x}x}x}x}x}}d-j!                  |d   d.         j#                         }|j	                  d/g       D ]3  }|j"                  } |       }||v }
|
st        j                  d|
fd0||f      d1t        j                         v st        j                  |      rt        j                  |      nd1t        j                  |      t        j                  |      d2t        j                         v st        j                  |      rt        j                  |      nd2d3z  }t        j$                  d4|d5|d   d.          d6z   d|iz  }t        t        j                  |            d x}x}}
6 |d   d7   } |d   d8   }!t'        t)        | |!|            }"|j	                  d9g       D ]  }#|"|#z  }	|	j*                  } |       }
|
st        j$                  d:|#d;|"       d<z   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        t        j                  |            d x}	x}}
 |"t,        z  }	|	j.                  } |       }
|
 }$|$sd@d=t        j                         v st        j                  |"      rt        j                  |"      nd=dAt        j                         v st        j                  t,              rt        j                  t,              ndAt        j                  |      t        j                  |
      d?z  }%t        t        j                  |%            d x}	x}x}
}$y )BNfrozen_now_kstmerge_ready_resultpr_identitygate_snapshotdryrun_artifactcallback_envelopechair_authorizationactivation_flagchanged_filesr5   r6   r7   r8   r9   r:   r;   subprocess_runnercanonical_rootr<   clockresult_enum)==rB   )%(py1)s == %(py4)sz%(py4)s == %(py6)sexpected_enum)py1py4py6zassert %(py8)spy8)in)z%(py1)s in %(py3)sr   )rE   py3assert %(py5)spy5decisionactually_executedFisz%(py1)s is %(py4)srE   rF   assert %(py6)srG   execution_resultexecution_result_pathsubprocess_invocationsrB   rC   chair_report_required)z%(py11)s
{%(py11)s = %(py0)s(%(py9)s
{%(py9)s = %(py3)s
{%(py3)s = %(py1)s.get
}(%(py5)s, %(py7)s)
})
} == %(py24)s
{%(py24)s = %(py13)s(%(py22)s
{%(py22)s = %(py16)s
{%(py16)s = %(py14)s.get
}(%(py18)s, %(py20)s)
})
}booloutr"   )py0rE   rJ   rL   py7py9py11py13py14py16py18py20py22py24zassert %(py26)spy26 reasonsdecision_reason_keywords)zD%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.lower
}()
} in %(py6)skwreasons_text)r\   py2rF   rG   zmissing keyword z in reasons: z
>assert %(py8)sprhead_shaartifacts_writtenzexpected artifact z not written under zP
>assert %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = (%(py0)s / %(py1)s).is_file
}()
}artifact_dirfname)r\   rE   rF   rG   zQassert not %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = (%(py0)s / %(py1)s).exists
}()
}r   )r$   r-   strr   getrZ   r2   
@pytest_ar_call_reprcompare	_saferepr@py_builtinslocals_should_repr_global_namer/   _format_explanationr   joinlower_format_assertmsgr   r	   is_filer   exists)&r   rD   tmp_pathr!   r"   r@   r?   r[   @py_assert0@py_assert2@py_assert5@py_assert3@py_format7@py_format9@py_format4@py_format6@py_format5@py_assert4@py_assert6@py_assert8@py_assert10@py_assert15@py_assert17@py_assert19@py_assert21@py_assert23@py_assert12@py_format25@py_format27rl   rk   @py_assert1rn   ro   rq   rr   @py_assert7@py_format8s&                                         r#   test_no_op_fixturer   @   si   xHh6F(6RJx 012X\E]N
#<<(<=]+ll?3 %67",,':;$LL)>?X&7890%ll?3C }III(=2II2IIIIII2IIIIIIIIIIIIIIII2IIIIIIII}........................z?./858/58888/5888/88858888888!"*d*"d****"d***"***d*******&'/4/'4////'4///'///4///////'(.B.(B....(B...(...B....... /  /7 478 ,.3,e4D4= 8 =    8 =                            0    27    8    9      =A    =A      	   	   	   -   /4   	5  =        
 88C
OI67==?Lll5r: 
xx 	
xz 	
z\) 	
 	
 	
z\ 	
 	
	6	
 	
   	
 	
 		  	
 	
 		  	
 	
 		  	
 	
	6	
 	
  * 	
 	
 		 * 	
 	
  rfM#j/)2L1MN	
 	
 	
 	
 	
 	

 
-	 	&B&z2H,R>JKL126 
u$ 	
$-- 	
-/ 	
/ 	
  !	)<\NK	
 	
	6	
 	
   	
 	
 		  	
 	
	6	
 	
   % 	
 	
 		  % 	
 	
 		 . 	
 	
 		 0 	
 	
 	
 	
 	
 	


 88B8@@B@BBBBBBBBBBBBBBBBBBBB8BBB8BBB@BBBBBBBBBBr%   c                   g dfd}t         D ]3  \  }}t        |      \  }}d|v rt        |d         nd}t        |j	                  d      |d   |j	                  d      |j	                  d      |j	                  d      |j	                  d	      t        |d
         |t        | |z        |j	                  d      |      }|d   }g }	||	k(  }
|
slt        j                  d|
fd||	f      t        j                  |      t        j                  |	      dz  }dd|iz  }t        t        j                  |            dx}x}
}	6 g }
|
k(  }|st        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  }t        t        j                  |            dx}}
y)u   Aggregate guarantee — across all 6 NO_OP fixtures the injected runner
    is never invoked, so the global "실 gh pr merge 0" invariant holds.c                 @    j                  | |f       t        d      )Nz'runner must not be called in NO_OP path)appendr/   )argskwargs
seen_callss     r#   trap_runnerzGtest_subprocess_runner_zero_calls_across_all_no_op.<locals>.trap_runnerv   s!    4.)FGGr%   r4   Nr5   r6   r7   r8   r9   r:   r;   r<   r=   rV   rW   rX   rR   rS   rG   z%(py0)s == %(py3)sr   r\   rJ   rK   rL   )r   r   r   r   returnr   )NO_OP_SCENARIOSr$   r-   r   rt   rZ   rs   ru   rv   rw   r/   r{   rx   ry   rz   )r   r   r   _enumr!   _r@   r[   r   r   r   r   r   r   r   r   r   s                   @r#   2test_subprocess_runner_zero_calls_across_all_no_opr   q   s{    JH + 3%Ho!:Jh:V
8$456\` '||,@A /",,7$LL):;&ll+>? (-B C *;!<=)x(23",,7
 +,22,2222,222,2222222222!3" ::::r%   c                     t        d      \  } }| d   }t        |      }g }||k(  }|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}}|d   }d}	||	u }|d   }
|	|
k(  }|r|st        j                  d||fd||	|
f      t        j                  |      t        j                  |	      t        j                  |
      dz  }dd|iz  }t        t        j                  |            d
x}x}x}x}	}
|j                  }d} ||      }d}||u }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d
x}x}x}x}}|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}}y
)uX   post_smoke_fail_report_only fixture — writer schema-only (writer 본 task 범위 외).post_smoke_fail_report_onlypost_smoke_payloadrW   r   errorsr   zunexpected schema errors: z
>assert %(py5)srL   Nall_okF)rP   rB   )z%(py1)s is %(py5)sz%(py5)s == %(py7)s)rE   rL   r]   zassert %(py9)sr^   rollback_recommendedTrO   )zI%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.get
}(%(py4)s)
} is %(py9)spayload)r\   rm   rF   rG   r^   zassert %(py11)sr_   auto_rollback_invokedrQ   rR   rS   rG   )r$   r
   ru   rv   rx   ry   rz   rw   r~   r/   r{   rt   )r!   r"   r   r   r   r   r   r   r   r   r   r   r   @py_format10r   r   r   @py_format12r   r   s                       r#   ,test_post_smoke_fail_report_only_schema_onlyr      s   <=Hh+,G(1F>6R<>>>6R>>>>>>6>>>6>>>R>>>5fX>>>>>>>8;;;;();;);;;;;;);;;;;;;;;;);;;;;;;;;;6-6;-.6$6.$6666.$66666676667666;666-666.666$6666666+,55,5555,555,5555555555r%   c                R   dD ]  }t        |      \  }}t        |d         }t        |j                  d      |d   |j                  d      |j                  d      |j                  d      |j                  d      d	t        t        | |z        |j                  d
      |      }|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   }g }||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   Two fixtures must surface chair_report_required=True (spec §10).)r   r   r4   r5   r6   r7   r8   r9   r:   Tr<   r=   rY   rO   rQ   rR   rS   rG   NrV   rW   rX   )r$   r-   r   rt   r2   rs   ru   rv   rw   r/   r{   )r   r   r!   r   r@   r[   r   r   r   r   r   s              r#   ;test_chair_report_required_set_on_admin_override_and_secretr      sJ   K 3Ho!8$456 '||,@A /",,7$LL):;&ll+>? (-B C 4x(23",,7
 *+3t3+t3333+t333+333t3333333+,22,2222,222,2222222222#3r%   )r   rs   )r,   rs   )r0   r   r1   r   r   r   )*__doc__
__future__r   builtinsrx   _pytest.assertion.rewrite	assertionrewriteru   r   r   pathlibr   typingr   r   pytest utils.real_merge_artifact_schemar   r	   r
   utils.real_merge_hooksr   r   r   r   r   r   __file__resolveparentr   r   r$   r-   r2   markparametrizer   r   r   r   r(   r%   r#   <module>r      s    #        
  	N##**Z7:MM 
 56!45+,1201
 1?C-C D-C`:	63r%   