
    \j                        d dl mZ d dlZd dlmc mZ d dlZd dl	m	Z	m
Z
 d dlmZmZ dddd ddZd	 Zd
 Zd Zd Zd Zd ZdS )    )annotationsN)datetimetimezone)
CANDIDATESinspect_candidate{   T)pidenv_ok
command_okheartbeat_agec               T   | dz  }||j         z  }|                    d           |dz                      t          |          d           | dz  }|t          |          z  }	|	                    d           |rd|j         d	|j          d
nd}
|	dz                      |
                                           d
                    d|j          dddd|rdndf          d
z   }|	dz                      |                                           t          j	        t          j                                                  }t          j        ||z
  t          j                                                  }|dz                      t          j        |dd          dz   d           |||fS )NruntimeTparentszbot.pidzutf-8)encodingprocz
python -m z --strategy-id  zpython other cmdlinezCTB_STRATEGY_ID=zCTB_PAPER_TRADING=truezCTB_DRY_RUN=falsezCTB_LIVE_TRADING_ALLOWED=falsezCTB_LIVE_ORDER_ALLOWED=falsezHL_MAINNET_SIGNED_ACTION=falsezHL_MAINNET_SIGNED_ACTION=trueenvironzruntime_health.jsonlok)	timestampstatus
)strategy_idmkdir
write_textstrmodulewrite_bytesencodejoinr   nowr   utcr   fromtimestamp	isoformatjsondumps)tmp_pathspecr	   r
   r   r   runtime_rootr   	proc_rootr   commandenvr"   stamps                 Y/home/agent/projects/CryptoTradingBot/Crypto_Agent/tests/test_paper_runtime_supervisor.py_proc_fixturer0   	   s   i'LT--GMM$My$$SXX$@@@6!Is3xxDJJtJ]g  CYYY4CSYYYY  nCG	I""7>>#3#3444
++-4+-- (&,2W((8W   
C 
I""3::<<000
,x|
$
$
.
.
0
0C"3#6EEOOQQE%%11$*5\`=a=a2b2bei2it{1|||C''    c                   t           d         }t          | |          \  }}}t          ||||          }|j        }d}||k    }|st	          j        d|fd||f          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          dz  }	dd	|	iz  }
t          t	          j        |
                    d x}x}}|j        }d
}||u }|st	          j        d|fd||f          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          dz  }	dd	|	iz  }
t          t	          j        |
                    d x}x}}|j        }d}||u }|st	          j        d|fd||f          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          dz  }	dd	|	iz  }
t          t	          j        |
                    d x}x}}d S )N*candidate_v77_trend_retest_anti_chase_longr*   r+   r"   healthy==z-%(py2)s
{%(py2)s = %(py0)s.state
} == %(py5)sresultpy0py2py5assert %(py7)spy7Fisz7%(py2)s
{%(py2)s = %(py0)s.restart_allowed
} is %(py5)sT)z6%(py2)s
{%(py2)s = %(py0)s.environment_ok
} is %(py5)s)r   r0   r   state
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationrestart_allowedenvironment_ok)r(   r)   r   r   r"   r9   @py_assert1@py_assert4@py_assert3@py_format6@py_format8s              r/   4test_inspector_accepts_only_exact_safe_fresh_processrS   "   s   BCD&x66GT3t'TsSSSF<$9$<9$$$$$$$$$$<9$$$$$$$$$$$$6$$$$$6$$$$$$<$$$$9$$$$$$$$$$$$$$$$$$$$$$$$$$$!*U*!U**********!U************6*****6******!****U*************************** (D( D(((((((((( D((((((((((((6(((((6(((((( ((((D(((((((((((((((((((((((((((((r1   c                   t           d         }| dz  }||j        z                      d           t          ||| dz  d          }|j        }d}||k    }|st          j        d	|fd
||f          dt          j                    v st          j	        |          rt          j
        |          ndt          j
        |          t          j
        |          dz  }dd|iz  }t          t          j        |                    d x}x}}|j        }d}||u }|st          j        d|fd||f          dt          j                    v st          j	        |          rt          j
        |          ndt          j
        |          t          j
        |          dz  }dd|iz  }t          t          j        |                    d x}x}}d S )Nr3   r   Tr   r   r   r4   missingr6   r8   r9   r:   r>   r?   r@   rB   )r   r   r   r   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   )	r(   r)   r   r9   rN   rO   rP   rQ   rR   s	            r/   :test_inspector_allows_restart_only_when_process_is_missingrV   +   s   BCD"Gt&&t&444t'XPVEV\]^^^F<$9$<9$$$$$$$$$$<9$$$$$$$$$$$$6$$$$$6$$$$$$<$$$$9$$$$$$$$$$$$$$$$$$$$$$$$$$$!)T)!T))))))))))!T))))))))))))6)))))6))))))!))))T)))))))))))))))))))))))))))))r1   c                J   t           d         }t          | |d          \  }}}t          ||||          }|j        }d}||k    }|st	          j        d|fd||f          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          d	z  }	d
d|	iz  }
t          t	          j        |
                    d x}x}}|j        }d}||u }|st	          j        d|fd||f          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          d	z  }	d
d|	iz  }
t          t	          j        |
                    d x}x}}t          | dz  |dd          \  }}}t          ||||          }|j        }d}||k    }|st	          j        d|fd||f          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          d	z  }	d
d|	iz  }
t          t	          j        |
                    d x}x}}|j        }d}||u }|st	          j        d|fd||f          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          d	z  }	d
d|	iz  }
t          t	          j        |
                    d x}x}}d}|j        }||v }|st	          j        d|fd||f          t	          j	        |          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          dz  }	d
