
    UŁjD                    *   d dl mZ d dlZd dl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Z e	e      j                  Zej                   j#                  dedz        Zerej&                  sJ ej                   j)                  e      Zeej,                  ej.                  <   ej&                  j1                  e       dddd,d	Zd
dd	 	 	 	 	 	 	 	 	 d-dZd.dZdd	 	 	 	 	 	 	 	 	 	 	 d/dZ	 	 	 	 	 	 d0dZd1dZd1dZd1dZ d2dZ!	 	 d2dZ"d2dZ#d2dZ$d2dZ%d2dZ&d2dZ'ejP                  jS                  dg d      d3d       Z*	 	 d2d Z+d2d!Z,d2d"Z-d2d#Z.d2d$Z/d4d%Z0	 	 d2d&Z1ejP                  jS                  d'd(      	 	 	 	 	 	 d5d)       Z2d2d*Z3d6d+Z4y)7    )annotationsN)Path)Anycontinuous_v3_finalzcontinuous_lifecycle.pyTlegacyinclude_schedulec                    i ddddddddd	| rt         j                  nd
d| rdnt         j                  dddd dd ddg dddg dddg dddg dddg dddg dddg dddddddd}|rd |d!<   |S )"Ndate_of_birthz
1996-08-01equation_sex_basismale	height_cm180	weight_kg80activity_categorymoderateactivity_rationale   주 3회 근력운동	goal_typemaintaintarget_weight_kgtarget_date	allergiesnone)statusitemsintolerancesreligious_ethical_exclusionsdisliked_foodsdietary_preferences
conditionsmedicationspregnancy_breastfeedingFu   기본 조리 가능   보통   )eating_disorder_riskcooking_accessbudget_band
meal_count   없음schedule_constraints)mLEGACY_ACTIVITYDETAILED_RATIONALE)r   r	   values      b.omo/evidence/task26/task26-continuous-lifecycle-observer-v4-4e9962be/test_continuous_lifecycle.pyanswersr2      s1     f  	U  	T	 
 	&Q..j  	5QEYEY  	Z  	D  	t  	4  	6B7  	'6B(G  	Vb9  	&2>  	"5   	&26! " 	"5# $ !&0+ E. (0$%L    resolvedF)statecanonical_summaryc          
         g }|dk(  s|rddddg}d|t         j                  |       |rt         j                  |       ndg g g g |d||d	}t         j                  |      |d
<   |S )N
clarifyingr   	ambiguityu+   평소 활동량은 어느 정도인가요?)fieldkindquestion_ko!nutrition_input_reconciliation_v1u"   수정 전 활동 요약입니다.)
summary_kofacts_koambiguities_kocontradictions_kosafety_observations_koclarifications)schema_versionr5   answers_digestadvisoryrC   current_indexdigest)r-   canonical_digestauthoritative_summary)r0   rG   r5   r6   rC   records         r1   reconciliationrL   4   s     /1N -#L
 >,,U3 % ''.9 !#&(,
 )&#!F& ))&1F8Mr3   c                 l   t               } dt        j                  |       dd}t        j                  ddd|d}dd	t        j                  t        j                  d
dt        j
                  t        j
                  dgddd| t        | d      dgd|i |dt        j
                  dgdgg d g g i i g dS )Ncustomer_attestation@3230cb1a3c13f8e164c2171148c6e3183cbce0d36289cc647c10634b840d8060r5   rE   body_digest   	COMMITTED   
session_id
generationr5   
message_idpayloadAWAITING_ACTIVATION   )r5   rW   rV   sid_hashF0)enabledroute      rG      r5   cursorr2   rL   consumed_updatescustomerroler_   )	bootstraprg   workflowpublicationoutboxowner_callbackswizardgenerationscardsdrafts
deliveries
activation)r2   r-   rI   SESSIONSIDCUSTOMERrL   )r0   rY   rl   s      r1   baserx   [   s    IE',,U3YG iiK +))	
 !&QZZ0MN+,U!D!$
 #RkR:S@QRS/ r3   rg   ri   c                   t         j                  |d||d}|| d<   |dk(  rt         j                  dgnt         j                  dg}| d   j	                  i |||d       y )NrS   rU   rl   rg   r]   rm   rh   )r-   ru   rw   OWNERappend)snapshotrW   rX   rY   ri   rl   r_   s          r1   publishr~      si     ii  K *H]!%!3QZZ!''3EXKKdUKLr3   c                   | d   d   }t         j                  | d   ||      }|J dt         j                  |      t         j                  j	                  |j                               j                         dS )Nrk   r2   rN   rP   )r-   candidate_attestation_textrI   hashlibsha256encode	hexdigest)r}   rG   r0   texts       r1   candidate_payloadr      st     Z +E''(<e]SD',,U3yy''6@@B r3   c           	     6    t        | ddt        | d             y )N      ra   rb   )r~   r   r}   s    r1   startupr      s    Hb#0KLr3   c           	     V    ddt        dd      ddgd| d<   t        | d	d
dddd       y )N
collecting   Fr   rc   ,  )r5   re   r2   rf   rk         @cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc	broadcast)r5   rQ   force_reply_mode)r2   r~   r   s    r1   normalized_rewindr      sF    %%@ #J	HZ 
!# +	
		r3   c           	         t        d      }dd|t        |dd      g dd	| d
