
    j5                       d Z ddlmZ ddlZddlmc mZ ddl	Z
ddlZddlZddlmZ ddlZ ee      j#                         j$                  d   Z ee      ej*                  vr"ej*                  j-                  d ee             ddZ edd        ed	d
       ddlmZmZ ddlmZmZmZmZ ddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z+m,Z,m-Z-m.Z.m/Z/ dZ*dZ0dZ1dZ2d Z3d Z4d Z5d Z6d Z7d Z8d Z9d Z:d Z;d Z<y)u   tests/regression/test_callback_runtime_enforcement_2626.py

task-2626 — CALLBACK_RUNTIME_ENFORCEMENT_WIRING regression (회장 §6, 10건).
mock-based · 실 cron 0 · 실 발사 0 · subprocess 0.
    )annotationsN)Path   c                   t         j                  j                  |       }|t        |dd      j	                  |      r|S t
        j                  j                  | t        |z        }g }d }||u}|}|r|j                  }d }	||	u}
|
}|slt        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }dd|iz  }|j!                  |       |rt        j                  d
fd		f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      d
z  }dd|iz  }|j!                  |       t        j"                  |d      i z  }dd|iz  }t%        t        j&                  |            d x}x}x}x}x}x}
}	t
        j                  j)                  |      }|t         j                  | <   |j                  j+                  |       |S )N__file__ is not)z%(py2)s is not %(py5)sspec)py2py5z%(py7)spy7)z5%(py11)s
{%(py11)s = %(py9)s.loader
} is not %(py14)s)py9py11py14z%(py16)spy16r   zassert %(py19)spy19)sysmodulesgetgetattrendswith	importlibutilspec_from_file_location_ROOTloader
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprappend_format_boolopAssertionError_format_explanationmodule_from_specexec_module)modnamerelpathexistingr   @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_format20mods                     N/home/jay/workspace/tests/regression/test_callback_runtime_enforcement_2626.py
_load_realr<      sa   {{w'H*b A J J7 S>>11'57?KD7t74t77474 777774t77777747774777t77777774777777777777777477777777777777
..
)
)$
/CCKKKKC J    z dispatch.callback_owner_enforcerz#dispatch/callback_owner_enforcer.pyz(dispatch.normal_fallback_callback_helperz+dispatch/normal_fallback_callback_helper.py)DISPATCH_CONTRACT_VIOLATIONclassify_dispatch_contract)SELF_COLLECTOR_FORBIDDENCOLLECTOR_ROLE_ANUPATH_DISPATCH_PYenforce_callback_owner)CALLBACK_KIND_FALLBACKCALLBACK_KIND_NORMALLAUNCH_FAIL_CLOSEDLAUNCH_PASSSTATUS_ANU_OWNED_READY STATUS_CALLBACK_PROMPT_TOO_LARGESTATUS_SELF_KEY_FAIL_CLOSEDlaunch_callback)ANU_KEYANU_CHAT_IDCancelClassificationRemoverResultcancel_fallback_on_successc119085addb0f8b71e41a2324a3ccdd0
6937032012z?task_id=task-2626
owner_key=c119085addb0f8b7
collector_role=ANUc            
     J   t        t        dt        t        t        t
        dd      } | j                  }|t        k(  }|st        j                  d|fd|t        f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndd	z  }d
d|iz  }t        t        j                  |            dx}}| j                   }|t"        k(  }|st        j                  d|fd|t"        f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      dt        j                         v st        j                  t"              rt        j                  t"              ndd	z  }d
d|iz  }t        t        j                  |            dx}}g }| j$                  }d}||u}|}|r.| j$                  }t        |v }	|	}|	r| j$                  }
t        |
v}|}|st        j                  d|fd||f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      t        j                  |      dz  }dd|iz  }|j'                  |       |rt        j                  d	fdt        f      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      dz  }dd|iz  }|j'                  |       |	rt        j                  dfdt        
f      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  |       rt        j                  |       ndt        j                  |
      dz  }dd|iz  }|j'                  |       t        j(                  |d       i z  }d!d"|iz  }t        t        j                  |            dx}x}x}x}x}x}	x}x}}
