33import  asyncio 
44
55import  pytest 
6+ from  inline_snapshot  import  snapshot 
67
78from  agents  import  Agent , RunConfig , Runner , trace 
89
910from  .fake_model  import  FakeModel 
1011from  .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 
1213
1314
1415@pytest .mark .asyncio  
@@ -25,6 +26,25 @@ async def test_single_run_is_single_trace():
2526    traces  =  fetch_traces ()
2627    assert  len (traces ) ==  1 , f"Expected 1 trace, got { len (traces )}  
2728
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+ 
2848    spans  =  fetch_ordered_spans ()
2949    assert  len (spans ) ==  1 , (
3050        f"Got { len (spans )}  
@@ -52,6 +72,39 @@ async def test_multiple_runs_are_multiple_traces():
5272    traces  =  fetch_traces ()
5373    assert  len (traces ) ==  2 , f"Expected 2 traces, got { len (traces )}  
5474
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+ 
55108    spans  =  fetch_ordered_spans ()
56109    assert  len (spans ) ==  2 , f"Got { len (spans )}  
57110
@@ -79,6 +132,43 @@ async def test_wrapped_trace_is_single_trace():
79132    traces  =  fetch_traces ()
80133    assert  len (traces ) ==  1 , f"Expected 1 trace, got { len (traces )}  
81134
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+ 
82172    spans  =  fetch_ordered_spans ()
83173    assert  len (spans ) ==  3 , f"Got { len (spans )}  
84174
@@ -97,6 +187,8 @@ async def test_parent_disabled_trace_disabled_agent_trace():
97187
98188    traces  =  fetch_traces ()
99189    assert  len (traces ) ==  0 , f"Expected 0 traces, got { len (traces )}  
190+     assert  fetch_normalized_spans () ==  snapshot ([])
191+ 
100192    spans  =  fetch_ordered_spans ()
101193    assert  len (spans ) ==  0 , (
102194        f"Expected no spans, got { len (spans )} { [x .span_data  for  x  in  spans ]}  
@@ -116,6 +208,8 @@ async def test_manual_disabling_works():
116208
117209    traces  =  fetch_traces ()
118210    assert  len (traces ) ==  0 , f"Expected 0 traces, got { len (traces )}  
211+     assert  fetch_normalized_spans () ==  snapshot ([])
212+ 
119213    spans  =  fetch_ordered_spans ()
120214    assert  len (spans ) ==  0 , f"Got { len (spans )}  
121215
@@ -164,6 +258,25 @@ async def test_not_starting_streaming_creates_trace():
164258    traces  =  fetch_traces ()
165259    assert  len (traces ) ==  1 , f"Expected 1 trace, got { len (traces )}  
166260
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+ 
167280    spans  =  fetch_ordered_spans ()
168281    assert  len (spans ) ==  1 , f"Got { len (spans )}  
169282
0 commit comments