(t *testing.T)
| 1080 | } |
| 1081 | |
| 1082 | func TestOpenAIInjectedTools(t *testing.T) { |
| 1083 | t.Parallel() |
| 1084 | |
| 1085 | for _, streaming := range []bool{true, false} { |
| 1086 | t.Run(fmt.Sprintf("streaming=%v", streaming), func(t *testing.T) { |
| 1087 | t.Parallel() |
| 1088 | |
| 1089 | // Build the requirements & make the assertions which are common to all providers. |
| 1090 | bridgeServer, mockMCP, resp := setupInjectedToolTest(t, fixtures.OaiChatSingleInjectedTool, streaming, defaultTracer, pathOpenAIChatCompletions, openaiChatToolResultValidator(t)) |
| 1091 | defer resp.Body.Close() |
| 1092 | |
| 1093 | // Ensure expected tool was invoked with expected input. |
| 1094 | toolUsages := bridgeServer.Recorder.RecordedToolUsages() |
| 1095 | require.Len(t, toolUsages, 1) |
| 1096 | require.Equal(t, mockToolName, toolUsages[0].Tool) |
| 1097 | expected, err := json.Marshal(map[string]any{"owner": "admin"}) |
| 1098 | require.NoError(t, err) |
| 1099 | actual, err := json.Marshal(toolUsages[0].Args) |
| 1100 | require.NoError(t, err) |
| 1101 | require.EqualValues(t, expected, actual) |
| 1102 | invocations := mockMCP.getCallsByTool(mockToolName) |
| 1103 | require.Len(t, invocations, 1) |
| 1104 | actual, err = json.Marshal(invocations[0]) |
| 1105 | require.NoError(t, err) |
| 1106 | require.EqualValues(t, expected, actual) |
| 1107 | |
| 1108 | var ( |
| 1109 | content *openai.ChatCompletionChoice |
| 1110 | message openai.ChatCompletion |
| 1111 | ) |
| 1112 | if streaming { |
| 1113 | // Parse the response stream. |
| 1114 | decoder := oaissestream.NewDecoder(resp) |
| 1115 | stream := oaissestream.NewStream[openai.ChatCompletionChunk](decoder, nil) |
| 1116 | var acc openai.ChatCompletionAccumulator |
| 1117 | detectedToolCalls := make(map[string]struct{}) |
| 1118 | for stream.Next() { |
| 1119 | chunk := stream.Current() |
| 1120 | acc.AddChunk(chunk) |
| 1121 | |
| 1122 | if len(chunk.Choices) == 0 { |
| 1123 | continue |
| 1124 | } |
| 1125 | |
| 1126 | for _, c := range chunk.Choices { |
| 1127 | if len(c.Delta.ToolCalls) == 0 { |
| 1128 | continue |
| 1129 | } |
| 1130 | |
| 1131 | for _, t := range c.Delta.ToolCalls { |
| 1132 | if t.Function.Name == "" { |
| 1133 | continue |
| 1134 | } |
| 1135 | |
| 1136 | detectedToolCalls[t.Function.Name] = struct{}{} |
| 1137 | } |
| 1138 | } |
| 1139 | } |
nothing calls this directly
no test coverage detected