<   t        | ddt        | d             y )NFr   rN   r`   r   T)rG   r6   )rc   r   -  rd   rk         rb   )r2   rL   r~   r   )r}   r0   s     r1   canonical_attestationr      sM    5!E'(d
 ,HZ Hb#0KLr3   c                     t         j                  dk(  sJ t         j                  dk(  sJ t         j                  dk(  sJ y )N@4e9962be49b72951c3b9ed7e1a4fe36d0ca03e757872ae03364c1ab7a790f32b@88caabf3dee923e720463d917d35b6dd32ecc31102ed3ab4df4c6a203df4a760@33688875a0d1ce20955bd8272257ee34d84cb138f6a23a43e5d16682368ae5e5)r-   	SUCCESSORCOREWHEEL r3   r1   test_final_candidate_bindingsr      sE    	M	N	N 66WWWW77XXXXr3   c                     dt         j                  z  } t        j                  t        j
                  d| gdddd      }t        j                  |j                        dt         j                  gddk(  sJ y )	Na  
import json
from types import SimpleNamespace
from gateway.platforms.telegram_nutrition_onboarding_copy import parse_legacy_activity_answer
from gateway.platforms.telegram_nutrition_onboarding_runtime_publication_transport import publication_generation
legacy = %r
parsed = parse_legacy_activity_answer(legacy)
status = SimpleNamespace(answer_count=22, state=SimpleNamespace(value='customer_attestation'))
current = SimpleNamespace(generation=24, payload={'body_digest': 'old'})
generation = publication_generation(status, current=current, payload={'body_digest': 'candidate-changed'})
print(json.dumps({'parsed': parsed, 'generation': generation}, ensure_ascii=False))
z-cz(/home/cube/projects/richard/hermes-agentT)cwdcheckcapture_outputr   r   r   )parsedrW   )
r-   r.   
subprocessrunsys
executablejsonloadsstdoutr/   )coderesults     r1   Jtest_product_runtime_recovers_exact_legacy_activity_and_startup_generationr      s}    	 

	 	 ^^	t$6F ::fmm$q334)   r3   c                     t         j                  t                     } | j                  dk(  sJ | j                  J | j
                  dk(  sJ y )NWAIT_DEPLOYzdeploy-final-candidate)r-   classifyrx   r   rX   action)prompts    r1   1test_current_inactive_authority_emits_wait_deployr      sI    ZZF==M)))$$$==4444r3   c                 0   t               } t        |        t        j                  |       }|j                  dk(  sJ |j
                  dk(  sJ |j                  t        j                  dd      k(  sJ |j                  t        j                  dd      k7  sJ y )NREADY_CUSTOMER_REVISION209reviser   rR   )rx   r   r-   r   r   rX   r   callbackr}   r   s     r1   =test_startup_changed_body_generation_25_emits_latest_revisionr      s    vHHZZ!F==5555%%%==AJJx4444==AJJx4444r3   c                     t               } t        |        t        j                  | d   d         | d<   t        j                  |       }|j                  dk(  sJ |j                  J y )Nrm   r   rl   "WAIT_MATCHING_CUSTOMER_PUBLICATION)rx   r   copydeepcopyr-   r   r   rX   r   s     r1   9test_stale_generation_24_message_207_callback_is_rejectedr     sa    vHH"mmHX,>q,ABH]ZZ!F==@@@@$$$r3   c                     t               } t        j                  |       J t        |        t        j                  |       }|J |d   dk(  sJ |d   dk(  sJ |d   t        j	                  dd      k(  sJ y )Nr   r   rX   r   r   r   r   )rx   r-   candidate_revision_handoffr   r   )r}   handoffs     r1   <test_revision_handoff_helper_never_authorizes_predeploy_cardr     s    vH''1999H**84G8 9999< E)))8

8R 8888r3   c                 n   t               } t        |        t        |        | d   }|d   d   dk(  sJ |d   d   t        j                  k(  sJ d|d   vsJ d|vsJ t        j                  |       }|j                  dk(  sJ |j                  d	k(  sJ |j                  d
k(  sJ |j                  dk(  sJ y )Nrk   r2   r   r   r   r,   rL   READY_CUSTOMER_RESUBMIT211z"submit_answer:schedule_constraintsr+   )
rx   r   r   r-   r/   r   r   rX   r   command)r}   rk   r   s      r1   Htest_authorized_rewind_normalizes_activity_and_preserves_exact_rationaler     s    vHHh
#HI23zAAAI348L8LLLL!))<<<<8+++ZZ!F==5555%%%==@@@@>>X%%%r3   fault)activity	rationalerL   rW   c                   t               }t        |       t        |       | dk(  rt        j                  |d   d   d<   nL| dk(  rd|d   d   d<   n;| dk(  r	i |d   d<   n-d	|d
   d<   t        j                  |      j                  dk(  sJ y t        j                  t        j                        5  t        j                  |       d d d        y # 1 sw Y   y xY w)Nr   rk   r2   r   r   r   r   rL   r   rl   rW   r   )
rx   r   r   r-   r.   r   r   pytestraisesLifecycleError)r   r}   s     r1   3test_rewind_rejects_noncanonical_or_stale_authorityr   '  s     vHHh
?@?P?PY'(;<	+	@WY'(<=	"	"13-.02-zz(#**.RRRR	q''	(	

8 
)	(	(s   /CCc                    t               } t        |        t        |        t        |        | d   d   }t        j                  |      sJ t        j                  | d   |d      }|J dD ]  }||vrJ  ddt        j                  dfD ]  }||v rJ  t        j                  |       }|j                  dk(  sJ |j                  d	k(  sJ |j                  t        j                  d
d      k(  sJ y )Nrk   r2   r   )	{r   r   r   r   u	   미입력u   위험 신호u
   수정 전u    실제 총활동량은 불명확u   유지r%   u%   별도 검토 입력이 없습니다.READY_CUSTOMER_ATTEST213attestr   )rx   r   r   r   r-   baseline_valid_answersr   r/   r   r   rX   r   r   )r}   r0   r   	forbiddenrequiredr   s         r1   Jtest_new_reconciliation_summary_is_canonical_baseline_valid_and_attestabler   <  s    vHHh(#Z +E##E***''(<eQGD
	 $$$
 		/	 4 ZZ!F==3333%%%==AJJx4444r3   c                    t               } t        |        t        |        t        |        d| d   d   d<   d| d   d   d   d<   t        j                  |       j                  dk(  sJ t               } t        |        t        |        t        |        d| d	   d
   d<   t        j                  | d	   d
         }|| d	   d   d<   | d	   d   j                         D ci c]  \  }}|dk7  s|| }}}t        j                  |      | d	   d   d<   || d   d   d<   || d   d   d   d<   t        j                  |       j                  dk(  sJ y c c}}w )N@0000000000000000000000000000000000000000000000000000000000000000rl   rY   rQ   rm   WAIT_CANDIDATE_PUBLICATIONr   rk   r2   r   rL   rE   rH   r   )	rx   r   r   r   r-   r   r   rI   r   )r}   rH   kvunsigneds        r1   Ftest_final_summary_rejects_bad_body_and_accepts_domain_valid_rationaler   `  s   vHHh(#8@H]I&}57?HXr9%m4::h&&*FFFFvHHh(#<SHZ#$89 4Y ?@F?EHZ)*+;<!*-.>?EEGGA1PX=1G   897I7I(7SHZ)*84;AH]I&'78:@HXr9%&67::h&&*AAAAs   E,Ec                 ,   t               } t        d      }dd|t        |dd      d| d	<   dt        t        j                  |            d
dd}t        | dd|       t        j                  |       }|j                  dk(  sJ |j                  dk(  sJ y )NFr   rN   r`   r   r8   )rG   r5   )r5   re   r2   rL   rk   @ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddr   )r5   rE   rQ   clarification_fieldr   r   READY_CUSTOMER_CLARIFICATIONz&submit_clarification:activity_category)
rx   r2   rL   strr-   rI   r~   r   r   r   )r}   r0   rY   r   s       r1   /test_matching_clarification_remains_field_boundr   x  s    vH5!E'(a|T	HZ (a00782	"G Hb#w'ZZ!F==::::==DDDDr3   c                    t               } | d   j                  t        j                  | d   d                t	        j
                  t        j                  d      5  t        j                  |        d d d        y # 1 sw Y   y xY w)Nrm   r   zduplicate publication)match)	rx   r|   r   r   r   r   r-   r   r   r   s    r1   2test_duplicate_publication_generation_fails_closedr     s]    vHXdmmHX,>q,ABC	q''/F	G	

8 
H	G	Gs   A<<Bc                    t               } d| d   d<   t        | dddddd	       t        j                  |       }|j                  d
k(  sJ |j
                  dk(  sJ |j                  t        j                  dd      k(  sJ y )Nowner_reviewrk   r5         @eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee)r5   rQ   ownerry   READY_OWNER_ONBOARDING_APPROVE217owner_ok)rx   r~   r-   r   r   rX   r   r   r   s     r1   6test_owner_review_uses_only_matching_owner_publicationr     s    vH$2HZ!
 : ZZ!F==<<<<%%%==AJJz26666r3   c                    d}t        d      }||d<   dd|t        |d      g d	d
| d<   t        | d      }t        | dd|       |S )Nu   현재도 주 3회, 회당 60분 정도의 중간 강도 근력운동을 꾸준히 하고 있으며,
 앞으로도 같은 수준으로 유지할 계획입니다. 평소 하루 6,000~8,000보 정도 걷습
 니다.Fr   r   rN   r`   ra   rb   )rc   r   r   i.  rd   rk      r   )r2   rL   r   r~   )r}   r   r0   rY   s       r1   current_generation_28r     sf    	 
 5!E"+E
