mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-05-07 09:02:08 +00:00
- Restrict code fence stripping to fences at start-of-line (prevents inline "~~~markdown" from being treated as a fence and merging lines) - Only strip fences for full JSON templates in Agent.read_prompt() and files.parse_file() - Preserve fenced examples in markdown/tool prompts while keeping json-only prompts parseable - Add regression tests for fence stripping and prompt fence policy
29 lines
775 B
Python
29 lines
775 B
Python
import sys
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
if str(PROJECT_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
from python.helpers.files import remove_code_fences
|
|
|
|
|
|
def test_remove_code_fences_does_not_strip_inline_tildes_or_join_lines():
|
|
src = (
|
|
"full message is automatically markdown do not wrap ~~~markdown\n"
|
|
"use emojis as icons improve readability\n"
|
|
"usage:\n"
|
|
"~~~json\n"
|
|
"{\n"
|
|
' \"a\": 1\n'
|
|
"}\n"
|
|
"~~~\n"
|
|
)
|
|
|
|
out = remove_code_fences(src)
|
|
|
|
assert "wrap ~~~markdown\nuse emojis" in out
|
|
assert "wrap ~~~markdownuse emojis" not in out
|
|
assert "~~~json" not in out
|
|
assert "\n~~~\n" not in out
|
|
assert '"a": 1' in out
|