| j*                  d#   }d$}||k(  }|slt        j                  d|fd%||f      t        j                  |      t        j                  |      d&z  }d
d|iz  }t        t        j                  |            dx}x}}y)'uW   ANU key + normal kind → LAUNCH_PASS, argv 에 ANU_KEY 포함, contract_fields 확인.	task-262610m/home/jay/workspacekindtask_idexecutor_key	owner_keychat_idpromptatcanonical_root==z/%(py2)s
{%(py2)s = %(py0)s.verdict
} == %(py4)sdecrG   py0r   py4assert %(py6)spy6Nz.%(py2)s
{%(py2)s = %(py0)s.status
} == %(py4)srH   r	   z0%(py4)s
{%(py4)s = %(py2)s.argv
} is not %(py7)sr   rg   r   %(py9)sr   inz0%(py11)s in %(py15)s
{%(py15)s = %(py13)s.argv
}rL   r   py13py15%(py17)spy17)not in)z4%(py19)s not in %(py23)s
{%(py23)s = %(py21)s.argv
}EXEC_SELF_KEY)r   py21py23z%(py25)spy25r   zassert %(py28)spy28callback_roleCOLLECTOR_ANUz%(py1)s == %(py4)spy1rg   )rK   rE   rw   rL   CHATENVELOPEverdictrG   r   r   r    r!   r"   r#   r&   r'   statusrH   argvr$   r%   contract_fields)rd   r-   r/   @py_format5@py_format7@py_assert6@py_assert5r0   @py_assert14r3   @py_assert22@py_assert20r5   @py_format10@py_format16r8   @py_format24@py_format26@py_format27@py_format29@py_assert2s                        r;   $test_01_anu_key_normal_callback_passr   G   s   
!",	C ;;%;+%%%%;+%%%%%%3%%%3%%%;%%%%%%+%%%+%%%%%%%::/://///:///////3///3///://////////////////Y388Y4Y84YsxxYGx$7YQTQYQYYMQY<YYYYY84YYYYYY3YYY3YYY8YYY4YYYYYYYGxYYYYYYGYYYGYYYYYYsYYYsYYYxYYYYYYYMQYYYYYYYMYYYMYYYYYYQTYYYQTYYYQYYYYYYYYYYYYYYYY/B?B/?BBBB/?BBB/BBB?BBBBBBBr=   c            
        t        t        dt        t        t        t        dd      } | j
                  }|t        k(  }|st        j                  d|fd|t        f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndd	z  }d
d|iz  }t        t        j                  |            dx}}| j                  }|t         k(  }|st        j                  d|fd|t         f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      dt        j                         v st        j                  t               rt        j                  t               ndd	z  }d
d|iz  }t        t        j                  |            dx}}| 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                  |            dx}x}}y)ua   self-key normal → verdict LAUNCH_FAIL_CLOSED, status STATUS_SELF_KEY_FAIL_CLOSED, argv is None.rU   rV   rW   rX   ra   rc   rd   rF   re   rh   ri   Nrj   rJ   isz,%(py2)s
{%(py2)s = %(py0)s.argv
} is %(py5)srf   r   r   assert %(py7)sr   )rK   rE   rw   r   r   r   rF   r   r   r    r!   r"   r#   r&   r'   r   rJ   r   rd   r-   r/   r   r   r.   r4   r5   s           r;   ,test_02_executor_self_key_normal_fail_closedr   [   s   
!",	C ;;,;,,,,,;,,,,,,,3,,,3,,,;,,,,,,,,,,,,,,,,,,::4:44444:444444434443444:44444444444444444488t8t8t338tr=   c            
     j   t        t        dt        t        t        t
        dd      } | j                  }|t        k(  }|st        j                  d|fd|t        f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndd	z  }d
