mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-01 01:10:21 +08:00
* feat: filesystem grep, read, edit file * feat: add file write tool and enhance file read functionality * feat: enhance tool prompt formatting and add escaped text decoding for file editing * feat: remove redundant safe path tests from security restrictions * feat: implement file read tool with support for text and image files, including validation for large files * feat: add file read utilities and integrate with filesystem tools * refactor: move computer tools to builtin tools registry * refactor: remove unused plugin_context parameter from _apply_sandbox_tools * feat: supports to display enabled builtin tools in configs * feat: add tooltip for disabled builtin tools and update localization strings * feat: add workspace extra prompt handling in message processing * feat: add ripgrep installation to Dockerfile * perf: shell executed in workspace dir in local env * feat: enhance file reading capabilities to support PDF and DOCX parsing, including workspace storage for long documents * feat: update converted text notice to suggest using grep for large files * feat: implement handling for large tool results with overflow file writing and read tool integration * fix: test * feat: enhance onboarding steps to include computer access configuration and related help information * feat: add support for additional temporary path in restricted environment checks * feat: update computer access hints and add detailed configuration instructions
101 lines
2.7 KiB
Python
101 lines
2.7 KiB
Python
import json
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from astrbot.core.agent.run_context import ContextWrapper
|
|
from astrbot.core.tools.computer_tools.shipyard_neo.browser import BrowserExecTool
|
|
from astrbot.core.tools.computer_tools.shipyard_neo.neo_skills import (
|
|
GetExecutionHistoryTool,
|
|
)
|
|
|
|
|
|
class _FakeBrowser:
|
|
async def exec(self, **kwargs):
|
|
return {
|
|
"ok": True,
|
|
"cmd": kwargs["cmd"],
|
|
}
|
|
|
|
|
|
class _FakeSandbox:
|
|
async def get_execution_history(self, **kwargs):
|
|
return {
|
|
"items": [],
|
|
"limit": kwargs["limit"],
|
|
}
|
|
|
|
|
|
def _make_run_context(require_admin: bool, role: str = "member") -> ContextWrapper:
|
|
config_holder = SimpleNamespace(
|
|
get_config=lambda umo: { # noqa: ARG005
|
|
"provider_settings": {
|
|
"computer_use_require_admin": require_admin,
|
|
}
|
|
}
|
|
)
|
|
event = SimpleNamespace(
|
|
role=role,
|
|
unified_msg_origin="qq_official:friend:user-1",
|
|
get_sender_id=lambda: "user-1",
|
|
)
|
|
astr_ctx = SimpleNamespace(context=config_holder, event=event)
|
|
return ContextWrapper(context=astr_ctx)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_browser_tool_allows_non_admin_when_admin_requirement_disabled(
|
|
monkeypatch,
|
|
):
|
|
async def _fake_get_booter(_ctx, _session_id):
|
|
return SimpleNamespace(browser=_FakeBrowser())
|
|
|
|
monkeypatch.setattr(
|
|
"astrbot.core.tools.computer_tools.shipyard_neo.browser.get_booter",
|
|
_fake_get_booter,
|
|
)
|
|
|
|
result = await BrowserExecTool().call(
|
|
_make_run_context(require_admin=False),
|
|
cmd="open https://example.com",
|
|
)
|
|
|
|
assert json.loads(result)["ok"] is True
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_neo_skill_tool_allows_non_admin_when_admin_requirement_disabled(
|
|
monkeypatch,
|
|
):
|
|
async def _fake_get_booter(_ctx, _session_id):
|
|
return SimpleNamespace(
|
|
bay_client=object(),
|
|
sandbox=_FakeSandbox(),
|
|
)
|
|
|
|
monkeypatch.setattr(
|
|
"astrbot.core.tools.computer_tools.shipyard_neo.neo_skills.get_booter",
|
|
_fake_get_booter,
|
|
)
|
|
|
|
result = await GetExecutionHistoryTool().call(
|
|
_make_run_context(require_admin=False),
|
|
limit=5,
|
|
)
|
|
|
|
payload = json.loads(result)
|
|
assert payload["items"] == []
|
|
assert payload["limit"] == 5
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_browser_tool_still_denies_non_admin_when_admin_requirement_enabled():
|
|
result = await BrowserExecTool().call(
|
|
_make_run_context(require_admin=True),
|
|
cmd="open https://example.com",
|
|
)
|
|
|
|
assert "Permission denied" in result
|
|
assert "Using browser tools is only allowed for admin users" in result
|
|
assert "User's ID is: user-1" in result
|