Skip to content

Commit e02e1c0

Browse files
mafredriethanndickson
authored andcommitted
test(providers/openai): cover the reasoning skip directly
The item ID test now uses finalized encrypted reasoning, so only the ID check rejects it. A reasoning-only assistant message is dropped with the empty-message warning. The two Combined tests only rechecked the skip, and the store false row repeated the store true one.
1 parent ac9627e commit e02e1c0

3 files changed

Lines changed: 39 additions & 143 deletions

File tree

‎providers/openai/openai_test.go‎

Lines changed: 35 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,6 +3829,35 @@ func TestResponsesToPrompt_DropsEmptyMessages(t *testing.T) {
38293829
require.Contains(t, warnings[0].Message, "dropping empty assistant message")
38303830
})
38313831

3832+
t.Run("should drop assistant messages with only reasoning that cannot be sent", func(t *testing.T) {
3833+
t.Parallel()
3834+
3835+
prompt := fantasy.Prompt{
3836+
{
3837+
Role: fantasy.MessageRoleUser,
3838+
Content: []fantasy.MessagePart{
3839+
fantasy.TextPart{Text: "Hello"},
3840+
},
3841+
},
3842+
{
3843+
Role: fantasy.MessageRoleAssistant,
3844+
Content: []fantasy.MessagePart{
3845+
fantasy.ReasoningPart{ProviderOptions: fantasy.ProviderOptions{
3846+
Name: &ResponsesReasoningMetadata{ItemID: "rs_1"},
3847+
}},
3848+
},
3849+
},
3850+
}
3851+
3852+
input, warnings, err := toResponsesPrompt(prompt, "system")
3853+
3854+
require.NoError(t, err)
3855+
3856+
require.Len(t, input, 1, "should only have user message")
3857+
require.Len(t, warnings, 1)
3858+
require.Contains(t, warnings[0].Message, "dropping empty assistant message")
3859+
})
3860+
38323861
t.Run("should keep assistant messages with text content", func(t *testing.T) {
38333862
t.Parallel()
38343863

@@ -4764,7 +4793,11 @@ func TestResponsesToPrompt_SkipsReasoningThatCannotGoInline(t *testing.T) {
47644793
fantasy.ReasoningPart{
47654794
Text: "thinking",
47664795
ProviderOptions: fantasy.ProviderOptions{
4767-
Name: &ResponsesReasoningMetadata{Summary: []string{}},
4796+
Name: &ResponsesReasoningMetadata{
4797+
EncryptedContent: &encryptedContent,
4798+
Summary: []string{},
4799+
Finalized: true,
4800+
},
47684801
},
47694802
},
47704803
fantasy.TextPart{Text: "4"},
@@ -4783,8 +4816,7 @@ func TestResponsesToPrompt_SkipsReasoningThatCannotGoInline(t *testing.T) {
47834816
require.NoError(t, err)
47844817
require.Empty(t, warnings)
47854818

4786-
// Without an ItemID the reasoning cannot be sent. Order: user,
4787-
// assistant text, user.
4819+
// user, assistant text, user.
47884820
require.Len(t, input, 3)
47894821
for _, item := range input {
47904822
require.Nil(t, item.OfReasoning)
@@ -4810,138 +4842,6 @@ func TestResponsesToPrompt_SkipsReasoningThatCannotGoInline(t *testing.T) {
48104842
})
48114843
}
48124844

4813-
func TestResponsesToPrompt_ReasoningWithWebSearchCombined(t *testing.T) {
4814-
t.Parallel()
4815-
4816-
reasoningItemID := "rs_002"
4817-
webSearchItemID := "ws_002"
4818-
4819-
prompt := fantasy.Prompt{
4820-
{
4821-
Role: fantasy.MessageRoleUser,
4822-
Content: []fantasy.MessagePart{
4823-
fantasy.TextPart{Text: "What is the weather in San Francisco?"},
4824-
},
4825-
},
4826-
{
4827-
Role: fantasy.MessageRoleAssistant,
4828-
Content: []fantasy.MessagePart{
4829-
fantasy.ReasoningPart{
4830-
Text: "I should look this up.",
4831-
ProviderOptions: fantasy.ProviderOptions{
4832-
Name: &ResponsesReasoningMetadata{
4833-
ItemID: reasoningItemID,
4834-
Summary: []string{},
4835-
},
4836-
},
4837-
},
4838-
fantasy.ToolCallPart{
4839-
ToolCallID: webSearchItemID,
4840-
ToolName: "web_search",
4841-
ProviderExecuted: true,
4842-
},
4843-
fantasy.ToolResultPart{
4844-
ToolCallID: webSearchItemID,
4845-
ProviderExecuted: true,
4846-
ProviderOptions: fantasy.ProviderOptions{
4847-
Name: &WebSearchCallMetadata{
4848-
ItemID: webSearchItemID,
4849-
Status: "completed",
4850-
Action: &WebSearchAction{Type: "search", Query: "weather in San Francisco"},
4851-
},
4852-
},
4853-
},
4854-
fantasy.TextPart{Text: "Sunny."},
4855-
},
4856-
},
4857-
{
4858-
Role: fantasy.MessageRoleUser,
4859-
Content: []fantasy.MessagePart{
4860-
fantasy.TextPart{Text: "And Tokyo?"},
4861-
},
4862-
},
4863-
}
4864-
4865-
input, warnings, err := toResponsesPrompt(prompt, "system")
4866-
4867-
require.NoError(t, err)
4868-
require.Empty(t, warnings)
4869-
4870-
// Reasoning without encrypted content is skipped. Order: user,
4871-
// web_search_call, assistant text, user.
4872-
require.Len(t, input, 4)
4873-
require.NotNil(t, input[1].OfWebSearchCall)
4874-
for _, item := range input {
4875-
require.Nil(t, item.OfItemReference)
4876-
require.Nil(t, item.OfReasoning)
4877-
}
4878-
}
4879-
4880-
func TestResponsesToPrompt_ReasoningWithFunctionCallCombined(t *testing.T) {
4881-
t.Parallel()
4882-
4883-
reasoningItemID := "rs_003"
4884-
functionCallID := "call_003"
4885-
4886-
prompt := fantasy.Prompt{
4887-
{
4888-
Role: fantasy.MessageRoleUser,
4889-
Content: []fantasy.MessagePart{
4890-
fantasy.TextPart{Text: "compute 1+1"},
4891-
},
4892-
},
4893-
{
4894-
Role: fantasy.MessageRoleAssistant,
4895-
Content: []fantasy.MessagePart{
4896-
fantasy.ReasoningPart{
4897-
Text: "I'll call add.",
4898-
ProviderOptions: fantasy.ProviderOptions{
4899-
Name: &ResponsesReasoningMetadata{
4900-
ItemID: reasoningItemID,
4901-
Summary: []string{},
4902-
},
4903-
},
4904-
},
4905-
fantasy.ToolCallPart{
4906-
ToolCallID: functionCallID,
4907-
ToolName: "add",
4908-
Input: `{"a":1,"b":1}`,
4909-
},
4910-
},
4911-
},
4912-
{
4913-
Role: fantasy.MessageRoleTool,
4914-
Content: []fantasy.MessagePart{
4915-
fantasy.ToolResultPart{
4916-
ToolCallID: functionCallID,
4917-
Output: fantasy.ToolResultOutputContentText{Text: "2"},
4918-
},
4919-
},
4920-
},
4921-
{
4922-
Role: fantasy.MessageRoleUser,
4923-
Content: []fantasy.MessagePart{
4924-
fantasy.TextPart{Text: "thanks"},
4925-
},
4926-
},
4927-
}
4928-
4929-
input, warnings, err := toResponsesPrompt(prompt, "system")
4930-
4931-
require.NoError(t, err)
4932-
require.Empty(t, warnings)
4933-
4934-
// Reasoning without encrypted content is skipped. Order: user,
4935-
// function_call(call_003), function_call_output(call_003), user.
4936-
require.Len(t, input, 4)
4937-
4938-
require.NotNil(t, input[1].OfFunctionCall)
4939-
require.Equal(t, functionCallID, input[1].OfFunctionCall.CallID)
4940-
4941-
require.NotNil(t, input[2].OfFunctionCallOutput)
4942-
require.Equal(t, functionCallID, input[2].OfFunctionCallOutput.CallID)
4943-
}
4944-
49454845
func TestResponsesStream_RequiresTerminalEventBeforeFinish(t *testing.T) {
49464846
t.Parallel()
49474847

‎providers/openai/responses_reasoning_replay_test.go‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ func TestResponsesReplay_FinalizedReasoningInput(t *testing.T) {
124124
encrypted *string
125125
summary []string
126126
webSearch bool
127-
// unfinalized marks metadata saved before Finalized existed.
127+
// unfinalized clears Finalized, as in streaming placeholders and
128+
// metadata saved before Finalized existed.
128129
unfinalized bool
129130
// want is the reasoning input item; nil means none is sent.
130131
want map[string]any
@@ -164,11 +165,6 @@ func TestResponsesReplay_FinalizedReasoningInput(t *testing.T) {
164165
encrypted: new("enc-final"),
165166
unfinalized: true,
166167
},
167-
{
168-
name: "unfinalized store false",
169-
encrypted: new("enc-final"),
170-
unfinalized: true,
171-
},
172168
{
173169
name: "store true before web search",
174170
store: true,

‎providers/openai/responses_web_search_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ func TestResponsesToPrompt_WebSearchCallReplay(t *testing.T) {
590590
want: `[` + userJSON + `,` + searchJSON + `]`,
591591
},
592592
{
593-
name: "Pre62SearchWithoutStatus",
593+
name: "LegacySearchWithoutStatus",
594594
content: append(
595595
webSearchCallParts("ws_01", &WebSearchCallMetadata{
596596
ItemID: "ws_01",
@@ -603,7 +603,7 @@ func TestResponsesToPrompt_WebSearchCallReplay(t *testing.T) {
603603
{
604604
// Before #62 only Type and Query were saved. The API accepts a
605605
// find_in_page action without url and pattern.
606-
name: "Pre62FindInPageWithoutStatus",
606+
name: "LegacyFindInPageWithoutStatus",
607607
content: append(
608608
webSearchCallParts("ws_01", &WebSearchCallMetadata{
609609
ItemID: "ws_01",

0 commit comments

Comments
 (0)