d|iz  }t        t        j                  |            dx}}g }| j                   }d}||u}|}|r| j                   }t        |v }	|	}|st        j                  d|fd||f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      t        j                  |      dz  }
dd|
iz  }|j#                  |       |rt        j                  d	fdt        f      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      dz  }dd|iz  }|j#                  |       t        j$                  |d      i z  }dd|iz  }t        t        j                  |            dx}x}x}x}x}x}	}| j&                  d   }d}||u }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }d
d|iz  }t        t        j                  |            dx}x}}| j&                  d    }d!}||k(  }|slt        j                  d|fd"||f      t        j                  |      t        j                  |      dz  }d
d|iz  }t        t        j                  |            dx}x}}y)#u   ANU key + fallback kind → LAUNCH_PASS, argv 에 ANU_KEY 포함,
    fallback_safety_net_registered is True, fallback_safety_net_role_single_purpose 확인.rU   rV   rW   rX   ra   rc   rd   rG   re   rh   ri   Nr	   rk   rl   rm   r   rn   rp   rL   rq   rt   ru   r   assert %(py20)spy20fallback_safety_net_registeredTr   )z%(py1)s is %(py4)sr   'fallback_safety_net_role_single_purpose%RECOVERY_ONLY_NO_FINAL_REPORT_TRIGGERr~   )rK   rD   rw   rL   r   r   r   rG   r   r   r    r!   r"   r#   r&   r'   r   r$   r%   r   )rd   r-   r/   r   r   r   r   r0   r   r3   r5   r   r   r8   @py_format19@py_format21r   s                    r;   test_03_anu_key_fallback_passr   n   s    #",	C ;;%;+%%%%;+%%%%%%3%%%3%%%;%%%%%%+%%%+%%%%%%%7388747847sxx7Gx$777778477777737773777877747777777Gx777777G777G777777s777s777x77777777777777?@HDH@DHHHH@DHHH@HHHDHHHHHHHEF2F2	3 F2   	G   3      r=   c            
        t        t        dt        t        t        t        dd      } | j
                  }|t        k(  }|st        j                  d|fd|t        f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndd	z  }d
d|iz  }t        t        j                  |            dx}}| j                  }|t         k(  }|st        j                  d|fd|t         f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      dt        j                         v st        j                  t               rt        j                  t               ndd	z  }d
d|iz  }t        t        j                  |            dx}}| 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                  |            dx}x}}y)uS   fallback + self-key → LAUNCH_FAIL_CLOSED, STATUS_SELF_KEY_FAIL_CLOSED, argv None.rU   rV   rW   rX   ra   rc   rd   rF   re   rh   ri   Nrj   rJ   r   r   r   r   r   )rK   rD   rw   r   r   r   rF   r   r   r    r!   r"   r#   r&   r'   r   rJ   r   r   s           r;   .test_04_executor_self_key_fallback_fail_closedr      s   
#",	C ;;,;,,,,,;,,,,,,,3,,,3,,,;,,,,,,,,,,,,,,,,,,::4:44444:444444434443444:44444444444444444488t8t8t338tr=   c                   d| dz  }|j                  t        j                  ddi      d       | dz  }|j                  dd       | d	z  }|j                  d
d       | dz  }|j                  t        j                  dt        t        ddd      d       | dz  }ddfd
}t        d|||||d|d
      }|j                  }t        j                  }	||	k(  }
|
st        j                  d|
fd||	f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndt        j                  |	      dz  }dd|iz  }t        t        j                   |            dx}x}
}	|j"                  }d}||u }
|
st        j                  d|
fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }d d!|iz  }t        t        j                   |            dx}x}
}|j$                  } |       }
|
sd"d#t        j                         v st        j                  |      rt        j                  |      nd#t        j                  |      t        j                  |
      d$z  }t        t        j                   |            dx}}
