
    j)                    ,   d Z ddlmZ ddlZddlmc mZ ddl	Z	ddl
mZmZmZ ddlZddlmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZ d Z d Z!d	 Z"d
 Z#d Z$ddZ%d Z&d Z'd Z(d Z)d Z*d Z+d Z, G d d      Z-d Z.d Z/d Z0d Z1d Z2d Z3d Z4y)u}  tests/regression/test_anu_callback_registrar.py

task-2635 — registrar ANU key 단언 + envelope ≤3900 + cron 호출 시그니처.

Spec §5: ANU key 정확 단언 (c119085addb0f8b7) · self-key 차단 · envelope UTF-8
byte 측정 ≤3900 · cron 등록 시도 subprocess 호출 시그니처 일관.

Live cokacdir CLI 호출 0 (모든 subprocess 는 fake runner 로 주입).
    )annotationsN)AnyDictList)COKACDIR_CLIDEFAULT_CHAT_IDINDEPENDENT_ANU_KEYSelfKeyForbidden_assert_independent_anu_key_build_cokacdir_cron_argv_parse_schedule_idbuild_callback_envelopeenvelope_byte_warning$merge_registrar_result_into_enveloperegister_normal_callback)ENVELOPE_BYTE_LIMIT NormalCallbackRegistrationStatusenvelope_utf8_byte_countvalidate_envelopec                 p   d} t         | k(  }|st        j                  d|fdt         | f      dt        j                         v st        j
                  t               rt        j                  t               ndt        j                  |       dz  }dd|iz  }t        t        j                  |            d x}} y )Nc119085addb0f8b7==z%(py0)s == %(py3)sr	   py0py3assert %(py5)spy5)	r	   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation)@py_assert2@py_assert1@py_format4@py_format6s       C/home/jay/workspace/tests/regression/test_anu_callback_registrar.py.test_independent_anu_key_constant_is_hardcodedr-   *   sb    "44"44444"4444444444444"44444444    c                 (    t        t        d        y )Nc                     y N _s    r,   <lambda>zEtest_assert_independent_anu_key_accepts_correct_key.<locals>.<lambda>/       r.   
env_lookup)r   r	   r2   r.   r,   3test_assert_independent_anu_key_accepts_correct_keyr9   .   s     3Or.   c                 |    t        j                  t              5  t        dd        d d d        y # 1 sw Y   y xY w)N c                     y r1   r2   r3   s    r,   r5   z?test_assert_independent_anu_key_rejects_empty.<locals>.<lambda>4   r6   r.   r7   pytestraisesr
   r   r2   r.   r,   -test_assert_independent_anu_key_rejects_emptyr@   2   s2    	'	( C#B>BC C Cs   2;c                     t        j                  t        d      5  t        dd        d d d        y # 1 sw Y   y xY w)Ndriftmatchdeadbeefdeadbeefc                     y r1   r2   r3   s    r,   r5   z?test_assert_independent_anu_key_rejects_drift.<locals>.<lambda>9   r6   r.   r7   r=   r2   r.   r,   -test_assert_independent_anu_key_rejects_driftrG   7   s5    	'w	7 S#$6>RS S Ss   4=c                     dd} t        j                  t        d      5  t        t        |        d d d        y # 1 sw Y   y xY w)Nc                    | dk(  rt         S d S )NCOKACDIR_KEY_DEV6)r	   )names    r,   envzGtest_assert_independent_anu_key_rejects_self_key_collision.<locals>.env>   s    &*.A&A"KtKr.   zself-keyrC   r7   )rK   str)r>   r?   r
   r   r	   )rL   s    r,   :test_assert_independent_anu_key_rejects_self_key_collisionrN   <   s=    L 
