Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

Adds more unit tests for state persistence

elijahbenizzy57c2230604cc
diff --git a/burr/core/persistence.py b/burr/core/persistence.py
index 03bd3ec8..66a1b85a 100644
--- a/burr/core/persistence.py
+++ b/burr/core/persistence.py
@@ -112,6 +112,29 @@ class PersisterHook(PostRunStepHook):
self.persister.save(partition_key, app_id, sequence_id, action.name, state, "failed")
+class DevNullPersister(BaseStatePersister):
+ """Does nothing, do not use this. This is for testing only."""
+
+ def load(
+ self, partition_key: str, app_id: Optional[str], sequence_id: Optional[int] = None
+ ) -> Optional[PersistedStateData]:
+ return None
+
+ def list_app_ids(self, partition_key: str) -> list[str]:
+ return []
+
+ def save(
+ self,
+ partition_key: Optional[str],
+ app_id: str,
+ sequence_id: int,
+ position: str,
+ state: State,
+ status: Literal["completed", "failed"],
+ ):
+ return
+
+
class SQLLitePersister(BaseStatePersister):
"""Class for SQLLite persistence of state. This is a simple implementation."""
diff --git a/tests/core/test_application.py b/tests/core/test_application.py
index c112e3dd..62e0187b 100644
--- a/tests/core/test_application.py
+++ b/tests/core/test_application.py
@@ -32,6 +32,7 @@ from burr.core.application import (
_validate_start,
_validate_transitions,
)
+from burr.core.persistence import DevNullPersister
from burr.lifecycle import (
PostRunStepHook,
PostRunStepHookAsync,
@@ -1430,3 +1431,13 @@ async def test_application_gives_graph():
assert len(graph.actions) == 2
assert len(graph.transitions) == 2
assert graph.entrypoint.name == "counter"
+
+
+def test_application_builder_initialize_does_not_allow_state_setting():
+ with pytest.raises(ValueError, match="Cannot call initialize_from"):
+ ApplicationBuilder().with_entrypoint("foo").with_state(**{"foo": "bar"}).initialize_from(
+ DevNullPersister(),
+ resume_at_next_action=True,
+ default_state={},
+ default_entrypoint="foo",
+ )