11import inspect
22
33import pandas as pd
4+ import pytest
45import app .services .trading_executor as trading_executor
56
67from app .services .strategy_v2 import OrderIntent
@@ -347,8 +348,15 @@ def test_target_rebalance_skips_sub_dollar_dust_order():
347348 assert calls == []
348349
349350
350- def test_live_order_carries_run_sizing_diagnostics ():
351- executor = TradingExecutor .__new__ (TradingExecutor )
351+ @pytest .mark .parametrize ("lease_owned" , [None , True , False ])
352+ def test_live_order_carries_run_sizing_diagnostics (lease_owned ):
353+ executor = TradingExecutor ()
354+ guard_calls = []
355+ if lease_owned is not None :
356+ def guard (strategy_id ):
357+ guard_calls .append (strategy_id )
358+ return lease_owned
359+ executor .runtime_guard = guard
352360 executor ._load_strategy = lambda _strategy_id : {"user_id" : 12 }
353361 captured = {}
354362
@@ -373,6 +381,10 @@ def submit(self, request):
373381 )
374382
375383 assert result is False
384+ assert guard_calls == ([] if lease_owned is None else [7 ])
385+ if lease_owned is False :
386+ assert captured == {}
387+ return
376388 assert captured ["request" ].sizing == {
377389 "initial_capital" : 100.0 ,
378390 "entry_pct" : 30.0 ,
@@ -450,7 +462,7 @@ def submit(_request):
450462
451463
452464def test_limit_queue_log_identifies_grid_level_order (monkeypatch ):
453- executor = TradingExecutor . __new__ ( TradingExecutor )
465+ executor = TradingExecutor ( )
454466 executor ._load_strategy = lambda _strategy_id : {
455467 "user_id" : 12 ,
456468 "status" : "running" ,
0 commit comments