- extend OptionsManager to support multi-namespace option resolution and toggling - integrate OptionsManager more deeply across Action, ChainedAction, and ActionGroup - propagate shared runtime configuration through execution layers - refine action composition model (sequential + parallel execution semantics) - improve lifecycle consistency across BaseAction, Action, ChainedAction, and ActionGroup - begin aligning execution flow with centralized context and options handling wip: routing and root option parsing behavior still in progress
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
import pytest
|
|
|
|
from falyx import Falyx
|
|
from falyx.action import Action
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_execute_command():
|
|
"""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.execute_command("T")
|
|
assert result == "Hello, World!"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_execute_command_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.execute_command("E")
|
|
assert result == "ok"
|