o
    pj	                     @  s   d Z ddlmZ ddlZddlZddlmZ ee j	d Z
ejdee
 ejdZedur;eeds;ejd= ddlmZmZ d	d
 ZG dd dejZedkr\ejdd dS dS )z6Agent Profile v1 validation and tool filtering checks.    )annotationsN)Path   platform__path__)AgentProfileContractfilter_profile_toolsc                  K  s*   ddddddd}| |  tdi |S )Ntest_assistantzTest Assistantz1.0.0zProfile contract test.)records.read)	agent_keynameversioninstructions_versiondescriptionallowed_capabilities )updater   )	overridesvaluesr   r   &tests/platform/agent_profile_checks.pyprofile   s   
r   c                   @  s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
AgentProfileChecksc                 C  sH   dddidddddiddg}t t |}| dgdd |D  d S )	Nr
   categoryreadnever
capabilityriskconfirmationinvoices.extractc                 S  s   g | ]}|d  qS )r   r   ).0toolr   r   r   
<listcomp>&   s    zRAgentProfileChecks.test_single_app_profile_filters_other_tools.<locals>.<listcomp>)r   r   assertEqual)selftoolsfilteredr   r   r   +test_single_app_profile_filters_other_tools    s
   z>AgentProfileChecks.test_single_app_profile_filters_other_toolsc                 C  sD   t dd}dddidddddiddg}| d	tt|| d S )
N)r
   r   zfuture.tool)r   r
   r   r   r   r   r   r   )r   r#   lenr   )r$   contractr%   r   r   r   9test_multi_app_profile_keeps_available_allowed_tools_only(   s
   
zLAgentProfileChecks.test_multi_app_profile_keeps_available_allowed_tools_onlyc                 C  s>   t ddid}dddidd}| dt||gd d	  d S )
Nwrite_reversiblealways)confirmation_policyr
   r   policyr   r   r   )r   r#   r   )r$   r)   r!   r   r   r   0test_profile_can_only_make_confirmation_stricter0   s
    zCAgentProfileChecks.test_profile_can_only_make_confirmation_stricterc                 C  sD   t ddd }| tdd |D  | tdd |D  d S )N)zBad Capabilityr   )r   	max_stepsc                 s      | ]}d |v V  qdS )r   Nr   r    errorr   r   r   	<genexpr>:       z_AgentProfileChecks.test_invalid_profile_limits_and_capabilities_are_rejected.<locals>.<genexpr>c                 s  r1   )r0   Nr   r2   r   r   r   r4   ;   r5   )r   validate
assertTrueany)r$   errorsr   r   r   9test_invalid_profile_limits_and_capabilities_are_rejected8   s   zLAgentProfileChecks.test_invalid_profile_limits_and_capabilities_are_rejectedN)__name__
__module____qualname__r'   r*   r/   r:   r   r   r   r   r      s
    r   __main__)	verbosity)__doc__
__future__r   sysunittestpathlibr   __file__resolveparentsPROJECT_ROOTpathinsertstrmodulesgetloaded_platformhasattrbridge_platform.agents.profilesr   r   r   TestCaser   r;   mainr   r   r   r   <module>   s     