'z	: I#$7CHI I Is	   ;Ac                     ddddddddS )Nzdispatch-executor-dev6z'memory/tasks/task-2635-test.result.jsonz memory/reports/task-2635-test.md(0000000000000000000000000000000000000000ztest envelope@0fbd1dad1e110c49474dfbdf13a21fb3bdd9c7f094128004dba8472840bb832d)executor_nameresult_pathreport_path
commit_shafile_summaryregression_summaryspec_sha256r2   r2   r.   r,   _minimal_resultrY   H   s!    1@9'-Y r.   c                    t        dt                     } | d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}}| d   }|t        k(  }|st        j                  d|fd	|t        f      t        j                  |      d
t        j                         v st        j                  t              rt        j                  t              nd
dz  }dd|iz  }t        t        j                  |            d x}}| d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}}| d   }t        j                  }|j                  }	||	k(  }|st        j                  d|fd||	f      t        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |	      dz  }
dd|
iz  }t        t        j                  |            d x}x}x}}	| d   }d}||u }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}}| d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}}y )Ntask-2635-testtask_idr   z%(py1)s == %(py4)spy1py4assert %(py6)spy6anu_keyz%(py1)s == %(py3)sr	   r_   r   r   r   collector_roleANUregistration_status)zQ%(py1)s == %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py3)s.NOT_REGISTERED
}.value
}r   r_   r   r   py7assert %(py9)spy9attempted_callback_registrationTis)z%(py1)s is %(py4)sdelivery_methodanu_cron_callback)r   rY   r    r!   r%   r&   r'   r	   r"   r#   r$   r   NOT_REGISTEREDvalue)rL   @py_assert0@py_assert3r(   @py_format5@py_format7r*   r+   @py_assert4@py_assert6@py_format8@py_format10s               r,   <test_build_callback_envelope_seeds_not_registered_by_defaultr|   T   sX   
!"2O4E
FCy>--->----->---->-----------y>0>00000>0000>000000000000000000 )E) E)))) E))) )))E)))))))$%^)I)X)X^)X)^)^^%)^^^^^%)^^^^%^^^^^^)I^^^)I^^^)X^^^)^^^^^^^^019T91T99991T9991999T9999999 !8%88!%88888!%8888!888%88888888r.   c                     t        j                  t        d      5  t        dt	               d       d d d        y # 1 sw Y   y xY w)Nrf   rC   r[   executor)rf   r>   r?   
ValueErrorr   rY   r2   r.   r,   9test_build_callback_envelope_rejects_wrong_collector_roler   _   s8    	z)9	: 
o/
	

 
 
s	   <Ac                     t        j                  t              5  t        dt	                      d d d        y # 1 sw Y   y xY w)Nr;   r   r2   r.   r,   2test_build_callback_envelope_rejects_empty_task_idr   f   s0    	z	" 7O$567 7 7s	   8Ac                 @   t        dt                     } t        |       }|t        k  }|st	        j
                  d|fd|t        f      dt        j                         v st	        j                  |      rt	        j                  |      nddt        j                         v st	        j                  t              rt	        j                  t              nddz  }t	        j                  d| dt               d	z   d
