+
    u,Qj  c                       R t ^ 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 R4      tR tR tR tR tR tR	 tR
 tR tR tR tR tR# )u   Device-tool WS bridge: action frame out, action_result in, timeout, and the
resolve/dispatch routing. No network, no real phone — a FakeWS captures frames
and we feed results back by hand.Nc                   2   a  ] tR t^t o R tR tR tRtV tR# )FakeWSc                "    . V n         . V n        R # N)sentbinary)selfs   &N/Users/ahmed/devFolder/Ultron/claude-voice/gateway/tests/test_device_bridge.py__init__FakeWS.__init__   s    	    c                D   "   V P                   P                  V4       R # 5ir   )r   append)r   frames   &&r   	send_jsonFakeWS.send_json   s     		    c                D   "   V P                   P                  V4       R # 5ir   )r   r   )r   datas   &&r   
send_bytesFakeWS.send_bytes   s     4 r   )r   r   N)	__name__
__module____qualname____firstlineno__r	   r   r   __static_attributes____classdictcell__)__classdict__s   @r   r   r      s      ! !r   r   c                  @    \         P                  ! \        4       R 7      # ))ws)mainSessionr    r   r   _sessionr"      s    <<68$$r   c            	      2   \         P                   EF  p V R ,          pRq!V8H  q3'       gy   \        P                  ! RV3RW34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;r2V R,          p. qvR,          q3q'       d   VR,          qpV'       g   R	R
\        P                  ! V4      /,          qP                  V	4       V'       d0   RR\        P                  ! X4      /,          qWP                  V4       \        P                  ! V^ 4      / ,          p
RRV
/,          p\        \        P                  ! V4      4      hR;p;p;r8\        P                  ! V 4       EK  	  \         P                  p0 RmqV8H  q"'       g   \        P                  ! RV3RW|34      RR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P                  ! \         4      MRR\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p
\        \        P                  ! V
4      4      hR;p;r,R# )typefunctionpy1py4assert %(py6)spy6Nnamedescription%(py3)spy3z%(py6)sassert %(py9)spy9py0device_toolspy2py5assert %(py7)spy7==z%(py1)s == %(py4)s>	   navigateopen_appopen_url	set_timer
play_musicopen_cameracall_contactget_locationtake_screenshot)z9%(py2)s
{%(py2)s = %(py0)s.DEVICE_TOOL_NAMES
} == %(py5)s)r1   DEVICE_TOOL_SPECS
@pytest_ar_call_reprcompare	_safereprAssertionError_format_explanationr   _format_boolopjsondumpsDEVICE_TOOL_NAMES@py_builtinslocals_should_repr_global_name)spec@py_assert0@py_assert3@py_assert2@py_format5@py_format7fn@py_assert1@py_assert5@py_format4@py_format8@py_format10@py_assert4@py_format6s                 r   &test_device_tool_specs_valid_and_namedr]      s   ..F|)z)z)))))|)))|)))z))))))))*/&z/zb/////z////z//////////////////

4	 /
 )) L .L L .L L L L:K:KL) L LEKVL L3K3KL< L LBK)L< L LBK)L) L LBK)L .L L L L L L8K8KL L Lr   c            	      0  "   \        4       p \        P                  ! V P                  R / 4      4      p\        P                  ! ^ 4      G Rj  xL
  V P
                  P                  R,          p. q2R,          pRqTV8H  qfqv'       d   VR,          pR qV	8H  qpV'       Eg$   \        P                  ! RV3R WE34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          qP                  V4       V'       dk   \        P                  ! RX
