shoc-pr-review-runner/tests/test-input-validation.sh

51 lines
2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Tests for scripts/resolve-inputs.sh (spec §8.2 rejection matrix).
set -euo pipefail
TESTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(cd "$TESTS_DIR/.." && pwd)"
pass=0
fail=0
# run_case <expect: ok|err> <name> <REVIEW_TYPE> <FRONTEND_PR> <BACKEND_PR>
run_case() {
local expect="$1" name="$2" review_type="$3" fe="$4" be="$5"
local tmp
tmp="$(mktemp -d)"
local rc=0
env -i PATH="$PATH" HOME="$HOME" \
WORKSPACE_DIR="$tmp" \
REVIEW_TYPE="$review_type" FRONTEND_PR="$fe" BACKEND_PR="$be" \
FRONTEND_REPO="Sea-Haven-Industries/shoc-frontend-new" \
BACKEND_REPO="Sea-Haven-Industries/shoc-backend" \
GITHUB_OUTPUT="$tmp/out" \
"$REPO_DIR/scripts/resolve-inputs.sh" >/dev/null 2>&1 || rc=$?
local got="ok"
[ "$rc" -eq 0 ] || got="err"
if [ "$got" = "$expect" ]; then
pass=$((pass + 1))
else
echo "FAIL: $name (expected $expect, got $got, rc=$rc)"
fail=$((fail + 1))
fi
rm -rf "$tmp"
}
run_case ok "frontend with number" frontend "47" ""
run_case ok "frontend with URL" frontend "https://github.com/Sea-Haven-Industries/shoc-frontend-new/pull/47" ""
run_case ok "backend with number" backend "" "25"
run_case ok "paired with both" paired "47" "25"
run_case err "frontend without frontend_pr" frontend "" ""
run_case err "backend without backend_pr" backend "" ""
run_case err "paired missing backend_pr" paired "47" ""
run_case err "paired missing frontend_pr" paired "" "25"
run_case err "URL from wrong repo" frontend "https://github.com/Sea-Haven-Industries/shoc-backend/pull/25" ""
run_case err "URL from foreign org" frontend "https://github.com/evil-org/shoc-frontend-new/pull/47" ""
run_case err "non-numeric garbage" frontend "abc" ""
run_case err "invalid review type" sideways "47" "25"
run_case err "shell metacharacters rejected" frontend '47; rm -rf /' ""
echo "input-validation: $pass passed, $fail failed"
[ "$fail" -eq 0 ]