This commit is contained in:
@@ -569,7 +569,11 @@ class ElephantAlphaAutonomousEngine:
|
||||
ctx.set_tokens(input=0, output=0) # Hermes 已自己記
|
||||
ctx.status = 'cache_only' # 不算 ok 也不算 error
|
||||
except Exception:
|
||||
pass # logger 失敗不影響主流程
|
||||
self._log.warning(
|
||||
"EA short-circuit telemetry failed; trigger=%s",
|
||||
trigger.trigger_type,
|
||||
exc_info=True,
|
||||
)
|
||||
return
|
||||
|
||||
# Hermes 有實證 threats → 把它存進 trigger.conditions 給 orchestrator 用
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
|
||||
def test_run_with_timeout_supports_sync_function():
|
||||
@@ -82,3 +83,34 @@ def test_autoheal_derives_python_exception_from_traceback():
|
||||
svc = AutoHealService()
|
||||
|
||||
assert svc._derive_error_type({"traceback_str": "Traceback (most recent call last):\nNameError"}) == "python_exception"
|
||||
|
||||
|
||||
def test_execute_autonomous_decision_logs_short_circuit_telemetry_failure(monkeypatch, caplog):
|
||||
from services.elephant_alpha_autonomous_engine import (
|
||||
AutonomousTrigger,
|
||||
ElephantAlphaAutonomousEngine,
|
||||
)
|
||||
import services.ai_call_logger as ai_call_logger
|
||||
|
||||
engine = ElephantAlphaAutonomousEngine()
|
||||
|
||||
async def _no_hermes_threats(top_n=5):
|
||||
return None
|
||||
|
||||
def _broken_log_ai_call(*args, **kwargs):
|
||||
raise RuntimeError("ai telemetry unavailable")
|
||||
|
||||
monkeypatch.setattr(engine, "_fetch_hermes_threats_summary", _no_hermes_threats)
|
||||
monkeypatch.setattr(ai_call_logger, "log_ai_call", _broken_log_ai_call)
|
||||
caplog.set_level(logging.WARNING, logger="services.elephant_alpha_autonomous_engine")
|
||||
|
||||
trigger = AutonomousTrigger(
|
||||
trigger_type="price_drop_alert",
|
||||
conditions={},
|
||||
threshold=0.8,
|
||||
enabled=True,
|
||||
)
|
||||
|
||||
asyncio.run(engine._execute_autonomous_decision(trigger))
|
||||
|
||||
assert "EA short-circuit telemetry failed" in caplog.text
|
||||
|
||||
Reference in New Issue
Block a user