
    4jm+                    R   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mZ ddlmZ ddlmZ  ee      j)                         j*                  j*                  j*                  Z ee      ej0                  vr"ej0                  j3                  d ee             d)dZ edd	      Z ed
d        edd        edd        edd        edd        edd        edd      Z edd      Z edd      Zej>                  Zej@                  Z ejB                  Z!ejD                  Z"ejF                  Z#dZ$dZ%e$fZ&dZ'dZ(e G d  d!             Z) G d" d#ejT                        Z+ G d$ d%ejT                        Z, G d& d'ejT                        Z-e.d(k(  r ej^                          yy)*u   task-2553+49 AUTHORITATIVE — self-collector / self-adjudication /
self-dispatch + write-back binding conflict runtime regression
(§8 reg 11, 12, 19, 20, 28, 29).

회장 §5 중요: 실 runtime guard entrypoint 직접 호출. mock-only 금지.
    )annotationsN)	dataclass)Path)Optionalc                r   | t         j                  v rt         j                  |    S t        j                  j	                  | t
        |z        }g }d }||u}|}|r|j                  }d }||u}	|	}|slt        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                  |      t        j                  |      dz  }d	d
|iz  }|j                  |       t        j                  |d      i z  }dd|iz  }t        t        j                   |            d x}x}x}x}x}x}	}t        j                  j#                  |      }|t         j                  | <   |j                  j%                  |       |S )N)is not)z%(py2)s is not %(py5)sspec)py2py5z%(py7)spy7)z5%(py11)s
{%(py11)s = %(py9)s.loader
} is not %(py14)s)py9py11py14z%(py16)spy16r   zassert %(py19)spy19)sysmodules	importlibutilspec_from_file_location_ROOTloader
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprappend_format_boolopAssertionError_format_explanationmodule_from_specexec_module)modnamerelpathr	   @py_assert1@py_assert4@py_assert3@py_assert0@py_assert10@py_assert13@py_assert12@py_format6@py_format8@py_format15@py_format17@py_format18@py_format20mods                    T/home/jay/workspace/tests/regression/test_self_collector_guard_runtime_2553plus49.py_loadr6      sI   #++{{7##>>11'57?KD7t74t77474 777774t77777747774777t77777774777777777777777477777777777777
..
)
)$
/CCKKKKC J    z%dispatch.executor_completion_contractz(dispatch/executor_completion_contract.pyz dispatch.spec_template_validatorz#dispatch/spec_template_validator.pyzanu_v3.callback_4tuple_registryz"anu_v3/callback_4tuple_registry.pyz dispatch.callback_owner_enforcerz#dispatch/callback_owner_enforcer.pyz(dispatch.normal_fallback_callback_helperz+dispatch/normal_fallback_callback_helper.pyzanu_v3.callback_owner_validator"anu_v3/callback_owner_validator.pyz%anu_v3.authoritative_verdict_selector(anu_v3/authoritative_verdict_selector.pyzanu_v3.self_collector_guardanu_v3/self_collector_guard.pyz'anu_v3.writeback_binding_conflict_guard*anu_v3/writeback_binding_conflict_guard.pyzdispatch.cron_dispatch_guardzdispatch/cron_dispatch_guard.pyc119085addb0f8b70b94683120a691cf
6937032012u   [EXECUTOR COMPLETION CALLBACK — MANDATORY] executor 는 ANU 에 normal completion callback cron 을 반드시 발사해야 한다.c                  J    e Zd ZU ded<   ded<   ded<   ded<   ded<   ded<   y	)

