def test_user_agent_default(
    sync_client: Elasticsearch, sync_client_request_saving: Elasticsearch
) -> None:
    """Test to make sure the user-agent is set correctly."""

    if not model_is_deployed(sync_client, MODEL_ID):
        pytest.skip(f"{MODEL_ID} model is not deployed in ML Node, skipping test")

    embeddings = ElasticsearchEmbeddings(
        client=sync_client_request_saving, model_id=MODEL_ID
    )

    expected_pattern = r"^elasticsearch-py-es/\d+\.\d+\.\d+$"

    got_agent = embeddings.client._headers["User-Agent"]
    assert (
        re.match(expected_pattern, got_agent) is not None
    ), f"The user agent '{got_agent}' does not match the expected pattern."

    embeddings.embed_query("foo bar")

    requests = embeddings.client.transport.requests  # type: ignore
    assert len(requests) == 1

    got_request_agent = requests[0]["headers"]["User-Agent"]
    assert (
        re.match(expected_pattern, got_request_agent) is not None
    ), f"The user agent '{got_request_agent}' does not match the expected pattern."
Test to make sure the user-agent is set correctly.
test_elasticsearch/test_server/test_vectorstore/test_embedding_service.py