Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
77 changes: 75 additions & 2 deletions internal/scaffold/fullsend-repo/scripts/reconcile-repos-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ trap 'rm -rf "${TMPDIR}"' EXIT
CONFIG_DIR="${TMPDIR}/config"
MOCK_BIN="${TMPDIR}/bin"
GH_LOG="${TMPDIR}/gh-calls.log"
COMMIT_MSGS_LOG="${TMPDIR}/commit-msgs.log"
mkdir -p "${CONFIG_DIR}/templates" "${MOCK_BIN}"

cat > "${CONFIG_DIR}/config.yaml" <<'EOF'
Expand Down Expand Up @@ -74,20 +75,30 @@ if [[ "\$1" != "api" ]]; then
exit 1
fi

# Extract --jq filter if present.
# Extract --jq filter and --input if present.
jq_filter=""
has_input=false
shift # consume "api"
endpoint="\$1"; shift
while [[ \$# -gt 0 ]]; do
case "\$1" in
--jq) jq_filter="\$2"; shift 2 ;;
--input) shift 2 ;; # consume --input -
--input) has_input=true; shift 2 ;; # consume --input -
--method|--field) shift 2 ;;
--silent) shift ;;
*) shift ;;
esac
done

# Capture commit messages from stdin for the git/commits endpoint.
input_data=""
if [[ "\$has_input" == "true" ]]; then
input_data=\$(cat)
if [[ "\$endpoint" == */git/commits ]]; then
printf '%s\0' "\$input_data" >> "${COMMIT_MSGS_LOG}"
fi
fi

json=""
rc=0
case "\$endpoint" in
Expand Down Expand Up @@ -169,3 +180,65 @@ if grep -q "contents/.github/workflows/fullsend.yaml.*--method PUT" "${GH_LOG}";
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] test-inadequate

Only the stale-shim-update commit message path is exercised by the test. The enrollment, refresh-existing-PR, and removal paths are not reached, so their commit messages are not validated.

Suggested fix: Add test scenarios exercising the other three commit message paths: a repo with no existing shim (enrollment), a repo with an existing enrollment PR (refresh), and a disabled repo with an existing shim (removal).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] test-inadequate

The removal commit message is sent via the Contents API DELETE endpoint using --field, not via the Git Objects API with --input stdin. The test infrastructure only captures stdin payloads for git/commits calls, so the removal message cannot be validated even if a removal scenario were added.

Suggested fix: Extend the mock gh script to also capture --field message= values for DELETE calls to the contents endpoint.


echo "PASS: stale shim branch update is atomic"

# ===========================
# Test: commit messages include a non-trivial body
# ===========================

if [ ! -f "${COMMIT_MSGS_LOG}" ]; then
echo "FAIL: no commit messages were captured"
exit 1
fi

# The log contains null-delimited JSON payloads from git/commits calls.
# Extract each message and verify it has a subject, blank line, and body.
msg_index=0
fail=0
while IFS= read -r -d '' json_payload; do
[ -z "$json_payload" ] && continue
msg=$(printf '%s' "$json_payload" | jq -r '.message')
msg_index=$((msg_index + 1))

# A well-formed message has: subject, blank line, body.
subject=$(printf '%s\n' "$msg" | head -n1)
second_line=$(printf '%s\n' "$msg" | sed -n '2p')
body=$(printf '%s\n' "$msg" | tail -n +3)

if [ -n "$second_line" ]; then
echo "FAIL: commit message #${msg_index} missing blank line after subject"
echo " subject: $subject"
echo " line 2: $second_line"
fail=1
continue
fi

body_trimmed=$(printf '%s' "$body" | tr -d '[:space:]')
if [ -z "$body_trimmed" ]; then
echo "FAIL: commit message #${msg_index} has no body"
echo " subject: $subject"
fail=1
continue
fi

# Verify no line in the message exceeds 72 characters.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] test-integrity

The commit message line-length check applies the 72-character limit to all lines including the subject. Conventional commit convention limits subjects to 50 characters. Not a bug (the actual subjects are well under 50 chars), but the test would not catch a subject between 51-72 characters if one were introduced later.

while IFS= read -r bline; do
if [ "${#bline}" -gt 72 ]; then
echo "FAIL: commit message #${msg_index} has a line exceeding 72 chars"
echo " line (${#bline} chars): $bline"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] test-inadequate

The commit message validation loop checks that each captured message is well-formed but does not assert the expected count of messages (should be 4: one each for update, add, refresh, and remove). If a code path silently fails to produce a commit, the test would still pass as long as at least one message is captured and well-formed.

Suggested fix: Add an assertion after the validation loop: [ "$msg_index" -eq 4 ] || { echo "FAIL: expected 4 commit messages, got $msg_index"; exit 1; }

