from nanobot.providers.responses_adapter import ResponsesAdapter, ResponsesAdapterConfig


def test_build_request_moves_system_messages_to_instructions() -> None:
    adapter = ResponsesAdapter(ResponsesAdapterConfig(model="gpt-5.4"))

    body = adapter.build_request(
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "hello"},
        ],
        tools=[{"type": "function", "function": {"name": "ping"}}],
    )

    assert body["instructions"] == "You are a helpful assistant."
    assert body["input"] == [
        {
            "type": "message",
            "role": "user",
            "content": [{"type": "input_text", "text": "hello"}],
        }
    ]
    assert body["tools"] == [{"type": "function", "function": {"name": "ping"}}]


def test_build_request_merges_system_developer_and_explicit_instructions() -> None:
    adapter = ResponsesAdapter(ResponsesAdapterConfig(model="gpt-5.4"))

    body = adapter.build_request(
        messages=[
            {"role": "system", "content": "system rule"},
            {"role": "developer", "content": [{"text": "dev note"}]},
            {"role": "assistant", "content": "previous answer"},
            {"role": "user", "content": "next question"},
        ],
        instructions="extra guidance",
    )

    assert body["instructions"] == "system rule\n\ndev note\n\nextra guidance"
    assert body["input"] == [
        {
            "type": "message",
            "role": "assistant",
            "content": [{"type": "input_text", "text": "previous answer"}],
        },
        {
            "type": "message",
            "role": "user",
            "content": [{"type": "input_text", "text": "next question"}],
        },
    ]
