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
16 changes: 14 additions & 2 deletions .github/scripts/native-queue-policy.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const FORWARD_MERGE = {
author: { login: 'github-actions[bot]', id: 41898282, type: 'Bot' },
};
const PROW = { login: 'kubestellar-prow[bot]', id: 208851060, context: 'dco' };
// Line-to-line forward-merge heads (v6-topup.yml's `sync/v5-to-v6`, a hand-carried
// `sync/v5-to-v6-<date>`, `sync/v4-to-v5`, `topup/...`). They must land by merge
// commit: a squash or rebase keeps the content but drops the source line's
// history, and every later top-up then re-conflicts on all of it (#18931).
const FORWARD_MERGE_HEAD = /^(?:sync\/v\d+-to-v\d+|topup\/)/;
// REST pull-request commit listing stops at 250; a longer list is unverifiable.
const MAX_PR_COMMITS = 250;
const PROBOT_DCO_PATH = 'DCO path: probot DCO (App 1861)';
Expand Down Expand Up @@ -417,7 +422,14 @@ async function evaluateOnce({ github, context }) {
...repo, basehead: `${head}...${group.head_sha}`,
});
if (!['ahead', 'identical'].includes(comparison.status) || comparison.merge_base_commit?.sha !== head) {
throw new Error(`#${number}: current PR head is not contained in the tested group`);
// A queue configured to squash or rebase never contains the PR's own head
// commit, so the containment test above is also the merge-method guard
// for top-ups; name it, because "not contained" reads like a CI fault.
throw new Error(FORWARD_MERGE_HEAD.test(pr.head?.ref ?? '')
? `#${number}: forward-merge PR ${pr.head.ref} must land with a merge commit, never a squash or rebase ` +
`(the tested group does not contain its head ${head}, so v5's ancestry would be lost; #18931). ` +
'Remove it from the queue and merge it with the merge-commit method'
: `#${number}: current PR head is not contained in the tested group`);
}
await assertReviews(github, repo, number, head);
paths.push(`#${number} ${await assertEvidence(github, repo, number, head, { ...POLICY_CHECKS, ...BUILD_CHECKS }, pr)}`);
Expand All @@ -444,7 +456,7 @@ module.exports = {
ACTIONS_APP_ID, DCO_APP_ID, POLICY_CHECKS, BUILD_CHECKS,
PendingEvidence, membersForGroup, assertEligible, evidenceForHead, closedNoop, evaluate,
isTransientAPIError, isCosmeticLabelFlip, replayLastVerdict, BLOCKED_LABEL,
ProviderUnavailable, ProviderVerdict, PROVIDER_VERDICT_NOTE, FORWARD_MERGE, PROW,
ProviderUnavailable, ProviderVerdict, PROVIDER_VERDICT_NOTE, FORWARD_MERGE, FORWARD_MERGE_HEAD, PROW,
DCO_ENUMERATION_SUMMARY_PREFIX, DCO_ENUMERATION_SUMMARY_FALLBACK,
DCO_PROVIDER_UNAVAILABLE_TEXT, DCO_PROVIDER_RUNBOOK,
};
28 changes: 27 additions & 1 deletion .github/scripts/native-queue-policy.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {
ACTIONS_APP_ID, DCO_APP_ID, POLICY_CHECKS, BUILD_CHECKS,
PendingEvidence, membersForGroup, assertEligible, evidenceForHead, closedNoop, evaluate,
isTransientAPIError, isCosmeticLabelFlip, replayLastVerdict,
ProviderUnavailable, ProviderVerdict, PROVIDER_VERDICT_NOTE, FORWARD_MERGE, PROW,
ProviderUnavailable, ProviderVerdict, PROVIDER_VERDICT_NOTE, FORWARD_MERGE, FORWARD_MERGE_HEAD, PROW,
DCO_ENUMERATION_SUMMARY_PREFIX,
DCO_ENUMERATION_SUMMARY_FALLBACK,
DCO_PROVIDER_UNAVAILABLE_TEXT,
Expand Down Expand Up @@ -290,6 +290,32 @@ test('one commit unreachable from v5 keeps the forward-merge on probot DCO', asy
assert.match(await evaluate(unreachable), /DCO path: probot DCO \(App 1861\); sync\/v5-to-v6 fallback/);
});