'(a@0HZ  :GHb#w'Lr3   c                    t               } t        |       }t        j                  |      dk(  sJ | d   d   d   dk(  sJ t        j	                  |      \  }}|du sJ |dj                  t        |d         j                               k(  sJ t        j                  |       }|j                  d	k(  sJ |j                  d
k(  sJ |j                  t        j                  dd      k(  sJ y )N@280dabc7a1705face34a68fb61f62f079e20f6fc3844afe82f9752db0f5cf669rl   rY   rQ   @f760b5ac4c2109067a2798ec3480898afe6f77722efa18635684a45e51406b65T r   r   r   r   r   )rx   r   r-   rI   shipped_baseline_validationjoinr   splitr   r   rX   r   r   )r}   r0   valid
normalizedr   s        r1   Jtest_current_transport_whitespace_rationale_is_domain_valid_and_attestabler    s     vH!(+E	5!M	N	N 		*=9M	N	N 55e<E:D==#e,@&A"B"H"H"JKKKKZZ!F==3333%%%==AJJx4444r3   )categoryr   ))r    )r     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)	arbitraryzvalid rationalec                t    t        d      }| |d<   ||d<   t        j                  |      \  }}|du sJ |J y )NFr   r   r   )r2   r-   r  )r  r   r0   r  r  s        r1   3test_shipped_baseline_gate_rejects_invalid_activityr    sQ     5!E!)E
"+E
55e<E:E>>r3   c                    t               } t        |        t        j                  |       }d|d   d   d<   d|d   d   d   d<   t        j                  |      j                  dk(  sJ t        j                  |       }d|d   d	<   d|d   d   d	<   t        j                  |      j                  dk(  sJ t        j                  |       }d
|d   d   d<   d
|d   d   d   d<   t        j                  |      j                  dk(  sJ y )Nr   rl   rY   rE   rm   r   r      rX   @ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffrQ   r   )rx   r   r   r   r-   r   r   )r}   stale_digeststale_messagebad_bodys       r1   @test_current_authority_rejects_stale_digest_message_and_bad_bodyr    s   vH(#==*L?GL	*+;<>FL2y)*:;::l#**.RRRRMM(+M14M- .03M(B-::m$++/SSSS}}X&H8@H]I&}57?HXr9%m4::h&&*FFFFr3   c                r   | dz  }t         j                  |ddi       t         j                  |ddi       |j                         j                         D cg c]!  }t         j                  j                  |      # }}|j                         j                  dz  dk(  sJ |d   d   |d	   d
   k(  sJ y c c}w )Nzevents.jsonlr   ABi  i  ra   previous_event_sha256r   event_sha256)r-   append_event	read_text
