refactor: bind cron jobs to origin sessions
This commit is contained in:
@@ -16,7 +16,6 @@ from nanobot.cron.types import CronJob, CronPayload
|
||||
from nanobot.providers.factory import ProviderSnapshot, make_provider
|
||||
from nanobot.providers.openai_codex_provider import _strip_model_prefix
|
||||
from nanobot.providers.registry import find_by_name
|
||||
from nanobot.session.routing import SESSION_ROUTING_METADATA_KEY
|
||||
from nanobot.webui.metadata import WEBUI_MESSAGE_SOURCE_METADATA_KEY, WEBUI_TURN_METADATA_KEY
|
||||
|
||||
runner = CliRunner()
|
||||
@@ -1548,38 +1547,10 @@ def test_gateway_bound_cron_runs_as_session_turn(
|
||||
)
|
||||
monkeypatch.setattr("nanobot.bus.queue.MessageBus", lambda: bus)
|
||||
|
||||
route_metadata = {
|
||||
"websocket:chat-1": {
|
||||
"workspace_scope": {
|
||||
"project_path": str(tmp_path),
|
||||
"access_mode": "restricted",
|
||||
},
|
||||
SESSION_ROUTING_METADATA_KEY: {
|
||||
"channel": "websocket",
|
||||
"chat_id": "chat-1",
|
||||
"metadata": {},
|
||||
},
|
||||
},
|
||||
"discord:456:thread:777": {
|
||||
SESSION_ROUTING_METADATA_KEY: {
|
||||
"channel": "discord",
|
||||
"chat_id": "777",
|
||||
"metadata": {
|
||||
"context_chat_id": "456",
|
||||
"parent_channel_id": "456",
|
||||
"thread_id": "777",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
class _FakeSessionManager:
|
||||
def __init__(self, _workspace: Path) -> None:
|
||||
pass
|
||||
|
||||
def read_session_file(self, key: str) -> dict[str, object] | None:
|
||||
return {"metadata": route_metadata.get(key, {})}
|
||||
|
||||
monkeypatch.setattr("nanobot.session.manager.SessionManager", _FakeSessionManager)
|
||||
|
||||
class _FakeCron:
|
||||
@@ -1651,10 +1622,9 @@ def test_gateway_bound_cron_runs_as_session_turn(
|
||||
assert msg.channel == "websocket"
|
||||
assert msg.chat_id == "chat-1"
|
||||
assert msg.sender_id == "cron"
|
||||
assert msg.session_key_override == "websocket:chat-1"
|
||||
assert msg.session_key_override is None
|
||||
assert "Cron job: Check repository health." in msg.content
|
||||
assert msg.metadata["webui"] is True
|
||||
assert msg.metadata["workspace_scope"]["project_path"] == str(tmp_path)
|
||||
assert msg.metadata[WEBUI_MESSAGE_SOURCE_METADATA_KEY] == {
|
||||
"kind": "cron",
|
||||
"label": "Repo check",
|
||||
@@ -1675,7 +1645,7 @@ def test_gateway_bound_cron_runs_as_session_turn(
|
||||
name="Thread check",
|
||||
payload=CronPayload(
|
||||
message="Check the Discord thread.",
|
||||
session_key="discord:456:thread:777",
|
||||
session_key="discord:777",
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1686,10 +1656,7 @@ def test_gateway_bound_cron_runs_as_session_turn(
|
||||
assert isinstance(msg, InboundMessage)
|
||||
assert msg.channel == "discord"
|
||||
assert msg.chat_id == "777"
|
||||
assert msg.session_key_override == "discord:456:thread:777"
|
||||
assert msg.metadata["context_chat_id"] == "456"
|
||||
assert msg.metadata["parent_channel_id"] == "456"
|
||||
assert msg.metadata["thread_id"] == "777"
|
||||
assert msg.session_key_override is None
|
||||
|
||||
|
||||
def test_gateway_cron_job_suppresses_intermediate_progress(
|
||||
|
||||
Reference in New Issue
Block a user