|iz  }t        t	        j                  |            d }y )Nr[   )<)z%(py0)s < %(py2)snr   r   py2zenvelope size z >= hard limit 
>assert %(py4)sr`   )r   rY   r   r   r    r!   r"   r#   r$   r%   _format_assertmsgr&   r'   )rL   r   r)   @py_format3rv   s        r,   #test_envelope_byte_count_under_3900r   k   s    
!"2O4E
FC %A""\\\1"\\\\\\1\\\1\\\\\\"\\\"\\\\nQCGZF[$\\\\\\\r.   c                    t        dt                     } d| d<   t        |       }|d}||v }|st        j                  d|fd||f      t        j
                  |      dt        j                         v st        j                  |      rt        j
                  |      nddz  }d	d
|iz  }t        t        j                  |            d x}}y y )Nr[   
  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrV   z	warn bandinz%(py1)s in %(py3)swarnre   r   r   )r   rY   r   r    r!   r%   r"   r#   r$   r&   r'   )rL   r   rt   r(   r*   r+   s         r,   &test_envelope_byte_warning_band_signalr   q   s    
!"2O4E
FC$C %D"{d""""{d"""{""""""d"""d""""""" r.   c                    t        dt                     } ddz  | d<   g fd}t        | |d       }|j                  }t        j
                  }|j                  }||k(  }|s
t        j                  d|fd	||f      d
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}x}}d}	g }
|j                  }|}|sd}|}|	|v }|sdd
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |      dz  }|
j!                  |       |s+ddt        j                        iz  }|
j!                  |       t        j"                  |
d      i z  }t        j                  d|fd|	|f      t        j                  |	      |dz  }dd|iz  }t        t        j                  |            d x}	x}x}x}
x}}g }|k(  }|st        j                  d|fd|f      dt        j                         v st        j                        rt        j                        ndt        j                  |      dz  }t        j$                  d      dz   d|iz  }t        t        j                  |            d x}}y ) Nr[   xi  rV   c                Z    j                  t        |               G d d      } |       S )Nc                      e Zd ZdZdZdZy)Wtest_envelope_over_hard_limit_triggers_register_failed.<locals>.fake_runner.<locals>._Pr   z{"status":"ok","id":"X"}r;   N)__name__
__module____qualname__
returncodestdoutstderrr2   r.   r,   _Pr      s    J/FFr.   r   )appendlist)argvtimeoutr   captureds      r,   fake_runnerzKtest_envelope_over_hard_limit_triggers_register_failed.<locals>.fake_runner   s&    T
#	 	
 tr.   c                     yNTr2   r3   s    r,   r5   zHtest_envelope_over_hard_limit_triggers_register_failed.<locals>.<lambda>   r6   r.   subprocess_runnercli_exists_checkr   zn%(py2)s
{%(py2)s = %(py0)s.status
} == %(py8)s
{%(py8)s = %(py6)s
{%(py6)s = %(py4)s.REGISTER_FAILED
}.value
}rrr   r   r   r`   rb   py8assert %(py10)spy10z
hard limitr;   "%(py7)s
{%(py7)s = %(py5)s.error
}r   rj   %(py10)s   r   z%(py1)s in (%(py13)s)r_   py13assert %(py15)spy15r   r   r   z:subprocess must NOT be invoked when envelope exceeds limitz
>assert %(py5)sr   )r   rY   r   statusr   REGISTER_FAILEDrs   r    r!   r"   r#   r$   r%   r&   r'   errorr   _format_boolopr   )rL   r   r   r)   @py_assert5@py_assert7ru   @py_format9@py_format11rt   rx   ry   @py_assert9r(   rz   @py_format12@py_format14@py_format16r*   r+   r   s                       @r,   6test_envelope_over_hard_limit_triggers_register_failedr   {   s   
!"2O4E
FC*C "H 
"%'
B
 99N8HHNHNNN9NNNNN9NNNNNNN2NNN2NNN9NNNNNN8NNN8NNNHNNNNNNNNNNN+BHH+H+H++<++++++++B+++B+++H++++H++++++++++++<+++<++++++++W8r>WWW8rWWWWWW8WWW8WWWrWWWWWWWWWWr.   c                    t        dt                     } t        | dt        t        t
              }|d   }|t
        k(  }|st        j                  d|fd|t
        f      t        j                  |      dt        j                         v st        j                  t
              rt        j                  t
              nddz  }d	d