_LedgerRecstrstatusdispatch_idchat_idzOptional[str]normal_collector_cron_idrolefallback_callback_cron_idN)__name__
__module____qualname____annotations__ r7   r5   r@   r@   I   s#    KL++
I,,r7   r@   c                      e Zd Zd Zd Zd Zy)SelfActionRuntimeRegressionc                   t        t        t        dd      }| j                  |j                  d       | j                  |j                  d       t        t        t
        dd      }| j                  |j                  d       y )NT)executor_key	actor_keyis_codex_auditis_adjudicationFAIL$EXECUTOR_SELF_ADJUDICATION_FORBIDDENPASS)guard_self_adjudicationEXEC_KEYassertEqualverdictclassificationANU_KEYselfroks      r5   -test_11_executor_self_codex_adjudication_failzISelfActionRuntimeRegression.test_11_executor_self_codex_adjudication_failU   sr    #!X
 	F+D	
 %!W
 	V,r7   c                   t        t        t        d      }| j                  |j                  d       | j                  |j                  d       t        t        t
        d      }| j                  |j                  d       y )NT)rP   rQ   is_followup_dispatchrT    EXECUTOR_SELF_DISPATCH_FORBIDDENrV   )guard_self_dispatchrX   rY   rZ   r[   r\   r]   s      r5   ,test_12_executor_self_followup_dispatch_failzHSelfActionRuntimeRegression.test_12_executor_self_followup_dispatch_faile   sn    !X!%
 	F+@	
 !!W!%
 	V,r7   c                j    t        t        t        dd      }| j                  |j                  d       y )NTF)rP   rQ   rc   is_executor_self_sessionrT   )re   rX   rY   rZ   r^   r_   s     r5   .test_self_session_flag_cannot_relax_key_signalzJSelfActionRuntimeRegression.test_self_session_flag_cannot_relax_key_signalt   s.      !X!%
 	F+r7   N)rH   rI   rJ   ra   rf   rj   rL   r7   r5   rN   rN   S   s    - -,r7   rN   c                  &    e Zd ZddZd Zd Zd Zy)!WritebackBindingRuntimeRegressionc                .    t        ddt        d||      gS )N	COMPLETEDDSPNC)rB   rC   rD   rE   rF   rG   )r@   CHAT)r^   rF   fbs      r5   _histz'WritebackBindingRuntimeRegression._hist   s#    "tR
 	
r7   c                L   t        | j                  dd      ddt        dddt        t        t
        	
      }| j                  |j                  d
       | j                  |j                  d       | j                  |j                         | j                  |j                         y )NexecutorFB-ANUrF   rr   task-2553+49ro   rp   fallbackzFB-DIFFERENT	task_idrC   rD   rE   candidate_rolecandidate_fallback_cron_idcandidate_owner_keyrP   anu_keysrT   WRITEBACK_BINDING_CONFLICT)guard_writeback_bindingrs   rq   r\   rX   KEYSrY   rZ   r[   
assertTrueconflicting_fieldsassertFalsecompleted_acknowledgedri   s     r5   /test_19_role_fallback_binding_mismatch_conflictzQWritebackBindingRuntimeRegression.test_19_role_fallback_binding_mismatch_conflict   s    #JJJ8J4"t%)%'5 'h
 	F+))+GH,,-112r7   c                   t        | j                  dd      ddt        dddt        t        t
        
      }| j                  |j                  d       | j                  |j                  d	       | j                  |j                         y )
Nru   rv   rw   rx   ro   rp   rz   rV   WRITEBACK_IDEMPOTENT_SKIP)r   rs   rq   r\   rX   r   rY   rZ   r[   r   r   ri   s     r5   'test_20_valid_duplicate_idempotent_skipzIWritebackBindingRuntimeRegression.test_20_valid_duplicate_idempotent_skip   ss    #JJJ8J4"t%)%'/ 'h
 	F+))+FG001r7   c                   t        | j                         ddt        dddt        t        t        
      }| j                  |j                  d       | j                  |j                  d       | j                  |j                         y )	Nrx   ro   rp   ru   rv   rz   rT   "WRITEBACK_SELF_CHAIN_NOT_COMPLETED)
r   rs   rq   rX   r   rY   rZ   r[   r   r   ri   s     r5   'test_self_chain_writeback_not_completedzIWritebackBindingRuntimeRegression.test_self_chain_writeback_not_completed   ss    #JJL"t%)%'/ (x
 	F+B	
 	112r7   N)ru   rv   )rH   rI   rJ   rs   r   r   r   rL   r7   r5   rl   rl   ~   s    
