
    jKj[                         d Z ddlmZmZ ddlmZmZmZmZmZ d Z	d Z
d Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)a,  Unit tests for the layered truncation pipeline (_truncation.py).

This module bounds untrusted/large tool payloads before capture, so its branches
(string caps, depth/breadth limits, cycle detection, the 100KB size budget) are
worth exercising directly rather than only through the end-to-end paths.
    )datetimetimezone)MAX_EVENT_BYTESMAX_STRING_LENGTH_json_byte_size	normalizetruncate_eventc                  ~    t        dt        dz   z        } | j                  d      rt        |       t        dz   k(  sJ y )Nxd   ...   )r   r   endswithlenouts    q/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/posthog/test/mcp/test_truncation.py test_normalize_caps_long_stringsr      s=    
C,s23
4C<<3s8/@1/D#DDD#D    c                  `    t        d      du sJ t        d      du sJ t        d      dk(  sJ y )NTF   r    r   r   +test_normalize_keeps_bool_distinct_from_intr      s9    T?d"""Uu$$$Q<1r   c                      t        t        d            dk(  sJ t        t        d            dk(  sJ t        t        d            dk(  sJ y )Nnanz[NaN]infz
[Infinity]z-infz[-Infinity])r   floatr   r   r   'test_normalize_handles_nan_and_infinityr   !   sG    U5\"g---U5\"l222U6]#}444r   c            	          t        ddddddt        j                        } t        |       | j	                         k(  sJ y )Ni        r         )tzinfo)r   r   utcr   	isoformat)dts    r   $test_normalize_datetime_to_isoformatr)   '   s4    	$1aAhll	;BR=BLLN***r   c                  *    d } t        |       dk(  sJ y )Nc                       y )Nr   r   r   r   my_toolz<test_normalize_callable_becomes_placeholder.<locals>.my_tool-   s    r   z[Function: my_tool]r   )r,   s    r   +test_normalize_callable_becomes_placeholderr-   ,   s     W!6666r   c                      i } | }t        d      D ]  }i |d<   |d   } dd l}d|j                  t        |             v sJ y )N   r   r   z[Object])rangejsondumpsr   )nestedcur_r1   s       r   test_normalize_bounds_depthr6   3   sM    F
C2YC#h  If$56666r   c                      t        t        d      D  ci c]  } d|  | 
 c}       }|d   dk(  sJ t        |      dk(  sJ y c c} w )N   kr   [MaxProperties ~]e   )r   r0   r   )ir   s     r   "test_normalize_bounds_dict_breadthr=   >   sQ    
s4AqWaZ4
5Cu:,,,,s8s?? 5s   Ac                  r    t        t        t        d                  } | d   dk(  sJ t        |       dk(  sJ y )Nr8   r:   r;   )r   listr0   r   r   s    r   #test_normalize_bounds_array_breadthrA   D   s8    
Ds$
%Cr7))))s8s??r   c                  8    i } | | d<   t        |       d   dk(  sJ y )Nself[Circular ~]r   )ds    r   !test_normalize_detects_dict_cyclerF   J   s'    AAfIQ<>111r   c                  P    g } | j                  |        t        |       d   dk(  sJ y )Nr   rD   )appendr   )as    r   !test_normalize_detects_list_cyclerJ   P   s(    AHHQKQ<?n,,,r   c                  B     G d d      } t         |              dk(  sJ y )Nc                       e Zd Zd Zy)=test_normalize_coerces_unknown_objects_to_str.<locals>.Widgetc                      y)Nwidget-instancer   )rC   s    r   __str__zEtest_normalize_coerces_unknown_objects_to_str.<locals>.Widget.__str__X   s    $r   N)__name__
__module____qualname__rP   r   r   r   WidgetrM   W   s    	%r   rT   rO   r   )rT   s    r   -test_normalize_coerces_unknown_objects_to_strrU   V   s$    % % VX"3333r   c                  r    t        ddz  dd      } t        | d         dk(  sJ t        | d         dk(  sJ y )	Nr<       rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr)user_intentresource_namerY     rZ   i  r	   r   r   s    r   (test_truncate_event_caps_metadata_fieldsr]   a   sE    
tiP
QCs=!"h...s?#$///r   c                      t        d      D  cg c]  } d| i }} t        ddddz  d|idgii      }|d   d   d	   }t        |d
         dk(  sJ t        |d   d         dk(  sJ y c c} w )Nx   frameerrorz$exception_listerW   frames)value
stacktracer   rd   r[   re   2   )r0   r	   r   )r<   rc   r   excs       r   3test_truncate_event_caps_exception_value_and_framesrh   g   s    $)#J/JqwlJF/
!!Dj68JK$	
C g,(
)!
,Cs7|(((s< *+r111 0s   A(c                  h    t        dddddz  dgii      } t        | d   d   d   d         dk(  sJ y )	Nresponsecontenttextti@  )typerl   r   i  r\   r   s    r   ,test_truncate_event_caps_response_text_blockro   w   sM    
	i63;"G!HIJC s:y)!,V45CCCr   c                      dt        d      D  ci c]  } d|  ddz   c} d}t        |      t        kD  sJ t        |      }t        |      t        k  sJ y c c} w )N$mcp_tool_call<   field_zrW   )
event_type
parameters)r0   r   r   r	   )r<   eventr   s      r   :test_truncate_event_enforces_byte_budget_with_many_stringsrx      sk     '9>rCAs|S4Z/CE 5!O333

C3?222	 Ds   Ac                  P    t        ddddz  ii      } t        |       t        k  sJ y )Nrv   blobrt   i )r	   r   r   r   s    r   8test_truncate_event_caps_single_huge_string_under_budgetr{      s-    
,w(?@
AC3?222r   c                  0    dddd} t        |       | k(  sJ y )Nrq   echoF)ru   rZ   is_error)r	   )rw   s    r   1test_truncate_event_leaves_small_events_untouchedr      s"    +fRWXE% E)))r   N)__doc__r   r   posthog.mcp._truncationr   r   r   r   r	   r   r   r   r)   r-   r6   r=   rA   rF   rJ   rU   r]   rh   ro   rx   r{   r   r   r   r   <module>r      sp    ( E
5+
772-402 D	33
*r   