3R!XX	34      R\        P                  ! V4      R	\        P                  ! V	4      /,          pR
RV/,          qP                  V4       \        P                  ! V^ 4      / ,          pRRV/,          p\        \        P                  ! V4      4      hR;p;p;p;p;p;p;rVR,          pV P                  RVRRRRR//4       VG Rj  xL
 p. pVR,          qDqt'       d   VR,          R,          pRpVV8H  pTpV'       g   RR\        P                  ! V4      /,          pVP                  V4       V'       dl   \        P                  ! RX3R"VX34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          pVP                  V4       \        P                  ! V^ 4      / ,          pRR	V/,          p\        \        P                  ! V4      4      hR;p;p;p;p;ppV P                  p/ qcV8H  pV'       g   \        P                  ! RV3R#W634      RR\         P"                  ! 4       9   g   \        P$                  ! V 4      '       d   \        P                  ! V 4      MRR\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;ppR#  EL EL5i)$rA   Nr$   actionr-   r)   z%(py8)spy8py11py14z%(py16)spy16zassert %(py19)spy19idokTr   messagesnapr,   r/   z%(py11)szassert %(py14)sr0   sessr2   r3   r4   r5   r6   )z%(py3)s == %(py6)s)z%(py11)s == %(py14)s)z%(py6)s == %(py9)sz0%(py2)s
{%(py2)s = %(py0)s._pending
} == %(py5)s)r"   asynciocreate_task_device_callsleepr   r   rC   rD   rE   r   rH   rF   rG   _resolve_action_pendingrL   rM   rN   )ri   taskr   rV   rR   rW   r[   rP   @py_assert10@py_assert13@py_assert12rT   @py_format9@py_format15@py_format17@py_format18@py_format20aidres@py_assert8@py_assert7rX   rZ   @py_format12@py_format13rQ   r\   rY   s                               r   ,test_device_call_resolves_on_matching_resultr   '   sN    :Dt001BBGHD
--
GGLLEM=MHMH$MMxM<MM<M)MMMMM=MMM=MMMHMMMMMMMMM<MMMMMMM<MMMMMMMMMMMMMMMMM
+C$T4)V9LMN*C93t999VY/969/699999999999999/6999/99969999999999999999==BB=44=B 
 s@   A
PPAPEP8P97P17P)D)PA>PPc            	        "   \        4       p V P                  R / RR7      G Rj  xL
 pRRRR/q!V8H  q3'       g   \        P                  ! RV3RW34      RR	\        P
                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR	R
\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;r2V P                  p/ qcV8H  qw'       g   \        P                  ! RV3RW634      RR\        P
                  ! 4       9   g   \        P                  ! V 4      '       d   \        P                  ! V 4      MRR\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;rvR#  EL5i)r@   g{Gz?)timeoutNrf   Ferrorr   r0   r|   r-   assert %(py5)sr3   ri   r2   r4   r5   r6   z%(py0)s == %(py3)srk   )r"   rn   rC   rD   rL   rM   rN   rE   rF   rG   rq   )	ri   r|   rR   rV   rX   r\   r[   rQ   rY   s	            r   )test_device_call_times_out_without_clientr   4   s    :D!!."d!C
CC333333333333333333333333333333333==BB=44=B Ds   "GGA%GCGA=Gc                   "   \        4       pR  pV P                  \        P                  RV4       \        P
                  ! VP                  RRR/4      4      p\        P                  ! ^ 4      G Rj  xL
  VP                  P                  R,          pVR,          pRqeV8H  qw'       gy   \        P                  ! RV3RWV34      R\        P                  ! V4      R\        P                  ! V4      /,          pR	R
V/,          p	\        \        P                  ! V	4      4      hR;p;rvVR,          R,          pRqeV8H  qw'       gy   \        P                  ! RV3RWV34      R\        P                  ! V4      R\        P                  ! V4      /,          pR	R
V/,          p	\        \        P                  ! V	4      4      hR;p;rvVR,          R,          pRqeV8H  qw'       gy   \        P                  ! RV3RWV34      R\        P                  ! V4      R\        P                  ! V4      /,          pR	R
V/,          p	\        \        P                  ! V	4      4      hR;p;rvVP                  RVR,          RRR/ /4       VG Rj  xL
 p
RqZP                   q! 4       qV9   qw'       g   \        P                  ! RV3RW\34      R\        P                  ! V4      RR\"        P$                  ! 4       9   g   \        P&                  ! V
4      '       d   \        P                  ! V
4      MRR\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;p;rR#  EL EL5i)c           	      h  "   \         P                  q V8H  q3'       Eg   \        P                  ! RV3RW34      RR\        P
                  ! 4       9   g   \        P                  ! V 4      '       d   \        P                  ! V 4      MRRR\        P
                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P                  ! \         4      MRR\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;r2R	R
