mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-22 16:06:50 +00:00
fix(oauth): Harden Claude OAuth cache-control handling (#1583)
This commit is contained in:
committed by
GitHub
parent
fc7de7fffe
commit
5ceb19f6f6
@@ -1,6 +1,8 @@
|
||||
"""Tests for ClaudeChatModel._apply_oauth_billing."""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -108,3 +110,45 @@ def test_metadata_non_dict_replaced_with_dict(model):
|
||||
model._apply_oauth_billing(payload)
|
||||
assert isinstance(payload["metadata"], dict)
|
||||
assert "user_id" in payload["metadata"]
|
||||
|
||||
|
||||
def test_sync_create_strips_cache_control_from_oauth_payload(model):
|
||||
payload = {
|
||||
"system": [{"type": "text", "text": "sys", "cache_control": {"type": "ephemeral"}}],
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [{"type": "text", "text": "hi", "cache_control": {"type": "ephemeral"}}],
|
||||
}
|
||||
],
|
||||
"tools": [{"name": "demo", "input_schema": {"type": "object"}, "cache_control": {"type": "ephemeral"}}],
|
||||
}
|
||||
|
||||
with mock.patch.object(model._client.messages, "create", return_value=object()) as create:
|
||||
model._create(payload)
|
||||
|
||||
sent_payload = create.call_args.kwargs
|
||||
assert "cache_control" not in sent_payload["system"][0]
|
||||
assert "cache_control" not in sent_payload["messages"][0]["content"][0]
|
||||
assert "cache_control" not in sent_payload["tools"][0]
|
||||
|
||||
|
||||
def test_async_create_strips_cache_control_from_oauth_payload(model):
|
||||
payload = {
|
||||
"system": [{"type": "text", "text": "sys", "cache_control": {"type": "ephemeral"}}],
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [{"type": "text", "text": "hi", "cache_control": {"type": "ephemeral"}}],
|
||||
}
|
||||
],
|
||||
"tools": [{"name": "demo", "input_schema": {"type": "object"}, "cache_control": {"type": "ephemeral"}}],
|
||||
}
|
||||
|
||||
with mock.patch.object(model._async_client.messages, "create", new=mock.AsyncMock(return_value=object())) as create:
|
||||
asyncio.run(model._acreate(payload))
|
||||
|
||||
sent_payload = create.call_args.kwargs
|
||||
assert "cache_control" not in sent_payload["system"][0]
|
||||
assert "cache_control" not in sent_payload["messages"][0]["content"][0]
|
||||
assert "cache_control" not in sent_payload["tools"][0]
|
||||
|
||||
Reference in New Issue
Block a user