- 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
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
from unittest.mock import AsyncMock
|
|
|
|
import pytest
|
|
from prompt_toolkit.document import Document
|
|
from prompt_toolkit.validation import ValidationError
|
|
|
|
from falyx.validators import CommandValidator
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_command_validator_validates_command():
|
|
fake_falyx = AsyncMock()
|
|
fake_falyx.get_command.return_value = (False, object(), (), {}, {})
|
|
validator = CommandValidator(fake_falyx, "Invalid!")
|
|
|
|
await validator.validate_async(Document("valid"))
|
|
fake_falyx.get_command.assert_awaited_once()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_command_validator_rejects_invalid_command():
|
|
fake_falyx = AsyncMock()
|
|
fake_falyx.get_command.return_value = (False, None, (), {}, {})
|
|
validator = CommandValidator(fake_falyx, "Invalid!")
|
|
|
|
with pytest.raises(ValidationError):
|
|
await validator.validate_async(Document("not_a_command"))
|
|
|
|
with pytest.raises(ValidationError):
|
|
await validator.validate_async(Document(""))
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_command_validator_is_preview():
|
|
fake_falyx = AsyncMock()
|
|
fake_falyx.get_command.return_value = (True, None, (), {}, {})
|
|
validator = CommandValidator(fake_falyx, "Invalid!")
|
|
|
|
await validator.validate_async(Document("?preview_command"))
|
|
fake_falyx.get_command.assert_awaited_once_with(
|
|
"?preview_command", from_validate=True
|
|
)
|