3
3
import asyncio
4
4
5
5
import pytest
6
+ from inline_snapshot import snapshot
6
7
7
8
from agents import Agent , RunConfig , Runner , trace
8
9
9
10
from .fake_model import FakeModel
10
11
from .test_responses import get_text_message
11
- from .testing_processor import fetch_ordered_spans , fetch_traces
12
+ from .testing_processor import fetch_normalized_spans , fetch_ordered_spans , fetch_traces
12
13
13
14
14
15
@pytest .mark .asyncio
@@ -25,6 +26,25 @@ async def test_single_run_is_single_trace():
25
26
traces = fetch_traces ()
26
27
assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
27
28
29
+ assert fetch_normalized_spans () == snapshot (
30
+ [
31
+ {
32
+ "workflow_name" : "Agent workflow" ,
33
+ "children" : [
34
+ {
35
+ "type" : "agent" ,
36
+ "data" : {
37
+ "name" : "test_agent" ,
38
+ "handoffs" : [],
39
+ "tools" : [],
40
+ "output_type" : "str" ,
41
+ },
42
+ }
43
+ ],
44
+ }
45
+ ]
46
+ )
47
+
28
48
spans = fetch_ordered_spans ()
29
49
assert len (spans ) == 1 , (
30
50
f"Got { len (spans )} , but expected 1: the agent span. data:"
@@ -52,6 +72,39 @@ async def test_multiple_runs_are_multiple_traces():
52
72
traces = fetch_traces ()
53
73
assert len (traces ) == 2 , f"Expected 2 traces, got { len (traces )} "
54
74
75
+ assert fetch_normalized_spans () == snapshot (
76
+ [
77
+ {
78
+ "workflow_name" : "Agent workflow" ,
79
+ "children" : [
80
+ {
81
+ "type" : "agent" ,
82
+ "data" : {
83
+ "name" : "test_agent_1" ,
84
+ "handoffs" : [],
85
+ "tools" : [],
86
+ "output_type" : "str" ,
87
+ },
88
+ }
89
+ ],
90
+ },
91
+ {
92
+ "workflow_name" : "Agent workflow" ,
93
+ "children" : [
94
+ {
95
+ "type" : "agent" ,
96
+ "data" : {
97
+ "name" : "test_agent_1" ,
98
+ "handoffs" : [],
99
+ "tools" : [],
100
+ "output_type" : "str" ,
101
+ },
102
+ }
103
+ ],
104
+ },
105
+ ]
106
+ )
107
+
55
108
spans = fetch_ordered_spans ()
56
109
assert len (spans ) == 2 , f"Got { len (spans )} , but expected 2: agent span per run"
57
110
@@ -79,6 +132,43 @@ async def test_wrapped_trace_is_single_trace():
79
132
traces = fetch_traces ()
80
133
assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
81
134
135
+ assert fetch_normalized_spans () == snapshot (
136
+ [
137
+ {
138
+ "workflow_name" : "test_workflow" ,
139
+ "children" : [
140
+ {
141
+ "type" : "agent" ,
142
+ "data" : {
143
+ "name" : "test_agent_1" ,
144
+ "handoffs" : [],
145
+ "tools" : [],
146
+ "output_type" : "str" ,
147
+ },
148
+ },
149
+ {
150
+ "type" : "agent" ,
151
+ "data" : {
152
+ "name" : "test_agent_1" ,
153
+ "handoffs" : [],
154
+ "tools" : [],
155
+ "output_type" : "str" ,
156
+ },
157
+ },
158
+ {
159
+ "type" : "agent" ,
160
+ "data" : {
161
+ "name" : "test_agent_1" ,
162
+ "handoffs" : [],
163
+ "tools" : [],
164
+ "output_type" : "str" ,
165
+ },
166
+ },
167
+ ],
168
+ }
169
+ ]
170
+ )
171
+
82
172
spans = fetch_ordered_spans ()
83
173
assert len (spans ) == 3 , f"Got { len (spans )} , but expected 3: the agent span per run"
84
174
@@ -97,6 +187,8 @@ async def test_parent_disabled_trace_disabled_agent_trace():
97
187
98
188
traces = fetch_traces ()
99
189
assert len (traces ) == 0 , f"Expected 0 traces, got { len (traces )} "
190
+ assert fetch_normalized_spans () == snapshot ([])
191
+
100
192
spans = fetch_ordered_spans ()
101
193
assert len (spans ) == 0 , (
102
194
f"Expected no spans, got { len (spans )} , with { [x .span_data for x in spans ]} "
@@ -116,6 +208,8 @@ async def test_manual_disabling_works():
116
208
117
209
traces = fetch_traces ()
118
210
assert len (traces ) == 0 , f"Expected 0 traces, got { len (traces )} "
211
+ assert fetch_normalized_spans () == snapshot ([])
212
+
119
213
spans = fetch_ordered_spans ()
120
214
assert len (spans ) == 0 , f"Got { len (spans )} , but expected no spans"
121
215
@@ -164,6 +258,25 @@ async def test_not_starting_streaming_creates_trace():
164
258
traces = fetch_traces ()
165
259
assert len (traces ) == 1 , f"Expected 1 trace, got { len (traces )} "
166
260
261
+ assert fetch_normalized_spans () == snapshot (
262
+ [
263
+ {
264
+ "workflow_name" : "Agent workflow" ,
265
+ "children" : [
266
+ {
267
+ "type" : "agent" ,
268
+ "data" : {
269
+ "name" : "test_agent" ,
270
+ "handoffs" : [],
271
+ "tools" : [],
272
+ "output_type" : "str" ,
273
+ },
274
+ }
275
+ ],
276
+ }
277
+ ]
278
+ )
279
+
167
280
spans = fetch_ordered_spans ()
168
281
assert len (spans ) == 1 , f"Got { len (spans )} , but expected 1: the agent span"
169
282
0 commit comments