from app.utils.sanitize import strip_thinking, response_has_thinking
def test_strip_simple_think_tag():
assert strip_thinking("planfinal") == "final"
def test_strip_multiline_think_tag():
raw = "line1\nline2\nactual reply"
assert strip_thinking(raw) == "actual reply"
def test_strip_nested_reasoning_blocks():
raw = (
"step 1\nstep 2"
"more thinking"
"real text"
)
assert strip_thinking(raw) == "real text"
def test_strip_multiple_think_blocks():
raw = "amiddlebend"
assert strip_thinking(raw) == "middleend"
def test_strip_uppercase_tag():
assert strip_thinking("planfinal") == "final"
def test_idempotent():
cleaned = strip_thinking("foobar")
assert strip_thinking(cleaned) == cleaned
def test_empty_inputs_safe():
assert strip_thinking(None) == ""
assert strip_thinking("") == ""
assert strip_thinking(" \n\t ") == ""
def test_thought_prologue():
raw = "Thought: I should probably mention X.\n\nReal response here."
assert strip_thinking(raw) == "Real response here."
def test_response_has_thinking_via_text():
assert response_has_thinking("planx")
assert not response_has_thinking("just plain text")
def test_response_has_thinking_via_msg_field():
assert response_has_thinking("plain text", {"reasoning_content": "stuff"})
assert response_has_thinking("plain text", {"reasoning": "stuff"})
assert not response_has_thinking("plain text", {"content": "x"})
def test_strip_framing_tokens():
raw = "<|reasoning|>plan<|/reasoning|>final"
assert strip_thinking(raw) == "final"