Files
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
Build Skills Index / trigger-deploy (push) Waiting to run
CI / Deny unrelated histories (push) Has been skipped
CI / CI timing report (push) Blocked by required conditions
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / All required checks pass (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

76 lines
2.7 KiB
Python

"""Tests that handle_function_call forwards session_id into registry.dispatch."""
import json
from unittest.mock import MagicMock, patch
def _make_registry(captured: dict):
"""Return a mock registry whose dispatch records the kwargs it receives."""
registry = MagicMock()
def _dispatch(name, args, **kwargs):
captured.update(kwargs)
return json.dumps({"result": "ok"})
registry.dispatch.side_effect = _dispatch
return registry
class TestSessionIdForwarding:
def test_standard_path_forwards_session_id(self):
"""registry.dispatch receives session_id on the normal tool path."""
captured = {}
with patch("model_tools.registry", _make_registry(captured)):
from model_tools import handle_function_call
handle_function_call(
"web_search",
{"query": "test"},
task_id="t1",
session_id="sess-abc",
skip_pre_tool_call_hook=True,
)
assert captured.get("session_id") == "sess-abc"
def test_execute_code_path_forwards_session_id(self):
"""registry.dispatch receives session_id on the execute_code path."""
captured = {}
with patch("model_tools.registry", _make_registry(captured)):
from model_tools import handle_function_call
handle_function_call(
"execute_code",
{"code": "print(1)"},
task_id="t1",
session_id="sess-xyz",
skip_pre_tool_call_hook=True,
)
assert captured.get("session_id") == "sess-xyz"
def test_session_id_default_is_none(self):
"""When session_id is omitted, dispatch receives None."""
captured = {}
with patch("model_tools.registry", _make_registry(captured)):
from model_tools import handle_function_call
handle_function_call(
"web_search",
{"query": "test"},
task_id="t1",
skip_pre_tool_call_hook=True,
)
assert "session_id" in captured
assert captured["session_id"] is None
def test_task_id_still_forwarded(self):
"""Existing task_id forwarding is not broken by this change."""
captured = {}
with patch("model_tools.registry", _make_registry(captured)):
from model_tools import handle_function_call
handle_function_call(
"web_search",
{"query": "test"},
task_id="task-999",
session_id="sess-1",
skip_pre_tool_call_hook=True,
)
assert captured.get("task_id") == "task-999"