forked from retoor/devplacepy
ticket #84 attempt 1
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
# 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"
|
||||
@@ -0,0 +1,36 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
import unittest.mock
|
||||
|
||||
from devplacepy.services.correction import correct_text
|
||||
|
||||
|
||||
def test_correct_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, _ = correct_text(
|
||||
"test-key", "Fix spelling", "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 correct prose outside code blocks" in system
|
||||
), "System prompt must limit corrections to non-code text"
|
||||
assert (
|
||||
"triple backticks" in system
|
||||
), "System prompt must mention triple backticks as the delimiter"
|
||||
Reference in New Issue
Block a user