Skip to content

Commit ad4890f

Browse files
congxiao-wxxclaude
andcommitted
test(e2e): add workspace_id parameter to e2e test fixtures
Update all e2e tests to pass workspace_id through test fixtures, covering sandbox, template, credential, model, agent_runtime, and workspace_id-specific test cases. Change-Id: Ia3bd725749ab1539207fb65c950c03749018fba5 Co-developed-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: congxiao.wxx <congxiao.wxx@alibaba-inc.com>
1 parent 651caaa commit ad4890f

9 files changed

Lines changed: 175 additions & 72 deletions

tests/e2e/test_agent_ruintime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
77
使用 `make codegen` 命令重新生成。
88
9-
source: tests/e2e/__test_agent_ruintime_async_template.py
9+
source: .claude/worktrees/infallible-pasteur-94186e/tests/e2e/__test_agent_ruintime_async_template.py
1010
1111
1212
Credential 模块的 E2E 测试

tests/e2e/test_credential.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
77
使用 `make codegen` 命令重新生成。
88
9-
source: tests/e2e/__test_credential_async_template.py
9+
source: .claude/worktrees/infallible-pasteur-94186e/tests/e2e/__test_credential_async_template.py
1010
1111
1212
Credential 模块的 E2E 测试

tests/e2e/test_model.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
77
使用 `make codegen` 命令重新生成。
88
9-
source: tests/e2e/__test_model_async_template.py
9+
source: .claude/worktrees/infallible-pasteur-94186e/tests/e2e/__test_model_async_template.py
1010
1111
1212
Model 模块的 E2E 测试
@@ -274,7 +274,9 @@ def assert_model_service(ms: ModelService):
274274

275275
# 更新 model service
276276
new_description = f"更新后的描述 - {time.time()}"
277-
ms.update(ModelServiceUpdateInput(description=new_description))
277+
ms.update(
278+
ModelServiceUpdateInput(description=new_description)
279+
)
278280
ms.wait_until_ready_or_failed()
279281

280282
# 检查返回的内容是否符合预期
@@ -310,7 +312,9 @@ def assert_model_service_2(ms: ModelService):
310312
assert_model_service_2(ms2)
311313

