From e683d6b06a2219921b9412c6c257e6265d34da6b Mon Sep 17 00:00:00 2001 From: David Ahmann Date: Sun, 1 Mar 2026 11:47:18 -0500 Subject: [PATCH 1/2] tests: enforce deterministic equal-priority task ordering (#4664) --- lib/crewai/tests/test_crew.py | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lib/crewai/tests/test_crew.py b/lib/crewai/tests/test_crew.py index 64d122a7ce..b9baeb7eb5 100644 --- a/lib/crewai/tests/test_crew.py +++ b/lib/crewai/tests/test_crew.py @@ -2288,6 +2288,48 @@ def condition_succeeds(task_output: TaskOutput) -> bool: ) # Third task used first task's output +def test_equal_priority_tasks_preserve_declared_order(researcher): + """Equal-priority tasks should execute in the order they are declared.""" + first_task = Task( + description="Task B", + expected_output="Output B", + agent=researcher, + config={"priority": 1}, + ) + second_task = Task( + description="Task A", + expected_output="Output A", + agent=researcher, + config={"priority": 1}, + ) + third_task = Task( + description="Task C", + expected_output="Output C", + agent=researcher, + config={"priority": 1}, + ) + + declared_order = [first_task.description, second_task.description, third_task.description] + observed_order: list[str] = [] + + def capture_execution_order(task: Task, context=None, tools=None): + observed_order.append(task.description) + return f"result:{task.description}" + + crew = Crew( + agents=[researcher], + tasks=[first_task, second_task, third_task], + process=Process.sequential, + ) + + with patch.object(Agent, "execute_task") as mock_execute_task: + mock_execute_task.side_effect = capture_execution_order + result = crew.kickoff() + + assert observed_order == declared_order + assert [task_output.description for task_output in result.tasks_output] == declared_order + + @pytest.mark.vcr() def test_conditional_tasks_result_collection(researcher, writer): """Test that task outputs are properly collected based on execution status.""" From 2caac657894382f03b7f2acf6007cdf0c8ae326f Mon Sep 17 00:00:00 2001 From: David Ahmann Date: Sun, 1 Mar 2026 11:55:05 -0500 Subject: [PATCH 2/2] tests: align ordering contract coverage (#4664) --- lib/crewai/tests/test_crew.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/crewai/tests/test_crew.py b/lib/crewai/tests/test_crew.py index b9baeb7eb5..7ca480020c 100644 --- a/lib/crewai/tests/test_crew.py +++ b/lib/crewai/tests/test_crew.py @@ -2288,25 +2288,22 @@ def condition_succeeds(task_output: TaskOutput) -> bool: ) # Third task used first task's output -def test_equal_priority_tasks_preserve_declared_order(researcher): - """Equal-priority tasks should execute in the order they are declared.""" +def test_sequential_tasks_preserve_declared_order(researcher): + """Sequential execution should preserve the order tasks are declared.""" first_task = Task( - description="Task B", + description="Task 2", expected_output="Output B", agent=researcher, - config={"priority": 1}, ) second_task = Task( - description="Task A", + description="Task 10", expected_output="Output A", agent=researcher, - config={"priority": 1}, ) third_task = Task( - description="Task C", + description="Task 1", expected_output="Output C", agent=researcher, - config={"priority": 1}, ) declared_order = [first_task.description, second_task.description, third_task.description]