Skip to content

Commit 213fc6c

Browse files
committed
test: remove LangChain invoke methods integration test and rename test toolsets
Removed the comprehensive LangChain invoke methods integration test file which was testing various invocation patterns (astream_events, astream, stream, invoke, ainvoke) with both streaming and non-streaming scenarios. Also renamed TestToolSet to SampleToolSet across multiple integration test files to avoid confusion with actual test classes. The removed test file contained extensive setup for mocking OpenAI protocol services and comprehensive test cases for different LangChain/LangGraph invocation methods including streaming protocols and tool call scenarios. The toolset renaming affects AgentScope, CrewAI, Google ADK, LangChain, LangGraph, and PydanticAI integration tests to maintain consistency and prevent naming conflicts. feat(browser-toolset): add thread awareness and error handling for Playwright connections Added comprehensive thread awareness to BrowserToolSet's Playwright connection management. The implementation now tracks which thread created the Playwright connection and properly recreates it when the creating thread exits, preventing greenlet binding errors in multi-threaded environments like LangGraph ToolNodes. Also added proper error handling for 'cannot switch to a different thread' exceptions, automatically resetting both Playwright connections and sandbox instances when such errors occur to prevent cascading failures. The changes include new test coverage for concurrent access, thread lifecycle management, and error recovery scenarios to ensure robust operation in production environments. test(browser-toolset): enhance error handling tests with thread awareness Expanded the browser toolset error handling tests to cover thread-aware Playwright connection management. Added comprehensive test cases for concurrent access patterns, thread lifecycle scenarios, and specific error handling for greenlet binding issues that occur when switching between threads in LangGraph environments. The new tests verify proper connection reuse within the same thread, correct recreation when the creating thread exits, and appropriate error handling for cross-thread Playwright operations. chore(test): remove duplicate LangChain invoke methods test file Removed the duplicate test file that appears to be an older version of the LangChain invoke methods tests, maintaining only the comprehensive version that covers all invocation patterns and streaming scenarios. test: 移除 LangChain 调用方法集成测试并重命名测试工具集 移除了全面的 LangChain 调用方法集成测试文件,该文件测试了各种调用模式(astream_events、astream、stream、invoke、ainvoke)以及流式和非流式场景。同时在多个集成测试文件中将 TestToolSet 重命名为 SampleToolSet,以避免与实际测试类混淆。 被删除的测试文件包含大量用于模拟 OpenAI 协议服务的设置,以及针对不同 LangChain/LangGraph 调用方法的全面测试用例,包括流式协议和工具调用场景。 工具集重命名影响了 AgentScope、CrewAI、Google ADK、LangChain、LangGraph 和 PydanticAI 集成测试,以保持一致性并防止命名冲突。 feat(browser-toolset): 为 Playwright 连接添加线程感知和错误处理功能 为 BrowserToolSet 的 Playwright 连接管理添加了全面的线程感知功能。实现现在跟踪哪个线程创建了 Playwright 连接,并在线程退出时正确重新创建它,防止在多线程环境(如 LangGraph ToolNodes)中的 greenlet 绑定错误。 还为 'cannot switch to a different thread' 异常添加了适当的错误处理,在发生此类错误时自动重置 Playwright 连接和沙箱实例,以防止级联故障。 更改包括对并发访问、线程生命周期管理和错误恢复场景的新测试覆盖,以确保在生产环境中稳健运行。 test(browser-toolset): 使用线程感知增强错误处理测试 扩展浏览器工具集错误处理测试以涵盖线程感知的 Playwright 连接管理。添加了对并发访问模式、线程生命周期场景的全面测试用例,以及针对在 LangGraph 环境中跨线程切换时发生的 greenlet 绑定问题的具体错误处理。 新测试验证同一线程内的正确连接复用、创建线程退出时的正确重建,以及跨线程 Playwright 操作的适当错误处理。 chore(test): 删除重复的 LangChain 调用方法测试文件 删除似乎是 LangChain 调用方法测试旧版本的重复测试文件,只保留涵盖所有调用模式和流式场景的完整版本。 Change-Id: I4d963b9b041bf81cc2f5f20d3c2f7cd47abe6bbb Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent ac0252e commit 213fc6c

File tree

