diff --git a/internal/scaffold/fullsend-repo/scripts/pre-code-test.sh b/internal/scaffold/fullsend-repo/scripts/pre-code-test.sh index 472c1bd0f..13e06d204 100644 --- a/internal/scaffold/fullsend-repo/scripts/pre-code-test.sh +++ b/internal/scaffold/fullsend-repo/scripts/pre-code-test.sh @@ -165,6 +165,62 @@ run_test_stdout() { echo "PASS: ${test_name}" } +# Check stdout contains one string and does NOT contain another. +run_test_stdout_excludes() { + local test_name="$1" + local pr_list_output="$2" + local expected_stdout="$3" + local excluded_stdout="$4" + local expect_exit="$5" + local extra_env="${6:-}" + + local mock_bin + mock_bin="$(build_mock "${pr_list_output}")" + + local env_cmd=( + env + PATH="${mock_bin}:${PATH}" + ISSUE_NUMBER="42" + REPO_FULL_NAME="test-org/test-repo" + GITHUB_ISSUE_URL="https://github.com/test-org/test-repo/issues/42" + GH_TOKEN="fake-token" + ) + + if [[ -n "${extra_env}" ]]; then + while IFS= read -r kv; do + [[ -n "${kv}" ]] && env_cmd+=("${kv}") + done <<< "${extra_env}" + fi + + local exit_code=0 + "${env_cmd[@]}" bash "${PRE_SCRIPT}" > "${TMPDIR}/stdout.log" 2>&1 || exit_code=$? + + if [[ ${exit_code} -ne ${expect_exit} ]]; then + echo "FAIL: ${test_name} — expected exit ${expect_exit}, got ${exit_code}" + cat "${TMPDIR}/stdout.log" + FAILURES=$((FAILURES + 1)) + return + fi + + if ! grep -qF "${expected_stdout}" "${TMPDIR}/stdout.log" 2>/dev/null; then + echo "FAIL: ${test_name} — expected stdout '${expected_stdout}' not found" + echo "Actual stdout:" + cat "${TMPDIR}/stdout.log" + FAILURES=$((FAILURES + 1)) + return + fi + + if grep -qF "${excluded_stdout}" "${TMPDIR}/stdout.log" 2>/dev/null; then + echo "FAIL: ${test_name} — excluded stdout '${excluded_stdout}' was found" + echo "Actual stdout:" + cat "${TMPDIR}/stdout.log" + FAILURES=$((FAILURES + 1)) + return + fi + + echo "PASS: ${test_name}" +} + # --- Test cases --- # Tab character for readability. @@ -250,6 +306,38 @@ run_test "pr-label-created" \ "gh label create pr-open --repo test-org/test-repo" \ 0 +# --- Regression tests: --force bypasses PR search (issue #1697) --- + +# COMMENT_BODY with --force must exit before PR search is reached. +run_test_stdout_excludes "force-comment-body-no-pr-search" \ + "99${TAB}human-dev${TAB}https://github.com/test-org/test-repo/pull/99" \ + "Force override" \ + "Checking for existing open PRs" \ + 0 \ + "COMMENT_BODY=/fs-code --force" + +# CODE_FORCE=true must exit before PR search is reached. +run_test_stdout_excludes "force-code-force-no-pr-search" \ + "99${TAB}human-dev${TAB}https://github.com/test-org/test-repo/pull/99" \ + "Force override" \ + "Checking for existing open PRs" \ + 0 \ + "CODE_FORCE=true" + +# Force check logs COMMENT_BODY value for debuggability. +run_test_stdout "force-check-logs-comment-body" \ + "" \ + "Evaluating force override:" \ + 0 \ + "COMMENT_BODY=/fs-code --force" + +# Without --force, PR search IS reached (no false bypass). +run_test_stdout "no-force-reaches-pr-search" \ + "" \ + "Checking for existing open PRs" \ + 0 \ + "COMMENT_BODY=/fs-code" + # --- Summary --- echo "" diff --git a/internal/scaffold/fullsend-repo/scripts/pre-code.sh b/internal/scaffold/fullsend-repo/scripts/pre-code.sh index 4a0fff348..a64641ce2 100755 --- a/internal/scaffold/fullsend-repo/scripts/pre-code.sh +++ b/internal/scaffold/fullsend-repo/scripts/pre-code.sh @@ -61,6 +61,7 @@ if [[ -z "${GH_TOKEN:-}" ]]; then fi # Allow override when --force is in the trigger comment or CODE_FORCE is set. +echo "Evaluating force override: CODE_FORCE='${CODE_FORCE:-}' COMMENT_BODY='${COMMENT_BODY:-}'" if [[ "${CODE_FORCE:-}" == "true" ]] || [[ "${COMMENT_BODY:-}" == *--force* ]]; then echo "Force override — skipping existing-PR check" exit 0 @@ -101,14 +102,14 @@ if [[ -n "${HUMAN_PR_LINES}" ]]; then - #${pr_num} by @${pr_author}" done <<< "${HUMAN_PR_LINES}" - COMMENT_BODY="An open PR already addresses this issue — skipping automated implementation. + SKIP_COMMENT="An open PR already addresses this issue — skipping automated implementation. ${PR_LIST_MD} To override, comment \`/fs-code --force\` on this issue. Posted by fullsend pre-code check" - printf '%s' "${COMMENT_BODY}" | gh issue comment "${ISSUE_NUMBER}" \ + printf '%s' "${SKIP_COMMENT}" | gh issue comment "${ISSUE_NUMBER}" \ --repo "${REPO_FULL_NAME}" --body-file - 2>/dev/null || true echo "Skipping code agent — existing PR(s) found for issue #${ISSUE_NUMBER}"