Fix supervisor AI empty replies with fallback templates

Skip appending AI error strings to the session and use event-specific fallback commentary when the model returns empty content.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-23 20:10:33 +08:00
parent acc158f85d
commit 65901c5577
3 changed files with 113 additions and 16 deletions
+22
View File
@@ -136,3 +136,25 @@ def test_normalize_supervisor_settings_env(monkeypatch):
cfg = sup.normalize_supervisor_settings({})
assert cfg["wechat_webhook"] == "https://example.com/hook"
assert cfg["wechat_link_base"] == "https://hub.example/ai?mode=supervisor"
def test_supervisor_fallback_reply_program_sl():
text = sup.build_supervisor_fallback_reply(
{
"event_type": sup.EVENT_PROGRAM_SL,
"symbol": "ZEC/USDT",
"pnl_amount": -0.9557,
}
)
assert "程序止损" in text
assert "AI 生成失败" not in text
def test_supervisor_fallback_not_error_reply():
from hub_ai.text_util import is_ai_error_reply
text = sup.build_supervisor_fallback_reply(
{"event_type": sup.EVENT_MANUAL_CLOSE, "symbol": "ETH/USDT", "pnl_amount": -1}
)
assert text
assert not is_ai_error_reply(text)