Skip to content

Commit 52906b2

Browse files
Merge pull request #55 from LittleCoinCoin/dev
Dev
2 parents 23876c8 + 18f6c84 commit 52906b2

8 files changed

+225
-123
lines changed

.github/workflows/semantic-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
pip install -e .
3333
3434
- name: Run tests
35-
run: python run_tests.py --regression --feature
35+
run: python run_tests.py --regression --feature --skip requires_api_key
3636

3737
release:
3838
needs: test

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies = [
3737
"ollama==0.5.1",
3838
"openai==1.97.0",
3939

40-
"hatch @ git+https://github.com/CrackingShells/Hatch.git@feat/dependency-installers"
40+
"hatch @ git+https://github.com/CrackingShells/Hatch.git@v0.5.1"
4141
]
4242

4343
[project.scripts]

tests/feature_test_llm_provider_base.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ def llm_to_hatchling_tool_call(self, event):
107107
def mcp_to_provider_tool(self, tool_info):
108108
"""Mock implementation of mcp_to_provider_tool."""
109109
return {"type": "function", "function": {"name": tool_info.name}}
110+
111+
def hatchling_to_llm_tool_call(self, tool_call):
112+
"""Mock implementation of hatchling_to_llm_tool_call."""
113+
return {
114+
"id": tool_call.tool_call_id,
115+
"function": {
116+
"name": tool_call.function_name,
117+
"arguments": tool_call.arguments
118+
}
119+
}
120+
121+
def hatchling_to_provider_tool_result(self, tool_result):
122+
"""Mock implementation of hatchling_to_provider_tool_result."""
123+
return {
124+
"tool_call_id": tool_result.tool_call_id,
125+
"content": str(tool_result.result)
126+
}
110127

111128
# Should be able to instantiate concrete implementation
112129
test_settings = test_data.get_test_settings()
@@ -164,6 +181,23 @@ def llm_to_hatchling_tool_call(self, event):
164181
def mcp_to_provider_tool(self, tool_info):
165182
"""Mock implementation of mcp_to_provider_tool."""
166183
return {"type": "function", "function": {"name": tool_info.name}}
184+
185+
def hatchling_to_llm_tool_call(self, tool_call):
186+
"""Mock implementation of hatchling_to_llm_tool_call."""
187+
return {
188+
"id": tool_call.tool_call_id,
189+
"function": {
190+
"name": tool_call.function_name,
191+
"arguments": tool_call.arguments
192+
}
193+
}
194+
195+
def hatchling_to_provider_tool_result(self, tool_result):
196+
"""Mock implementation of hatchling_to_provider_tool_result."""
197+
return {
198+
"tool_call_id": tool_result.tool_call_id,
199+
"content": str(tool_result.result)
200+
}
167201

