Skip to content
Open
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
88 changes: 88 additions & 0 deletions internal/scaffold/fullsend-repo/scripts/pre-code-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ""
Expand Down
5 changes: 3 additions & 2 deletions internal/scaffold/fullsend-repo/scripts/pre-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

<sub>Posted by <a href=\"https://github.com/fullsend-ai/fullsend\">fullsend</a> pre-code check</sub>"

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}"
Expand Down
Loading