8 files changed

+41
-39
lines changed

8 files changed

+41
-39
lines changed

tests/unittests/integration/langchain/test_agent_invoke_methods.py renamed to tests/unittests/integration/langchain/test_agent_invoke_methods_unittests.py

File renamed without changes.

tests/unittests/integration/test_agentscope.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .scenarios import Scenarios
2222

2323

24-
class TestToolSet(CommonToolSet):
24+
class SampleToolSet(CommonToolSet):
2525
"""测试用工具集"""
2626

2727
def __init__(self, timezone: str = "UTC"):
@@ -150,9 +150,9 @@ def mocked_model(
150150
return model("mock-model")
151151

152152
@pytest.fixture
153-
def mocked_toolset(self) -> TestToolSet:
153+
def mocked_toolset(self) -> SampleToolSet:
154154
"""创建 mock 的工具集"""
155-
return TestToolSet(timezone="UTC")
155+
return SampleToolSet(timezone="UTC")
156156

157157
# =========================================================================
158158
# 测试:简单对话(无工具调用)
@@ -194,7 +194,7 @@ async def test_multi_tool_calls(
194194
self,
195195
mock_server: MockLLMServer,
196196
mocked_model: CommonModel,
197-
mocked_toolset: TestToolSet,
197+
mocked_toolset: SampleToolSet,
198198
):
199199
"""测试多工具同时调用"""
200200
# 使用默认的多工具场景
@@ -223,7 +223,7 @@ async def test_stream_options_validation(
223223
self,
224224
mock_server: MockLLMServer,
225225
mocked_model: CommonModel,
226-
mocked_toolset: TestToolSet,
226+
mocked_toolset: SampleToolSet,
227227
):
228228
"""测试 stream_options 在请求中的正确性"""
229229
# 使用默认场景

tests/unittests/integration/test_browser_toolset_error_handling.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ def toolset(self, mock_sandbox):
337337
ts.lock = threading.Lock()
338338
return ts
339339

340-
def test_get_playwright_records_creating_thread(self, toolset, mock_sandbox):
340+
def test_get_playwright_records_creating_thread(
341+
self, toolset, mock_sandbox
342+
):
341343
"""测试 _get_playwright 记录创建连接的线程"""
342344
toolset._get_playwright(mock_sandbox)
343345

tests/unittests/integration/test_crewai.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from .scenarios import Scenarios
2424

2525

26-
class TestToolSet(CommonToolSet):
26+
class SampleToolSet(CommonToolSet):
2727
"""测试用工具集"""
2828

2929
def __init__(self, timezone: str = "UTC"):
@@ -149,9 +149,9 @@ def mocked_model(
149149
return model("mock-model")
150150

151151
@pytest.fixture
152-
def mocked_toolset(self) -> TestToolSet:
152+
def mocked_toolset(self) -> SampleToolSet:
153153
"""创建 mock 的工具集"""
154-
return TestToolSet(timezone="UTC")
154+
return SampleToolSet(timezone="UTC")
155155

156156
# =========================================================================
157157
# 测试:简单对话(无工具调用)
@@ -191,7 +191,7 @@ def test_multi_tool_calls(
191191
self,
192192
mock_server: MockLLMServer,
193193
mocked_model: CommonModel,
194-
mocked_toolset: TestToolSet,
194+
mocked_toolset: SampleToolSet,
195195
):
196196
"""测试多工具同时调用
197197
@@ -210,7 +210,7 @@ def test_stream_options_validation(
210210
self,
211211
mock_server: MockLLMServer,
212212
mocked_model: CommonModel,
213-
mocked_toolset: TestToolSet,
213+
mocked_toolset: SampleToolSet,
214214
):
215215
"""测试 stream_options 在请求中的正确性
216216

tests/unittests/integration/test_google_adk.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .scenarios import Scenarios
2222

2323

24-
class TestToolSet(CommonToolSet):
24+
class SampleToolSet(CommonToolSet):
2525
"""测试用工具集"""
2626

2727
def __init__(self, timezone: str = "UTC"):
@@ -208,9 +208,9 @@ def mocked_model(
208208
return model("mock-model")
209209

210210
@pytest.fixture
211-
def mocked_toolset(self) -> TestToolSet:
211+
def mocked_toolset(self) -> SampleToolSet:
212212
"""创建 mock 的工具集"""
213-
return TestToolSet(timezone="UTC")
213+
return SampleToolSet(timezone="UTC")
214214

215215
# =========================================================================
216216
# 测试:简单对话(无工具调用)
@@ -252,7 +252,7 @@ async def test_single_tool_call(
252252
self,
253253
mock_server: MockLLMServer,
254254
mocked_model: CommonModel,
255-
mocked_toolset: TestToolSet,
255+
mocked_toolset: SampleToolSet,
256256
):
257257
"""测试单次工具调用"""
258258
# 配置场景
@@ -284,7 +284,7 @@ async def test_multi_tool_calls(
284284
self,
285285
mock_server: MockLLMServer,
286286
mocked_model: CommonModel,
287-
mocked_toolset: TestToolSet,
287+
mocked_toolset: SampleToolSet,
288288
):
289289
"""测试多工具同时调用"""
290290
# 使用默认的多工具场景
@@ -315,7 +315,7 @@ async def test_stream_options_validation(
315315
self,
316316
mock_server: MockLLMServer,
317317
mocked_model: CommonModel,
318-
mocked_toolset: TestToolSet,
318+
mocked_toolset: SampleToolSet,
319319
):
320320
"""测试 stream_options 在请求中的正确性"""
321321
# 使用默认场景

tests/unittests/integration/test_langchain.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from .scenarios import Scenarios
2323

2424

25-
class TestToolSet(CommonToolSet):
25+
class SampleToolSet(CommonToolSet):
2626
"""测试用工具集"""
2727

2828
def __init__(self, timezone: str = "UTC"):
@@ -201,9 +201,9 @@ def mocked_model(
201201
return model("mock-model")
202202

203203
@pytest.fixture
204-
def mocked_toolset(self) -> TestToolSet:
204+
def mocked_toolset(self) -> SampleToolSet:
205205
"""创建 mock 的工具集"""
206-
return TestToolSet(timezone="UTC")
206+
return SampleToolSet(timezone="UTC")
207207

208208
# =========================================================================
209209
# 测试:简单对话(无工具调用)
@@ -244,7 +244,7 @@ def test_single_tool_call(
244244
self,
245245
mock_server: MockLLMServer,
246246
mocked_model: CommonModel,
247-
mocked_toolset: TestToolSet,
247+
mocked_toolset: SampleToolSet,
248248
):
249249
"""测试单次工具调用"""
250250
# 配置场景
@@ -276,7 +276,7 @@ def test_multi_tool_calls(
276276
self,
277277
mock_server: MockLLMServer,
278278
mocked_model: CommonModel,
279-
mocked_toolset: TestToolSet,
279+
mocked_toolset: SampleToolSet,
280280
):
281281
"""测试多工具同时调用"""
282282
# 使用默认的多工具场景
@@ -307,7 +307,7 @@ def test_stream_options_in_requests(
307307
self,
308308
mock_server: MockLLMServer,
309309
mocked_model: CommonModel,
310-
mocked_toolset: TestToolSet,
310+
mocked_toolset: SampleToolSet,
311311
):
312312
"""测试请求中的 stream_options 设置"""
313313
from langchain_openai import ChatOpenAI
@@ -324,7 +324,7 @@ def test_stream_options_validation(
324324
self,
325325
mock_server: MockLLMServer,
326326
mocked_model: CommonModel,
327-
mocked_toolset: TestToolSet,
327+
mocked_toolset: SampleToolSet,
328328
):
329329
"""测试 stream_options 在请求中的正确性"""
330330
# 使用默认场景
@@ -370,7 +370,7 @@ async def test_async_invoke(
370370
self,
371371
mock_server: MockLLMServer,
372372
mocked_model: CommonModel,
373-
mocked_toolset: TestToolSet,
373+
mocked_toolset: SampleToolSet,
374374
):
375375
"""测试异步调用"""
376376
# 使用默认场景

tests/unittests/integration/test_langgraph.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from .scenarios import Scenarios
2323

2424

25-
class TestToolSet(CommonToolSet):
25+
class SampleToolSet(CommonToolSet):
2626
"""测试用工具集"""
2727

2828
def __init__(self, timezone: str = "UTC"):
@@ -233,9 +233,9 @@ def mocked_model(
233233
return model("mock-model")
234234

235235
@pytest.fixture
236-
def mocked_toolset(self) -> TestToolSet:
236+
def mocked_toolset(self) -> SampleToolSet:
237237
"""创建 mock 的工具集"""
238-
return TestToolSet(timezone="UTC")
238+
return SampleToolSet(timezone="UTC")
239239

240240
# =========================================================================
241241
# 测试:简单对话(无工具调用)
@@ -275,7 +275,7 @@ def test_single_tool_call(
275275
self,
276276
mock_server: MockLLMServer,
277277
mocked_model: CommonModel,
278-
mocked_toolset: TestToolSet,
278+
mocked_toolset: SampleToolSet,
279279
):
280280
"""测试单次工具调用"""
281281
# 配置场景
@@ -306,7 +306,7 @@ def test_multi_tool_calls(
306306
self,
307307
mock_server: MockLLMServer,
308308
mocked_model: CommonModel,
309-
mocked_toolset: TestToolSet,
309+
mocked_toolset: SampleToolSet,
310310
):
311311
"""测试多工具同时调用"""
312312
# 使用默认的多工具场景
@@ -336,7 +336,7 @@ def test_stream_options_validation(
336336
self,
337337
mock_server: MockLLMServer,
338338
mocked_model: CommonModel,
339-
mocked_toolset: TestToolSet,
339+
mocked_toolset: SampleToolSet,
340340
):
341341
"""测试 stream_options 在请求中的正确性"""
342342
# 使用默认场景
@@ -377,7 +377,7 @@ async def test_async_invoke(
377377
self,
378378
mock_server: MockLLMServer,
379379
mocked_model: CommonModel,
380-
mocked_toolset: TestToolSet,
380+
mocked_toolset: SampleToolSet,
381381
):
382382
"""测试异步调用"""
383383
# 使用默认场景

tests/unittests/integration/test_pydanticai.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from .scenarios import Scenarios
2323

2424

25-
class TestToolSet(CommonToolSet):
25+
class SampleToolSet(CommonToolSet):
2626
"""测试用工具集"""
2727

2828
def __init__(self, timezone: str = "UTC"):
@@ -203,9 +203,9 @@ def mocked_model(
203203
return model("mock-model")
204204

205205
@pytest.fixture
206-
def mocked_toolset(self) -> TestToolSet:
206+
def mocked_toolset(self) -> SampleToolSet:
207207
"""创建 mock 的工具集"""
208-
return TestToolSet(timezone="UTC")
208+
return SampleToolSet(timezone="UTC")
209209

210210
# =========================================================================
211211
# 测试:简单对话(无工具调用)
@@ -245,7 +245,7 @@ def test_single_tool_call(
245245
self,
246246
mock_server: MockLLMServer,
247247
mocked_model: CommonModel,
248-
mocked_toolset: TestToolSet,
248+
mocked_toolset: SampleToolSet,
249249
):
250250
"""测试单次工具调用"""
251251
# 配置场景
@@ -276,7 +276,7 @@ def test_multi_tool_calls(
276276
self,
277277
mock_server: MockLLMServer,
278278
mocked_model: CommonModel,
279-
mocked_toolset: TestToolSet,
279+
mocked_toolset: SampleToolSet,
280280
):
281281
"""测试多工具同时调用"""
282282
# 使用默认的多工具场景
@@ -305,7 +305,7 @@ def test_stream_options_validation(
305305
self,
306306
mock_server: MockLLMServer,
307307
mocked_model: CommonModel,
308-
mocked_toolset: TestToolSet,
308+
mocked_toolset: SampleToolSet,
309309
):
310310
"""测试 stream_options 在请求中的正确性
311311
@@ -349,7 +349,7 @@ async def test_async_invoke(
349349
self,
350350
mock_server: MockLLMServer,
351351
mocked_model: CommonModel,
352-
mocked_toolset: TestToolSet,
352+
mocked_toolset: SampleToolSet,
353353
):
354354
"""测试异步调用"""
355355
# 使用默认场景

0 commit comments

Comments
 (0)