+
    5mj  c                     ^ RI Ht ^ RIt^ RIHu Ht ^ RIt^ RI	t	^ RI
t
^ RIHt ^ RIt]
P                  P                  ^ ]! ]! ]4      P%                  4       P&                  ^,          4      4       ^ RIHt ^ RIHtHtHt RtR R ltR	]R
R/R R llt]P:                  R R l4       tR R ltR R lt R R lt!R R lt"R R lt#R R lt$R R lt%R R lt&R  R! lt'R# )"    )annotationsN)Path)AccountRegistry)PI_PROVIDER_KEY
PiAuthSyncPiAuthSyncErrorl    Wi c                    V ^8  d   QhRRRR/# )   payloaddictreturnstr )formats   "a/home/user/overdeck-private-tests/workstation-ai-broad/modules/systray/tests/test_pi_auth_sync.py__annotate__r      s     5 5$ 53 5    c                    \         P                  ! \        P                  ! V 4      P	                  R 4      4      P                  R4      pRVP                  R4       R2# )utf-8asciizheader.=z
.signature)base64urlsafe_b64encodejsondumpsencodedecoderstrip)r
   encodeds   & r   _jwtr      sK    &&tzz'':'A'A''JKRRSZ[GW^^C()44r   expinclude_account_id_fieldTc               0    V ^8  d   QhRRRRRRRRRR	R
R/# )r	   pathr   emailr   
account_idr    intr!   boolr   Noner   )r   s   "r   r   r      sL     F F
FF F
 
F #F 
Fr   c                   R RV//pR\        RV/VC4      R\        RV/VC4      RRV 2/pV'       d   W&R&   V P                  P                  R	R	R
7       V P                  \        P
                  ! RV/4      RR7       R# )zhttps://api.openai.com/authchatgpt_account_idid_tokenr$   access_tokenr    refresh_tokenzrt-r%   T)parentsexist_oktokensr   encodingN)r   parentmkdir
write_textr   r   )r#   r$   r%   r    r!   claimsr0   s   &&&$$  r   write_codex_authr7      s     ,.BJ-OPFD'53F34eS3F343zl+F
  )|KKdT2OODJJ&12WOEr   c                    V ^8  d   QhRRRR/# )r	   tmp_pathr   r   r   r   )r   s   "r   r   r   ,   s     	 	t 	 	r   c                    V R ,          pVP                  4        V R,          pVP                  4        \        V R,          VVR7      # )legacyzpi-agenttraybase_dirlegacy_codex_homepi_agent_dir)r4   r   )r9   r;   pi_agents   &  r   registryrB   +   sD     F
