mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-04-28 04:38:25 +00:00
test(tool_deduplication): pass app_config explicitly instead of patching removed singleton
This commit is contained in:
parent
3e6a34297d
commit
e99cb01fe1
@ -56,27 +56,25 @@ def _make_minimal_config(tools):
|
||||
return config
|
||||
|
||||
|
||||
@patch("deerflow.tools.tools.get_app_config")
|
||||
@patch("deerflow.tools.tools.is_host_bash_allowed", return_value=True)
|
||||
@patch("deerflow.tools.tools.reset_deferred_registry")
|
||||
def test_no_duplicates_returned(mock_reset, mock_bash, mock_cfg):
|
||||
def test_no_duplicates_returned(mock_reset, mock_bash):
|
||||
"""get_available_tools() never returns two tools with the same name."""
|
||||
mock_cfg.return_value = _make_minimal_config([])
|
||||
cfg = _make_minimal_config([])
|
||||
|
||||
# Patch the builtin tools so we control exactly what comes back.
|
||||
with patch("deerflow.tools.tools.BUILTIN_TOOLS", [_tool_alpha, _tool_alpha_dup, _tool_beta]):
|
||||
result = get_available_tools(include_mcp=False)
|
||||
result = get_available_tools(include_mcp=False, app_config=cfg)
|
||||
|
||||
names = [t.name for t in result]
|
||||
assert len(names) == len(set(names)), f"Duplicate names detected: {names}"
|
||||
|
||||
|
||||
@patch("deerflow.tools.tools.get_app_config")
|
||||
@patch("deerflow.tools.tools.is_host_bash_allowed", return_value=True)
|
||||
@patch("deerflow.tools.tools.reset_deferred_registry")
|
||||
def test_first_occurrence_wins(mock_reset, mock_bash, mock_cfg):
|
||||
def test_first_occurrence_wins(mock_reset, mock_bash):
|
||||
"""When duplicates exist, the first occurrence is kept."""
|
||||
mock_cfg.return_value = _make_minimal_config([])
|
||||
cfg = _make_minimal_config([])
|
||||
|
||||
sentinel_alpha = MagicMock(spec=BaseTool, name="_sentinel")
|
||||
sentinel_alpha.name = _tool_alpha.name # same name
|
||||
@ -84,23 +82,22 @@ def test_first_occurrence_wins(mock_reset, mock_bash, mock_cfg):
|
||||
sentinel_alpha_dup.name = _tool_alpha.name # same name — should be dropped
|
||||
|
||||
with patch("deerflow.tools.tools.BUILTIN_TOOLS", [sentinel_alpha, sentinel_alpha_dup, _tool_beta]):
|
||||
result = get_available_tools(include_mcp=False)
|
||||
result = get_available_tools(include_mcp=False, app_config=cfg)
|
||||
|
||||
returned_alpha = next(t for t in result if t.name == _tool_alpha.name)
|
||||
assert returned_alpha is sentinel_alpha
|
||||
|
||||
|
||||
@patch("deerflow.tools.tools.get_app_config")
|
||||
@patch("deerflow.tools.tools.is_host_bash_allowed", return_value=True)
|
||||
@patch("deerflow.tools.tools.reset_deferred_registry")
|
||||
def test_duplicate_triggers_warning(mock_reset, mock_bash, mock_cfg, caplog):
|
||||
def test_duplicate_triggers_warning(mock_reset, mock_bash, caplog):
|
||||
"""A warning is logged for every skipped duplicate."""
|
||||
import logging
|
||||
|
||||
mock_cfg.return_value = _make_minimal_config([])
|
||||
cfg = _make_minimal_config([])
|
||||
|
||||
with patch("deerflow.tools.tools.BUILTIN_TOOLS", [_tool_alpha, _tool_alpha_dup]):
|
||||
with caplog.at_level(logging.WARNING, logger="deerflow.tools.tools"):
|
||||
get_available_tools(include_mcp=False)
|
||||
get_available_tools(include_mcp=False, app_config=cfg)
|
||||
|
||||
assert any("Duplicate tool name" in r.message for r in caplog.records), "Expected a duplicate-tool warning in log output"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user