Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cron/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def _resolve_cron_enabled_toolsets(job: dict, cfg: dict) -> list[str] | None:
"bluebubbles": "BLUEBUBBLES_HOME_CHANNEL",
"qqbot": "QQBOT_HOME_CHANNEL",
"whatsapp": "WHATSAPP_HOME_CHANNEL",
"yuanbao": "YUANBAO_HOME_CHANNEL",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a scheduler regression test alongside this mapping, e.g. set YUANBAO_HOME_CHANNEL and assert _resolve_delivery_targets({"deliver": "yuanbao", "origin": None}) resolves the configured target. The PR's current test changes cover unrelated session hooks.

}

# Legacy env var names kept for back-compat. Each entry is the current
Expand Down
3 changes: 3 additions & 0 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7029,6 +7029,7 @@ async def _handle_message_with_agent(self, event, source, _quick_key: str, run_g
await self.hooks.emit("session:start", {
"platform": source.platform.value if source.platform else "",
"user_id": source.user_id,
"chat_id": source.chat_id or "",
"session_id": session_entry.session_id,
"session_key": session_key,
})
Expand Down Expand Up @@ -8161,13 +8162,15 @@ async def _handle_reset_command(self, event: MessageEvent) -> Union[str, Ephemer
await self.hooks.emit("session:end", {
"platform": source.platform.value if source.platform else "",
"user_id": source.user_id,
"chat_id": source.chat_id or "",
"session_key": session_key,
})

# Emit session:reset hook
await self.hooks.emit("session:reset", {
"platform": source.platform.value if source.platform else "",
"user_id": source.user_id,
"chat_id": source.chat_id or "",
"session_key": session_key,
})

Expand Down
34 changes: 34 additions & 0 deletions tests/gateway/test_session_boundary_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,40 @@ async def test_reset_fires_reset_hook(mock_invoke_hook):
)


@pytest.mark.asyncio
@patch("hermes_cli.plugins.invoke_hook")
async def test_session_end_hook_includes_chat_id(mock_invoke_hook):
"""session:end gateway hook must carry chat_id so hook authors can route replies."""
runner = _make_runner()

await runner._handle_reset_command(_make_event("/new"))

end_calls = [
c for c in runner.hooks.emit.call_args_list
if c.args and c.args[0] == "session:end"
]
assert end_calls, "session:end was not emitted"
ctx = end_calls[0].args[1]
assert ctx.get("chat_id") == "c1"


@pytest.mark.asyncio
@patch("hermes_cli.plugins.invoke_hook")
async def test_session_reset_hook_includes_chat_id(mock_invoke_hook):
"""session:reset gateway hook must carry chat_id so hook authors can route replies."""
runner = _make_runner()

await runner._handle_reset_command(_make_event("/new"))

reset_calls = [
c for c in runner.hooks.emit.call_args_list
if c.args and c.args[0] == "session:reset"
]
assert reset_calls, "session:reset was not emitted"
ctx = reset_calls[0].args[1]
assert ctx.get("chat_id") == "c1"


@pytest.mark.asyncio
@patch("hermes_cli.plugins.invoke_hook")
async def test_finalize_before_reset(mock_invoke_hook):
Expand Down
Loading