- add CommandExecutor to unify shared command execution lifecycle across Falyx and standalone command execution - add CommandRunner for running a single Command directly as a CLI or programmatic entrypoint - add Command.build() factory and rename parse_args() to resolve_args() to clarify the parsing-to-execution boundary - introduce ExecutionOption and wire execution-scoped flags into CommandArgumentParser and Command construction - refactor Falyx to use FalyxParser/ParseResult and CommandExecutor instead of the older argparse-based flow and run_key path - simplify __main__.py bootstrap by building a bootstrap Falyx instance directly and running flx.run() - improve completer support for preview commands and unique-prefix command resolution - default BottomBar toggle namespace to "default" - expand module/class docstrings to reflect the new execution architecture
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"
|