y)%uS   durable evidence + dispatch-fired marker → fake remover 로 cancel → CANCELLED.fb-cron-2626ztask-2626.result.jsonr   okutf-8encodingztask-2626.mdz# report
okzcollector.markerdonezdispatch-fired.jsonrU   fallbackfallback_callback_cron_idr]   anu_keyfallback_rolerZ   callback_policy_azfallback_cancelled.jsonTdry_runc                  | k(  }|st        j                  d|fd| f      dt        j                         v st        j                  |       rt        j
                  |       nddt        j                         v st        j                        rt        j
                        nddz  }dd|iz  }t        t        j                  |            d }t        dd	
      S )Nra   )z%(py0)s == %(py2)scron_idtarget)rf   r   zassert %(py4)srg   removedfake)r   detail)	r   r   r    r!   r"   r#   r&   r'   rO   )r   r   r-   @py_format3r   r   s        r;   fake_removerzGtest_05_normal_success_fallback_cancel_on_success.<locals>.fake_remover   sx    &    w&      w   w      &   &       If==r=   )
rZ   target_cron_iddispatch_fired_marker_pathresult_json_pathreport_pathcollector_result_marker_pathfallback_cancelled_marker_pathnormal_collector_successremoverr   ra   )zU%(py2)s
{%(py2)s = %(py0)s.classification
} == %(py6)s
{%(py6)s = %(py4)s.CANCELLED
}rd   rN   rf   r   rg   ri   assert %(py8)spy8Nr   )z:%(py2)s
{%(py2)s = %(py0)s.fallback_cancelled
} is %(py5)sr   r   r   zAassert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}	fb_markerre   )
write_textjsondumpsrM   CANCEL_ANU_KEYrP   classificationrN   	CANCELLEDr   r   r    r!   r"   r#   r&   r'   fallback_cancelledexists)tmp_pathresult_jsonreportcollector_markermarkerr   r   rd   r-   r   r/   r   @py_format9r.   r4   r5   r   r   s                    @r;   1test_05_normal_success_fallback_cancel_on_successr      sf   F44K4::x&67'J&F
nw7"449--F


"-3&)!+	"
 	    44I)- > %#)$%5'0!%C ?!5!?!??!?????!???????3???3?????????!5???!5???!????????!!)T)!T))))!T))))))3)))3)))!)))T)))))))99r=   c                "   d}| dz  }|j                  t        j                  ddi      d       | dz  }|j                  dd       | dz  }|j                  d	d       | d
z  }|j                  t        j                  d|t        t        ddd      d       | dz  }|j                  dd       | dz  }g ddfd
}t        d|||||||d|d      }	|	j                  }
t        j                  }|
|k(  }|st        j                  d|fd|
|f      dt        j                         v st        j                  |	      rt        j                  |	      ndt        j                  |
      dt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      dz  }dd|iz  }t        t        j                   |            dx}
x}}|	j"                  }
d}|
|u }|st        j                  d|fd |
|f      dt        j                         v st        j                  |	      rt        j                  |	      ndt        j                  |
      t        j                  |      d!z  }d"d#|iz  }t        t        j                   |            dx}
x}}g }|k(  }
|
st        j                  d|
fd$|f      d%t        j                         v st        j                        rt        j                        nd%t        j                  |      d&z  }d'd(|iz  }t        t        j                   |            dx}
}|j$                  }
 |
       }| }|sd)d*t        j                         v st        j                  |      rt        j                  |      nd*t        j                  |
      t        j                  |      d+z  }t        t        j                   |            dx}