LLN*$HNNF"  r   c               (    V ^8  d   QhRRRRRRRR/# )r	   rB   r   slugr   aliasr   r   r   )r   s   "r   r   r   8   s(      ? # c d r   c                \    V P                  W4      p\        VR ,          V R2RV 24       V# )	auth.jsonz@example.comacct-)add_dirr7   )rB   rD   rE   
codex_homes   &&& r   _add_accountrK   8   s6    !!$.JZ+-$|/DdVnUr   c                    V ^8  d   QhRRRR/# r	   rB   r   r   r(   r   )r   s   "r   r   r   >   s     
 
o 
RV 
r   c                  a \        V R R4       \        V RR4       V P                  P                  pV P                  R,          pR. EF.  o\	        V3R lV P                  4        4       4      pV P                  V4       V P                  S,          R,          R,          pVP                  qU! 4       pV P                  pVS,          pRp	W,          p
RpW,          pVP                  q! 4       qV8H  q'       Eg   \        P                  ! R/V3R0Wn3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R\        P                  ! 4       9   g   \        P                  ! V 4      '       d   \        P                  ! V 4      MRR\        P                  ! V4      RR\        P                  ! 4       9   g   \        P                  ! S4      '       d   \        P                  ! S4      MR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;p	;p
;p;p;rVP"                  qU! 4       qf'       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;rVVP                  qU! 4       qdP                  qw! 4       pVV8H  q'       EgB   \        P                  ! R/V3R1VV3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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;pp\$        P&                  ! VP)                  RR7      4      \*        ,          pRR R!\$        P&                  ! V P                  S,          R,          R,          P)                  4       4      R",          R#,          R$R%S 2R&\,        R',          R(R)S 2/pVV8H  qU'       g   \        P                  ! R/V3R2VV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;ppEK1  	  R# )3rafaRafaroyRoyrG   c              3  L   <"   T F  qP                   S8X  g   K  Vx  K  	  R # 5i)NrD   ).0arD   s   & r   	<genexpr>Btest_set_default_switches_codex_and_pi_together.<locals>.<genexpr>E   s     D/QVVt^qq/s   $
$PI_HOME
CODEX_HOMEpy0
codex_linkpy2py4py6rB   py8py9rD   py12py15py18py20zassert %(py22)spy22NEassert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.is_symlink
}()
}pi_linkexpected_pipy10zassert %(py12)sr   r1   typeoauthaccessr0   r,   refreshzrt-acct-expiresi  	accountIdrH   
credentialpy3zassert %(py5)spy5)rO   rQ   rO   ==)z%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.resolve
}()
} == %(py20)s
{%(py20)s = %(py18)s
{%(py18)s = (((%(py8)s
{%(py8)s = %(py6)s.accounts_dir
} / %(py9)s) / %(py12)s) / %(py15)s).resolve
}()
})z|%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.resolve
}()
} == %(py10)s
{%(py10)s = %(py8)s
{%(py8)s = %(py6)s.resolve
}()
})z%(py0)s == %(py3)s)rK   _pi_auth_syncactive_auth_pathr?   nextlistset_defaultaccounts_dirresolve
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation
is_symlinkr   loads	read_textr   EXP_2100)rB   rh   r\   accountri   @py_assert1@py_assert3@py_assert7@py_assert10@py_assert11@py_assert13@py_assert14@py_assert16@py_assert17@py_assert19@py_assert5@py_format21@py_format23@py_format5@py_assert9@py_format11@py_format13rq   @py_assert2@py_format4@py_format6rD   s   &                         @r   /test_set_default_switches_codex_and_pi_togetherr   >   s   66*5%($$55G++k9J'D(--/DDW%++d2Y>L!! 	!# 	!!	!D(	+7	(7	:E	7E	E
'	 ( ( 	 (  	 		# 	 	V	 	 	z 	 	
)	z 	 	
)	! 	 	
)	# 	 	V	 	 		 	
)		 	
)	!	 	V	 	 	$(	 	
)	$(	 	
)	+7	 	
)	:E	 	
)	 ( 	 	
)	 ( 	 	 	 	 	  	 	 	 	 !!#!#########w####w###!##########9 9$7$79$7$99 $999999 $9999999w9999w999999 999999K9999K999$7999$999999999ZZ 5 5w 5 GHY
Gdjj&&-<{JUUW&( $(x$5
 	
z 
 
 	
 	
 	
z 
 	
 	
 
6	
 	
 	
z 	
 	
 
		
z 	
 	
 
		
 
 	
 	
 	
 	
 	
 	
 	
 	
 (r   c                    V ^8  d   QhRRRR/# rM   r   )r   s   "r   r   r   Z   s     ? ??	?r   c           	        \        V R R4       V P                  R ,          R,          R,          pVP                  P                  RR7       VP	                  \
        P                  ! RRRR	R
//4      RR7       V P                  V P                  4       ^ ,          4       \
        P                  ! VP                  RR7      4      pVR,          pRRR	R
/qCV8H  qU'       gy   \        P                  ! RV3RW434      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;rTV\         ,          R,          pRqCV8H  qU'       gy   \        P                  ! RV3RW434      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;rTR# )rO   rP   rY   rG   T)r.   googlerk   zapi-keykeygr   r1   py1r^   assert %(py6)sr_   Nrp   z	acct-rafart   z%(py1)s == %(py4)s)rK   r{   r3   r4   r5   r   r   rz   ry   r   r   r}   r~   r   r   r   r   )rB   pi_authmerged@py_assert0r   r   r   @py_format7s   &       r   Dtest_prepare_merges_into_existing_pi_auth_preserving_other_providersr   Z   sU    66*##f,y8;FGNN&tzz8fi-L"MNY`a+,ZZ))7);<F(>	5#>>>>>>>>>>>>>>>>>>>>>>>/";/>;>;>>>>>/>>>/>>>;>>>>>>>>r   c               $    V ^8  d   QhRRRRRR/# )r	   r9   r   capsyszpytest.CaptureFixture[str]r   r(   r   )r   s   "r   r   r   i   s$     8 8868	8r   c                   V R ,          pVP                  4        \        V R,          VV R,          R7      p\        VRR4       VP                  VP	                  4       ^ ,          4       RqBV,          qUP
                  qf! 4       qw'       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      R\        P                  ! V4      /,          p\        \        P                  ! V4      4      hR;p;p;rgRq@V,          qUP                  qf! 4       qw'       * 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      R\        P                  ! V4      /,          p
\        \        P                  ! V
4      4      hR;p;p;p;ryRqP                  qf! 4       qwP                  qV	9   q'       g   \        P                   ! RV3RW3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      R\        P                  ! V	4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;p;p;ryR# )r;   r<   zabsent-pi-agentr=   rO   rP   rG   zQassert %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = (%(py0)s / %(py2)s).is_symlink
}()
}r[   r]   rs   py7NzQassert not %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = (%(py0)s / %(py2)s).exists
}()
}r9   r   rr   r   ra   zassert %(py11)spy11)in)zb%(py1)s in %(py9)s
{%(py9)s = %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py3)s.readouterr
}()
}.err
})r4   r   rK   rz   ry   r   r   r   r}   r   r   r   r   exists
readouterrerrr~   )r9   r   r;   rB   r   r   @py_assert4@py_assert6@py_format8@py_assert8@py_format9r   r   @py_format10@py_format12s   &&             r   Btest_missing_pi_agent_dir_skips_pi_with_warning_and_switches_codexr   i   s     F
LLNF"  11H
 66*+, .[ .,,.,.........F....F...[...,...........,6,,64464666666666666666666,6664666666666667 1 17 1 37 7 77 7777777777777777777777 1777 3777 7777777777r   c                    V ^8  d   QhRRRR/# rM   r   )r   s   "r   r   r   |   s      	r   c                   \        V R R4       V P                  RR4      pVR,          P                  \        P                  ! R/ /4      RR7       V P                  \        R V P                  4        4       4      4       V P                  R,          pV P                  P                  p\        P                  ! \        4      ;_uu_ 4        V P                  \        R	 V P                  4        4       4      4       R
R
R
4       V P                  qDP                  pRqe! VR7      pRqV8H  q'       Eg	   \         P"                  ! RV	3R Wx3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      R\         P*                  ! V4      R\         P*                  ! V4      /,          p
RRV
/,          p\-        \         P.                  ! V4      4      hR
;p;p;p;p;rVP0                  qD! 4       pV P2                  pR p	Wy,          pRpW,          pRpW,          pVP0                  pV! 4       pVV8H  qf'       Eg   \         P"                  ! RV3R!VV3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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      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	;p;p;p;p;p;ppVP0                  qD! 4       pV P2                  pR p	Wy,          pRpW,          pRpW,          pVP0                  pV! 4       pVV8H  qf'       Eg   \         P"                  ! RV3R!VV3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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      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	;p;p;p;p;p;ppR
#   + '       g   i     ELo; i)"rO   rP   rQ   rR   rG   r0   r   r1   c              3  J   "   T F  qP                   R 8X  g   K  Vx  K  	  R# 5i)rO   NrT   rU   rV   s   & r   rW   Otest_underivable_codex_auth_fails_closed_without_half_switch.<locals>.<genexpr>   s     MAFFf<Laa   #
#c              3  J   "   T F  qP                   R 8X  g   K  Vx  K  	  R# 5i)rQ   NrT   r   s   & r   rW   r      s     !P_%!!_r   Nzrafa
r[   rB   r]   r^   r_   r`   r   zassert %(py13)spy13rZ   r\   rj   py16py19py21zassert %(py23)spy23rY   rh   rt   )z{%(py8)s
{%(py8)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.default_path
}.read_text
}(encoding=%(py6)s)
} == %(py11)s)z%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.resolve
}()
} == %(py21)s
{%(py21)s = %(py19)s
{%(py19)s = (((%(py8)s
{%(py8)s = %(py6)s.accounts_dir
} / %(py10)s) / %(py13)s) / %(py16)s).resolve
}()
})rK   rI   r5   r   r   rz   rx   ry   r?   rv   rw   pytestraisesr   default_pathr   r}   r~   r   r   r   r   r   r   r|   r{   )rB   roy_homer\   rh   r   r   r   r   r   r   r   @py_format14r   @py_assert12r   @py_assert15r   @py_assert18@py_assert20@py_format22@py_format24s   &                    r   <test_underivable_codex_auth_fails_closed_without_half_switchr   |   s    66*u-H''

Hb>(BW'UMMMN++k9J$$55G		'	'T!PX]]_!PPQ 
(   H**HGH*G<HHHHHHH<HHHHHH8HHHH8HHH HHH*HHHGHHH<HHHHHHHHHHHH   &&)5&58C5CCg $ $  $     $  	  :  i:  i  i  	   i i i & i)5 i8C i $  i $           ?? ?  &&)2&25@2@@g ! !  !     !  	  7  i7  i?  i  	   i i i & i)2 i5@ i !  i !           
(	'	's   
0Y  Y1	c                    V ^8  d   QhRRRR/# rM   r   )r   s   "r   r   r      s     	G 	Go 	G$ 	Gr   c                   \        V R R4       V P                  V P                  4       ^ ,          4       V P                  P                  pVP
                  q"! 4       q3'       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;r#V P                  R 4       VP
                  q"! 4       q3'       * qU'       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;r5V P                  pR	q2V,          qUP
                  qw! 4       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      R\        P                  ! V4      R\        P                  ! V4      /,          p
\        \        P                  ! V
4      4      hR;p;p;p;p;rR# )rO   rP   rg   r[   rh   r]   r^   NzIassert not %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.is_symlink
}()
}rG   z|assert not %(py9)s
{%(py9)s = %(py7)s
{%(py7)s = (%(py2)s
{%(py2)s = %(py0)s.legacy_codex_home
} / %(py4)s).is_symlink
}()
}rB   r   ra   )rK   rz   ry   rv   rw   r   r   r   r}   r   r   r   r   remover?   )rB   rh   r   r   r   r   r   r   r   r   r   s   &          r   'test_remove_last_account_clears_pi_linkr      s   66*+,$$55G77OOF!!#!###########w####w###!##########**F[F[8FDDFDFFFFFFFFFFFFFFFFFF*FFF[FFFDFFFFFFFFFFFr   c                    V ^8  d   QhRRRR/# r	   r9   r   r   r(   r   )r   s   "r   r   r      s     * *d *t *r   c           	     &   V R ,          pVP                  4        \        V R,          VR7      pVP                  pRqCVJ qU'       g   \        P                  ! R
V3RW43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;rTR# )r;   r<   )r>   r?   Nr[   rB   r]   rs   zassert %(py7)sr   )is)z5%(py2)s
{%(py2)s = %(py0)s._pi_auth_sync
} is %(py5)s)r4   r   rv   r}   r~   r   r   r   r   r   r   )r9   r;   rB   r   r   r   r   r   s   &       r   7test_registry_without_pi_agent_dir_has_pi_sync_disabledr      s     F
LLN6(9VTH!!)T)T)))))!))))))8))))8)))!)))T))))))))r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r      s     / /t /PT /r   c                   \        V R ,          V R,          R7      pV R,          R,          R,          R,          p\        VRRRR	7       VP                  VR4      pVR
,          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# )piaccounts	agent_dirr{   xrZ   rG   zx@example.comzacct-xF)r!   rp   r   r^   r   r_   Nrt   r   )r   r7   _derive_credentialr}   r~   r   r   r   )	r9   syncauthrq   r   r   r   r   r   s	   &        r   8test_derive_uses_jwt_claim_when_account_id_field_missingr      s    4h>STDj 3&5CDT?HuU((s3Jk".h.h....."..."...h........r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r      s     + +4 +D +r   c                d   \        V R ,          V R,          R7      pV R,          pVP                  \        P                  ! RR\	        RR/4      RR	R
R//4      RR7       \
        P                  ! \        4      ;_uu_ 4        VP                  VR4       RRR4       R#   + '       g   i     R# ; i)r   r   r   rG   r0   r,   no_expTr-   rtr%   acctr   r1   r   N)	r   r5   r   r   r   r   r   r   r   )r9   r   r   s   &  r   ,test_derive_rejects_access_token_without_expr      s    4h>STDk!DOO

"D(D)9$:#T &	
    
	'	'c* 
(	'	'	's   BB/	)(
__future__r   builtinsr   _pytest.assertion.rewrite	assertionrewriter}   r   r   syspathlibr   r   r#   insertr   __file__r|   r.   account_registryr   pi_auth_syncr   r   r   r   r   r7   fixturerB   rK   r   r   r   r   r   r   r   r   r   r   r   <module>r      s    "     
   3tH~--/77:; < , E E5
F
 F &*F( 	 	
8?8&,	G*/+r   