Revert SDK integration, fix test paths, restore original code

- Delete astrbot-sdk package entirely
- Remove SDK dependencies from pyproject.toml
- Restore core modules to pre-sdk versions
- Fix test monkeypatch paths to use correct module paths
- Fix bool type checking bug in command filter
- Fix tools=None preservation in subagent orchestrator
This commit is contained in:
LIghtJUNction
2026-03-23 01:56:39 +08:00
parent 4db5063b77
commit 05053c221d
222 changed files with 115 additions and 72824 deletions

View File

@@ -1,7 +1,6 @@
from __future__ import annotations
import asyncio
import zipfile
from pathlib import Path
from typing import cast
@@ -42,31 +41,17 @@ class _FakeBooter:
def __init__(self, sync_payload_json: str):
self.shell = _FakeShell(sync_payload_json)
self.uploads: list[tuple[str, str]] = []
self.uploaded_entries: list[str] = []
async def upload_file(self, path: str, file_name: str) -> dict:
self.uploads.append((path, file_name))
with zipfile.ZipFile(path) as zf:
self.uploaded_entries = sorted(
name.replace("\\", "/") for name in zf.namelist()
)
return {"success": True}
def _write_sdk_registered_skill(
root: Path,
skill_name: str,
) -> None:
skill_dir = root / skill_name
skill_dir.mkdir(parents=True, exist_ok=True)
skill_dir.joinpath("SKILL.md").write_text("# demo", encoding="utf-8")
def test_sync_skills_keeps_builtin_skills_when_local_is_empty(monkeypatch, tmp_path: Path):
data_dir = tmp_path / "data"
def test_sync_skills_keeps_builtin_skills_when_local_is_empty(
monkeypatch, tmp_path: Path
):
skills_root = tmp_path / "skills"
temp_root = tmp_path / "temp"
data_dir.mkdir(parents=True, exist_ok=True)
skills_root.mkdir(parents=True, exist_ok=True)
temp_root.mkdir(parents=True, exist_ok=True)
@@ -83,14 +68,6 @@ def test_sync_skills_keeps_builtin_skills_when_local_is_empty(monkeypatch, tmp_p
"astrbot.core.computer.computer_client.get_astrbot_temp_path",
lambda: str(temp_root),
)
monkeypatch.setattr(
"astrbot.core.skills.skill_manager.get_astrbot_data_path",
lambda: str(data_dir),
)
monkeypatch.setattr(
"astrbot.core.skills.skill_manager.get_astrbot_temp_path",
lambda: str(temp_root),
)
monkeypatch.setattr(
"astrbot.core.computer.computer_client.SkillManager.set_sandbox_skills_cache",
_fake_set_cache,
@@ -116,11 +93,9 @@ def test_sync_skills_uses_managed_strategy_instead_of_wiping_all(
monkeypatch,
tmp_path: Path,
):
data_dir = tmp_path / "data"
skills_root = tmp_path / "skills"
temp_root = tmp_path / "temp"
skill_dir = skills_root / "custom-agent-skill"
data_dir.mkdir(parents=True, exist_ok=True)
skill_dir.mkdir(parents=True, exist_ok=True)
skill_dir.joinpath("SKILL.md").write_text("# demo", encoding="utf-8")
temp_root.mkdir(parents=True, exist_ok=True)
@@ -138,14 +113,6 @@ def test_sync_skills_uses_managed_strategy_instead_of_wiping_all(
"astrbot.core.computer.computer_client.get_astrbot_temp_path",
lambda: str(temp_root),
)
monkeypatch.setattr(
"astrbot.core.skills.skill_manager.get_astrbot_data_path",
lambda: str(data_dir),
)
monkeypatch.setattr(
"astrbot.core.skills.skill_manager.get_astrbot_temp_path",
lambda: str(temp_root),
)
monkeypatch.setattr(
"astrbot.core.computer.computer_client.SkillManager.set_sandbox_skills_cache",
_fake_set_cache,
@@ -157,7 +124,7 @@ def test_sync_skills_uses_managed_strategy_instead_of_wiping_all(
asyncio.run(computer_client._sync_skills_to_sandbox(cast(ComputerBooter, booter)))
assert len(booter.uploads) == 1
assert booter.uploads[0][1].replace("\\", "/") == "skills/skills.zip"
assert booter.uploads[0][1] == "skills/skills.zip"
assert not any(
"find skills -mindepth 1 -delete" in cmd for cmd in booter.shell.commands
)
@@ -170,67 +137,15 @@ def test_sync_skills_uses_managed_strategy_instead_of_wiping_all(
]
def test_sync_skills_includes_sdk_registered_skills(monkeypatch, tmp_path: Path):
data_dir = tmp_path / "data"
skills_root = tmp_path / "skills"
temp_root = tmp_path / "temp"
registered_root = tmp_path / "sdk_registered"
data_dir.mkdir(parents=True, exist_ok=True)
skills_root.mkdir(parents=True, exist_ok=True)
temp_root.mkdir(parents=True, exist_ok=True)
registered_root.mkdir(parents=True, exist_ok=True)
_write_sdk_registered_skill(registered_root, "browser-helper")
def test_build_scan_command_frontmatter_newline_is_escaped_literal():
command = computer_client._build_scan_command()
script = _extract_embedded_python(command)
captured = {"skills": None}
assert 'frontmatter = "\\n".join(lines[1:end_idx])' in script
def _fake_set_cache(self, skills):
captured["skills"] = skills
monkeypatch.setattr(
"astrbot.core.computer.computer_client.get_astrbot_skills_path",
lambda: str(skills_root),
)
monkeypatch.setattr(
"astrbot.core.computer.computer_client.get_astrbot_temp_path",
lambda: str(temp_root),
)
monkeypatch.setattr(
"astrbot.core.skills.skill_manager.get_astrbot_data_path",
lambda: str(data_dir),
)
monkeypatch.setattr(
"astrbot.core.skills.skill_manager.get_astrbot_temp_path",
lambda: str(temp_root),
)
monkeypatch.setattr(
"astrbot.core.computer.computer_client.SkillManager.set_sandbox_skills_cache",
_fake_set_cache,
)
SkillManager(skills_root=str(skills_root)).replace_sdk_plugin_skills(
"sdk-demo",
[
{
"name": "sdk-demo.browser-helper",
"description": "",
"path": str(registered_root / "browser-helper" / "SKILL.md"),
"skill_dir": str(registered_root / "browser-helper"),
}
],
)
booter = _FakeBooter(
'{"skills":[{"name":"sdk-demo.browser-helper","description":"","path":"skills/sdk-demo.browser-helper/SKILL.md"}]}'
)
asyncio.run(computer_client._sync_skills_to_sandbox(booter))
assert len(booter.uploads) == 1
assert "sdk-demo.browser-helper/" in booter.uploaded_entries
assert "sdk-demo.browser-helper/SKILL.md" in booter.uploaded_entries
assert captured["skills"] == [
{
"name": "sdk-demo.browser-helper",
"description": "",
"path": "skills/sdk-demo.browser-helper/SKILL.md",
}
]
def test_build_scan_command_embedded_python_is_syntax_valid():
command = computer_client._build_scan_command()
script = _extract_embedded_python(command)
compile(script, "<scan_script>", "exec")