x}}y),uh   cancel lock 선점 시 fallback 뒤늦은 발화 → ALREADY_FIRED, remover 미호출, 마커 미생성.r   zr.jsonr   r   r   r   zr.mdzc.markerr   zd.jsonrU   r   r   r   zcancel.lockzheld-by-normal-successzfb.jsonTr   c               >    j                  |        t        d      S )Nr   )r   )r$   rO   )r   r   r   s     r;   r   zPtest_06_fallback_fires_after_success_noop_no_ledger_append.<locals>.fake_remover   s    wI..r=   )rZ   r   r   r   r   r   r   cancel_lock_pathr   r   r   ra   )zY%(py2)s
{%(py2)s = %(py0)s.classification
} == %(py6)s
{%(py6)s = %(py4)s.ALREADY_FIRED
}rd   rN   r   r   r   NFr   )z;%(py2)s
{%(py2)s = %(py0)s.cron_remove_invoked
} is %(py5)sr   r   r   )z%(py0)s == %(py3)sr   )rf   py3zassert %(py5)sr   zEassert not %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}r   re   )r   r   r   rM   r   rP   r   rN   ALREADY_FIREDr   r   r    r!   r"   r#   r&   r'   cron_remove_invokedr   )r   r   r   r   r   r   lockr   r   rd   r-   r   r/   r   r   r.   r4   r5   r   @py_format4r   s                       @r;   :test_06_fallback_fires_after_success_noop_no_ledger_appendr      s   FX%K4::x&67'JF
dW-*,9 F


"-3&)!+	"
 	    m#DOO,wO?9$IG)- / %#)$%5'0!%C C!5!C!CC!CCCCC!CCCCCCC3CCC3CCCCCCCCC!5CCC!5CCC!CCCCCCCC""+e+"e++++"e++++++3+++3+++"+++e+++++++7b=7b77b!!!!!!!!!!!!y!!!y!!!!!!!!!!!!!r=   c                    t        dddd      } | j                  }|t        k(  }|st        j                  d|fd|t        f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      dt        j                         v st        j                  t              rt        j                  t              ndd	z  }d
