68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
import pytest
|
|
|
|
from agentci.domain.commands import CommandError, parse_command, resolve_job_kind
|
|
from agentci.domain.models import CommandName, JobKind
|
|
|
|
|
|
def test_ignores_non_commands() -> None:
|
|
assert parse_command("please run /agent plan") is None
|
|
|
|
|
|
@pytest.mark.parametrize("name", list(CommandName))
|
|
@pytest.mark.parametrize("line_breaks", [1, 2, 5])
|
|
def test_all_commands_accept_messages_after_any_number_of_lines(
|
|
name: CommandName, line_breaks: int
|
|
) -> None:
|
|
command = parse_command(
|
|
f"/agent {name.value}{'\n' * line_breaks}"
|
|
"focus on the API\nand add tests"
|
|
)
|
|
assert command is not None
|
|
assert command.name is name
|
|
assert command.message == "focus on the API\nand add tests"
|
|
|
|
|
|
@pytest.mark.parametrize("name", list(CommandName))
|
|
def test_all_commands_accept_crlf_separated_multiline_messages(
|
|
name: CommandName,
|
|
) -> None:
|
|
command = parse_command(
|
|
f"/agent {name.value}\r\n\r\n\r\n"
|
|
"focus on the API\r\nand add tests"
|
|
)
|
|
assert command is not None
|
|
assert command.name is name
|
|
assert command.message == "focus on the API\r\nand add tests"
|
|
|
|
|
|
def test_discuss_requires_message() -> None:
|
|
with pytest.raises(CommandError, match="requires a message"):
|
|
parse_command("/agent discuss")
|
|
|
|
|
|
def test_rejects_wrong_location() -> None:
|
|
command = parse_command("/agent fix")
|
|
assert command is not None
|
|
with pytest.raises(CommandError, match="pull request"):
|
|
resolve_job_kind(command, is_pull_request=False)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("body", "message"),
|
|
[
|
|
("/agent iterate", ""),
|
|
("/agent iterate refine tests", "refine tests"),
|
|
(
|
|
"/agent iterate\n\nkeep the API stable\nlimit changes to the parser",
|
|
"keep the API stable\nlimit changes to the parser",
|
|
),
|
|
],
|
|
)
|
|
def test_iterate_accepts_optional_message(body: str, message: str) -> None:
|
|
command = parse_command(body)
|
|
assert command is not None
|
|
assert command.name is CommandName.ITERATE
|
|
assert command.message == message
|
|
assert resolve_job_kind(command, is_pull_request=False) is JobKind.ITERATE_PLAN
|
|
assert resolve_job_kind(command, is_pull_request=True) is JobKind.ITERATE_IMPLEMENT
|