d|	iz  }
t          t	          j        |
                    d x}x}}d S )N$research_v77_bear_trend_retest_shortF)r
   r4   unsafe_or_unclearr6   r8   unsafer:   r>   r?   r@   rB   stale|      )r	   r   heartbeat_stale)in)z0%(py1)s in %(py5)s
{%(py5)s = %(py3)s.blockers
})py1py3r=   )r   r0   r   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   blockers)r(   r)   r   r   r"   rZ   rN   rO   rP   rQ   rR   runtime2proc2now2r[   @py_assert0@py_assert2s                    r/   :test_inspector_refuses_restart_for_unsafe_or_stale_processrh   4   s   <=D&xeDDDGT3t'TsSSSF<...<...........<.............6.....6......<................................!*U*!U**********!U************6*****6******!****U***************************)(W*<d[^___HeTdUPTUUUE;!'!;'!!!!!!!!!!;'!!!!!!!!!!!!5!!!!!5!!!!!!;!!!!'!!!!!!!!!!!!!!!!!!!!!!!!!!! )E) E)))))))))) E))))))))))))5)))))5)))))) ))))E)))))))))))))))))))))))))))....................................................................r1   c                B   t           d         }t          ||           }|j        }d}||k    }|st          j        d|fd||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd	|iz  }t          t          j
        |                    d x}x}}|j        }d
}||u }|st          j        d|fd||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd	|iz  }t          t          j
        |                    d x}x}}d S )N*research_v78_market_neutral_relative_value)r*   disabledr6   r8   r9   r:   r>   r?   Fr@   rB   )r   r   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   )r(   r)   r9   rN   rO   rP   rQ   rR   s           r/   )test_relative_value_candidate_is_disabledrl   A   s   BCDt(;;;F<%:%<:%%%%%%%%%%<:%%%%%%%%%%%%6%%%%%6%%%%%%<%%%%:%%%%%%%%%%%%%%%%%%%%%%%%%%%!*U*!U**********!U************6*****6******!****U*****************************r1   c                     t           d         } | j        }d}||u }|st          j        d|fd||f          dt	          j                    v st          j        |           rt          j        |           ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j	        |                    d x}x}}| j
        }d}||u }|st          j        d|fd	||f          dt	          j                    v st          j        |           rt          j        |           ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j	        |                    d x}x}}| j        }d
}||k    }|st          j        d|fd||f          dt	          j                    v st          j        |           rt          j        |           ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j	        |                    d x}x}}| j        }d}||k    }|st          j        d|fd||f          dt	          j                    v st          j        |           rt          j        |           ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j	        |                    d x}x}}d S )N6research_v77_2_relative_strength_momentum_continuationTr@   )z/%(py2)s
{%(py2)s = %(py0)s.enabled
} is %(py5)sr)   r:   r>   r?   z2%(py2)s
{%(py2)s = %(py0)s.paper_only
} is %(py5)szv77.2.0r6   z8%(py2)s
{%(py2)s = %(py0)s.strategy_version
} == %(py5)s)BTCETHLINKz-%(py2)s
{%(py2)s = %(py0)s.coins
} == %(py5)s)r   enabledrD   rE   rF   rG   rH   rI   rJ   rK   
paper_onlystrategy_versioncoinsr)   rN   rO   rP   rQ   rR   s         r/   6test_v77_2_momentum_candidate_is_registered_paper_onlyrz   H   s   NOD<4<4<444<4?"d"?d""""""""""?d""""""""""""4"""""4""""""?""""d""""""""""""""""""""""""""" -I- I---------- I------------4-----4------ ----I---------------------------:///:///////////://///////////4/////4//////://////////////////////////////////r1   c                 $   t           d         } | j        }d}||k    }|st          j        d|fd||f          dt	          j                    v st          j        |           rt          j        |           ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j	        |                    d x}x}}| j
        }d	}||k    }|st          j        d|fd
||f          dt	          j                    v st          j        |           rt          j        |           ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j	        |                    d x}x}}| j        }d}||k    }|st          j        d|fd||f          dt	          j                    v st          j        |           rt          j        |           ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j	        |                    d x}x}}| j        }d}||u }|st          j        d|fd||f          dt	          j                    v st          j        |           rt          j        |           ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j	        |                    d x}x}}d S )N(research_v78_2_confirmed_range_reversionzv78.2.0r6   rp   r)   r:   r>   r?   zsrc.tools.v78_2_range_runtime)z.%(py2)s
{%(py2)s = %(py0)s.module
} == %(py5)s)rq   rr   SOLrs   HYPErt   Tr@   ro   )r   rw   rD   rE   rF   rG   rH   rI   rJ   rK   r   rx   rv   ry   s         r/   =test_v78_2_confirmed_range_candidate_is_registered_separatelyr   P   s   @AD -I- I---------- I------------4-----4------ ----I---------------------------;999;99999999999;99999999999994999994999999;99999999999999999999999999999999:>>>:>>>>>>>>>>>:>>>>>>>>>>>>>4>>>>>4>>>>>>:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>?"d"?d""""""""""?d""""""""""""4"""""4""""""?""""d"""""""""""""""""""""""""""""r1   )
__future__r   builtinsrF   _pytest.assertion.rewrite	assertionrewriterD   r&   r   r   "src.tools.paper_runtime_supervisorr   r   r0   rS   rV   rh   rl   rz   r    r1   r/   <module>r      s    " " " " " "               ' ' ' ' ' ' ' ' L L L L L L L L *-TdZ[ ( ( ( ( (2) ) )* * *
/ 
/ 
/+ + +0 0 0# # # # #r1   