|iz  }t        t        j                  |            d x}}|d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}}t        j                  |d         }	|	d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}}g }
d}||v }|}|r ||j!                  d      dz      }d}||k(  }|}|s+t        j                  d|fd||f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }dd|iz  }|
j#                  |       |r_t        j                  dfdf      t        j                  |      t        j                  |      dz  }dd|iz  }|
j#                  |       t        j$                  |
d      i z  }dd |iz  }t        t        j                  |            d x}x}
x}x}x}x}}g }
d!}||v }|}|r"||j!                  d!      dz      }|t        k(  }|}|sdt        j                  d|fd||f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }dd|iz  }|
j#                  |       |rt        j                  d|fd"|t        f      t        j                  |      d#t        j                         v st        j                  t              rt        j                  t              nd#d$z  }d%d&|iz  }|
j#                  |       t        j$                  |
d      i z  }d'd(|iz  }t        t        j                  |            d x}x}
x}x}x}}g }
d)}||v }|}|r"||j!                  d)      dz      }|t        k(  }|}|sdt        j                  d|fd||f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }dd|iz  }|
j#                  |       |rt        j                  d|fd"|t        f      t        j                  |      d*t        j                         v st        j                  t              rt        j                  t              nd*d$z  }d%d&|iz  }|
j#                  |       t        j$                  |
d      i z  }d'd(|iz  }t        t        j                  |            d x}x}
x}x}x}}d+}||v }|st        j                  d|fd,||f      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }d	d
|iz  }t        t        j                  |            d x}}y )-Nr[   
   )envelopedelay_secondschat_idrc   cokacdir_pathr   r   rd   r   re   r   r   r   z--cronr]   r^   ra   rb      r\   z--at10sr   )z%(py3)s in %(py5)sr   )r   r   z%(py7)srj   )z%(py10)s == %(py13)s)r   r   z%(py15)sr   zassert %(py18)spy18z--chat)z%(py10)s == %(py12)sr   )r   py12z%(py14)spy14zassert %(py17)spy17z--keyr	   z--oncer   )r   rY   r   r   r	   r   r    r!   r%   r"   r#   r$   r&   r'   jsonloadsindexr   r   )rL   r   rt   r(   r*   r+   ru   rv   rw   parsedr)   rx   r   @py_assert12@py_assert11rz   r   r   @py_format17@py_format19@py_format13@py_format15@py_format18s                          r,   +test_cron_argv_signature_is_stable_and_safer      s   
!"2O4E
FC$#"D 7"7l""""7l"""7""""""l"""l"""""""7h7h7h7hZZQ F)0 00 00000 0000000 00000000C6C6T>Cd4::f#5#9:CeC:eCCCCC6TCCC6CCCCCCTCCCTCCCCCCC:eCCC:CCCeCCCCCCCCCCCCCCQ8Q8tQTZZ%9A%= >Q >/ QQQQQ8tQQQ8QQQQQQtQQQtQQQQQQQ >/QQQ >QQQQQQ/QQQ/QQQQQQQQQQQQQQS7S7d?StDJJw$7!$;<S<@SSSSSS7dSSS7SSSSSSdSSSdSSSSSSS<@SSSS<SSSSSS@SSSS@SSSSSSSSSSSSSSS8t8t8ttr.   c                      e Zd ZdddZy)	_FakeProcc                .    || _         || _        || _        y r1   )r   r   r   )selfr   r   r   s       r,   __init__z_FakeProc.__init__   s    $r.   N)r;   r;   )r   intr   rM   r   rM   )r   r   r   r   r2   r.   r,   r   r      s    r.   r   c                    t        dt                     } t        j                  ddd      fd}t	        | |d       }|j
                  }t        j                  }|j                  }||k(  }|s
t        j                  d|fd	||f      d
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                   |            d x}x}x}}|j"                  }d}	||	k(  }|st        j                  d|fd||	f      d
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |      t        j                  |	      dz  }
dd|
iz  }t        t        j                   |            d x}x}}	|j$                  }d }	||	u}|st        j                  d|fd||	f      d
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |      t        j                  |	      dz  }
dd|
iz  }t        t        j                   |            d x}x}}	|j&                  }d }	||	u }|st        j                  d|fd||	f      d
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |      t        j                  |	      dz  }
dd|
iz  }t        t        j                   |            d x}x}}	y )Nr[   okzCRON-ABC-001)r   idc                   t         | v }|st        j                  d|fdt         | f      dt        j                         v st        j
                  t               rt        j                  t               nddt        j                         v st        j
                  |       rt        j                  |       nddz  }dd|iz  }t        t        j                  |            d }t        dd	      S )
