diff --git a/falyx/version.py b/falyx/version.py index f3b4574..970659c 100644 --- a/falyx/version.py +++ b/falyx/version.py @@ -1 +1 @@ -__version__ = "0.1.15" +__version__ = "0.1.16" diff --git a/pyproject.toml b/pyproject.toml index 038bfa4..2806646 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "falyx" -version = "0.1.15" +version = "0.1.16" description = "Reliable and introspectable async CLI action framework." authors = ["Roland Thomas Jr "] license = "MIT" diff --git a/tests/test_run_key.py b/tests/test_run_key.py new file mode 100644 index 0000000..ed470c9 --- /dev/null +++ b/tests/test_run_key.py @@ -0,0 +1,45 @@ +import pytest + +from falyx import Action, Falyx + + +@pytest.mark.asyncio +async def test_run_key(): + """Test if Falyx can run in run key mode.""" + falyx = Falyx("Run Key Test") + + # Add a simple command + falyx.add_command( + key="T", + description="Test Command", + action=lambda: "Hello, World!", + ) + + # Run the CLI + result = await falyx.run_key("T") + assert result == "Hello, World!" + + +@pytest.mark.asyncio +async def test_run_key_recover(): + """Test if Falyx can recover from a failure in run key mode.""" + falyx = Falyx("Run Key Recovery Test") + + state = {"count": 0} + + async def flaky(): + if not state["count"]: + state["count"] += 1 + raise RuntimeError("Random failure!") + return "ok" + + # Add a command that raises an exception + falyx.add_command( + key="E", + description="Error Command", + action=Action("flaky", flaky), + retry=True, + ) + + result = await falyx.run_key("E") + assert result == "ok"