39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
|
|
# retoor <retoor@molodetz.nl>
|
||
|
|
|
||
|
|
import unittest.mock
|
||
|
|
|
||
|
|
from devplacepy.services.ai_modifier import modify_text
|
||
|
|
|
||
|
|
|
||
|
|
def test_modify_text_prompt_preserves_fenced_code_blocks():
|
||
|
|
captured = {}
|
||
|
|
|
||
|
|
def fake_gateway(api_key, system, text, timeout, max_growth_factor):
|
||
|
|
captured["system"] = system
|
||
|
|
captured["text"] = text
|
||
|
|
return ("fake result", {"calls": 1})
|
||
|
|
|
||
|
|
with unittest.mock.patch(
|
||
|
|
"devplacepy.services.correction.gateway_complete", fake_gateway
|
||
|
|
):
|
||
|
|
result, _ = modify_text(
|
||
|
|
"test-key",
|
||
|
|
"Make it more formal",
|
||
|
|
"Some text\n```python\nx = 1\n```\nMore text",
|
||
|
|
)
|
||
|
|
|
||
|
|
assert result == "fake result"
|
||
|
|
system = captured["system"]
|
||
|
|
assert (
|
||
|
|
"Do NOT modify content inside Markdown fenced code blocks" in system
|
||
|
|
), "System prompt must instruct the model to preserve code blocks"
|
||
|
|
assert (
|
||
|
|
"Preserve the code block fences, the language identifier" in system
|
||
|
|
), "System prompt must mention preserving language identifiers"
|
||
|
|
assert (
|
||
|
|
"Only modify prose outside code blocks" in system
|
||
|
|
), "System prompt must limit modifications to non-code text"
|
||
|
|
assert (
|
||
|
|
"triple backticks" in system
|
||
|
|
), "System prompt must mention triple backticks as the delimiter"
|