mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-23 23:28:15 +00:00
chore: add missing event scope
This commit is contained in:
@@ -237,6 +237,7 @@ SCOPE_ENDING_EVENTS: frozenset[str] = frozenset(
|
|||||||
"flow_paused",
|
"flow_paused",
|
||||||
"method_execution_finished",
|
"method_execution_finished",
|
||||||
"method_execution_failed",
|
"method_execution_failed",
|
||||||
|
"method_execution_paused",
|
||||||
"crew_kickoff_completed",
|
"crew_kickoff_completed",
|
||||||
"crew_kickoff_failed",
|
"crew_kickoff_failed",
|
||||||
"crew_train_completed",
|
"crew_train_completed",
|
||||||
@@ -287,6 +288,7 @@ VALID_EVENT_PAIRS: dict[str, str] = {
|
|||||||
"flow_paused": "flow_started",
|
"flow_paused": "flow_started",
|
||||||
"method_execution_finished": "method_execution_started",
|
"method_execution_finished": "method_execution_started",
|
||||||
"method_execution_failed": "method_execution_started",
|
"method_execution_failed": "method_execution_started",
|
||||||
|
"method_execution_paused": "method_execution_started",
|
||||||
"crew_kickoff_completed": "crew_kickoff_started",
|
"crew_kickoff_completed": "crew_kickoff_started",
|
||||||
"crew_kickoff_failed": "crew_kickoff_started",
|
"crew_kickoff_failed": "crew_kickoff_started",
|
||||||
"crew_train_completed": "crew_train_started",
|
"crew_train_completed": "crew_train_started",
|
||||||
|
|||||||
@@ -14,10 +14,16 @@ from crewai.events.event_context import (
|
|||||||
EventContextConfig,
|
EventContextConfig,
|
||||||
get_current_parent_id,
|
get_current_parent_id,
|
||||||
get_enclosing_parent_id,
|
get_enclosing_parent_id,
|
||||||
|
get_last_event_id,
|
||||||
|
get_triggering_event_id,
|
||||||
handle_empty_pop,
|
handle_empty_pop,
|
||||||
handle_mismatch,
|
handle_mismatch,
|
||||||
pop_event_scope,
|
pop_event_scope,
|
||||||
push_event_scope,
|
push_event_scope,
|
||||||
|
reset_last_event_id,
|
||||||
|
set_last_event_id,
|
||||||
|
set_triggering_event_id,
|
||||||
|
triggered_by_scope,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -96,4 +102,79 @@ class TestEventTypeSets:
|
|||||||
|
|
||||||
def test_starting_and_ending_are_disjoint(self) -> None:
|
def test_starting_and_ending_are_disjoint(self) -> None:
|
||||||
overlap = SCOPE_STARTING_EVENTS & SCOPE_ENDING_EVENTS
|
overlap = SCOPE_STARTING_EVENTS & SCOPE_ENDING_EVENTS
|
||||||
assert not overlap
|
assert not overlap
|
||||||
|
|
||||||
|
|
||||||
|
class TestLastEventIdTracking:
|
||||||
|
"""Tests for linear chain event ID tracking."""
|
||||||
|
|
||||||
|
def test_initial_last_event_id_is_none(self) -> None:
|
||||||
|
reset_last_event_id()
|
||||||
|
assert get_last_event_id() is None
|
||||||
|
|
||||||
|
def test_set_and_get_last_event_id(self) -> None:
|
||||||
|
reset_last_event_id()
|
||||||
|
set_last_event_id("event-123")
|
||||||
|
assert get_last_event_id() == "event-123"
|
||||||
|
|
||||||
|
def test_reset_clears_last_event_id(self) -> None:
|
||||||
|
set_last_event_id("event-123")
|
||||||
|
reset_last_event_id()
|
||||||
|
assert get_last_event_id() is None
|
||||||
|
|
||||||
|
def test_overwrite_last_event_id(self) -> None:
|
||||||
|
reset_last_event_id()
|
||||||
|
set_last_event_id("event-1")
|
||||||
|
set_last_event_id("event-2")
|
||||||
|
assert get_last_event_id() == "event-2"
|
||||||
|
|
||||||
|
|
||||||
|
class TestTriggeringEventIdTracking:
|
||||||
|
"""Tests for causal chain event ID tracking."""
|
||||||
|
|
||||||
|
def test_initial_triggering_event_id_is_none(self) -> None:
|
||||||
|
set_triggering_event_id(None)
|
||||||
|
assert get_triggering_event_id() is None
|
||||||
|
|
||||||
|
def test_set_and_get_triggering_event_id(self) -> None:
|
||||||
|
set_triggering_event_id("trigger-123")
|
||||||
|
assert get_triggering_event_id() == "trigger-123"
|
||||||
|
set_triggering_event_id(None)
|
||||||
|
|
||||||
|
def test_set_none_clears_triggering_event_id(self) -> None:
|
||||||
|
set_triggering_event_id("trigger-123")
|
||||||
|
set_triggering_event_id(None)
|
||||||
|
assert get_triggering_event_id() is None
|
||||||
|
|
||||||
|
|
||||||
|
class TestTriggeredByScope:
|
||||||
|
"""Tests for triggered_by_scope context manager."""
|
||||||
|
|
||||||
|
def test_scope_sets_triggering_id(self) -> None:
|
||||||
|
set_triggering_event_id(None)
|
||||||
|
with triggered_by_scope("trigger-456"):
|
||||||
|
assert get_triggering_event_id() == "trigger-456"
|
||||||
|
|
||||||
|
def test_scope_restores_previous_value(self) -> None:
|
||||||
|
set_triggering_event_id(None)
|
||||||
|
with triggered_by_scope("trigger-456"):
|
||||||
|
pass
|
||||||
|
assert get_triggering_event_id() is None
|
||||||
|
|
||||||
|
def test_nested_scopes(self) -> None:
|
||||||
|
set_triggering_event_id(None)
|
||||||
|
with triggered_by_scope("outer"):
|
||||||
|
assert get_triggering_event_id() == "outer"
|
||||||
|
with triggered_by_scope("inner"):
|
||||||
|
assert get_triggering_event_id() == "inner"
|
||||||
|
assert get_triggering_event_id() == "outer"
|
||||||
|
assert get_triggering_event_id() is None
|
||||||
|
|
||||||
|
def test_scope_restores_on_exception(self) -> None:
|
||||||
|
set_triggering_event_id(None)
|
||||||
|
try:
|
||||||
|
with triggered_by_scope("trigger-789"):
|
||||||
|
raise ValueError("test error")
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
assert get_triggering_event_id() is None
|
||||||
Reference in New Issue
Block a user