168202
provider = OllamaProvider({})
169203
self.assertEqual(provider.provider_name, "ollama",

tests/feature_test_mcp_tool_call_subscriber.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44
using provider methods directly instead of the registry pattern.
55
"""
66

7+
import os
78
import sys
89
import logging
910
import unittest
1011
import time
12+
from pathlib import Path
13+
from asyncio.log import logger
1114
from unittest.mock import MagicMock
15+
from dotenv import load_dotenv
1216

1317
from tests.test_decorators import feature_test, requires_api_key
1418

19+
from hatchling.config.openai_settings import OpenAISettings
20+
from hatchling.config.settings import AppSettings
1521
from hatchling.core.llm.event_system import Event, EventType
16-
1722
from hatchling.mcp_utils.mcp_tool_execution import MCPToolExecution
1823
from hatchling.mcp_utils.mcp_tool_call_subscriber import MCPToolCallSubscriber
1924
from hatchling.core.llm.providers.registry import ProviderRegistry
@@ -98,8 +103,23 @@ def test_on_event_openai(self):
98103
timestamp=time.time()
99104
)
100105

106+
# load the test api key from local .env
107+
# Load environment variables for API key
108+
env_path = Path(__file__).parent / ".env"
109+
if load_dotenv(env_path):
110+
logger.info("Loaded environment variables from .env file")
111+
else:
112+
logger.warning("No .env file found, using system environment variables")
113+
114+
api_key = os.environ.get('OPENAI_API_KEY')
115+
if not api_key:
116+
logger.warning("OPENAI_API_KEY environment variable not set")
117+
self.skipTest("OpenAI API key is not set. Please set OPENAI_API_KEY environment variable.")
118+
101119
# Use provider to get the strategy
102-
provider = ProviderRegistry.get_provider(ELLMProvider.OPENAI)
120+
openai_settings = OpenAISettings(api_key=api_key, timeout=30.0)
121+
app_settings = AppSettings(openai=openai_settings)
122+
provider = ProviderRegistry.get_provider(ELLMProvider.OPENAI, app_settings)
103123
subscriber = MCPToolCallSubscriber(self.mock_tool_execution)
104124
subscriber.on_event(first_event)
105125

tests/feature_test_provider_registry.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ def llm_to_hatchling_tool_call(self, event):
7474
def mcp_to_provider_tool(self, tool_info):
7575
"""Mock implementation of mcp_to_provider_tool."""
7676
return {"type": "function", "function": {"name": tool_info.name}}
77+
78+
def hatchling_to_llm_tool_call(self, tool_call):
79+
"""Mock implementation of hatchling_to_llm_tool_call."""
80+
return {
81+
"id": tool_call.tool_call_id,
82+
"function": {
83+
"name": tool_call.function_name,
84+
"arguments": tool_call.arguments
85+
}
86+
}
87+
88+
def hatchling_to_provider_tool_result(self, tool_result):
89+
"""Mock implementation of hatchling_to_provider_tool_result."""
90+
return {
91+
"tool_call_id": tool_result.tool_call_id,
92+
"content": str(tool_result.result)
93+
}
7794

7895
return TestProvider
7996

tests/integration_test_command_system.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ def test_mcp_command_structure(self):
136136
'mcp:tool:info',
137137
'mcp:tool:enable',
138138
'mcp:tool:disable',
139-
'mcp:tool:execute',
140-
'mcp:tool:schema',
139+
#'mcp:tool:execute',
140+
#'mcp:tool:schema',
141141
'mcp:health',
142-
'mcp:citations',
143-
'mcp:reset'
142+
#'mcp:citations',
143+
#'mcp:reset'
144144
]
145145

146146
for cmd_name in expected_commands:

tests/integration_test_openai.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from hatchling.config.openai_settings import OpenAISettings
3636
from hatchling.config.settings import AppSettings
3737
from hatchling.config.llm_settings import ELLMProvider
38-
from hatchling.mcp_utils.mcp_tool_lifecycle_subscriber import ToolLifecycleSubscriber
3938
from hatchling.core.llm.providers.registry import ProviderRegistry
4039
from hatchling.mcp_utils.mcp_tool_data import MCPToolInfo, MCPToolStatus, MCPToolStatusReason
4140
from hatchling.core.llm.event_system import (
@@ -47,7 +46,6 @@
4746
EventType,
4847
Event
4948
)
50-
from hatchling.mcp_utils.mcp_tool_lifecycle_subscriber import ToolLifecycleSubscriber
5149
from hatchling.core.llm.providers.openai_provider import OpenAIProvider
5250

5351
logger = logging.getLogger("integration_test_openai")
@@ -165,6 +163,7 @@ def tearDown(self):
165163
self.loop.close()
166164

167165
@integration_test
166+
@requires_api_key
168167
def test_provider_registration(self):
169168
"""Test that OpenAIProvider is properly registered in the provider registry.
170169
@@ -238,6 +237,7 @@ def test_health_check_sync(self):
238237
self.fail(f"Health check test failed: {e}")
239238

240239
@integration_test
240+
@requires_api_key
241241
def test_payload_preparation(self):
242242
"""Test chat payload preparation for API requests.
243243
@@ -430,6 +430,7 @@ def test_simple_chat_integration_sync(self):
430430
self.fail(f"Simple chat integration test failed: {e}")
431431

432432
@integration_test
433+
@requires_api_key
433434
def test_api_key_validation(self):
434435
"""Test that provider validates API key requirement.
435436

0 commit comments

Comments
 (0)