d|iz  }t        t        j                  |            dx}}| 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                  |            dx}x}}y)ud   result 존재 + normal·fallback 둘 다 부재 → DISPATCH_CONTRACT_VIOLATION + recovery_required.rU   FT)rZ   normal_callback_presentfallback_presentresult_presentra   )z6%(py2)s
{%(py2)s = %(py0)s.classification
} == %(py4)srecr>   re   rh   ri   Nr   )z9%(py2)s
{%(py2)s = %(py0)s.recovery_required
} is %(py5)sr   r   r   )r?   r   r>   r   r   r    r!   r"   r#   r&   r'   recovery_required)r   r-   r/   r   r   r.   r4   r5   s           r;   <test_07_result_present_normal_and_fallback_missing_violationr      s   
$ %	C <!<<<<<!<<<<<<<3<<<3<<<<<<<<<!<<<<!<<<<<<<<  (D( D(((( D((((((3(((3((( (((D(((((((r=   c                 T   t        t        dt        t        t        dddd	      } | j
                  }|t        k(  }|st        j                  d|fd|t        f      d	t        j                         v st        j                  |       rt        j                  |       nd	t        j                  |      d
t        j                         v st        j                  t              rt        j                  t              nd
dz  }dd|iz  }t        t        j                  |            dx}}g }| j                  }|t         k(  }|}|r| j"                  }d}||u }	|	}|st        j                  d|fd|t         f      d	t        j                         v st        j                  |       rt        j                  |       nd	t        j                  |      dt        j                         v st        j                  t               rt        j                  t               nddz  }dd|iz  }
|j%                  |
       |rt        j                  d	fdf      d	t        j                         v st        j                  |       rt        j                  |       nd	t        j                  |      t        j                  |      dz  }dd|iz  }|j%                  |       t        j&                  |d      i z  }dd|iz  }t        t        j                  |            dx}x}x}x}x}x}	}| j(                  d   }d}||kD  }|slt        j                  d|fd||f      t        j                  |      t        j                  |      d z  }dd|iz  }t        t        j                  |            dx}x}}y)!u]   3900 bytes 초과 prompt → STATUS_CALLBACK_PROMPT_TOO_LARGE, LAUNCH_FAIL_CLOSED, argv None.rU   a  task_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrV   rW   F)	rY   rZ   r[   r\   r]   r^   r_   r`   require_envelopera   rj   rd   rI   re   rh   ri   Nz/%(py4)s
{%(py4)s = %(py2)s.verdict
} == %(py6)srF   r   rg   ri   %(py8)sr   r   z0%(py12)s
{%(py12)s = %(py10)s.argv
} is %(py15)spy10py12rs   rt   ru   r   r   r   callback_prompt_utf8_bytesi<  )>)z%(py1)s > %(py4)sr   )rK   rE   rw   rL   r   r   rI   r   r   r    r!   r"   r#   r&   r'   r   rF   r   r$   r%   r   )rd   r-   r/   r   r   r   r0   @py_assert11r   r2   r   r   r8   r   r   r   s                   r;   !test_08_callback_prompt_too_larger   
  s   
!"&,
C ::9:99999:999999939993999:999999999999999999A3;;A;,,AATAT1AAAAA;,AAAAAA3AAA3AAA;AAAAAA,AAA,AAAAAAATAAAAAAAAAAAAAAATAAAAAAAAAAAAAA;<CtC<tCCCC<tCCC<CCCtCCCCCCCr=   c            
     L   t        t        dt        t        t        t
        dd      } | j                  }d}||k(  }|st        j                  d|fd||f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      t        j                  |      d	z  }d
d|iz  }t        t        j                  |            dx}x}}| j                  }d}||u }|st        j                  d|fd||f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      t        j                  |      d	z  }d
d|iz  }t        t        j                  |            dx}x}}| j                   }|t"        k(  }|st        j                  d|fd|t"        f      dt        j                         v st        j                  |       rt        j                  |       ndt        j                  |      dt        j                         v st        j                  t"              rt        j                  t"              nddz  }dd|iz  }t        t        j                  |            dx}}t        t        dt        t        t        t
        dd      }|j                   }|t$        k(  }|st        j                  d|fd|t$        f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dt        j                         v st        j                  t$              rt        j                  t$              nddz  }dd|iz  }t        t        j                  |            dx}}g }d}	|j&                  }
|	|
v }|}|s'd}|j&                  }|j(                  } |       }||v }|}|st        j                  d|fd|	|
f      t        j                  |	      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |
      dz  }dd|iz  }|j+                  |       |st        j                  dfdf      t        j                  |      dt        j                         v st        j                  |      rt        j                  |      ndt        j                        t        j                        t        j                  |      d z  }d!d"|iz  }|j+                  |       t        j,                  |d#      i z  }d$d%|iz  }t        t        j                  |            dx}x}x}	x}x}
x}x}x}x}}|j.                  }d}||u }|st        j                  d|fd&||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      d	z  }d
d|iz  }t        t        j                  |            dx}x}}y)'u   canonical_root 빈값 → 교정(canonical_root_corrected=True, verdict PASS).
    canonical_root='/tmp/evil' → LAUNCH_FAIL_CLOSED, canonical root invalid.rU   rV   r   rX   rW   ra   )z6%(py2)s
{%(py2)s = %(py0)s.canonical_root
} == %(py5)sdec_correctedr   r   r   NTr   )z@%(py2)s
{%(py2)s = %(py0)s.canonical_root_corrected
} is %(py5)src   rG   re   rh   ri   z	/tmp/evildec_evilrF   CANONICAL_ROOTinvalidrn   )z.%(py3)s in %(py7)s
{%(py7)s = %(py5)s.status
})r   r   r   rm   r   )zh%(py12)s in %(py20)s
{%(py20)s = %(py18)s
{%(py18)s = %(py16)s
{%(py16)s = %(py14)s.status
}.lower
}()
})r   r   r   py18r   z%(py22)spy22   zassert %(py25)srz   r   )rK   rE   rw   rL   r   r   r`   r   r   r    r!   r"   r#   r&   r'   canonical_root_correctedr   rG   rF   r   lowerr$   r%   r   )r   r-   r.   r/   r4   r5   r   r   r   r   r   r0   r   @py_assert15@py_assert17@py_assert19r2   r   r   @py_format23r   r   s                         r;   7test_09_canonical_root_missing_corrected_or_fail_closedr    s    $!"	M ''@+@@'+@@@@@'+@@@@@@@=@@@=@@@'@@@+@@@@@@@@119T91T99991T999999=999=9991999T9999999  / K//// K//////=///=/// //////K///K/////// !""	H 111111111111181118111111111111111111111VVxV.V)VxV?T?TV?T?VV)?V2VVVVVVVVVVVVVVxVVVxVVVVVVVVVV)?VVVV)VVVVVVxVVVxVVVVVV?TVVV?VVVVVVVVVVVVVVVV== D =D    =D      8   8   =   D       r=   c                    t        dt        t        t        t        dddt        dt              } | j
                  }t        |v }|st        j                  d|fdt        |f      d	t        j                         v st        j                  t              rt        j                  t              nd	d