Nr   )z%(py0)s in %(py2)sr	   r   r   assert %(py4)sr`   r   r;   )
r	   r    r!   r"   r#   r$   r%   r&   r'   r   )r   r   r)   r   rv   fake_stdouts        r,   r   zPtest_register_normal_callback_happy_path_returns_registered.<locals>.fake_runner   s}    "d****"d******"***"******d***d*******K,,r.   c                     yr   r2   r3   s    r,   r5   zMtest_register_normal_callback_happy_path_returns_registered.<locals>.<lambda>   r6   r.   r   r   )zi%(py2)s
{%(py2)s = %(py0)s.status
} == %(py8)s
{%(py8)s = %(py6)s
{%(py6)s = %(py4)s.REGISTERED
}.value
}r   r   r   r   r   )z3%(py2)s
{%(py2)s = %(py0)s.schedule_id
} == %(py5)sr   r   r   assert %(py7)srj   is not)z<%(py2)s
{%(py2)s = %(py0)s.registered_at_ts
} is not %(py5)srn   )z-%(py2)s
{%(py2)s = %(py0)s.error
} is %(py5)s)r   rY   r   dumpsr   r   r   
REGISTEREDrs   r    r!   r"   r#   r$   r%   r&   r'   schedule_idregistered_at_tsr   )rL   r   r   r)   r   r   ru   r   r   rx   r+   rz   r   s               @r,   ;test_register_normal_callback_happy_path_returns_registeredr      s<   
!"2O4E
FC**NCDK-
 
"{^
B 99I8CCICIII9IIIII9IIIIIII2III2III9IIIIII8III8IIICIIIIIIIIIII>>+^+>^++++>^++++++2+++2+++>+++^+++++++*d*d****d******2***2******d*******88t8t8t228tr.   c                    t        dt                     } d }t        | |d       }|j                  }t        j
                  }|j                  }||k(  }|s
t        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      d	z  }d
d|iz  }t        t        j                  |            d x}x}x}}|j                  }d }	||	u }|st        j                  d|fd||	f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      dz  }
dd|
iz  }t        t        j                  |            d x}x}}	d}g }	|j                   }|}|sd}|}||v }|sddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }|	j#                  |       |s+ddt        j                        iz  }|	j#                  |       t        j$                  |	d      i z  }t        j                  d|fd||f      t        j                  |      |dz  }dd|iz  }t        t        j                  |            d x}x}x}x}	x}}y )Nr[   c                    t        ddd      S )Nr   r;   z2{"status":"error","message":"network unreachable"}r   r   r   s     r,   r   z\test_register_normal_callback_cli_non_zero_exit_returns_register_failed.<locals>.fake_runner   s    B TUUr.   c                     yr   r2   r3   s    r,   r5   zYtest_register_normal_callback_cli_non_zero_exit_returns_register_failed.<locals>.<lambda>   r6   r.   r   r   r   r   r   r   r   r   rn   )z3%(py2)s
{%(py2)s = %(py0)s.schedule_id
} is %(py5)sr   r   rj   zexit=2r;   r   r   r   r   r   r   r   r   r   )r   rY   r   r   r   r   rs   r    r!   r"   r#   r$   r%   r&   r'   r   r   r   r   )rL   r   r   r)   r   r   ru   r   r   rx   r+   rz   rt   ry   r   r(   r   r   r   s                      r,   Gtest_register_normal_callback_cli_non_zero_exit_returns_register_failedr      s   
!"2O4E
FCV 
"{^
B 99N8HHNHNNN9NNNNN9NNNNNNN2NNN2NNN9NNNNNN8NNN8NNNHNNNNNNNNNNN>>!T!>T!!!!>T!!!!!!2!!!2!!!>!!!T!!!!!!!'''B'B'8'''''''''''''''''''''B'''''''''8'''8''''''''r.   c                    t        dt                     } d }t        | |d       }|j                  }t        j
                  }|j                  }||k(  }|s
t        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      d	z  }d
d|iz  }t        t        j                  |            d x}x}x}}y )Nr[   c                    t        ddd      S )Nr   z{"status":"ok"}r;   r   r   s     r,   r   z^test_register_normal_callback_missing_schedule_id_returns_register_failed.<locals>.fake_runner   s    -r22r.   c                     yr   r2   r3   s    r,   r5   z[test_register_normal_callback_missing_schedule_id_returns_register_failed.<locals>.<lambda>   r6   r.   r   r   r   r   r   r   r   r   )r   rY   r   r   r   r   rs   r    r!   r"   r#   r$   r%   r&   r'   )	rL   r   r   r)   r   r   ru   r   r   s	            r,   Itest_register_normal_callback_missing_schedule_id_returns_register_failedr      s    
!"2O4E
FC3 
"{^
B 99N8HHNHNNN9NNNNN9NNNNNNN2NNN2NNN9NNNNNN8NNN8NNNHNNNNNNNNNNNr.   c                 @   t        dt                     } d }t        | |d       }|j                  }t        j
                  }|j                  }||k(  }|s
t        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      d	z  }d
d|iz  }t        t        j                  |            d x}x}x}}d}	g }
|j                  }|}|sd}|}|	|v }|sddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }|
j!                  |       |s+ddt        j                        iz  }|
j!                  |       t        j"                  |
d      i z  }t        j                  d|fd|	|f      t        j                  |	      |dz  }dd|iz  }t        t        j                  |            d x}	x}x}x}
x}}y )Nr[   c                    t        d      )Nz2subprocess must not be invoked when CLI is missing)r&   r   s     r,   r   zVtest_register_normal_callback_cli_missing_returns_register_failed.<locals>.fake_runner   s    QRRr.   c                     y)NFr2   r3   s    r,   r5   zStest_register_normal_callback_cli_missing_returns_register_failed.<locals>.<lambda>   r6   r.   r   r   r   r   r   r   r   r   z	not foundr;   r   r   r   r   r   r   r   r   r   r   rY   r   r   r   r   rs   r    r!   r"   r#   r$   r%   r&   r'   r   r   r   rL   r   r   r)   r   r   ru   r   r   rt   rx   ry   r   r(   rz   r   r   r   s                     r,   Atest_register_normal_callback_cli_missing_returns_register_failedr     s   
!"2O4E
FCS 
"{_
B 99N8HHNHNNN9NNNNN9NNNNNNN2NNN2NNN9NNNNNN8NNN8NNNHNNNNNNNNNNN*288*8*8r*r*;********2***2***8****8***r*********;***;********r.   c                 @   t        dt                     } d }t        | |d       }|j                  }t        j
                  }|j                  }||k(  }|s
t        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      d	z  }d
d|iz  }t        t        j                  |            d x}x}x}}d}	g }
|j                  }|}|sd}|}|	|v }|sddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }|
j!                  |       |s+ddt        j                        iz  }|
j!                  |       t        j"                  |
d      i z  }t        j                  d|fd|	|f      t        j                  |	      |dz  }dd|iz  }t        t        j                  |            d x}	x}x}x}
x}}y )Nr[   c                    t        d      )Nboom)OSErrorr   s     r,   r   z[test_register_normal_callback_runner_exception_returns_register_failed.<locals>.fake_runner   s    for.   c                     yr   r2   r3   s    r,   r5   zXtest_register_normal_callback_runner_exception_returns_register_failed.<locals>.<lambda>   r6   r.   r   r   r   r   r   r   r   r   raisedr;   r   r   r   r   r   r   r   r   r   r  r  s                     r,   Ftest_register_normal_callback_runner_exception_returns_register_failedr     s   
!"2O4E
FC 
"{^
B 99N8HHNHNNN9NNNNN9NNNNNNN2NNN2NNN9NNNNNN8NNN8NNNHNNNNNNNNNNN'''B'B'8'''''''''''''''''''''B'''''''''8'''8''''''''r.   c                 4   t        dt                     } t        |       }ddlm}  |t
        j                  j                  ddt        |             }t        | |      }|| u}|st        j                  d|fd|| f      d	t        j                         v st        j                  |      rt        j                  |      nd	d
t        j                         v st        j                  |       rt        j                  |       nd
dz  }dd|iz  }t!        t        j"                  |            d }| |k(  }|st        j                  d|fd| |f      d
t        j                         v st        j                  |       rt        j                  |       nd
dt        j                         v st        j                  |      rt        j                  |      nddz  }t        j$                  d      dz   d|iz  }t!        t        j"                  |            d }|d   }t
        j                  }	|	j                  }
||
k(  }|st        j                  d|fd||
f      t        j                  |      dt        j                         v st        j                  t
              rt        j                  t
              ndt        j                  |	      t        j                  |
      dz  }dd|iz  }t!        t        j"                  |            d x}x}x}	}
|d   }d}||k(  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t!        t        j"                  |            d x}x}}t'        |      \  }}|s~t        j$                  d|       dz   d d!t        j                         v st        j                  |      rt        j                  |      nd!iz  }t!        t        j"                  |            y )"Nr[   r   )RegistrarResultz
CRON-XYZ-9z2026-05-23T02:00:10Z)r   r   r   
byte_countr   )z%(py0)s is not %(py2)smergedrL   r   r   r`   r   )z%(py0)s == %(py2)ssnapz"input envelope must not be mutatedr   rh   )zM%(py1)s == %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py3)s.REGISTERED
}.value
}r   ri   rk   rl   cron_schedule_idr]   r^   ra   rb   z#merged envelope failed validation: z
>assert %(py0)sr   r   )r   rY   dictutils.anu_callback_registrarr  r   r   rs   r   r   r    r!   r"   r#   r$   r%   r&   r'   r   r   )rL   r  r  r   r  r)   r   rv   rt   rx   ry   r(   rz   r{   ru   rw   r   errs@py_format1s                      r,   ?test_merge_registrar_result_into_envelope_is_immutable_on_inputr     sh   
!"2O4E
FC9D<	/::@@ /+C0	
B 2#r:F666$;<<<3$<<<<<<3<<<3<<<<<<$<<<$<<<<<<<<<<<'(],L,W,W],W,],]](,]]]]](,]]]](]]]]]],L]]],L]]],W]]],]]]]]]]]$%55%5555%555%5555555555 (HB;;4TF;;;;;;;2;;;2;;;;;2r.   c                 6   d} t        |       }d }||u }|st        j                  d|fd||f      dt        j                         v st        j
                  t               rt        j                  t               ndt        j                  |       t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x} x}x}}d} t        |       }d }||u }|st        j                  d|fd||f      dt        j                         v st        j
                  t               rt        j                  t               ndt        j                  |       t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x} x}x}}d	} t        |       }d }||u }|st        j                  d|fd||f      dt        j                         v st        j
                  t               rt        j                  t               ndt        j                  |       t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x} x}x}}d
} t        |       }d}||k(  }|st        j                  d|fd||f      dt        j                         v st        j
                  t               rt        j                  t               ndt        j                  |       t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x} x}x}}y )Nr;   rn   )z0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} is %(py7)sr   )r   r   r`   rj   rk   rl   znot jsonz{"status":"error"}z{"status":"ok","id":"OK1"}OK1r   )z0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py7)s)	r   r    r!   r"   r#   r$   r%   r&   r'   )r)   ru   ry   r   rz   r{   s         r,   ,test_parse_schedule_id_handles_garbage_inputr    s    )b!)T)!T))))!T))))))))))))b)))!)))T)))))))(1j)1T1)T1111)T111111111111j111)111T11111112;23;t;3t;;;;3t;;;;;;;;;;;;2;;;3;;;t;;;;;;;:D:;DuD;uDDDD;uDDDDDDDDDDDD:DDD;DDDuDDDDDDDr.   )returnzDict[str, Any])5__doc__
__future__r   builtinsr"   _pytest.assertion.rewrite	assertionrewriter    r   typingr   r   r   r>   r  r   r   r	   r
   r   r   r   r   r   r   r   utils.callback_envelope_schemar   r   r   r   r-   r9   r@   rG   rN   rY   r|   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r2   r.   r,   <module>r#     s    #    " "     5PC
S
I	9
7
]#X80 $(	O
+
(<(Er.   