feat: load editable prompts from markdown
This commit is contained in:
40
tests/test_prompts.py
Normal file
40
tests/test_prompts.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from llm_trade_bot.prompts import PromptError, PromptStore
|
||||
|
||||
|
||||
def test_loads_named_markdown_sections(tmp_path: Path):
|
||||
path = tmp_path / "prompts.md"
|
||||
path.write_text(
|
||||
"# Prompts\n\n## master_prompt\nMaster text.\n\n### Nested heading\nMore.\n\n## run_prompt\nRun text.\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
prompts = PromptStore(path).load()
|
||||
assert prompts.master_prompt == "Master text.\n\n### Nested heading\nMore."
|
||||
assert prompts.run_prompt == "Run text."
|
||||
|
||||
|
||||
def test_reloads_file_for_each_snapshot(tmp_path: Path):
|
||||
path = tmp_path / "prompts.md"
|
||||
path.write_text("## master_prompt\nFirst\n## run_prompt\nRun", encoding="utf-8")
|
||||
store = PromptStore(path)
|
||||
assert store.load().master_prompt == "First"
|
||||
path.write_text("## master_prompt\nSecond\n## run_prompt\nRun", encoding="utf-8")
|
||||
assert store.load().master_prompt == "Second"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"content, message",
|
||||
[
|
||||
("# no sections", "level-two sections"),
|
||||
("## master_prompt\nMaster", "run_prompt"),
|
||||
("## master_prompt\nOne\n## master_prompt\nTwo\n## run_prompt\nRun", "Duplicate"),
|
||||
],
|
||||
)
|
||||
def test_rejects_invalid_prompt_files(tmp_path: Path, content: str, message: str):
|
||||
path = tmp_path / "prompts.md"
|
||||
path.write_text(content, encoding="utf-8")
|
||||
with pytest.raises(PromptError, match=message):
|
||||
PromptStore(path).load()
|
||||
Reference in New Issue
Block a user