Skip to content

Commit 3b3d540

Browse files
committed
fix bedrock streaming tests
1 parent dc0ad44 commit 3b3d540

2 files changed

Lines changed: 33 additions & 47 deletions

File tree

bridge_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ func newMockServer(ctx context.Context, t *testing.T, files archiveFileMap, resp
15551555
var reqMsg msg
15561556
require.NoError(t, json.Unmarshal(body, &reqMsg))
15571557

1558-
if !reqMsg.Stream {
1558+
if !reqMsg.Stream && !strings.HasSuffix(r.URL.Path, "invoke-with-response-stream") {
15591559
resp := files[fixtureNonStreamingResponse]
15601560
if responseMutatorFn != nil {
15611561
resp = responseMutatorFn(ms.callCount.Load(), resp)

trace_integration_test.go

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ func TestTraceAnthropic(t *testing.T) {
4545
{"Intercept.ProcessRequest.Upstream", 1, codes.Unset},
4646
}
4747

48+
expectStreaming := []expectTrace{
49+
{"Intercept", 1, codes.Unset},
50+
{"Intercept.CreateInterceptor", 1, codes.Unset},
51+
{"Intercept.RecordInterception", 1, codes.Unset},
52+
{"Intercept.ProcessRequest", 1, codes.Unset},
53+
{"Intercept.RecordInterceptionEnded", 1, codes.Unset},
54+
{"Intercept.RecordPromptUsage", 1, codes.Unset},
55+
{"Intercept.RecordTokenUsage", 2, codes.Unset},
56+
{"Intercept.RecordToolUsage", 1, codes.Unset},
57+
{"Intercept.ProcessRequest.Upstream", 1, codes.Unset},
58+
}
59+
4860
cases := []struct {
4961
name string
5062
streaming bool
@@ -63,31 +75,13 @@ func TestTraceAnthropic(t *testing.T) {
6375
{
6476
name: "trace_anthr_streaming",
6577
streaming: true,
66-
expect: []expectTrace{
67-
{"Intercept", 1, codes.Unset},
68-
{"Intercept.CreateInterceptor", 1, codes.Unset},
69-
{"Intercept.RecordInterception", 1, codes.Unset},
70-
{"Intercept.ProcessRequest", 1, codes.Unset},
71-
{"Intercept.RecordInterceptionEnded", 1, codes.Unset},
72-
{"Intercept.RecordPromptUsage", 1, codes.Unset},
73-
{"Intercept.RecordTokenUsage", 2, codes.Unset},
74-
{"Intercept.RecordToolUsage", 1, codes.Unset},
75-
{"Intercept.ProcessRequest.Upstream", 1, codes.Unset},
76-
},
78+
expect: expectStreaming,
7779
},
7880
{
7981
name: "trace_bedrock_streaming",
8082
streaming: true,
8183
bedrock: true,
82-
expect: []expectTrace{
83-
{"Intercept", 1, codes.Unset},
84-
{"Intercept.CreateInterceptor", 1, codes.Unset},
85-
{"Intercept.RecordInterception", 1, codes.Unset},
86-
{"Intercept.ProcessRequest", 1, codes.Unset},
87-
{"Intercept.RecordInterceptionEnded", 1, codes.Unset},
88-
{"Intercept.RecordPromptUsage", 1, codes.Unset},
89-
{"Intercept.ProcessRequest.Upstream", 1, codes.Unset},
90-
},
84+
expect: expectStreaming,
9185
},
9286
}
9387

@@ -170,6 +164,17 @@ func TestTraceAnthropicErr(t *testing.T) {
170164
{"Intercept.ProcessRequest.Upstream", 1, codes.Error},
171165
}
172166

167+
expectStreaming := []expectTrace{
168+
{"Intercept", 1, codes.Error},
169+
{"Intercept.CreateInterceptor", 1, codes.Unset},
170+
{"Intercept.RecordInterception", 1, codes.Unset},
171+
{"Intercept.ProcessRequest", 1, codes.Error},
172+
{"Intercept.RecordPromptUsage", 1, codes.Unset},
173+
{"Intercept.RecordTokenUsage", 1, codes.Unset},
174+
{"Intercept.RecordInterceptionEnded", 1, codes.Unset},
175+
{"Intercept.ProcessRequest.Upstream", 1, codes.Unset},
176+
}
177+
173178
cases := []struct {
174179
name string
175180
streaming bool
@@ -183,16 +188,7 @@ func TestTraceAnthropicErr(t *testing.T) {
183188
{
184189
name: "anthr_streaming_err",
185190
streaming: true,
186-
expect: []expectTrace{
187-
{"Intercept", 1, codes.Error},
188-
{"Intercept.CreateInterceptor", 1, codes.Unset},
189-
{"Intercept.RecordInterception", 1, codes.Unset},
190-
{"Intercept.ProcessRequest", 1, codes.Error},
191-
{"Intercept.RecordPromptUsage", 1, codes.Unset},
192-
{"Intercept.RecordTokenUsage", 1, codes.Unset},
193-
{"Intercept.RecordInterceptionEnded", 1, codes.Unset},
194-
{"Intercept.ProcessRequest.Upstream", 1, codes.Unset},
195-
},
191+
expect: expectStreaming,
196192
},
197193
{
198194
name: "bedrock_non_streaming_err",
@@ -203,16 +199,7 @@ func TestTraceAnthropicErr(t *testing.T) {
203199
name: "bedrock_streaming_err",
204200
streaming: true,
205201
bedrock: true,
206-
expect: []expectTrace{
207-
// RecordTokenUsage missing?
208-
{"Intercept", 1, codes.Unset}, // TODO check why this is unset not Error
209-
{"Intercept.CreateInterceptor", 1, codes.Unset},
210-
{"Intercept.RecordInterception", 1, codes.Unset},
211-
{"Intercept.ProcessRequest", 1, codes.Unset}, // TODO check why this is unset not Error
212-
{"Intercept.RecordPromptUsage", 1, codes.Unset},
213-
{"Intercept.RecordInterceptionEnded", 1, codes.Unset},
214-
{"Intercept.ProcessRequest.Upstream", 1, codes.Unset},
215-
},
202+
expect: expectStreaming,
216203
},
217204
}
218205

@@ -323,12 +310,11 @@ func TestAnthropicInjectedToolsTrace(t *testing.T) {
323310
streaming: false,
324311
bedrock: true,
325312
},
326-
// TODO check why it fails
327-
// {
328-
// name: "bedrock_streaming",
329-
// streaming: true,
330-
// bedrock: true,
331-
// },
313+
{
314+
name: "bedrock_streaming",
315+
streaming: true,
316+
bedrock: true,
317+
},
332318
}
333319

334320
for _, tc := range tests {

0 commit comments

Comments
 (0)