@@ -447,6 +447,50 @@ def stream_chunks(x):
447447 assert ["a_0" , "a_1" ] in result
448448 assert ["b_0" , "b_1" ] in result
449449
450+ def test_collector_sets_stream_collected_marker (self ):
451+ """Test that Collector sets stream_collected=True on collected events."""
452+
453+ def stream_chunks (x ):
454+ for i in range (2 ):
455+ yield f"{ x } _{ i } "
456+
457+ controller = build_flow (
458+ [
459+ SyncEmitSource (),
460+ Map (stream_chunks ),
461+ Collector (),
462+ Reduce ([], lambda acc , x : acc + [x ], full_event = True ),
463+ ]
464+ ).run ()
465+
466+ controller .emit ("test" )
467+ controller .terminate ()
468+ result = controller .await_termination ()
469+
470+ assert len (result ) == 1
471+ event = result [0 ]
472+ assert event .stream_collected is True
473+
474+ def test_collector_passthrough_no_stream_collected_marker (self ):
475+ """Test that Collector does NOT set stream_collected on non-streaming events."""
476+
477+ controller = build_flow (
478+ [
479+ SyncEmitSource (),
480+ Map (lambda x : x * 2 ),
481+ Collector (),
482+ Reduce ([], lambda acc , x : acc + [x ], full_event = True ),
483+ ]
484+ ).run ()
485+
486+ controller .emit (5 )
487+ controller .terminate ()
488+ result = controller .await_termination ()
489+
490+ assert len (result ) == 1
491+ event = result [0 ]
492+ assert getattr (event , "stream_collected" , False ) is False
493+
450494 def test_collector_invalid_expected_completions (self ):
451495 """Test that Collector raises error for invalid expected_completions."""
452496 with pytest .raises (ValueError , match = "expected_completions must be at least 1" ):
0 commit comments