v2.3.0 (#429)
Co-authored-by: Carlo <carloantonio.patti@mistral.ai> Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai> Co-authored-by: Clement Sirieix <clem.sirieix@gmail.com> Co-authored-by: Michel Thomazo <michel.thomazo@mistral.ai> Co-authored-by: Clément Drouin <clement.drouin@mistral.ai> Co-authored-by: Vincent Guilloux <vincent.guilloux@mistral.ai> Co-authored-by: Thomas Kenbeek <thomas.kenbeek@mistral.ai> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
a560a47ce8
commit
5d2e01a6d7
139 changed files with 7152 additions and 1457 deletions
|
|
@ -227,6 +227,70 @@ class FileTool(BaseTool[FileToolArgs, FileToolResult, BaseToolConfig, BaseToolSt
|
|||
assert "file_tool" in tools
|
||||
|
||||
|
||||
class TestToolRuntimeAvailability:
|
||||
"""Tests for is_available() filtering in ToolManager."""
|
||||
|
||||
def test_unavailable_tool_excluded_from_available_tools(
|
||||
self, tmp_path: Path, monkeypatch
|
||||
):
|
||||
"""Tools where is_available() returns False should be excluded."""
|
||||
import sys
|
||||
|
||||
tool_dir = tmp_path / "tools"
|
||||
tool_dir.mkdir()
|
||||
(tool_dir / "conditional_tool.py").write_text("""
|
||||
import os
|
||||
from vibe.core.tools.base import BaseTool, BaseToolConfig, BaseToolState
|
||||
from pydantic import BaseModel
|
||||
|
||||
class ConditionalToolArgs(BaseModel):
|
||||
pass
|
||||
|
||||
class ConditionalToolResult(BaseModel):
|
||||
pass
|
||||
|
||||
class ConditionalTool(BaseTool[ConditionalToolArgs, ConditionalToolResult, BaseToolConfig, BaseToolState]):
|
||||
description = "Tool that requires TEST_VAR"
|
||||
|
||||
@classmethod
|
||||
def is_available(cls) -> bool:
|
||||
return bool(os.getenv("TEST_VAR"))
|
||||
|
||||
async def run(self, args, ctx=None):
|
||||
yield ConditionalToolResult()
|
||||
""")
|
||||
|
||||
to_remove = [k for k in sys.modules if "conditional_tool" in k]
|
||||
for k in to_remove:
|
||||
del sys.modules[k]
|
||||
|
||||
monkeypatch.delenv("TEST_VAR", raising=False)
|
||||
vibe_config = build_test_vibe_config(
|
||||
system_prompt_id="tests",
|
||||
include_project_context=False,
|
||||
tool_paths=[tool_dir],
|
||||
)
|
||||
manager = ToolManager(lambda: vibe_config)
|
||||
assert "conditional_tool" not in manager.available_tools
|
||||
|
||||
to_remove = [k for k in sys.modules if "conditional_tool" in k]
|
||||
for k in to_remove:
|
||||
del sys.modules[k]
|
||||
|
||||
monkeypatch.setenv("TEST_VAR", "1")
|
||||
manager2 = ToolManager(lambda: vibe_config)
|
||||
assert "conditional_tool" in manager2.available_tools
|
||||
|
||||
def test_default_is_available_returns_true(self):
|
||||
"""Tools without is_available() override should be available."""
|
||||
vibe_config = build_test_vibe_config(
|
||||
system_prompt_id="tests", include_project_context=False
|
||||
)
|
||||
manager = ToolManager(lambda: vibe_config)
|
||||
|
||||
assert "bash" in manager.available_tools
|
||||
|
||||
|
||||
class TestToolManagerModuleReuse:
|
||||
"""Tests for module reuse across ToolManager instances.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue