Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions claude-workflows/pr-review/scripts/pr-comment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,26 @@ shift 2
while [ $# -gt 0 ]; do
case "$1" in
--severity)
if [ $# -lt 2 ] || [[ "${2:-}" == --* ]]; then
echo "Error: Missing value for --severity. Use: --severity <critical|high|medium|low|nitpick>" >&2
exit 1
fi
SEVERITY="$2"
shift 2
;;
--title)
if [ $# -lt 2 ] || [[ "${2:-}" == --* ]]; then
echo "Error: Missing value for --title. Use: --title <description>" >&2
exit 1
fi
TITLE="$2"
shift 2
;;
--why)
if [ $# -lt 2 ] || [[ "${2:-}" == --* ]]; then
echo "Error: Missing value for --why. Use: --why <reason>" >&2
exit 1
fi
WHY="$2"
shift 2
;;
Expand Down
57 changes: 57 additions & 0 deletions tests/test_pr_comment_arg_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os
import subprocess
from pathlib import Path

import pytest


ROOT = Path(__file__).resolve().parent.parent
PR_COMMENT = ROOT / "claude-workflows" / "pr-review" / "scripts" / "pr-comment.sh"


def run_pr_comment(*args: str) -> subprocess.CompletedProcess[str]:
env = os.environ.copy()
env["PR_REVIEW_REPO"] = "elastic/ai-github-actions"
env["PR_REVIEW_PR_NUMBER"] = "1"
return subprocess.run(
["bash", str(PR_COMMENT), *args],
env=env,
capture_output=True,
text=True,
check=False,
)


@pytest.mark.parametrize(
("args", "expected_message"),
[
(("README.md", "1", "--severity"), "Missing value for --severity"),
(
("README.md", "1", "--severity", "high", "--title"),
"Missing value for --title",
),
(
("README.md", "1", "--severity", "high", "--title", "desc", "--why"),
"Missing value for --why",
),
(
(
"README.md",
"1",
"--severity",
"--title",
"desc",
"--why",
"impact",
"--no-suggestion",
),
"Missing value for --severity",
),
],
)
def test_missing_named_argument_values_emit_actionable_errors(args, expected_message):
result = run_pr_comment(*args)

assert result.returncode != 0
assert "Error:" in result.stderr
assert expected_message in result.stderr
Loading