splitlinesr   r   statst_mode)tmp_pathtargetlinerowss       r1   .test_append_ledger_is_private_and_hash_chainedr#    s    &FNN6Hc?+NN6Hc?++1+;+;+=+H+H+JK+J4AFFLL+JDK;;=  5(E1117*+tAw~/FFFF Ls   &B4)r   boolr	   r$  returndict[str, object])
r0   r&  rG   intr5   r   r6   r$  r%  r&  )r%  dict[str, Any])r}   r(  rW   r'  rX   r'  rY   r&  ri   r   r%  None)r}   r(  rG   r'  r%  r&  )r}   r(  r%  r)  )r%  r)  )r   r   r%  r)  )r}   r(  r%  r&  )r  r   r   r   r%  r)  )r  r   r%  r)  )5
__future__r   r   importlib.util	importlibr   r   r   pathlibr   typingr   r   __file__parentHEREutilspec_from_file_locationSPECloadermodule_from_specr-   modulesnameexec_moduler2   rL   rx   r~   r   r   r   r   r   r   r   r   r   r   r   markparametrizer   r   r   r   r   r   r   r  r  r  r#  r   r3   r1   <module>r<     s7   "     
   H~~~--4";;  NN##D)DII      #T B #$$ $ 	$
 $ $N&^ MMM M 	M M 
M(

03

M&MY>55%9&  F$!5!5HB0E*7 (55, Q!		G"Gr3   