mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-27 17:18:13 +00:00
test: Improve flow persistence test cases and logging
This commit is contained in:
@@ -13,6 +13,7 @@ from crewai.flow.persistence.sqlite import SQLiteFlowPersistence
|
|||||||
|
|
||||||
class TestState(FlowState):
|
class TestState(FlowState):
|
||||||
"""Test state model with required id field."""
|
"""Test state model with required id field."""
|
||||||
|
|
||||||
counter: int = 0
|
counter: int = 0
|
||||||
message: str = ""
|
message: str = ""
|
||||||
|
|
||||||
@@ -73,7 +74,6 @@ def test_flow_state_restoration(tmp_path):
|
|||||||
|
|
||||||
# First flow execution to create initial state
|
# First flow execution to create initial state
|
||||||
class RestorableFlow(Flow[TestState]):
|
class RestorableFlow(Flow[TestState]):
|
||||||
|
|
||||||
@start()
|
@start()
|
||||||
@persist(persistence)
|
@persist(persistence)
|
||||||
def set_message(self):
|
def set_message(self):
|
||||||
@@ -89,10 +89,7 @@ def test_flow_state_restoration(tmp_path):
|
|||||||
|
|
||||||
# Test case 1: Restore using restore_uuid with field override
|
# Test case 1: Restore using restore_uuid with field override
|
||||||
flow2 = RestorableFlow(persistence=persistence)
|
flow2 = RestorableFlow(persistence=persistence)
|
||||||
flow2.kickoff(inputs={
|
flow2.kickoff(inputs={"id": original_uuid, "counter": 43})
|
||||||
"id": original_uuid,
|
|
||||||
"counter": 43
|
|
||||||
})
|
|
||||||
|
|
||||||
# Verify state restoration and selective field override
|
# Verify state restoration and selective field override
|
||||||
assert flow2.state.id == original_uuid
|
assert flow2.state.id == original_uuid
|
||||||
@@ -101,10 +98,7 @@ def test_flow_state_restoration(tmp_path):
|
|||||||
|
|
||||||
# Test case 2: Restore using kwargs['id']
|
# Test case 2: Restore using kwargs['id']
|
||||||
flow3 = RestorableFlow(persistence=persistence)
|
flow3 = RestorableFlow(persistence=persistence)
|
||||||
flow3.kickoff(inputs={
|
flow3.kickoff(inputs={"id": original_uuid, "message": "Updated message"})
|
||||||
"id": original_uuid,
|
|
||||||
"message": "Updated message"
|
|
||||||
})
|
|
||||||
|
|
||||||
# Verify state restoration and selective field override
|
# Verify state restoration and selective field override
|
||||||
assert flow3.state.id == original_uuid
|
assert flow3.state.id == original_uuid
|
||||||
@@ -175,8 +169,12 @@ def test_multiple_method_persistence(tmp_path):
|
|||||||
assert final_state.counter == 99999
|
assert final_state.counter == 99999
|
||||||
assert final_state.message == "Step 99999"
|
assert final_state.message == "Step 99999"
|
||||||
|
|
||||||
|
|
||||||
def test_persist_decorator_verbose_logging(tmp_path, caplog):
|
def test_persist_decorator_verbose_logging(tmp_path, caplog):
|
||||||
"""Test that @persist decorator's verbose parameter controls logging."""
|
"""Test that @persist decorator's verbose parameter controls logging."""
|
||||||
|
# Set logging level to ensure we capture all logs
|
||||||
|
caplog.set_level("INFO")
|
||||||
|
|
||||||
db_path = os.path.join(tmp_path, "test_flows.db")
|
db_path = os.path.join(tmp_path, "test_flows.db")
|
||||||
persistence = SQLiteFlowPersistence(db_path)
|
persistence = SQLiteFlowPersistence(db_path)
|
||||||
|
|
||||||
@@ -192,7 +190,7 @@ def test_persist_decorator_verbose_logging(tmp_path, caplog):
|
|||||||
|
|
||||||
flow = QuietFlow(persistence=persistence)
|
flow = QuietFlow(persistence=persistence)
|
||||||
flow.kickoff()
|
flow.kickoff()
|
||||||
assert "Saving flow state to memory for ID: test-uuid-1" not in caplog.text
|
assert "Saving flow state" not in caplog.text
|
||||||
|
|
||||||
# Clear the log
|
# Clear the log
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
@@ -209,4 +207,4 @@ def test_persist_decorator_verbose_logging(tmp_path, caplog):
|
|||||||
|
|
||||||
flow = VerboseFlow(persistence=persistence)
|
flow = VerboseFlow(persistence=persistence)
|
||||||
flow.kickoff()
|
flow.kickoff()
|
||||||
assert "Saving flow state to memory for ID: test-uuid-2" in caplog.text
|
assert "Saving flow state" in caplog.text
|
||||||
|
|||||||
Reference in New Issue
Block a user