from agent.trajectory import convert_scratchpad_to_think, has_incomplete_scratchpad
def test_convert_scratchpad_to_think_rewrites_tags():
content = "think done"
assert convert_scratchpad_to_think(content) == "think done"
def test_has_incomplete_scratchpad_detects_real_unclosed_tag():
content = "Answering...\nstill thinking"
assert has_incomplete_scratchpad(content) is True
def test_has_incomplete_scratchpad_ignores_fenced_code_block_mentions():
content = """Here is the grep output:
```text
```
"""
assert has_incomplete_scratchpad(content) is False
def test_has_incomplete_scratchpad_ignores_blockquote_mentions():
content = "> literal token \n\nFinal answer."
assert has_incomplete_scratchpad(content) is False
def test_has_incomplete_scratchpad_ignores_inline_code_mentions():
content = "The user literally typed `` in the prompt."
assert has_incomplete_scratchpad(content) is False
def test_has_incomplete_scratchpad_still_flags_real_tag_after_quote():
content = "> quoted literal \n\nreal"
assert has_incomplete_scratchpad(content) is True