refactor tests
Publish container image / Build and push (push) Successful in 32s

This commit is contained in:
2026-07-26 23:49:40 +02:00
parent 5ef10d28fe
commit ce9f1e3d20
32 changed files with 1546 additions and 1923 deletions
+54 -28
View File
@@ -8,27 +8,45 @@ 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(
@pytest.mark.parametrize(
("name", "is_pull_request", "expected_kind"),
[
(CommandName.PLAN, False, JobKind.PLAN),
(CommandName.DISCUSS, False, JobKind.DISCUSS),
(CommandName.IMPLEMENT, False, JobKind.IMPLEMENT),
(CommandName.ITERATE, False, JobKind.ITERATE_PLAN),
(CommandName.ITERATE, True, JobKind.ITERATE_IMPLEMENT),
(CommandName.FIX, True, JobKind.FIX),
],
)
def test_supported_commands_parse_and_resolve(
name: CommandName,
is_pull_request: bool,
expected_kind: JobKind,
) -> None:
command = parse_command(f"/agent {name.value}\r\n\r\n\r\nfocus on the API\r\nand add tests")
command = parse_command(f"/agent {name.value}\nfocus on the API\nand add tests")
assert command is not None
assert command.name is name
assert command.message == "focus on the API\r\nand add tests"
assert (command.name, command.message) == (
name,
"focus on the API\nand add tests",
)
assert resolve_job_kind(command, is_pull_request=is_pull_request) is expected_kind
@pytest.mark.parametrize(
("separator", "line_breaks"),
[("\n", 1), ("\n", 2), ("\n", 5), ("\r\n", 3)],
)
def test_multiline_messages_accept_line_separators(
separator: str,
line_breaks: int,
) -> None:
message = f"focus on the API{separator}and add tests"
command = parse_command(f"/agent {CommandName.PLAN.value}{separator * line_breaks}{message}")
assert command is not None
assert (command.name, command.message) == (CommandName.PLAN, message)
def test_discuss_requires_message() -> None:
@@ -36,11 +54,25 @@ def test_discuss_requires_message() -> None:
parse_command("/agent discuss")
def test_rejects_wrong_location() -> None:
command = parse_command("/agent fix")
@pytest.mark.parametrize(
("name", "is_pull_request", "error_match"),
[
(CommandName.FIX, False, "pull request"),
(CommandName.PLAN, True, "issue"),
(CommandName.DISCUSS, True, "issue"),
(CommandName.IMPLEMENT, True, "issue"),
],
)
def test_rejects_wrong_location(
name: CommandName,
is_pull_request: bool,
error_match: str,
) -> None:
command = parse_command(f"/agent {name.value} details")
assert command is not None
with pytest.raises(CommandError, match="pull request"):
resolve_job_kind(command, is_pull_request=False)
with pytest.raises(CommandError, match=error_match):
resolve_job_kind(command, is_pull_request=is_pull_request)
@pytest.mark.parametrize(
@@ -48,10 +80,6 @@ def test_rejects_wrong_location() -> None:
[
("/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:
@@ -59,5 +87,3 @@ def test_iterate_accepts_optional_message(body: str, message: str) -> None:
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