open-swe/tests/test_sanitize_openai_responses.py
amoussa1229 2a35f89aad feat: port LangSmith LLM Gateway routing from upstream (#1671, #1673, #1674, #1678)
Ports four upstream commits that add opt-in LLM call routing through the
LangSmith Gateway, preserving fork conventions (Bedrock/Fireworks model IDs,
no-agent-attribution, bun toolchain).

- #1671 (e9dc6e01): opt-in gateway routing — new gateway.py, team-settings
  toggle, admin UI section, wired into make_model for all graph entrypoints
- #1673 (702ef908): dedicated LANGSMITH_GATEWAY_API_KEY precedence over
  platform LANGSMITH_API_KEY
- #1674 (5f7c2f46): fix Fireworks gateway base URL to /fireworks (bare host,
  SDK appends /v1/chat/completions) + SanitizeFireworksMessagesMiddleware
- #1678 (73b7d1c0): fix OpenAI Responses reasoning replay —
  SanitizeOpenAIResponsesMiddleware, store/include config for encrypted
  reasoning content, reasoning_effort coercion for Chat Completions fallback

Refs #134
2026-07-09 16:36:03 +00:00

55 lines
1.5 KiB
Python

from langchain_core.messages import AIMessage, HumanMessage
from agent.middleware.sanitize_openai_responses import _sanitize_messages
def test_sanitize_messages_drops_stale_reasoning_references() -> None:
messages = [
HumanMessage(content="review this"),
AIMessage(
content=[
{
"type": "reasoning",
"id": "rs_123",
"summary": [],
"content": [],
},
{
"type": "function_call",
"id": "fc_123",
"call_id": "call_123",
"name": "read_file",
"arguments": "{}",
},
],
tool_calls=[
{
"name": "read_file",
"args": {},
"id": "call_123",
}
],
),
]
_sanitize_messages(messages)
content = messages[1].content
assert isinstance(content, list)
assert [block["type"] for block in content] == ["function_call"]
assert messages[1].tool_calls[0]["id"] == "call_123"
def test_sanitize_messages_preserves_encrypted_reasoning() -> None:
reasoning = {
"type": "reasoning",
"id": "rs_123",
"encrypted_content": "encrypted",
"summary": [],
"content": [],
}
messages = [AIMessage(content=[reasoning])]
_sanitize_messages(messages)
assert messages[0].content == [reasoning]