from app.services.reasoning_policy_service import ReasoningPolicyService, ReasoningStreamParser


def test_reasoning_parser_handles_tags_split_across_chunks():
    parser = ReasoningStreamParser()
    segments = []
    for chunk in ["<thi", "nk>内部", "思考</th", "ink>## 回答"]:
        segments.extend(parser.feed(chunk))
    segments.extend(parser.finish())

    assert "".join(item.content for item in segments if item.kind == "reasoning") == "内部思考"
    assert "".join(item.content for item in segments if item.kind == "content") == "## 回答"


def test_reasoning_is_removed_from_history_text_when_policy_is_off():
    text = "<think>不应透出</think>\n正式回答"

    assert ReasoningPolicyService.strip_reasoning(text) == "\n正式回答"
