feat: Add module docs, Enum coercion, tracebacks, and toggle improvements

- Add comprehensive module docstrings across the codebase for better clarity and documentation.
- Refactor Enum classes (e.g., FileType, ConfirmType) to use `_missing_` for built-in coercion from strings.
- Add `encoding` attribute to `LoadFileAction`, `SaveFileAction`, and `SelectFileAction` for more flexible file handling.
- Enable lazy file loading by default in `SelectFileAction` to improve performance.
- Simplify bottom bar toggle behavior: all toggles now use `ctrl+<key>`, eliminating the need for key conflict checks with Falyx commands.
- Add `ignore_in_history` attribute to `Command` to refine how `ExecutionRegistry` identifies the last valid result.
- Improve History command output: now includes tracebacks when displaying exceptions.
This commit is contained in:
2025-07-19 14:44:43 -04:00
parent 21402bff9a
commit 7f63e16097
61 changed files with 2324 additions and 373 deletions

View File

@ -1,6 +1,12 @@
import pytest
from falyx.action import Action, ChainedAction, FallbackAction, LiteralInputAction
from falyx.action import (
Action,
ActionGroup,
ChainedAction,
FallbackAction,
LiteralInputAction,
)
from falyx.context import ExecutionContext
from falyx.execution_registry import ExecutionRegistry as er
@ -38,14 +44,13 @@ async def test_action_async_callable():
action = Action("test_action", async_callable)
result = await action()
assert result == "Hello, World!"
print(action)
assert (
str(action)
== "Action(name='test_action', action=async_callable, retry=False, rollback=False)"
== "Action(name='test_action', action=async_callable, args=(), kwargs={}, retry=False, rollback=False)"
)
assert (
repr(action)
== "Action(name='test_action', action=async_callable, retry=False, rollback=False)"
== "Action(name='test_action', action=async_callable, args=(), kwargs={}, retry=False, rollback=False)"
)
@ -60,11 +65,12 @@ async def test_chained_action():
return_list=True,
)
print(chain)
result = await chain()
assert result == [1, 2]
assert (
str(chain)
== "ChainedAction(name='Simple Chain', actions=['one', 'two'], auto_inject=False, return_list=True)"
== "ChainedAction(name=Simple Chain, actions=['one', 'two'], args=(), kwargs={}, auto_inject=False, return_list=True)"
)
@ -73,17 +79,17 @@ async def test_action_group():
"""Test if ActionGroup can be created and used."""
action1 = Action("one", lambda: 1)
action2 = Action("two", lambda: 2)
group = ChainedAction(
group = ActionGroup(
name="Simple Group",
actions=[action1, action2],
return_list=True,
)
print(group)
result = await group()
assert result == [1, 2]
assert result == [("one", 1), ("two", 2)]
assert (
str(group)
== "ChainedAction(name='Simple Group', actions=['one', 'two'], auto_inject=False, return_list=True)"
== "ActionGroup(name=Simple Group, actions=['one', 'two'], args=(), kwargs={}, inject_last_result=False, inject_into=last_result)"
)

View File

@ -0,0 +1,94 @@
import pytest
from falyx.action import ConfirmAction
@pytest.mark.asyncio
async def test_confirm_action_yes_no():
action = ConfirmAction(
name="test",
message="Are you sure?",
never_prompt=True,
confirm_type="yes_no",
)
result = await action()
assert result is True
@pytest.mark.asyncio
async def test_confirm_action_yes_cancel():
action = ConfirmAction(
name="test",
message="Are you sure?",
never_prompt=True,
confirm_type="yes_cancel",
)
result = await action()
assert result is True
@pytest.mark.asyncio
async def test_confirm_action_yes_no_cancel():
action = ConfirmAction(
name="test",
message="Are you sure?",
never_prompt=True,
confirm_type="yes_no_cancel",
)
result = await action()
assert result is True
@pytest.mark.asyncio
async def test_confirm_action_type_word():
action = ConfirmAction(
name="test",
message="Are you sure?",
never_prompt=True,
confirm_type="type_word",
)
result = await action()
assert result is True
@pytest.mark.asyncio
async def test_confirm_action_type_word_cancel():
action = ConfirmAction(
name="test",
message="Are you sure?",
never_prompt=True,
confirm_type="type_word_cancel",
)
result = await action()
assert result is True
@pytest.mark.asyncio
async def test_confirm_action_ok_cancel():
action = ConfirmAction(
name="test",
message="Are you sure?",
never_prompt=True,
confirm_type="ok_cancel",
)
result = await action()
assert result is True
@pytest.mark.asyncio
async def test_confirm_action_acknowledge():
action = ConfirmAction(
name="test",
message="Are you sure?",
never_prompt=True,
confirm_type="acknowledge",
)
result = await action()
assert result is True

View File

@ -1,6 +1,6 @@
import pytest
from falyx.action.selection_action import SelectionAction
from falyx.action import SelectionAction
from falyx.selection import SelectionOption

View File

@ -53,7 +53,7 @@ def test_command_str():
print(cmd)
assert (
str(cmd)
== "Command(key='TEST', description='Test Command' action='Action(name='test_action', action=dummy_action, retry=False, rollback=False)')"
== "Command(key='TEST', description='Test Command' action='Action(name='test_action', action=dummy_action, args=(), kwargs={}, retry=False, rollback=False)')"
)