本次提交实现了AgentRun全生命周期终态处理能力,覆盖以下核心变更: 1. 新增4种AgentRun终态错误类型与HTTP状态映射,透传上游错误上下文 2. 新增AgentRun终态信息查询接口与DTO,支持非事件流场景下的状态感知 3. 优化沙箱路径转义规则,兼容服务账号UID格式 4. 新增出站管道SKIP逻辑,针对取消/中断场景避免无效重试 5. 补充完整单元测试覆盖所有新功能与优化点
45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
"""Tests for yuxi.agents.backends.sandbox.paths uid sanitize behavior.
|
||
|
||
服务账号 uid 格式 ``svc:channel:{channel_type}:{account_id}`` 含冒号,
|
||
paths.py._sanitize_uid 必须将其转义为文件系统安全的路径组件,且与
|
||
docker/sandbox_provisioner/app.py 中的转义规则保持一致,确保宿主机
|
||
路径与容器挂载路径映射一致。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import pytest
|
||
|
||
from yuxi.agents.backends.sandbox.paths import _sanitize_uid
|
||
|
||
|
||
def test_sanitize_uid_passes_through_safe_chars() -> None:
|
||
assert _sanitize_uid("user-1_2") == "user-1_2"
|
||
assert _sanitize_uid("abcDEF123") == "abcDEF123"
|
||
|
||
|
||
def test_sanitize_uid_escapes_colons_in_service_account_uid() -> None:
|
||
# 服务账号 uid: svc:channel:{channel_type}:{account_id}
|
||
assert _sanitize_uid("svc:channel:wechat_woc:acc-1") == "svc_channel_wechat_woc_acc-1"
|
||
assert _sanitize_uid("svc:channel:feishu:host_1_bridge_2") == "svc_channel_feishu_host_1_bridge_2"
|
||
|
||
|
||
def test_sanitize_uid_escapes_unsafe_chars_to_underscore() -> None:
|
||
assert _sanitize_uid("user/name") == "user_name"
|
||
assert _sanitize_uid("user name") == "user_name"
|
||
assert _sanitize_uid("user;rm") == "user_rm"
|
||
assert _sanitize_uid("user.name") == "user_name"
|
||
# 路径穿越尝试被转义后不再包含 ..(每个非法字符独立替换为 _)
|
||
assert _sanitize_uid("../user") == "___user"
|
||
assert _sanitize_uid("..") == "__"
|
||
|
||
|
||
def test_sanitize_uid_rejects_empty_or_whitespace() -> None:
|
||
for value in ["", " ", None]:
|
||
with pytest.raises(ValueError):
|
||
_sanitize_uid(value) # type: ignore[arg-type]
|
||
|
||
|
||
def test_sanitize_uid_strips_surrounding_whitespace() -> None:
|
||
assert _sanitize_uid(" user-1 ") == "user-1"
|