Files
pi-kit/test/shell.test.sh
T
Aleksey Shakhmatov c068dfae0c fix(review): address review findings (guardrails, prompts, tests, docs)
- permission-gate: block refs/tags/v* pushes, rm -r -f separated flags,
  git reset --hard, git clean (verified against actual bypasses)
- prompts: /bugfix /feature /review no longer hardcode go-standards —
  reference profile-gated <lang>-standards instead
- company-context: drop hardcoded Go stack, note TRACKER_URL priority,
  warn on context truncation instead of silently dropping rules
- repo-map/docs-map: graceful degradation when config values are TODO
- /kit-doctor: warn on unfilled config fields (repoMap/trackerUrl/docsUrl)
- audit: retry POSTs to endpoint (3 attempts, backoff), still best-effort
- install.sh: remove TODO course URL from cheat sheet
- tests: expand guardrails (43 node checks), add shell tests for create-mr.sh
  (scp/https origin parse, GITLAB_HOST override, protected branch refusal),
  cover company-context lib (normalize/fetch/truncation) and mcp-bridge
- commit package-lock.json for reproducible installs
- document npm test Node >= 22.6 requirement (type stripping)
2026-08-06 11:22:53 +03:00

61 lines
2.2 KiB
Bash

#!/usr/bin/env bash
# Shell smoke tests for skills/jira-workflow/scripts/create-mr.sh.
# Network-free: uses MR_DRY_RUN=1 and a throwaway git repo.
# Run via `npm test` (after guardrails.test.ts) or directly: bash test/shell.test.sh
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
SCRIPT="$ROOT/skills/jira-workflow/scripts/create-mr.sh"
FAILS=0
check() { # <name> <expected-substring> <actual>
local name="$1" expected="$2" actual="$3"
if grep -qF -- "$expected" <<<"$actual"; then
echo "PASS $name"
else
echo "FAIL $name (expected substring: $expected)"
echo "--- actual ---"
echo "$actual"
FAILS=$((FAILS + 1))
fi
}
# Fresh throwaway repo with an empty commit.
DIR="$(mktemp -d)"
trap 'rm -rf "$DIR"' EXIT
cd "$DIR"
git init -q
git config user.email test@example.com
git config user.name Test
git remote add origin git@gitlab.tech.mvideo.ru:ai/foo.git
git commit --allow-empty -q -m "chore: init"
git checkout -q -b feature/PROJ-1-smoke
# 1. scp-like origin → API URL with encoded namespace.
OUT="$(GITLAB_TOKEN=dummy MR_DRY_RUN=1 bash "$SCRIPT" "Test MR" 2>&1)"
check "create-mr: scp-like origin parse" "POST https://gitlab.tech.mvideo.ru/api/v4/projects/ai%2Ffoo/merge_requests" "$OUT"
check "create-mr: dry-run shows would-push" "would push: git push -u origin feature/PROJ-1-smoke" "$OUT"
# 2. https-like origin → same API shape, different host.
git remote set-url origin "https://git.codelab.vc/ai/bar.git"
OUT="$(GITLAB_TOKEN=dummy MR_DRY_RUN=1 bash "$SCRIPT" "Test MR" 2>&1)"
check "create-mr: https origin parse" "POST https://git.codelab.vc/api/v4/projects/ai%2Fbar/merge_requests" "$OUT"
# 3. GITLAB_HOST overrides the derived host.
OUT="$(GITLAB_TOKEN=dummy GITLAB_HOST=gitlab.example.com MR_DRY_RUN=1 bash "$SCRIPT" "Test MR" 2>&1)"
check "create-mr: GITLAB_HOST override" "POST https://gitlab.example.com/api/v4/projects/ai%2Fbar/merge_requests" "$OUT"
# 4. Refuses to create MR from a protected/release source branch.
git checkout -q -b release-42
OUT="$(GITLAB_TOKEN=dummy MR_DRY_RUN=1 bash "$SCRIPT" "Test MR" 2>&1 || true)"
check "create-mr: refuses release-* source" "Refusing: source branch" "$OUT"
echo ""
if [ "$FAILS" -eq 0 ]; then
echo "shell tests: ALL PASS"
exit 0
else
echo "shell tests: $FAILS FAILED"
exit 1
fi