RRRRRR/# 5i)r7   r0   kindr2   phone_storer'   r(   r)   NlabelofficeaddressTower 1latL:@lng皙I@r6   )z2%(py0)s == %(py4)s
{%(py4)s = %(py2)s.KIND_PLACE
})
r   
KIND_PLACErC   rD   rL   rM   rN   rE   rF   rG   )r   keyrQ   rV   rS   rT   s   &&    r   fake_get4test_navigate_resolves_saved_place.<locals>.fake_get>   s     "---------t------t----t-------{----{------------9ieTRRs   A-D20AD2A0D2get_itemr9   destinationr   Nr_   r&   r'   r(   r)   paramsr   r   r   r   re   rf   Tr   r-   outr3   r5   r.   r/   rj   r6   r8   inzD%(py1)s in %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py3)s.lower
}()
})r"   setattrr   r   rl   rm   _dispatch_devicero   r   r   rC   rD   rE   rF   rG   rp   lowerrL   rM   rN   )monkeypatchri   r   rr   r   rP   rQ   rR   rS   rT   r   r[   @py_assert6rY   rZ   s   &              r   "test_navigate_resolves_saved_placer   ;   s)    :DS ((*h?t44Z6CX5N P QD
--
GGLLE?(j(j(((((?(((?(((j((((((((?9%2222222%222%22222222222?5!)T)T)))))!)))!)))T))))))))$dT4DE*C"yy"y{"{"""""8"""8""""""s""""s"""y"""{""""""""  s-   A0N2N3HN>N	?BNA?N	Nc                 N  a"   \        4       pR oV3R lpV P                  \        P                  RV4       \        P
                  ! VP                  RRR/4      4      p\        P                  ! ^ 4      G Rj  xL
  VP                  P                  R,          pVR,          pRqeV8H  qw'       gy   \        P                  ! RV3RWV34      R	\        P                  ! V4      R
\        P                  ! V4      /,          pRRV/,          p	\        \        P                  ! V	4      4      hR;p;rvVR,          R,          qUS8H  qw'       g   \        P                  ! RV3R VS34      R	\        P                  ! V4      RR\        P                   ! 4       9   g   \        P"                  ! S4      '       d   \        P                  ! S4      MR/,          p
RRV
/,          p\        \        P                  ! V4      4      hR;rWVP%                  RVR,          RRR/ /4       VG Rj  xL
 pRq\P&                  q! 4       qV9   qw'       g   \        P                  ! R!V3R"W^34      R	\        P                  ! V4      RR\        P                   ! 4       9   g   \        P"                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;p;rSV9  pV'       g   \        P                  ! R#V3R$SV34      RR\        P                   ! 4       9   g   \        P"                  ! S4      '       d   \        P                  ! S4      MRRR\        P                   ! 4       9   g   \        P"                  ! V4      '       d   \        P                  ! V4      MR/,          pRR
V/,          p\        \        P                  ! V4      4      hRpR#  EL EL5i)%
0501234567c           	      b  <"   \         P                  q V8H  q3'       Eg   \        P                  ! RV3RW34      RR\        P
                  ! 4       9   g   \        P                  ! V 4      '       d   \        P                  ! V 4      MRRR\        P
                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P                  ! \         4      MRR\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;r2R	R
RS/# 5i)r7   r0   r   r2   r   r'   r(   r)   Nr*   fathernumberr6   )z4%(py0)s == %(py4)s
{%(py4)s = %(py2)s.KIND_CONTACT
})
r   KIND_CONTACTrC   rD   rL   rM   rN   rE   rF   rG   )r   r   rQ   rV   rS   rT   r   s   &&    r   r   Etest_call_contact_dials_number_but_never_returns_it.<locals>.fake_getS   s     "/////////t//////t////t///////{////{////////////(F33s   A-D/1AD/A,D/r   r?   r*   r   Nr_   callr&   r'   r(   r)   r   r   r-   r   r3   re   rf   Tr   r   r5   r.   r/   r0   r2   zassert %(py4)srj   r6   r8   )z%(py1)s == %(py3)sr   r   )not in)z%(py0)s not in %(py2)s)r"   r   r   r   rl   rm   r   ro   r   r   rC   rD   rE   rF   rG   rL   rM   rN   rp   r   )r   ri   r   rr   r   rP   rQ   rR   rS   rT   rX   r\   r   r[   r   rY   rZ   rV   @py_format3r   s   &                  @r   3test_call_contact_dials_number_but_never_returns_itr   O   sb    :DF4 ((*h?t44^6<h5G I JD
--
GGLLE?$f$f$$$$$?$$$?$$$f$$$$$$$$?8$......$...$..................$dT4DE*C"yy"y{"{"""""8"""8""""""s""""s"""y"""{""""""""666 
 sB   A5P%8P9D6P%0A/P%P" BP%)CP%AP%AP%"P%c                 @  "   \        4       pR  pV P                  \        P                  RV4       VP	                  RRR/4      G Rj  xL
 pRqCP
                  qU! 4       qdV9   qw'       g   \        P                  ! RV3RWF34      R\        P                  ! V4      RR	\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR	R
\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p	\        \        P                  ! V	4      4      hR;p;p;rVVP                  qP                  q'       * q'       g   RRR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V
4      R\        P                  ! V4      /,          p\        \        P                  ! V4      4      hR;p
;rR#  EL5i)c                    "   R # 5ir   r!   )r   r   s   &&r   r   Btest_call_contact_unknown_returns_error_no_frame.<locals>.fake_getg   s        r   r?   r*   ghostNz	no numberr&   r-   r   r3   r5   r.   r/   zDassert not %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.ws
}.sent
}r0   ri   r2   r'   r   r   )r"   r   r   r   r   r   rC   rD   rE   rL   rM   rN   rF   rG   r   r   )r   ri   r   r   rP   r[   r   rR   rY   rZ   rV   rQ   rW   r\   s   &             r   0test_call_contact_unknown_returns_error_no_framer   d   s2    :D((*h?%%nvw6GH
HC%))%)+%+%%%%%;%%%;%%%%%%#%%%%#%%%)%%%+%%%%%%%%ww||ttw| Is!   AHH	BHCH*A2Hc                   "   \        4       pR  pV P                  VRV4       \        P                  ! VP	                  R/ 4      4      p\        P
                  ! ^ 4      G Rj  xL
  VP                  P                  R,          pVP                  RVR,          RRRRR	R
R//4       VG Rj  xL
 pRqfV9   qw'       g   \        P                  ! RV3RWe34      R\        P                  ! V4      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR/,          pRRV/,          p	\        \        P                   ! V	4      4      hR;rgR#  EL L5i)c                    "   R # 5i)homer!   )r   r   s   &&r   
fake_match8test_get_location_labels_known_place.<locals>.fake_matchr   s     r   _match_placer@   Nre   rf   Tr   r   r   r   r   r   r&   r-   r   r   r3   rj   r   )z%(py1)s in %(py3)s)r"   r   rl   rm   r   ro   r   r   rp   rC   rD   rE   rL   rM   rN   rF   rG   )
r   ri   r   rr   r   r   rP   rR   rX   r\   s
   &         r   $test_get_location_labels_known_placer   o   s     :Dnj9t44^RHID
--
GGLLE$dT4 5$t"<> ?*CS=66SS  s-   A E7"E2#AE7+E5,A7E7$AE75E7c                   a"   \        4       p/ oV3R  lpV P                  \        P                  RV4       V3R lpV P                  VRV4       VP	                  R/ 4      G Rj  xL
 pRqTV8H  qf'       gy   \
        P                  ! RV3RWE34      R\
        P                  ! V4      R\
        P                  ! V4      /,          pR	R
V/,          p\        \
        P                  ! V4      4      hR;p;reVP	                  R/ 4      G Rj  xL
 pRqTV8H  qf'       gy   \
        P                  ! RV3RWE34      R\
        P                  ! V4      R\
        P                  ! V4      /,          pR	R
V/,          p\        \
        P                  ! V4      4      hR;p;reRRRR/pSV8H  q'       g   \
        P                  ! RV	3RSV34      RR\        P                  ! 4       9   g   \
        P                  ! S4      '       d   \
        P                  ! S4      MRR\
        P                  ! V4      /,          p
RRV
/,          p\        \
        P                  ! V4      4      hR;rR#  EL ELZ5i)c                    <"   V SR &   R# 5i)server	server-okr!   r*   argsseens   &&r   	fake_exec=test_dispatch_tool_routes_device_vs_server.<locals>.fake_exec        X   executec                    <"   V SR &   R# 5i)device	device-okr!   r   s   &&r   fake_device?test_dispatch_tool_routes_device_vs_server.<locals>.fake_device   r   r   r   memory_searchNr   r&   r'   r(   r)   r9   r   r   r   r0   r   r-   r   r3   r6   r8   r   )r"   r   r   tools_dispatch_toolrC   rD   rE   rF   rG   rL   rM   rN   )r   ri   r   r   rP   rQ   rR   rS   rT   rV   rX   r\   r   s   &           @r   *test_dispatch_tool_routes_device_vs_serverr      s{    :DD 

Iy9 0+>$$_b99H[H[HHHHH9HHH9HHH[HHHHHHHH$$Z44CCCCCCC4CCC4CCCCCCCCCCCoxDD4DDDDDD4DDDDDDD4DDDD4DDDDDDDDDDDD :4s-   A"I&%I &B#I&	I#
C1I&<A%I&#I&c                    "   R p \         P                  qP                  pRRRR/pRqB! W44      qPV9   qf'       Eg'   \        P                  ! RV3RW34      R\        P
                  ! V 4      RR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P
                  ! \         4      MRR	\        P
                  ! V4      R
\        P
                  ! V4      R\        P
                  ! V4      R\        P
                  ! V4      R\        P
                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p ;p;p;p;p;rERp \         P                  qP                  pRR/pRqB! W44      qPV9   qf'       Eg'   \        P                  ! RV3RW34      R\        P
                  ! V 4      RR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P
                  ! \         4      MRR	\        P
                  ! V4      R
\        P
                  ! V4      R\        P
                  ! V4      R\        P
                  ! V4      R\        P
                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p ;p;p;p;p;rE\         P                  qP                  p
RRRRR//pRq! W4      pRq]V8H  q'       Eg(   \        P                  ! RV3R VV34      RR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P
                  ! \         4      MRR\        P
                  ! V	4      R\        P
                  ! V
4      R\        P
                  ! V4      R\        P
                  ! V4      R\        P
                  ! V4      R\        P
                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p	;p
;p;p;p;rR# 5i)!zdidn't respondrf   Fr   r   xr&   r-   r   r3   r5   r/   ra   py13zassert %(py15)spy15NDoneTzDone.r   rg   customr0   r2   r'   r)   r`   py10r   )z|%(py1)s in %(py13)s
{%(py13)s = %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py3)s.Session
}._device_reply
}(%(py9)s, %(py11)s)
}r6   )z|%(py10)s
{%(py10)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.Session
}._device_reply
}(%(py6)s, %(py8)s)
} == %(py13)s)r   r    _device_replyrC   rD   rE   rL   rM   rN   rF   rG   )rP   r[   r   r}   rs   ru   rR   @py_format14@py_format16rV   rQ   rW   r~   @py_assert9@py_assert11s                  r   +test_device_reply_timeout_and_error_wordingr      s     0t|| 099 0	ugy)0+.09) 0 0  0 0 0 0//0 0 0&/i0 0 0)/0 0//0t 0 0&/i0t 0 0&/i0| 0 0&/i09 0 0&/i0)0 0&/i0+.0 0&/i0  0 0 0 0 0 0//0 0 0FT\\F//FtFgF/FFFFFFFF6FFF6FFFFFFTFFFFTFFF\FFF/FFFFFFgFFFFFFFFFFFFF<< F%% F	tVi23F58F%3: F=EF=EF F F4E4EF :=EF F?EvF F-E-EF4 F F<EIF4 F F<EIF< F F<EIF% F F<EIF3F F<EIF58F F<EIF : F F<EIF=EF F F F F2E2EF F F Fs   B#Q&E(QEQ'C Qc                  ~  "   \        4       p \        P                  ! 4       pVP                  4       pW P                  R &   V P                  R4       VP                  q3! 4       pRRRR/qTV8H  qf'       g   \        P                  ! RV3RWE34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      R	\        P                  ! V4      /,          pR
RV/,          p\        \        P                  ! V4      4      hR;p;p;reV P                  p/ qV	8H  qD'       g   \        P                  ! RV3RW934      RR\        P                  ! 4       9   g   \        P                  ! V 4      '       d   \        P                  ! V 4      MRR\        P                  ! V4      R\        P                  ! V	4      /,          p
RR	V
/,          p\        \        P                  ! V4      4      hR;p;rIR# 5i)abczconnection closedrf   Fr   r0   futr2   r'   r5   r.   r/   Nri   r3   r4   r6   )zE%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.result
}()
} == %(py7)srk   )r"   rl   get_running_loopcreate_futurerq   _fail_pendingresultrC   rD   rL   rM   rN   rE   rF   rG   )ri   loopr   rV   rQ   r   rW   rY   rZ   r[   r\   s              r   #test_fail_pending_resolves_on_closer      sE    :D##%D



CMM%*+::F:<FD%2EFFFFFFFF<FFFFFF3FFFF3FFF:FFF<FFFFFFFFFFFF==BB=44=Bs   CH=C;H=A<H=)__doc__builtinsrL   _pytest.assertion.rewrite	assertionrewriterC   rl   rI   r1   r   r   r   r"   r]   r   r   r   r   r   r   r   r   r   r!   r   r   <module>r      sc   %      	! 	!%L
#(* E&Fr   