+
    j}  c                       ^ RI t^ RIHu Ht ^ RIt^ RIt^ RIt^ RI	t
^ RIt
^ RIHt ^ RIHt ^ RIHt  ! R R]P$                  4      t ! R R]P$                  4      t]R8X  d   ]P,                  ! 4        R# R# )	    N)
HTTPServer)patchc                   h   a  ] tR t^t o R tR tR tR tR tR t	R t
R tR	 tR
 tR tR tRtV tR# )AttentionStateTestsc                    R \         n        \         P                  ;_uu_ 4        \         P                  P	                  4        ^ \         n        RRR4       \         P                  ! 4        R#   + '       g   i     L'; i) N)server
NTFY_TOPIC_attention_lock_attention_recordsclear_attention_seq_invalidate_usage_cacheselfs   &K/Users/jameslopez/projects/CodexBar-ESP32/tests/test_companion_attention.pysetUpAttentionStateTests.setUp   sL    ###%%++-$%F! $ 	&&( $#s   *A--A=	c                d    R RRRRRRR/pVP                  V4       \        P                  ! V4      # )providerCodexeventPermissionRequest
session_idztest-sessioncwd)/Users/jameslopez/projects/CodexBar-ESP32)updater   ingest_attention_event)r   	overridespayloads   &, r   
post_eventAttentionStateTests.post_event   s>    (.>	
 	y!,,W55    c                V    \         P                  ! 4       R ,          ^,          R,          # )	providers	attention)r   get_status_payloadr   s   &r   codex_attention#AttentionStateTests.codex_attention   s     ((*;7:;GGr"   c                   V P                  R R7      w  rV P                  V4       V P                  VRR/4       V P                  4       pV P                  VR,          R4       V P                  VR,          ^4       V P                  VR,          R4       V P                  VR	,          R.4       V P                  VR
,          R4       R# )codexr   okTstate
needs_usercountprimary_projectCodexBar-ESP32projectsreasonpermission_requestNr    
assertTrueassertEqualr'   )r   r,   responser%   s   &   r   9test_permission_request_sets_needs_user_with_project_nameMAttentionStateTests.test_permission_request_sets_needs_user_with_project_name!   s    8D$<0((*	7+\:7+Q/#457GH:.1A0BC8,.BCr"   c                    V P                  4        V P                  R R7      w  rV P                  V4       V P                  VRR/4       V P                  V P                  4       R,          R4       R# )
SessionEndr   r,   Tr-   idleNr5   r   r,   r8   s   &  r   (test_session_end_clears_attention_record<AttentionStateTests.test_session_end_clears_attention_record-   s\    \:D$<0--/8&Ar"   c                    V P                  R R7      w  rV P                  V4       V P                  4       pV P                  VR,          R4       V P                  VR,          R4       R# )Stopr=   r-   doner3   stopNr    r6   r'   r7   r   r,   _r%   s   &   r   test_stop_defaults_to_done.AttentionStateTests.test_stop_defaults_to_done5   sX    f-((*	7+V48,f5r"   c                    V P                  R RR7      w  rV P                  V4       V P                  4       pV P                  VR,          R4       V P                  VR,          R4       R# )rC   z<I can implement either approach. Which option do you prefer?r   last_assistant_messager-   r.   r3   possible_questionNrF   rG   s   &   r   3test_stop_with_question_is_classified_as_needs_userGAttentionStateTests.test_stop_with_question_is_classified_as_needs_user=   sd    #a   

 	((*	7+\:8,.ABr"   c                    V P                  R RR7      w  rV P                  V4       V P                  4       pV P                  VR,          R4       V P                  VR,          R4       R# )rC   zAPossible next steps:
1. Wire hooks globally
2. Test on the devicerL   r-   r.   r3   rN   NrF   rG   s   &   r   6test_stop_with_choice_list_is_classified_as_needs_userJAttentionStateTests.test_stop_with_choice_list_is_classified_as_needs_userH   sd    #h   

 	((*	7+\:8,.ABr"   c                4   V P                  R R7       \        P                  ;_uu_ 4        \        P                  P	                  4        F  p^ VR&   K
  	  RRR4       V P                  V P                  4       R,          R4       R#   + '       g   i     L9; i)rC   r=   
updated_atNr-   r>   )r    r   r
   r   valuesr7   r'   )r   recs   & r   &test_done_record_expires_after_timeout:AttentionStateTests.test_done_record_expires_after_timeoutS   sm    f%###00779$%L! : $ 	--/8&A	 $#s   +BB	c                   V P                  R RR7       V P                  RRR7       V P                  4       pV P                  VR,          R4       V P                  VR,          ^4       \        P                  ;_uu_ 4        V P                  \        \        P                  4      ^4       RRR4       R#   + '       g   i     R# ; i)	rC   zold-session)r   r   SessionStartznew-sessionr-   runningr/   N)r    r'   r7   r   r
   lenr   )r   r%   s   & r   7test_new_session_start_replaces_old_same_project_recordKAttentionStateTests.test_new_session_start_replaces_old_same_project_record\   s    f?nG((*	7+Y77+Q/###S!:!:;Q? $###s   *B55C	c                V   \        ^4       F  pV P                  RV 2RV 2R7       K  	  V P                  4       pV P                  VR,          R4       V P                  VR,          ^4       V P                  \	        VR,          4      ^4       V P                  VR,          R	4       R
# )   zsession-z#/Users/jameslopez/projects/project-)r   r   r-   r.   r/   r2   r0   z	project-3N)ranger    r'   r7   r]   )r   idxr%   s   &  r   Etest_multiple_waiting_projects_are_counted_and_project_list_is_cappedYAttentionStateTests.test_multiple_waiting_projects_are_counted_and_project_list_is_cappedf   s    8COO%cU+9#?    ((*	7+\:7+Q/Yz23Q7#45{Cr"   c                    V P                  R R7      w  rV P                  V4       V P                  VR,          R4       V P                  RVR,          4       R# )Geminir+   r,   Fr   errorN)r    assertFalser7   assertInr?   s   &  r   !test_unknown_provider_is_rejected5AttentionStateTests.test_unknown_provider_is_rejecteds   sI    9$/j(7"34r"    N)__name__
__module____qualname____firstlineno__r   r    r'   r9   r@   rI   rO   rR   rX   r^   rd   rk   __static_attributes____classdictcell____classdict__s   @r   r   r      sN     )6H
DB6	C	CB@D5 5r"   r   c                   H   a  ] tR t^{t o R tR tR	R ltR tR tR t	Rt
V tR# )
AttentionHttpTestsc                   R \         n        \         P                  ;_uu_ 4        \         P                  P	                  4        ^ \         n        RRR4       \         P                  ! 4        \        R\         P                  4      V n	        V P                  P                  ^,          V n        \        P                  ! V P                  P                  RR7      V n        V P                  P!                  4        R#   + '       g   i     L; i)r   NT)targetdaemon)z	127.0.0.1r   )r   r	   r
   r   r   r   r   r   Handlerhttpdserver_addressport	threadingThreadserve_foreverthreadstartr   s   &r   r   AttentionHttpTests.setUp|   s    ###%%++-$%F! $ 	&&( 0&..A
JJ--a0	&&djj.F.FtT $#s   *C99D		c                    V P                   P                  4        V P                   P                  4        V P                  P	                  ^R7       R# )   timeoutN)r|   shutdownserver_closer   joinr   s   &r   tearDownAttentionHttpTests.tearDown   s7    



!#r"   Nc                   R V P                    V 2pVf   RM#\        P                  ! V4      P                  4       pVe   RR/M/ p\        P
                  P                  WEWcR7      p\        P
                  P                  V^R7      ;_uu_ 4       pVP                  \        P                  ! VP                  4       4      3uuRRR4       #   + '       g   i     R# ; i)http://127.0.0.1:NContent-Typeapplication/jsondataheadersmethodr   )r~   jsondumpsencodeurllibrequestRequesturlopenstatusloadsread)	r   pathr   r   urlr   r   reqresps	   &&&&     r   request_jsonAttentionHttpTests.request_json   s    !$))TF3tDJJw,?,F,F,H:A:M>#56SUnn$$SW$T^^##C#33t;;

499; 77 4333s   0CC	c                j   V P                  R RRRRRRRR/R	R
7      w  rV P                  V^4       V P                  VRR/4       V P                  R4      w  rV P                  V^4       VR,          ^ ,          R,          pV P                  VR,          R4       V P                  VR,          R4       R# )
/attentionr   Clauder   r   r   zhttp-sessionr   r   POST)r   r,   T/statusr$   r%   r-   r.   r0   r1   N)r   r7   )r   r   bodyclaudes   &   r   #test_post_attention_then_get_status6AttentionHttpTests.test_post_attention_then_get_status   s    ((H,nB	  ) 	
 	%d|,((3%k"1%k2,7 124DEr"   c                   \         P                  P                  R V P                   R2RRR/RR7      pV P	                  \         P
                  P                  4      ;_uu_ 4       p\         P                  P                  V^R7       RRR4       V P                  XP                  P                  R	4       \        P                  ! VP                  P                  4       4      pVP                  P                  4        V P                  VR
,          4       V P!                  RVR,          4       R#   + '       g   i     L; i)r   r      {r   r   r   r   r   Ni  r,   zinvalid JSONrh   )r   r   r   r~   assertRaisesrh   	HTTPErrorr   r7   	exceptioncoder   r   r   closeri   rj   )r   r   ctxr   s   &   r   $test_post_attention_rejects_bad_json7AttentionHttpTests.test_post_attention_rejects_bad_json   s    nn$$		{*5#%78	 % 
 v||5566#NN""3"2 7 	++S1zz#--,,./d$nd7m4 76s   %"D00E 	c                p   \         P                  ! \        R \        R4      R7      ;_uu_ 4        V P	                  R4      w  rRRR4       V P                  X^4       V P                  XR,          4       V P                  VR,          ^ ,          R,          R,          R	4       R#   + '       g   i     Lj; i)
get_access_tokenzshould not fetch usage)side_effectr   Nr,   r$   r%   r-   r>   )r   objectr   AssertionErrorr   r7   r6   )r   r   r   s   &  r   =test_status_does_not_fetch_usage_credentials_or_provider_apisPAttentionHttpTests.test_status_does_not_fetch_usage_credentials_or_provider_apis   s    \\&"4.QiBjkk,,Y7LF l 	%T
#k*1-k:7CVL lks   B%%B5	)r|   r~   r   )NN)rn   ro   rp   rq   r   r   r   r   r   r   rr   rs   rt   s   @r   rw   rw   {   s+     	$
8F(5 M Mr"   rw   __main__)builtins@py_builtins_pytest.assertion.rewrite	assertionrewrite
@pytest_arr   r   unittesturllib.errorr   urllib.requesthttp.serverr   unittest.mockr   companion.serverr   TestCaser   rw   rn   mainrm   r"   r   <module>r      se           "  !l5(++ l5^CM** CML zMMO r"   