feat: fix preserve escaped newlines in frontmatter & update tests & ci workflows (#6783)

This commit is contained in:
Ruochen Pan
2026-03-22 14:23:21 +08:00
committed by GitHub
parent ef43217117
commit 554c9cecfa
10 changed files with 129 additions and 21 deletions

View File

@@ -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")