Skip to content

Commit 116db18

Browse files
committed
✨ image to text tool v2
1 parent eb338fe commit 116db18

File tree

5 files changed

+62
-28
lines changed

5 files changed

+62
-28
lines changed

test/backend/agents/test_create_agent_info.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import pytest
22
import sys
33
import types
4-
from pathlib import Path
54
from unittest.mock import AsyncMock, MagicMock, patch, Mock, PropertyMock
65

7-
PROJECT_ROOT = Path(__file__).resolve().parents[3]
8-
if str(PROJECT_ROOT) not in sys.path:
9-
sys.path.insert(0, str(PROJECT_ROOT))
6+
from test.common.env_test_utils import bootstrap_env
7+
8+
env_state = bootstrap_env()
9+
consts_const = env_state["mock_const"]
1010

1111
# Utilities ---------------------------------------------------------------
1212
def _create_stub_module(name: str, **attrs):
@@ -17,28 +17,21 @@ def _create_stub_module(name: str, **attrs):
1717
return module
1818

1919

20-
# Mock consts module first to avoid ModuleNotFoundError
21-
consts_mock = MagicMock()
22-
consts_mock.const = MagicMock()
23-
# Set required constants in consts.const
24-
consts_mock.const.MINIO_ENDPOINT = "http://localhost:9000"
25-
consts_mock.const.MINIO_ACCESS_KEY = "test_access_key"
26-
consts_mock.const.MINIO_SECRET_KEY = "test_secret_key"
27-
consts_mock.const.MINIO_REGION = "us-east-1"
28-
consts_mock.const.MINIO_DEFAULT_BUCKET = "test-bucket"
29-
consts_mock.const.POSTGRES_HOST = "localhost"
30-
consts_mock.const.POSTGRES_USER = "test_user"
31-
consts_mock.const.NEXENT_POSTGRES_PASSWORD = "test_password"
32-
consts_mock.const.POSTGRES_DB = "test_db"
33-
consts_mock.const.POSTGRES_PORT = 5432
34-
consts_mock.const.DEFAULT_TENANT_ID = "default_tenant"
35-
consts_mock.const.LOCAL_MCP_SERVER = "http://localhost:5011"
36-
consts_mock.const.MODEL_CONFIG_MAPPING = {"llm": "llm_config"}
37-
consts_mock.const.LANGUAGE = {"ZH": "zh"}
38-
39-
# Add the mocked consts module to sys.modules
40-
sys.modules['consts'] = consts_mock
41-
sys.modules['consts.const'] = consts_mock.const
20+
# Configure required constants via shared bootstrap env
21+
consts_const.MINIO_ENDPOINT = "http://localhost:9000"
22+
consts_const.MINIO_ACCESS_KEY = "test_access_key"
23+
consts_const.MINIO_SECRET_KEY = "test_secret_key"
24+
consts_const.MINIO_REGION = "us-east-1"
25+
consts_const.MINIO_DEFAULT_BUCKET = "test-bucket"
26+
consts_const.POSTGRES_HOST = "localhost"
27+
consts_const.POSTGRES_USER = "test_user"
28+
consts_const.NEXENT_POSTGRES_PASSWORD = "test_password"
29+
consts_const.POSTGRES_DB = "test_db"
30+
consts_const.POSTGRES_PORT = 5432
31+
consts_const.DEFAULT_TENANT_ID = "default_tenant"
32+
consts_const.LOCAL_MCP_SERVER = "http://localhost:5011"
33+
consts_const.MODEL_CONFIG_MAPPING = {"llm": "llm_config"}
34+
consts_const.LANGUAGE = {"ZH": "zh"}
4235

4336
# Mock utils module
4437
utils_mock = MagicMock()

test/backend/app/test_image_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
if str(TEST_ROOT) not in sys.path:
99
sys.path.append(str(TEST_ROOT))
1010

11-
from common.env_test_utils import bootstrap_env
11+
from test.common.env_test_utils import bootstrap_env
1212

1313
helpers_env = bootstrap_env()
1414

test/backend/services/test_image_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
if str(TEST_ROOT) not in sys.path:
99
sys.path.append(str(TEST_ROOT))
1010

11-
from common.env_test_utils import bootstrap_env
11+
from test.common.env_test_utils import bootstrap_env
1212

1313
helpers_env = bootstrap_env()
1414

test/sdk/core/agents/test_nexent_agent.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,46 @@ def test_create_local_tool_analyze_image_tool(nexent_agent_instance):
693693
assert result == mock_analyze_tool_instance
694694

695695

696+
def test_create_local_tool_analyze_image_tool(nexent_agent_instance):
697+
"""Test AnalyzeImageTool creation injects observer and metadata."""
698+
mock_analyze_tool_class = MagicMock()
699+
mock_analyze_tool_instance = MagicMock()
700+
mock_analyze_tool_class.return_value = mock_analyze_tool_instance
701+
702+
tool_config = ToolConfig(
703+
class_name="AnalyzeImageTool",
704+
name="analyze_image",
705+
description="desc",
706+
inputs="{}",
707+
output_type="string",
708+
params={"prompt": "describe this"},
709+
source="local",
710+
metadata={
711+
"vlm_model": "vlm_model_obj",
712+
"storage_client": "storage_client_obj",
713+
},
714+
)
715+
716+
original_value = nexent_agent.__dict__.get("AnalyzeImageTool")
717+
nexent_agent.__dict__["AnalyzeImageTool"] = mock_analyze_tool_class
718+
719+
try:
720+
result = nexent_agent_instance.create_local_tool(tool_config)
721+
finally:
722+
if original_value is not None:
723+
nexent_agent.__dict__["AnalyzeImageTool"] = original_value
724+
elif "AnalyzeImageTool" in nexent_agent.__dict__:
725+
del nexent_agent.__dict__["AnalyzeImageTool"]
726+
727+
mock_analyze_tool_class.assert_called_once_with(
728+
observer=nexent_agent_instance.observer,
729+
vlm_model="vlm_model_obj",
730+
storage_client="storage_client_obj",
731+
prompt="describe this",
732+
)
733+
assert result == mock_analyze_tool_instance
734+
735+
696736
def test_create_local_tool_with_observer_attribute(nexent_agent_instance):
697737
"""Test create_local_tool sets observer attribute on tool if it exists."""
698738
mock_tool_class = MagicMock()

test/sdk/core/tools/test_analyze_image_tool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,4 @@ def test_forward_impl_wraps_model_errors(
119119
tool._forward_impl([b"img"], "question")
120120

121121
mock_vlm_model.analyze_image.assert_called_once()
122+

0 commit comments

Comments
 (0)