ForcePilot/backend/test/test_skills_backend_error_handling.py
Wenjie Zhang e4ae12dc75 refactor: 重构并清理多个模块的测试
- 移除了文件系统和沙盒路由器的过时集成测试。
- 更新了文件系统路由器测试,确保正确的身份验证和线程所有权检查。
- 调整了沙盒端到端测试,以改进附件处理和命令执行。
- 修改了设置路由器测试,对未授权访问返回404而不是401/403。
- 增强了任务路由器测试,以处理精简模式场景并确保任务创建和查询按预期工作。
- 优化了查看器文件系统测试,使用附件上传代替直接文件写入。
- 改进了技能后端测试中的错误处理,为越界访问引发适当的异常。
2026-03-25 06:32:14 +08:00

29 lines
1.1 KiB
Python

from __future__ import annotations
from deepagents.backends import FilesystemBackend
import pytest
from yuxi.agents.backends.skills_backend import SelectedSkillsReadonlyBackend
def test_skills_backend_read_outside_root_returns_error_message(monkeypatch) -> None:
def _fake_read(self, file_path: str, offset: int = 0, limit: int = 2000):
raise ValueError("Path:/app/package/yuxi/agents/skills/buildin/reporter outside root directory: /app/saves/skills")
monkeypatch.setattr(FilesystemBackend, "read", _fake_read)
backend = SelectedSkillsReadonlyBackend(selected_slugs=["reporter"])
with pytest.raises(ValueError, match="outside root directory"):
backend.read("/reporter/SKILL.md")
def test_skills_backend_ls_info_outside_root_returns_empty(monkeypatch) -> None:
def _fake_ls_info(self, path: str):
raise ValueError("Path outside root directory")
monkeypatch.setattr(FilesystemBackend, "ls_info", _fake_ls_info)
backend = SelectedSkillsReadonlyBackend(selected_slugs=["reporter"])
with pytest.raises(ValueError, match="outside root directory"):
backend.ls_info("/reporter")