t        j                         v st        j                  |       rt        j                  |       nd
t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}}t        t         dt        t        t        t"        dd      }g }|j$                  }|t&        k(  }|}|r|j(                  }d}	||	u }
|
}|st        j                  d|fd|t&        f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dt        j                         v st        j                  t&              rt        j                  t&              nddz  }dd|iz  }|j+                  |       |rt        j                  d
fd	f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      dz  }dd|iz  }|j+                  |       t        j,                  |d      i z  }dd |iz  }t        t        j                  |            dx}x}x}x}x}x}
}	y)!u   enforce_callback_owner self-collector → SELF_COLLECTOR_FORBIDDEN.
    launch_callback self-key → LAUNCH_FAIL_CLOSED, argv None.rU   NCFBDT)rZ   r[   collector_keycollector_owner_keycollector_rolenormal_collector_cron_idr   dispatch_cron_idr]   prompt_claims_anu_collector
entry_pathrn   )z7%(py0)s in %(py4)s
{%(py4)s = %(py2)s.classifications
}r@   enfre   rh   ri   NrV   rW   rX   ra   r   rd   rF   r   r   r   r   r   r   rt   ru   r   r   r   )rC   rw   rA   r   rB   classificationsr@   r   r   r    r!   r"   r#   r&   r'   rK   rE   r   r   rF   r   r$   r%   )r  r/   r-   r   r   rd   r   r0   r   r   r2   r   r   r8   r   r   s                   r;   (test_10_self_collector_attempt_forbiddenr  C  s    !"#))!%"&$(#C (+':'::#':::::#':::::::#:::#::::::s:::s:::'::::::::
!",	C B3;;A;,,AATAT1AAAAA;,AAAAAA3AAA3AAA;AAAAAA,AAA,AAAAAAATAAAAAAAAAAAAAAATAAAAAAAAAAAAAAr=   )r*   strr+   r  )=__doc__
__future__r   builtinsr    _pytest.assertion.rewrite	assertionrewriter   importlib.utilr   r   r   pathlibr   pytestr   resolveparentsr   r  pathinsertr<   !anu_v3.dispatch_callback_contractr>   r?    dispatch.callback_owner_enforcerr@   rA   rB   rC   (dispatch.normal_fallback_callback_helperrD   rE   rF   rG   rH   rI   rJ   rK   )utils.completion_callback_fallback_cancelrL   r   rM   rN   rO   rP   rw   r   r   r   r   r   r   r   r   r   r   r  r   r=   r;   <module>r)     s   
 #      
  X ((+u:SXXHHOOAs5z"	 -/T U 
57d e 	 	 	  "N
C(&0&*^/"h	)D( !JBr=   