// #18931: a squash or rebase queue never contains the PR's own head commit, so
// a forward-merge PR in such a group is refused by name.
test('a forward-merge PR whose head is not in the tested group is refused as a merge-method violation', async () => {
for (const ref of ['sync/v5-to-v6', 'sync/v5-to-v6-2026-11-18', 'sync/v4-to-v5', 'topup/v5-to-v6-202611171235']) {
const f = fixture('merge_group');
f.state.prs[0].head = { ...f.state.prs[0].head, ref };
f.state.ancestry = 'diverged';
await assert.rejects(evaluate(f), error => {
assert.match(error.message, /must land with a merge commit, never a squash or rebase/);
assert.ok(error.message.includes(ref), error.message);
return true;
});
// Contained head (the merge-commit method): the guard stays out of the way.
const ok = fixture('merge_group');
ok.state.prs[0].head = { ...ok.state.prs[0].head, ref };
await evaluate(ok);
}
// Any other branch keeps the generic message: the guard is scoped to forward-merges.
const other = fixture('merge_group');
other.state.prs[0].head = { ...other.state.prs[0].head, ref: 'feature/sync-things' };
other.state.ancestry = 'diverged';
await assert.rejects(evaluate(other), /current PR head is not contained in the tested group/);
for (const ref of ['sync/v5-to-v6', 'topup/x', 'sync/v4-to-v5-3']) assert.ok(FORWARD_MERGE_HEAD.test(ref), ref);
for (const ref of ['feature/topup/x', 'fix/sync/v5-to-v6', 'sync-v5-to-v6', 'topup']) assert.ok(!FORWARD_MERGE_HEAD.test(ref), ref);
});

