This commit is contained in:
@@ -8276,7 +8276,7 @@ def handle_cmd(cmd, arg, chat_id, reply_to):
|
||||
context={
|
||||
'host_label': host_label, 'host_url': host_url,
|
||||
'error_message': f'Ollama {host_label} marked unhealthy',
|
||||
'triggered_by': f'telegram_user_{cq_from_id if False else "tg_admin"}',
|
||||
'triggered_by': f'telegram_user_{_CURRENT_USER_ID_CTX.get() or "tg_admin"}',
|
||||
},
|
||||
)
|
||||
ok = bool(getattr(result, 'success', False))
|
||||
|
||||
@@ -137,6 +137,36 @@ def test_is_authorized_private_mode_switch(monkeypatch):
|
||||
assert bot._is_authorized("private", 777, 42) is False
|
||||
|
||||
|
||||
def test_obs_heal_audit_uses_current_callback_user(monkeypatch):
|
||||
from types import SimpleNamespace
|
||||
from routes import openclaw_bot_routes as bot
|
||||
import services.ollama_service as ollama_service
|
||||
import services.auto_heal_service as auto_heal_module
|
||||
|
||||
captured = {}
|
||||
|
||||
class FakeAutoHeal:
|
||||
def handle_exception(self, error_type, context):
|
||||
captured["error_type"] = error_type
|
||||
captured["context"] = context
|
||||
return SimpleNamespace(success=True, action="ALERT_ONLY", message="ok")
|
||||
|
||||
sent = []
|
||||
monkeypatch.setattr(bot, "send_message", lambda *args, **kwargs: sent.append((args, kwargs)))
|
||||
monkeypatch.setattr(ollama_service, "_is_unhealthy", lambda _host: True)
|
||||
monkeypatch.setattr(auto_heal_module, "auto_heal_service", FakeAutoHeal())
|
||||
|
||||
token = bot._CURRENT_USER_ID_CTX.set(777001)
|
||||
try:
|
||||
bot.handle_cmd("obs_heal", "GCP-A", -200, 55)
|
||||
finally:
|
||||
bot._CURRENT_USER_ID_CTX.reset(token)
|
||||
|
||||
assert captured["error_type"] == "ollama_unhealthy"
|
||||
assert captured["context"]["triggered_by"] == "telegram_user_777001"
|
||||
assert sent
|
||||
|
||||
|
||||
def test_webhook_menu_callback_edits_existing_message(monkeypatch):
|
||||
from routes import openclaw_bot_routes as bot
|
||||
|
||||
|
||||
Reference in New Issue
Block a user