mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-03 02:11:48 +00:00
fix(cron): clear auto-delivery thread context between jobs
This commit is contained in:
parent
16233711d9
commit
ffa65291d1
2 changed files with 88 additions and 2 deletions
|
|
@ -1027,6 +1027,80 @@ class TestRunJobSessionPersistence:
|
|||
assert os.getenv("HERMES_CRON_AUTO_DELIVER_THREAD_ID") is None
|
||||
fake_db.close.assert_called_once()
|
||||
|
||||
def test_run_job_clears_stale_auto_delivery_thread_id_between_jobs(self, tmp_path, monkeypatch):
|
||||
jobs = [
|
||||
{
|
||||
"id": "threaded-job",
|
||||
"name": "threaded",
|
||||
"prompt": "hello",
|
||||
"deliver": "telegram:-1001:42",
|
||||
},
|
||||
{
|
||||
"id": "threadless-job",
|
||||
"name": "threadless",
|
||||
"prompt": "hello again",
|
||||
"deliver": "telegram:-2002",
|
||||
},
|
||||
]
|
||||
fake_db = MagicMock()
|
||||
seen = []
|
||||
|
||||
monkeypatch.delenv("HERMES_CRON_AUTO_DELIVER_PLATFORM", raising=False)
|
||||
monkeypatch.delenv("HERMES_CRON_AUTO_DELIVER_CHAT_ID", raising=False)
|
||||
monkeypatch.delenv("HERMES_CRON_AUTO_DELIVER_THREAD_ID", raising=False)
|
||||
|
||||
class FakeAgent:
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def run_conversation(self, *args, **kwargs):
|
||||
from gateway.session_context import get_session_env
|
||||
|
||||
seen.append(
|
||||
{
|
||||
"platform": get_session_env("HERMES_CRON_AUTO_DELIVER_PLATFORM") or None,
|
||||
"chat_id": get_session_env("HERMES_CRON_AUTO_DELIVER_CHAT_ID") or None,
|
||||
"thread_id": get_session_env("HERMES_CRON_AUTO_DELIVER_THREAD_ID") or None,
|
||||
}
|
||||
)
|
||||
return {"final_response": "ok"}
|
||||
|
||||
with patch("cron.scheduler._hermes_home", tmp_path), \
|
||||
patch("hermes_state.SessionDB", return_value=fake_db), \
|
||||
patch(
|
||||
"hermes_cli.runtime_provider.resolve_runtime_provider",
|
||||
return_value={
|
||||
"api_key": "***",
|
||||
"base_url": "https://example.invalid/v1",
|
||||
"provider": "openrouter",
|
||||
"api_mode": "chat_completions",
|
||||
},
|
||||
), \
|
||||
patch("run_agent.AIAgent", FakeAgent):
|
||||
for job in jobs:
|
||||
success, output, final_response, error = run_job(job)
|
||||
assert success is True
|
||||
assert error is None
|
||||
assert final_response == "ok"
|
||||
assert "ok" in output
|
||||
|
||||
assert seen == [
|
||||
{
|
||||
"platform": "telegram",
|
||||
"chat_id": "-1001",
|
||||
"thread_id": "42",
|
||||
},
|
||||
{
|
||||
"platform": "telegram",
|
||||
"chat_id": "-2002",
|
||||
"thread_id": None,
|
||||
},
|
||||
]
|
||||
assert os.getenv("HERMES_CRON_AUTO_DELIVER_PLATFORM") is None
|
||||
assert os.getenv("HERMES_CRON_AUTO_DELIVER_CHAT_ID") is None
|
||||
assert os.getenv("HERMES_CRON_AUTO_DELIVER_THREAD_ID") is None
|
||||
assert fake_db.close.call_count == 2
|
||||
|
||||
|
||||
class TestRunJobConfigLogging:
|
||||
"""Verify that config.yaml parse failures are logged, not silently swallowed."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue