|
@@ -14,12 +14,12 @@ def sample_candles() -> list[Candle]:
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
-def fake_runner(stdout: str):
|
|
|
|
|
|
|
+def fake_runner(stdout: str, returncode: int = 0):
|
|
|
calls: list[tuple[object, bool, bool, bool]] = []
|
|
calls: list[tuple[object, bool, bool, bool]] = []
|
|
|
|
|
|
|
|
def runner(command, capture_output: bool, text: bool, check: bool):
|
|
def runner(command, capture_output: bool, text: bool, check: bool):
|
|
|
calls.append((command, capture_output, text, check))
|
|
calls.append((command, capture_output, text, check))
|
|
|
- return subprocess.CompletedProcess(command, 0, stdout=stdout, stderr="")
|
|
|
|
|
|
|
+ return subprocess.CompletedProcess(command, returncode, stdout=stdout, stderr="")
|
|
|
|
|
|
|
|
runner.calls = calls
|
|
runner.calls = calls
|
|
|
return runner
|
|
return runner
|
|
@@ -68,6 +68,29 @@ def test_analyzer_rejects_json_leverage_out_of_range():
|
|
|
assert which.calls == ["codex"]
|
|
assert which.calls == ["codex"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def test_analyzer_rejects_non_zero_exit_with_non_json_stdout():
|
|
|
|
|
+ runner = fake_runner(stdout="not json", returncode=1)
|
|
|
|
|
+ which = fake_which()
|
|
|
|
|
+
|
|
|
|
|
+ with pytest.raises(ValueError, match="codex execution failed"):
|
|
|
|
|
+ analyze_with_codex(candles=sample_candles(), symbol="BTC-USDT-SWAP", bar="1H", runner=runner, which=which)
|
|
|
|
|
+
|
|
|
|
|
+ assert which.calls == ["codex"]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def test_analyzer_rejects_non_zero_exit_with_json_stdout():
|
|
|
|
|
+ runner = fake_runner(
|
|
|
|
|
+ stdout='{"action":"long","confidence":0.8,"leverage":2,"entry_price":null,"take_profit_price":null,"stop_loss_price":null,"reason":"x"}',
|
|
|
|
|
+ returncode=1,
|
|
|
|
|
+ )
|
|
|
|
|
+ which = fake_which()
|
|
|
|
|
+
|
|
|
|
|
+ with pytest.raises(ValueError, match="codex execution failed"):
|
|
|
|
|
+ analyze_with_codex(candles=sample_candles(), symbol="BTC-USDT-SWAP", bar="1H", runner=runner, which=which)
|
|
|
|
|
+
|
|
|
|
|
+ assert which.calls == ["codex"]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def test_analyzer_returns_valid_trade_signal():
|
|
def test_analyzer_returns_valid_trade_signal():
|
|
|
runner = fake_runner(
|
|
runner = fake_runner(
|
|
|
stdout='{"action":"short","confidence":0.6,"leverage":2,"entry_price":101.5,"take_profit_price":99.0,"stop_loss_price":103.0,"reason":"trend"}'
|
|
stdout='{"action":"short","confidence":0.6,"leverage":2,"entry_price":101.5,"take_profit_price":99.0,"stop_loss_price":103.0,"reason":"trend"}'
|