mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-17 17:51:20 +08:00
feat: fix preserve escaped newlines in frontmatter & update tests & ci workflows (#6783)
This commit is contained in:
@@ -2,8 +2,21 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
from typing import cast
|
||||
|
||||
from astrbot.core.computer import computer_client
|
||||
from astrbot.core.computer.booters.base import ComputerBooter
|
||||
|
||||
|
||||
def _extract_embedded_python(command: str) -> str:
|
||||
start_marker = "$PYBIN - <<'PY'\n"
|
||||
end_marker = "\nPY"
|
||||
start = command.find(start_marker)
|
||||
assert start != -1
|
||||
start += len(start_marker)
|
||||
end = command.rfind(end_marker)
|
||||
assert end != -1
|
||||
return command[start:end]
|
||||
|
||||
|
||||
class _FakeShell:
|
||||
@@ -34,7 +47,9 @@ class _FakeBooter:
|
||||
return {"success": True}
|
||||
|
||||
|
||||
def test_sync_skills_keeps_builtin_skills_when_local_is_empty(monkeypatch, tmp_path: Path):
|
||||
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"
|
||||
skills_root.mkdir(parents=True, exist_ok=True)
|
||||
@@ -61,7 +76,7 @@ def test_sync_skills_keeps_builtin_skills_when_local_is_empty(monkeypatch, tmp_p
|
||||
booter = _FakeBooter(
|
||||
'{"skills":[{"name":"python-sandbox","description":"ship","path":"skills/python-sandbox/SKILL.md"}]}'
|
||||
)
|
||||
asyncio.run(computer_client._sync_skills_to_sandbox(booter))
|
||||
asyncio.run(computer_client._sync_skills_to_sandbox(cast(ComputerBooter, booter)))
|
||||
|
||||
assert booter.uploads == []
|
||||
assert any(cmd == "rm -f skills/skills.zip" for cmd in booter.shell.commands)
|
||||
@@ -106,7 +121,7 @@ def test_sync_skills_uses_managed_strategy_instead_of_wiping_all(
|
||||
booter = _FakeBooter(
|
||||
'{"skills":[{"name":"custom-agent-skill","description":"","path":"skills/custom-agent-skill/SKILL.md"}]}'
|
||||
)
|
||||
asyncio.run(computer_client._sync_skills_to_sandbox(booter))
|
||||
asyncio.run(computer_client._sync_skills_to_sandbox(cast(ComputerBooter, booter)))
|
||||
|
||||
assert len(booter.uploads) == 1
|
||||
assert booter.uploads[0][1] == "skills/skills.zip"
|
||||
@@ -121,3 +136,16 @@ def test_sync_skills_uses_managed_strategy_instead_of_wiping_all(
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_build_scan_command_frontmatter_newline_is_escaped_literal():
|
||||
command = computer_client._build_scan_command()
|
||||
script = _extract_embedded_python(command)
|
||||
|
||||
assert 'frontmatter = "\\n".join(lines[1:end_idx])' in script
|
||||
|
||||
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user