test('another head branch, base, fork or author keeps requiring probot DCO', async () => {
for (const change of [
pr => { pr.head.ref = 'sync/v5-to-v6-extra'; },
Expand Down
145 changes: 145 additions & 0 deletions .github/scripts/test-v6-topup-ancestry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/usr/bin/env bash
# test-v6-topup-ancestry.sh — exercises .github/scripts/v6-topup-ancestry.sh
# against throwaway repositories: a merge-commit top-up (ancestry intact), a
# squash-merged top-up (ancestry lost, #18931), the ours-merge heal that makes
# the next forward-merge conflict-free again, and the forged-marker cases the
# heal must refuse.
set -euo pipefail

ANCESTRY="$(cd "$(dirname "$0")" && pwd)/v6-topup-ancestry.sh"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
fail=0
export V5_REF=v5 V6_REF=v6

expect() {
local name="$1" want="$2"
shift 2
local rc=0
( "$@" ) >"$WORK/$name.log" 2>&1 || rc=$?
if { [ "$want" = ok ] && [ "$rc" -ne 0 ]; } || { [ "$want" = fail ] && [ "$rc" -eq 0 ]; }; then
echo "FAIL $name (want $want, rc=$rc)"; sed 's/^/ /' "$WORK/$name.log"; fail=1
else
echo "ok $name"
fi
}

# new_repo DIR: base commit on v5 plus a v6 branch with one adapted file.
new_repo() {
git init -q -b v5 "$1"
cd "$1"
git config user.name test
git config user.email test@example.com
echo base > shared.txt
git add -A && git commit -qm base
git branch v6
}

# topup_pr: build the bot's top-up head (merge of v5 into v6) on sync/v5-to-v6
# and leave the repo on v6. Prints nothing; sets HEAD_SHA and CARRIED.
topup_pr() {
CARRIED="$(git rev-parse v5)"
git checkout -q -B sync/v5-to-v6 v6
# -X theirs: v5's side wins every overlap, standing in for the human resolution.
git merge --no-ff -q -X theirs --signoff v5 -m "topup" >/dev/null
HEAD_SHA="$(git rev-parse HEAD)"
git checkout -q v6
}

# v5 and v6 both touch shared.txt in the carried range (v6 adapts it), then a
# top-up PR carries v5. Leaves v5 one commit past the carried head.
scenario_lost() {
new_repo "$1"
echo v5-one > shared.txt && git commit -qam "v5 one"
echo v5-only > newfile.txt && git add -A && git commit -qm "v5 adds newfile"
git checkout -q v6
echo v6-adapted > shared.txt && git commit -qam "v6 adapts"
topup_pr
# Squash-merge the PR: v6 gets the content as ONE single-parent commit.
git merge --squash -q sync/v5-to-v6 >/dev/null 2>&1 || true
git commit -qm "squash of the top-up" || true
MERGED_SHA="$(git rev-parse v6)"
# v5 moves on over the same lines.
git checkout -q v5
echo v5-two > shared.txt && git commit -qam "v5 two"
echo v5-two-new > newfile.txt && git commit -qam "v5 two newfile"
git checkout -q v6
}

case_marker_roundtrip() {
new_repo "$WORK/m" && cd "$WORK/m"
local sha=0123456789abcdef0123456789abcdef01234567 line
line="$(bash "$ANCESTRY" marker-line "$sha")"
[ "$line" = "<!-- hive:topup carried=$sha -->" ] || { echo "bad marker line: $line"; return 1; }
printf 'text\n%s\nmore\n' "$line" > "$WORK/body.md"
[ "$(bash "$ANCESTRY" marker "$WORK/body.md")" = "$sha" ] || { echo "marker not read back"; return 1; }
printf 'no marker here\n<!-- hive:topup carried=NOTASHA -->\n' > "$WORK/body2.md"
[ -z "$(bash "$ANCESTRY" marker "$WORK/body2.md")" ] || { echo "malformed marker accepted"; return 1; }
bash "$ANCESTRY" marker-line abc && { echo "short sha accepted"; return 1; }
return 0
}

case_level_after_merge_commit() {
new_repo "$WORK/lvl" && cd "$WORK/lvl"
echo v5-one > newfile.txt && git add -A && git commit -qm "v5 one"
git checkout -q v6
topup_pr
git merge --no-ff -q sync/v5-to-v6 -m "merge commit landing" >/dev/null
[ "$(bash "$ANCESTRY" classify "$CARRIED")" = level ] || { echo "merge-commit landing not level"; return 1; }
}

case_lost_after_squash() {
scenario_lost "$WORK/lost" && cd "$WORK/lost"
[ "$(bash "$ANCESTRY" classify "$CARRIED")" = lost ] || { echo "squash landing not detected"; return 1; }
bash "$ANCESTRY" verify "$CARRIED" "$HEAD_SHA" "$MERGED_SHA" || { echo "genuine marker refused"; return 1; }
}

case_unknown_without_marker() {
scenario_lost "$WORK/unk" && cd "$WORK/unk"
[ "$(bash "$ANCESTRY" classify "")" = unknown ] || { echo "empty carried not unknown"; return 1; }
}

# Without the heal the next forward-merge conflicts; with the ours-merge it is
# clean and v5 ends up an ancestor of the result.
case_heal_restores_clean_merge() {
scenario_lost "$WORK/heal" && cd "$WORK/heal"
git checkout -q -B plain v6
git merge --no-ff -q --signoff v5 -m plain >/dev/null 2>&1 && { echo "expected the un-healed merge to conflict"; return 1; }
git merge --abort
git checkout -q -B healed v6
git merge -s ours --no-ff --signoff "$CARRIED" -m "restore ancestry" >/dev/null
[ "$(git rev-parse 'HEAD^{tree}')" = "$(git rev-parse 'v6^{tree}')" ] || { echo "ours-merge changed the tree"; return 1; }
git merge --no-ff -q --signoff v5 -m healed >/dev/null 2>&1 || { echo "healed merge still conflicts"; return 1; }
git merge-base --is-ancestor v5 HEAD || { echo "v5 is not an ancestor after the heal"; return 1; }
git log -1 --format=%B HEAD~1 | grep -q '^Signed-off-by: test <test@example.com>$' || { echo "heal commit not signed off"; return 1; }
}

case_forged_marker_refused() {
scenario_lost "$WORK/forged" && cd "$WORK/forged"
# A v5 commit the top-up did NOT carry: ours-merging it would drop its content.
local uncarried
uncarried="$(git rev-parse v5)"
bash "$ANCESTRY" verify "$uncarried" "$HEAD_SHA" "$MERGED_SHA" && { echo "uncarried head accepted"; return 1; }
# The PR's merge commit must be on v6.
bash "$ANCESTRY" verify "$CARRIED" "$HEAD_SHA" "$uncarried" && { echo "merge commit off v6 accepted"; return 1; }
# The PR head must be a two-parent merge.
bash "$ANCESTRY" verify "$CARRIED" "$CARRIED" "$MERGED_SHA" && { echo "non-merge head accepted"; return 1; }
return 0
}

case_unrecoverable_off_v5() {
scenario_lost "$WORK/off" && cd "$WORK/off"
git checkout -q -b stray v5 && echo s > s.txt && git add -A && git commit -qm stray
[ "$(bash "$ANCESTRY" classify "$(git rev-parse stray)")" = unrecoverable ] || { echo "off-v5 head not unrecoverable"; return 1; }
[ "$(bash "$ANCESTRY" classify 0000000000000000000000000000000000000000)" = unrecoverable ] || { echo "missing commit not unrecoverable"; return 1; }
}

expect marker-roundtrip ok case_marker_roundtrip
expect level-after-merge-commit ok case_level_after_merge_commit
expect lost-after-squash ok case_lost_after_squash
expect unknown-without-marker ok case_unknown_without_marker
expect heal-restores-clean-merge ok case_heal_restores_clean_merge
expect forged-marker-refused ok case_forged_marker_refused
expect unrecoverable-off-v5 ok case_unrecoverable_off_v5

exit "$fail"
81 changes: 81 additions & 0 deletions .github/scripts/v6-topup-ancestry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash
# v6-topup-ancestry.sh — the v5-ancestry bookkeeping behind
# .github/workflows/v6-topup.yml (#18931).
#
# WHY. A v5 -> v6 top-up PR merged with a squash or rebase puts v5's CONTENT on
# v6 but not v5's HISTORY. `git merge-base origin/v5 origin/v6` then stays at
# the previous merge commit, and every later forward-merge replays the whole
# range against v6's already-adapted copies of the same files: #18689 was
# squash-merged and the next top-up hit 109 conflicted files (17 add/add).
#
# The workflow records the v5 head each top-up carried in the PR body as
# <!-- hive:topup carried=<40-hex sha> -->
# and, when that head is not an ancestor of origin/v6 (the PR was not merged
# with a merge commit), restores the ancestry with an ours-merge of it before
# merging origin/v5. An ours-merge records history and changes no file.
#
# Subcommands (run from the repo root):
# marker-line <sha> print the PR-body marker line
# marker <body-file> print the carried sha in the body, if any
# verify <carried> <pr-head> <merge-commit>
# exit 0 when the marker is trustworthy: the PR head is a two-parent
# merge whose second parent IS <carried> and the PR's merge commit is on
# v6. (Whether <carried> is still v5 history is classify's call.) A marker is only a claim in a PR body;
# an ours-merge of a v5 commit whose content is NOT on v6 would silently
# drop that content, so the claim is bound to the PR's own head commit.
# classify <carried|""> print one state:
# level carried head is an ancestor of origin/v6: ancestry intact
# unknown no carried head is known: nothing can be checked
# lost carried head is v5 history but not on v6: heal with an
# ours-merge of it
# unrecoverable carried head is not on origin/v5 (v5 history rewritten)
# Environment: V5_REF (default origin/v5), V6_REF (default origin/v6).
set -euo pipefail

V5_REF="${V5_REF:-origin/v5}"
V6_REF="${V6_REF:-origin/v6}"
SHA_RE='^[0-9a-f]{40}$'
MARKER_RE='<!-- hive:topup carried=([0-9a-f]{40}) -->'

is_commit() { git cat-file -e "$1^{commit}" 2>/dev/null; }
is_ancestor() { git merge-base --is-ancestor "$1" "$2"; }

cmd="${1:-}"
shift || true
case "$cmd" in
marker-line)
[[ "${1:-}" =~ $SHA_RE ]] || { echo "marker-line: need a full 40-hex sha" >&2; exit 2; }
printf '<!-- hive:topup carried=%s -->\n' "$1"
;;
marker)
[ -f "${1:-}" ] || { echo "marker: need a body file" >&2; exit 2; }
# Last marker wins; a body with none prints nothing and still exits 0.
while IFS= read -r line; do
if [[ "$line" =~ $MARKER_RE ]]; then found="${BASH_REMATCH[1]}"; fi
done < "$1"
[ -z "${found:-}" ] || printf '%s\n' "$found"
;;
verify)
carried="${1:-}" head="${2:-}" merged="${3:-}"
for s in "$carried" "$head" "$merged"; do
[[ "$s" =~ $SHA_RE ]] || { echo "verify: need three full 40-hex shas" >&2; exit 2; }
is_commit "$s" || { echo "verify: $s is not a fetched commit" >&2; exit 1; }
done
parents="$(git rev-list --parents -n 1 "$head")"
# shellcheck disable=SC2086
set -- $parents
[ "$#" -eq 3 ] && [ "$3" = "$carried" ] || { echo "verify: PR head $head is not a merge of $carried" >&2; exit 1; }
is_ancestor "$merged" "$V6_REF" || { echo "verify: merge commit $merged is not on $V6_REF" >&2; exit 1; }
;;
classify)
carried="${1:-}"
if [ -z "$carried" ]; then echo unknown; exit 0; fi
[[ "$carried" =~ $SHA_RE ]] || { echo "classify: not a full sha: $carried" >&2; exit 2; }
if ! is_commit "$carried" || ! is_ancestor "$carried" "$V5_REF"; then echo unrecoverable; exit 0; fi
if is_ancestor "$carried" "$V6_REF"; then echo level; else echo lost; fi
;;
*)
echo "usage: v6-topup-ancestry.sh marker-line|marker|verify|classify ..." >&2
exit 2
;;
esac
9 changes: 9 additions & 0 deletions .github/workflows/v6-topup-autoresolve-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ on:
paths:
- '.github/scripts/v6-topup-autoresolve.sh'
- '.github/scripts/test-v6-topup-autoresolve.sh'
- '.github/scripts/v6-topup-ancestry.sh'
- '.github/scripts/test-v6-topup-ancestry.sh'
- '.github/workflows/v6-topup.yml'
- '.github/workflows/v6-topup-autoresolve-tests.yml'
push:
branches: [v5]
paths:
- '.github/scripts/v6-topup-autoresolve.sh'
- '.github/scripts/test-v6-topup-autoresolve.sh'
- '.github/scripts/v6-topup-ancestry.sh'
- '.github/scripts/test-v6-topup-ancestry.sh'
- '.github/workflows/v6-topup.yml'
- '.github/workflows/v6-topup-autoresolve-tests.yml'

Expand All @@ -32,3 +36,8 @@ jobs:
# pattern and checks the resolver finishes them, and refuses others.
- name: Test v6-topup-autoresolve.sh
run: bash .github/scripts/test-v6-topup-autoresolve.sh
# Throwaway repos for the squash-merged-top-up case (#18931): the carried
# v5 head is detected as lost, the ours-merge heal restores a conflict-free
# forward-merge, and a forged PR-body marker is refused.
- name: Test v6-topup-ancestry.sh
run: bash .github/scripts/test-v6-topup-ancestry.sh
Loading
Loading