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
130 changes: 130 additions & 0 deletions internal/scaffold/fullsend-repo/scripts/post-code-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,136 @@ run_test "ci-type" \
"10" \
"ci(#10): update workflow permissions"

# ---------------------------------------------------------------------------
# Test helper — reimplements the PR body assembly logic from post-code.sh
# so we can test it without a git repo or network access.
# ---------------------------------------------------------------------------
build_pr_body() {
local commit_body="$1"
local issue_number="$2"
local branch="$3"
local scan_range="$4"

local description
if [ -z "${commit_body}" ]; then
description="Automated implementation for issue #${issue_number}."
else
description="${commit_body}"
fi

echo "${description}

---

Closes #${issue_number}

### Post-script verification

- [x] Branch is not main/master (\`${branch}\`)
- [x] Secret scan passed (gitleaks — \`${scan_range}\`)
- [x] Pre-commit hooks passed (authoritative run on runner)
- [x] Tests ran inside sandbox"
}

run_body_test() {
local test_name="$1"
local commit_body="$2"
local issue_number="$3"
local branch="$4"
local check_pattern="$5"
local expect_present="$6" # "yes" or "no"

local actual
actual="$(build_pr_body "${commit_body}" "${issue_number}" "${branch}" "abc123..def456")"

if [ "${expect_present}" = "yes" ]; then
if ! echo "${actual}" | grep -qF "${check_pattern}"; then
echo "FAIL: ${test_name}"
echo " expected to find: '${check_pattern}'"
echo " in body:"
echo "${actual}" | sed 's/^/ /'
FAILURES=$((FAILURES + 1))
return
fi
else
if echo "${actual}" | grep -qF "${check_pattern}"; then
echo "FAIL: ${test_name}"
echo " expected NOT to find: '${check_pattern}'"
echo " in body:"
echo "${actual}" | sed 's/^/ /'
FAILURES=$((FAILURES + 1))
return
fi
fi

echo "PASS: ${test_name}"
}

# --- PR body test cases ---

# Body should contain exactly one Closes line (the footer one)
run_body_test "closes-appears-once" \
"Fix the widget rendering." \
"42" "agent/42-fix-widget" \
"Closes #42" "yes"

# Body should NOT contain a Changed files section
run_body_test "no-changed-files-section" \
"Fix the widget rendering." \
"42" "agent/42-fix-widget" \
"Changed files" "no"

# Body should NOT contain a Created by footer
run_body_test "no-created-by-footer" \
"Fix the widget rendering." \
"42" "agent/42-fix-widget" \
"Created by" "no"

# Empty commit body should use fallback description
run_body_test "empty-body-fallback" \
"" \
"99" "agent/99-add-feature" \
"Automated implementation for issue #99." "yes"

# Empty commit body should still not have Changed files
run_body_test "empty-body-no-changed-files" \
"" \
"99" "agent/99-add-feature" \
"Changed files" "no"

# Empty commit body should still not have Created by
run_body_test "empty-body-no-created-by" \
"" \
"99" "agent/99-add-feature" \
"Created by" "no"

# Verify the Closes line count is exactly 1
count_closes_test() {
local test_name="$1"
local commit_body="$2"
local issue_number="$3"

local actual
actual="$(build_pr_body "${commit_body}" "${issue_number}" "branch" "range")"
local count
count="$(echo "${actual}" | grep -c "Closes #${issue_number}" || true)"

if [ "${count}" -ne 1 ]; then
echo "FAIL: ${test_name}"
echo " expected exactly 1 'Closes #${issue_number}', found ${count}"
FAILURES=$((FAILURES + 1))
return
fi

echo "PASS: ${test_name}"
}

count_closes_test "single-closes-with-body" \
"Fix rendering bug in the widget component." "42"

count_closes_test "single-closes-empty-body" \
"" "99"

# --- Summary ---

echo ""
Expand Down
20 changes: 4 additions & 16 deletions internal/scaffold/fullsend-repo/scripts/post-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fi
echo "Creating PR..."

COMMIT_SUBJECT="$(git log -1 --format='%s' HEAD)"
COMMIT_BODY_RAW="$(git log -1 --format='%b' HEAD | sed '/^Signed-off-by:/d' | sed -e :a -e '/^\n*$/{ $d; N; ba; }')"
COMMIT_BODY_RAW="$(git log -1 --format='%b' HEAD | sed '/^Signed-off-by:/d' | sed '/^Closes #/d' | sed -e :a -e '/^\n*$/{ $d; N; ba; }')"

COMMIT_BODY="$(echo "${COMMIT_BODY_RAW}" | awk '
/^$/ { if (buf) print buf; print; buf=""; next }
Expand Down Expand Up @@ -212,20 +212,10 @@ else
PR_TITLE="${COMMIT_SUBJECT}"
fi

FILE_SUMMARY="$(echo "${CHANGED_FILES}" | sort | sed 's|^| - `|; s|$|`|')"

if [ -z "${COMMIT_BODY}" ]; then
DESCRIPTION="Automated implementation for issue #${ISSUE_NUMBER}.

### Changed files

${FILE_SUMMARY}"
DESCRIPTION="Automated implementation for issue #${ISSUE_NUMBER}."
else
DESCRIPTION="${COMMIT_BODY}

### Changed files

${FILE_SUMMARY}"
DESCRIPTION="${COMMIT_BODY}"
fi

PR_BODY="${DESCRIPTION}
Expand All @@ -239,9 +229,7 @@ Closes #${ISSUE_NUMBER}
- [x] Branch is not main/master (\`${BRANCH}\`)
- [x] Secret scan passed (gitleaks — \`${SCAN_RANGE}\`)
- [x] Pre-commit hooks passed (authoritative run on runner)
- [x] Tests ran inside sandbox

<sub>Created by <a href=\"https://github.com/fullsend-ai/fullsend\">fullsend</a> code agent</sub>"
- [x] Tests ran inside sandbox"

PR_URL="$(gh pr create \
--repo "${REPO_FULL_NAME}" \
Expand Down
Loading