[fix]. Reply on unsupported @codex commands
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from gitea_codex_bot.services.commands import parse_command
|
||||
from gitea_codex_bot.services.commands import detect_prefixed_command, parse_command
|
||||
|
||||
|
||||
def test_parse_review_command_modes() -> None:
|
||||
@@ -49,3 +49,11 @@ def test_parse_help_long_flag_and_arguments() -> None:
|
||||
assert cmd is not None
|
||||
assert cmd.name == "help"
|
||||
assert cmd.arguments == ["status", "quick"]
|
||||
|
||||
|
||||
def test_detect_prefixed_command_for_unsupported_name() -> None:
|
||||
assert detect_prefixed_command("@codex shipit now", aliases={"codex"}) == "shipit"
|
||||
|
||||
|
||||
def test_detect_prefixed_command_returns_none_for_non_alias() -> None:
|
||||
assert detect_prefixed_command("@someone review", aliases={"codex"}) is None
|
||||
|
||||
@@ -254,6 +254,66 @@ def test_webhook_accepts_help_short_flag_and_queues(monkeypatch) -> None:
|
||||
assert queued.command == "help"
|
||||
|
||||
|
||||
def test_webhook_replies_fix_is_no_longer_supported(monkeypatch) -> None:
|
||||
posted_comments: list[str] = []
|
||||
monkeypatch.setattr(
|
||||
"gitea_codex_bot.services.gitea.GiteaClient.post_issue_comment",
|
||||
lambda _self, _repo, _pr, body: posted_comments.append(body) or 100,
|
||||
)
|
||||
|
||||
client = TestClient(app)
|
||||
payload_obj = _payload("@codex fix --branch", username="alice", comment_id=444)
|
||||
raw = json.dumps(payload_obj).encode()
|
||||
|
||||
response = client.post(
|
||||
"/webhook/gitea",
|
||||
content=raw,
|
||||
headers={
|
||||
"X-Gitea-Event": "issue_comment",
|
||||
"X-Gitea-Delivery": "d-fix-unsupported",
|
||||
"X-Gitea-Signature": _sign(raw),
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["reason"] == "unsupported command"
|
||||
assert response.json()["command"] == "fix"
|
||||
assert any("no longer supported" in body for body in posted_comments)
|
||||
session_factory = get_session_factory()
|
||||
with session_factory() as session:
|
||||
queued = session.execute(select(ReviewJob).where(ReviewJob.trigger_comment_id == 444)).scalar_one_or_none()
|
||||
assert queued is None
|
||||
|
||||
|
||||
def test_webhook_replies_for_unknown_prefixed_command(monkeypatch) -> None:
|
||||
posted_comments: list[str] = []
|
||||
monkeypatch.setattr(
|
||||
"gitea_codex_bot.services.gitea.GiteaClient.post_issue_comment",
|
||||
lambda _self, _repo, _pr, body: posted_comments.append(body) or 100,
|
||||
)
|
||||
|
||||
client = TestClient(app)
|
||||
payload_obj = _payload("@codex deploy", username="alice", comment_id=445)
|
||||
raw = json.dumps(payload_obj).encode()
|
||||
|
||||
response = client.post(
|
||||
"/webhook/gitea",
|
||||
content=raw,
|
||||
headers={
|
||||
"X-Gitea-Event": "issue_comment",
|
||||
"X-Gitea-Delivery": "d-unknown-unsupported",
|
||||
"X-Gitea-Signature": _sign(raw),
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["reason"] == "unsupported command"
|
||||
assert response.json()["command"] == "deploy"
|
||||
assert any("not supported" in body for body in posted_comments)
|
||||
|
||||
|
||||
def test_webhook_logs_when_repo_not_allowed(monkeypatch) -> None:
|
||||
messages: list[str] = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user