Skip to content

Commit 9cf5643

Browse files
Revert "deduplicate"
This reverts commit 01d0619.
1 parent 01d0619 commit 9cf5643

File tree

4 files changed

+51
-34
lines changed

4 files changed

+51
-34
lines changed

tests/conftest.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -592,30 +592,6 @@ def suppress_deprecation_warnings():
592592
yield
593593

594594

595-
@pytest.fixture(
596-
params=[
597-
pytest.param(
598-
({"role": "system", "content": "You are helpful."}, "system"),
599-
id="system",
600-
),
601-
pytest.param(
602-
({"role": "user", "content": "Hello"}, "user"),
603-
id="user",
604-
),
605-
pytest.param(
606-
({"role": "ai", "content": "Hi there!"}, "assistant"),
607-
id="ai",
608-
),
609-
pytest.param(
610-
({"role": "assistant", "content": "How can I help?"}, "assistant"),
611-
id="assistant",
612-
),
613-
]
614-
)
615-
def input_ai_message_and_expected_role(request):
616-
return request.param
617-
618-
619595
class MockServerRequestHandler(BaseHTTPRequestHandler):
620596
def do_GET(self): # noqa: N802
621597
# Process an HTTP GET request and return a response.

tests/integrations/anthropic/test_anthropic.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -899,14 +899,26 @@ def test_set_output_data_with_input_json_delta(sentry_init):
899899
assert span._data.get(SPANDATA.GEN_AI_USAGE_TOTAL_TOKENS) == 30
900900

901901

902+
# Test messages with mixed roles including "ai" that should be mapped to "assistant"
903+
@pytest.mark.parametrize(
904+
"test_message,expected_role",
905+
[
906+
({"role": "system", "content": "You are helpful."}, "system"),
907+
({"role": "user", "content": "Hello"}, "user"),
908+
(
909+
{"role": "ai", "content": "Hi there!"},
910+
"assistant",
911+
), # Should be mapped to "assistant"
912+
(
913+
{"role": "assistant", "content": "How can I help?"},
914+
"assistant",
915+
), # Should stay "assistant"
916+
],
917+
)
902918
def test_anthropic_message_role_mapping(
903-
sentry_init,
904-
capture_events,
905-
input_ai_message_and_expected_role,
919+
sentry_init, capture_events, test_message, expected_role
906920
):
907921
"""Test that Anthropic integration properly maps message roles like 'ai' to 'assistant'"""
908-
test_message, expected_role = input_ai_message_and_expected_role
909-
910922
sentry_init(
911923
integrations=[AnthropicIntegration(include_prompts=True)],
912924
traces_sample_rate=1.0,

tests/integrations/openai/test_openai.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,11 +1457,26 @@ def test_empty_tools_in_chat_completion(sentry_init, capture_events, tools):
14571457
assert "gen_ai.request.available_tools" not in span["data"]
14581458

14591459

1460+
# Test messages with mixed roles including "ai" that should be mapped to "assistant"
1461+
@pytest.mark.parametrize(
1462+
"test_message,expected_role",
1463+
[
1464+
({"role": "system", "content": "You are helpful."}, "system"),
1465+
({"role": "user", "content": "Hello"}, "user"),
1466+
(
1467+
{"role": "ai", "content": "Hi there!"},
1468+
"assistant",
1469+
), # Should be mapped to "assistant"
1470+
(
1471+
{"role": "assistant", "content": "How can I help?"},
1472+
"assistant",
1473+
), # Should stay "assistant"
1474+
],
1475+
)
14601476
def test_openai_message_role_mapping(
1461-
sentry_init, capture_events, input_ai_message_and_expected_role
1477+
sentry_init, capture_events, test_message, expected_role
14621478
):
14631479
"""Test that OpenAI integration properly maps message roles like 'ai' to 'assistant'"""
1464-
test_message, expected_role = input_ai_message_and_expected_role
14651480

14661481
sentry_init(
14671482
integrations=[OpenAIIntegration(include_prompts=True)],

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,12 +1324,26 @@ async def run():
13241324
assert txn3["transaction"] == "test_agent workflow"
13251325

13261326

1327+
# Test input messages with mixed roles including "ai"
1328+
@pytest.mark.parametrize(
1329+
"test_message,expected_role",
1330+
[
1331+
({"role": "system", "content": "You are helpful."}, "system"),
1332+
({"role": "user", "content": "Hello"}, "user"),
1333+
(
1334+
{"role": "ai", "content": "Hi there!"},
1335+
"assistant",
1336+
), # Should be mapped to "assistant"
1337+
(
1338+
{"role": "assistant", "content": "How can I help?"},
1339+
"assistant",
1340+
), # Should stay "assistant"
1341+
],
1342+
)
13271343
def test_openai_agents_message_role_mapping(
1328-
sentry_init, capture_events, input_ai_message_and_expected_role
1344+
sentry_init, capture_events, test_message, expected_role
13291345
):
13301346
"""Test that OpenAI Agents integration properly maps message roles like 'ai' to 'assistant'"""
1331-
test_message, expected_role = input_ai_message_and_expected_role
1332-
13331347
sentry_init(
13341348
integrations=[OpenAIAgentsIntegration()],
13351349
traces_sample_rate=1.0,

0 commit comments

Comments
 (0)