323r7   rl   c                  "    e Zd ZdZd Zd Zd Zy)SafetyPathInvariantsu   §8 reg 28/29 — checkpoint=recovery layer 유지(primary executor
    격상 금지) · callback/fallback safety path 유지.c                F   t         dz  dz  }| j                  |j                                |j                  d      }| j	                  d|j                                dD ]?  }t         |z  j                  d      }| j                  d|       | j                  d|       A y )	Nanu_v3z.runtime_reconcile_checkpoint_recovery_layer.pyzutf-8)encodingrecovery)r:   r9   r8   r;   primary_executorruntime_reconcile_checkpoint)r   r   is_file	read_textassertInlowerassertNotIn)r^   rl_pathsrcreltxts        r5   3test_28_runtime_checkpoint_recovery_layer_unchangedzHSafetyPathInvariants.test_28_runtime_checkpoint_recovery_layer_unchanged   s    
 H>? 	 	)*1j#))+.
 	BC 3;))7);C/5;SA	Br7   c                X   ddl m}  |dt        t        t        ddd dt        dt
        d	      }| j                  |j                  d
       | j                  d|j                          |dt        t        t        ddd dt        dt
        d	      }| j                  |j                  d       y )Nr   )validate_callback_owner_runtimerx   ANUrp   DTF)r{   rP   collector_keycollector_owner_keycollector_rolerE   rG   dispatch_cron_idrD   prompt_claims_anu_collectorr   no_fallbackrT   CALLBACK_4TUPLE_INVALIDrV   )
anu_v3.callback_owner_validatorr   rX   r\   rq   r   rY   rZ   r   classifications)r^   r   r_   r`   s       r5   /test_29_callback_fallback_safety_path_preservedzDSafetyPathInvariants.test_29_callback_fallback_safety_path_preserved   s    	
 ,"!w 4&*Sdu
 	F+/1B1BC -"!w 4&*Sdt
 	V,r7   c                   t        dddd      }t        di dt        ddd	|d
t        dt        dt        dddddddddt        dddt
        dt        dddd\  }}}}}| j                  |d       | j                  |j                  d       | j                  |j                  d       t        t        d|t        t        t        ddddt        dt
        t        d      \  }}}	}
}| j                  |d       y )Nrx   r   rp   FB)r{   r   rE   rG   	spec_text
entry_pathcokacdir_cron_directtuple_rP   r   r   r   r   r   rE   rG   rD   r   Tr   rQ   rh   rc   rT   F)r   r   r   rP   r   r   r   r   rE   rG   rD   r   r   rQ   rc   rV   rL   )	Callback4Tuple$guard_dispatch_runtime_authoritative_CLAUSErX   rq   r   rY   rZ   r\   )r^   tbaseownerscsdfinalbase2owner2sc2sd2final2s               r5   )test_runtime_authoritative_composite_gatez>SafetyPathInvariants.test_runtime_authoritative_composite_gate   sR    "S%)T
 &J 	&
	&
*@	&
IJ	&
!	&
19	&
 !)	&
 :?	&
 !		&
 <@		&

 '+	&

 59	&
 )-	&
 8<	&
 	&
 :>	&
 "&	&
"eRU 	'V,V, 1!.Dxw$+E!$t*.,04! 	(vsC 	(r7   N)rH   rI   rJ   __doc__r   r   r   rL   r7   r5   r   r      s    ?B,-: )r7   r   __main__)r%   rA   r&   rA   )0r   
__future__r   builtinsr   _pytest.assertion.rewrite	assertionrewriter   importlib.utilr   r   unittestdataclassesr   pathlibr   typingr   __file__resolveparentr   rA   pathinsertr6   _ecc_scg_wbg_grdrW   re   r   r   r   r\   rX   r   rq   r   r@   TestCaserN   rl   r   rH   mainrL   r7   r5   <module>r      s   #     
  !  X ''..55u:SXXHHOOAs5z" 479 (+- '*, (+- 035 '*, -02*-/69;+.0 66 .. 66  	-- % $$
zB  - - -(,("3"3 (,V73(9(9 73tW)8,, W)t zHMMO r7   