312314
# 列举 model services
313-
ms_list = client.list(ModelServiceListInput(model_type=ModelType.LLM))
315+
ms_list = client.list(
316+
ModelServiceListInput(model_type=ModelType.LLM)
317+
)
314318
assert len(ms_list) > 0
315319
matched_ms = 0
316320
for m in ms_list:
@@ -531,7 +535,10 @@ async def test_model_service_with_credential_async(
531535
await ms.delete_async()
532536
await cr.delete_async()
533537

534-
def test_model_service_with_credential(self, model_service_name: str):
538+
539+
def test_model_service_with_credential(
540+
self, model_service_name: str
541+
):
535542
# 创建 Credential
536543
from agentrun.credential import (
537544
Credential,
@@ -812,7 +819,9 @@ def test_model_proxy_lifecycle(self, model_proxy_name: str):
812819
time2 = datetime.datetime.now(datetime.timezone.utc)
813820

814821
assert mp.model_proxy_id
815-
mp2 = client.get(name=model_proxy_name, backend_type=BackendType.PROXY)
822+
mp2 = client.get(
823+
name=model_proxy_name, backend_type=BackendType.PROXY
824+
)
816825

817826
# 检查返回的内容是否符合预期
818827
pre_created_at: datetime.datetime
@@ -849,7 +858,9 @@ def assert_model_proxy(mp: ModelProxy):
849858

850859
# 更新 model proxy
851860
new_description = f"更新后的描述 - {time.time()}"
852-
mp.update(ModelProxyUpdateInput(description=new_description))
861+
mp.update(
862+
ModelProxyUpdateInput(description=new_description)
863+
)
853864
mp.wait_until_ready_or_failed()
854865

855866
# 检查返回的内容是否符合预期
@@ -912,7 +923,9 @@ def assert_model_proxy_2(mp: ModelProxy):
912923

913924
# 验证删除
914925
with pytest.raises(ResourceNotExistError):
915-
client.get(name=model_proxy_name, backend_type=BackendType.PROXY)
926+
client.get(
927+
name=model_proxy_name, backend_type=BackendType.PROXY
928+
)
916929

917930
defer()
918931

@@ -1113,7 +1126,9 @@ async def defer2():
11131126

11141127
return ms, mp, defer2
11151128

1116-
def prepare_model_proxy_with_credential(self, model_proxy_name: str):
1129+
def prepare_model_proxy_with_credential(
1130+
self, model_proxy_name: str
1131+
):
11171132

11181133
from agentrun.credential import (
11191134
Credential,
@@ -1208,7 +1223,9 @@ async def test_model_proxy_invoke_credential_async(
12081223

12091224
await defer()
12101225

1211-
def test_model_proxy_invoke_credential(self, model_proxy_name: str):
1226+
def test_model_proxy_invoke_credential(
1227+
self, model_proxy_name: str
1228+
):
12121229
_, mp, defer = self.prepare_model_proxy_with_credential(
12131230
model_proxy_name
12141231
)

tests/e2e/test_sandbox_aio.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
77
使用 `make codegen` 命令重新生成。
88
9-
source: tests/e2e/__test_sandbox_aio_async_template.py
9+
source: .claude/worktrees/infallible-pasteur-94186e/tests/e2e/__test_sandbox_aio_async_template.py
1010
1111
1212
Sandbox All-in-One (AIO) 模块的 E2E 测试
@@ -518,7 +518,9 @@ async def test_context_create_and_execute_async(self, sandbox):
518518

519519
def test_context_create_and_execute(self, sandbox):
520520
"""测试创建上下文并执行代码"""
521-
with sandbox.context.create(language=CodeLanguage.PYTHON) as ctx:
521+
with sandbox.context.create(
522+
language=CodeLanguage.PYTHON
523+
) as ctx:
522524
# 执行代码
523525
result = ctx.execute(code="x = 10\nprint(x)")
524526
assert result is not None
@@ -545,7 +547,9 @@ async def test_context_list_async(self, sandbox):
545547

546548
def test_context_list(self, sandbox):
547549
"""测试列举上下文"""
548-
with sandbox.context.create(language=CodeLanguage.PYTHON) as ctx:
550+
with sandbox.context.create(
551+
language=CodeLanguage.PYTHON
552+
) as ctx:
549553
contexts = ctx.list()
550554
assert contexts is not None
551555
assert isinstance(contexts, (list, dict))
@@ -1105,7 +1109,9 @@ def test_browser_code_file_integration(self, sandbox):
11051109

11061110
# 3. 文件操作
11071111
test_path = f"/home/user/integration-{int(time.time())}.txt"
1108-
sandbox.file.write(path=test_path, content="integration test")
1112+
sandbox.file.write(
1113+
path=test_path, content="integration test"
1114+
)
11091115
file_result = sandbox.file.read(path=test_path)
11101116
sandbox.file_system.remove(path=test_path)
11111117
assert file_result is not None
@@ -1218,7 +1224,9 @@ def test_aio_lifecycle(self, template):
12181224
path="/home/user/lifecycle.txt",
12191225
content="test",
12201226
)
1221-
read_result = sb.file.read(path="/home/user/lifecycle.txt")
1227+
read_result = sb.file.read(
1228+
path="/home/user/lifecycle.txt"
1229+
)
12221230
assert read_result is not None
12231231

12241232
# 7. 删除

tests/e2e/test_sandbox_browser.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
77
使用 `make codegen` 命令重新生成。
88
9-
source: tests/e2e/__test_sandbox_browser_async_template.py
9+
source: .claude/worktrees/infallible-pasteur-94186e/tests/e2e/__test_sandbox_browser_async_template.py
1010
1111
1212
Sandbox Browser 模块的 E2E 测试
@@ -77,7 +77,9 @@ async def test_create_browser_sandbox_async(
7777
finally:
7878
await sb.delete_async()
7979

80-
def test_create_browser_sandbox(self, browser_template: Template):
80+
def test_create_browser_sandbox(
81+
self, browser_template: Template
82+
):
8183
"""测试创建 Browser Sandbox"""
8284
sb = Sandbox.create(
8385
template_type=TemplateType.BROWSER,
@@ -251,7 +253,9 @@ async def test_playwright_async_navigation_async(
251253
finally:
252254
await sb.delete_async()
253255

254-
def test_playwright_navigation(self, browser_template: Template):
256+
def test_playwright_navigation(
257+
self, browser_template: Template
258+
):
255259
"""测试 Playwright 同步导航功能"""
256260
sb = Sandbox.create(
257261
template_type=TemplateType.BROWSER,
@@ -328,7 +332,9 @@ async def test_playwright_async_screenshot_async(
328332
if os.path.exists(screenshot_path):
329333
os.remove(screenshot_path)
330334

331-
def test_playwright_screenshot(self, browser_template: Template):
335+
def test_playwright_screenshot(
336+
self, browser_template: Template
337+
):
332338
"""测试 Playwright 同步截图功能"""
333339
sb = Sandbox.create(
334340
template_type=TemplateType.BROWSER,
@@ -410,7 +416,9 @@ async def test_playwright_async_search_async(
410416
finally:
411417
await sb.delete_async()
412418

413-
def test_playwright_search(self, browser_template: Template):
419+
def test_playwright_search(
420+
self, browser_template: Template
421+
):
414422
"""测试 Playwright 同步搜索功能"""
415423
sb = Sandbox.create(
416424
template_type=TemplateType.BROWSER,
@@ -507,7 +515,9 @@ async def test_playwright_async_multiple_pages_async(
507515
finally:
508516
await sb.delete_async()
509517

510-
def test_playwright_multiple_pages(self, browser_template: Template):
518+
def test_playwright_multiple_pages(
519+
self, browser_template: Template
520+
):
511521
"""测试 Playwright 同步多页面跳转"""
512522
sb = Sandbox.create(
513523
template_type=TemplateType.BROWSER,
@@ -544,13 +554,17 @@ def test_playwright_multiple_pages(self, browser_template: Template):
544554
# 后退
545555
playwright.go_back()
546556
time.sleep(1)
547-
url_after_back = playwright.evaluate("window.location.href")
557+
url_after_back = playwright.evaluate(
558+
"window.location.href"
559+
)
548560
assert "baidu.com" in url_after_back
549561

550562
# 前进
551563
playwright.go_forward()
552564
time.sleep(1)
553-
url_after_forward = playwright.evaluate("window.location.href")
565+
url_after_forward = playwright.evaluate(
566+
"window.location.href"
567+
)
554568
assert "aliyun.com" in url_after_forward
555569
finally:
556570
sb.delete()
@@ -886,7 +900,9 @@ async def test_browser_concurrent_operations_async(
886900
for sb in sandboxes:
887901
await sb.delete_async()
888902

889-
def test_browser_concurrent_operations(self, browser_template: Template):
903+
def test_browser_concurrent_operations(
904+
self, browser_template: Template
905+
):
890906
"""测试并发创建多个浏览器 Sandbox"""
891907
num_sandboxes = 2
892908
sandboxes = []
@@ -901,7 +917,7 @@ def test_browser_concurrent_operations(self, browser_template: Template):
901917
)
902918
for _ in range(num_sandboxes)
903919
]
904-
sandboxes = create_tasks
920+
sandboxes = (create_tasks)
905921

906922
# 验证所有 Sandbox 都创建成功
907923
assert len(sandboxes) == num_sandboxes

tests/e2e/test_sandbox_code_interpreter.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
77
使用 `make codegen` 命令重新生成。
88
9-
source: tests/e2e/__test_sandbox_code_interpreter_async_template.py
9+
source: .claude/worktrees/infallible-pasteur-94186e/tests/e2e/__test_sandbox_code_interpreter_async_template.py
1010
1111
1212
Sandbox Code Interpreter 模块的 E2E 测试
@@ -224,7 +224,9 @@ async def test_context_create_and_execute_async(self, sandbox):
224224
def test_context_create_and_execute(self, sandbox):
225225
"""测试创建上下文并执行代码"""
226226
# 创建 Python 上下文
227-
with sandbox.context.create(language=CodeLanguage.PYTHON) as ctx:
227+
with sandbox.context.create(
228+
language=CodeLanguage.PYTHON
229+
) as ctx:
228230
# 执行代码
229231
result = ctx.execute(code="x = 10\nprint(x)")
230232
assert result is not None
@@ -254,7 +256,9 @@ async def test_context_list_async(self, sandbox):
254256
def test_context_list(self, sandbox):
255257
"""测试列举上下文"""
256258
# 创建一个上下文
257-
with sandbox.context.create(language=CodeLanguage.PYTHON) as ctx:
259+
with sandbox.context.create(
260+
language=CodeLanguage.PYTHON
261+
) as ctx:
258262
# 列举上下文
259263
contexts = ctx.list()
260264
assert contexts is not None
@@ -590,7 +594,9 @@ def test_file_overwrite(self, sandbox):
590594
test_path = f"/test-overwrite-{int(time.time())}.txt"
591595

592596
# 第一次写入
593-
sandbox.file.write(path=test_path, content="original content")
597+
sandbox.file.write(
598+
path=test_path, content="original content"
599+
)
594600

595601
# 覆盖写入
596602
new_content = "new content"
@@ -958,14 +964,15 @@ def test_concurrent_operations(self, sandbox):
958964
tasks.append(task)
959965

960966
# 等待所有任务完成
961-
results = tasks
967+
results = (tasks)
962968
assert len(results) == 5
963969

964970
# 并发读取所有文件
965971
read_tasks = [
966-
sandbox.file.read(path=f"{base_dir}/file-{i}.txt") for i in range(5)
972+
sandbox.file.read(path=f"{base_dir}/file-{i}.txt")
973+
for i in range(5)
967974
]
968-
read_results = read_tasks
975+
read_results = (read_tasks)
969976

970977
# 验证内容
971978
for i, read_result in enumerate(read_results):

0 commit comments

Comments
 (0)