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
CI / Deny unrelated histories (push) Has been skipped
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 / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

46 lines
1.5 KiB
Python

"""Test that tool_name is correctly persisted to the session DB for tool-result messages.
make_tool_result_message() sets tool_name on every tool-result dict at construction
time. This test verifies that the value survives the flush path into the session DB.
"""
from unittest.mock import MagicMock, patch
from run_agent import AIAgent
from agent.tool_dispatch_helpers import make_tool_result_message
def _make_agent(session_db):
with (
patch("run_agent.get_tool_definitions", return_value=[]),
patch("run_agent.check_toolset_requirements", return_value={}),
patch("run_agent.OpenAI"),
):
return AIAgent(
api_key="test-key",
base_url="https://openrouter.ai/api/v1",
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
session_db=session_db,
)
def test_tool_name_persisted_to_session_db():
"""tool_name set by make_tool_result_message must be passed through to
append_message so the column is populated on first flush to the session DB."""
session_db = MagicMock()
agent = _make_agent(session_db)
messages = [
{"role": "user", "content": "run a command"},
make_tool_result_message("terminal", "$ ls\nfile.txt", "c1"),
]
agent._flush_messages_to_session_db(messages)
tool_appends = [
c for c in session_db.append_message.call_args_list
if c.kwargs.get("role") == "tool"
]
assert len(tool_appends) == 1
assert tool_appends[0].kwargs["tool_name"] == "terminal"