fail=1
fi
done <<< "$msg"
done < "${COMMIT_MSGS_LOG}"

if [ "$msg_index" -eq 0 ]; then
echo "FAIL: no commit messages found in log"
exit 1
fi

if [ "$fail" -ne 0 ]; then
echo "--- captured commit messages ---"
cat "${COMMIT_MSGS_LOG}"
exit 1
fi

echo "PASS: commit messages include a non-trivial body (≤72 chars/line)"
24 changes: 20 additions & 4 deletions internal/scaffold/fullsend-repo/scripts/reconcile-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ if [ -n "$ENABLED_REPOS" ]; then
# Shim is stale — update via PR to respect branch protection.
echo "⟳ $REPO enrolled but shim is stale — creating update PR"

if ! write_shim_to_branch_from_default "$REPO" "$ENROLL_BRANCH" "$EXPECTED_B64" "chore: update fullsend shim workflow"; then
UPDATE_COMMIT_MSG="chore: update fullsend shim workflow

Update the shim workflow to match the current template
in the .fullsend config repo."
if ! write_shim_to_branch_from_default "$REPO" "$ENROLL_BRANCH" "$EXPECTED_B64" "$UPDATE_COMMIT_MSG"; then
FAILED=$((FAILED + 1))
continue
fi
Expand Down Expand Up @@ -344,7 +348,11 @@ if [ -n "$ENABLED_REPOS" ]; then
if [ -n "$EXISTING_PR" ]; then
echo "✓ $REPO has existing enrollment PR: $EXISTING_PR"
# Update the shim on the existing branch to reflect the latest content.
if ! write_shim_to_branch_from_default "$REPO" "$ENROLL_BRANCH" "$(shim_content_b64)" "chore: update fullsend shim workflow"; then
REFRESH_COMMIT_MSG="chore: update fullsend shim workflow

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] naming-convention

UPDATE_COMMIT_MSG and REFRESH_COMMIT_MSG have identical text. If the stale-shim-update and existing-PR-refresh operations are semantically the same, consolidate into a single variable defined alongside the other constants at the top of the file. If they are intended to diverge, differentiate the messages now.


Update the shim workflow to match the current template
in the .fullsend config repo."
if ! write_shim_to_branch_from_default "$REPO" "$ENROLL_BRANCH" "$(shim_content_b64)" "$REFRESH_COMMIT_MSG"; then
FAILED=$((FAILED + 1))
else
ENROLLED=$((ENROLLED + 1))
Expand All @@ -362,7 +370,11 @@ if [ -n "$ENABLED_REPOS" ]; then
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] code-organization

ENROLL_COMMIT_MSG and UNENROLL_COMMIT_MSG are defined inside their respective loop bodies (reassigned on every iteration), while UPDATE_COMMIT_MSG is defined once at the top level alongside UPDATE_PR_BODY. All three are constant strings — hoisting them to the top would be more consistent.

Suggested fix: Move ENROLL_COMMIT_MSG and UNENROLL_COMMIT_MSG definitions to the top of the script alongside UPDATE_COMMIT_MSG (after line 51).

fi

if ! write_shim_to_branch_from_default "$REPO" "$ENROLL_BRANCH" "$SHIM_CONTENT" "chore: add fullsend shim workflow"; then
ENROLL_COMMIT_MSG="chore: add fullsend shim workflow

Add the shim workflow that routes repository events to
the fullsend agent dispatch pipeline."
if ! write_shim_to_branch_from_default "$REPO" "$ENROLL_BRANCH" "$SHIM_CONTENT" "$ENROLL_COMMIT_MSG"; then
FAILED=$((FAILED + 1))
continue
fi
Expand Down Expand Up @@ -444,9 +456,13 @@ if [ -n "$DISABLED_REPOS" ]; then
fi

# Delete the shim workflow on the removal branch.
REMOVE_COMMIT_MSG="chore: remove fullsend shim workflow

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] naming-convention

REMOVE_COMMIT_MSG breaks the established naming pattern. The existing variables for this operation use the UNENROLL prefix (UNENROLL_BRANCH, UNENROLL_PR_TITLE, UNENROLL_PR_BODY). Consider renaming to UNENROLL_COMMIT_MSG for consistency.


Remove the shim workflow. The repo has been set to
enabled: false in the fullsend config."
if ! gh api "repos/$ORG/$REPO/contents/$SHIM_PATH" \
--method DELETE \
--field "message=chore: remove fullsend shim workflow" \
--field "message=$REMOVE_COMMIT_MSG" \
--field "branch=$UNENROLL_BRANCH" \
--field "sha=$FILE_SHA" \
--silent; then
Expand Down
Loading