Skip to content

Commit 1c8b3ce

Browse files
charlesprostclaude
andcommitted
(Risk 1) Fix already_in_queue to detect pre-GA queue branches after GA tag
After a GA tag is pushed (e.g. 10.0.0.0), HotfixBranch.hfrev advances from 0 to 1. The next PR handle call would compute queue name q/w/{id}/10.0.0.1/... which does not exist, causing already_in_queue to return False and re-queue the PR — creating an orphaned q/10.0.0.1 branch alongside the valid one. Fix: after the exact-match lookup, fall back to a git branch -r --list prefix scan (origin/q/w/{id}/major.minor.micro.*) so the existing pre-GA queue branch is found regardless of which hfrev was in effect when the PR was first queued. Add test_pr_hotfix_no_requeue_after_ga: queues pre-GA, pushes 10.0.0.0 tag, then re-handles the PR — asserts NothingToDo (not Queued) and verifies no orphaned 10.0.0.1 branch is created. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d904bee commit 1c8b3ce

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

bert_e/tests/test_bert_e.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6033,6 +6033,42 @@ def test_pr_hotfix_pre_ga(self):
60336033
self.handle(sha1, options=self.bypass_all, backtrace=True)
60346034
self.assertEqual(self.prs_in_queue(), set())
60356035

6036+
def test_pr_hotfix_no_requeue_after_ga(self):
6037+
"""PR queued pre-GA must not be re-queued after the GA tag is pushed.
6038+
6039+
Without the already_in_queue prefix-scan fix, pushing 10.0.0.0 causes
6040+
already_in_queue to look for q/w/{id}/10.0.0.1/... (hfrev now 1) which
6041+
does not exist, so the PR is incorrectly re-queued and a new orphaned
6042+
q/10.0.0.1 branch is created.
6043+
"""
6044+
# Step 1 — queue PR before GA tag exists.
6045+
pr = self.create_pr('bugfix/TEST-00000', 'hotfix/10.0.0')
6046+
with self.assertRaises(exns.Queued):
6047+
self.handle(pr.id, options=self.bypass_all, backtrace=True)
6048+
self.assertEqual(self.prs_in_queue(), {pr.id})
6049+
6050+
# Step 2 — push the GA tag, advancing hfrev from 0 to 1.
6051+
self.gitrepo.cmd('git tag 10.0.0.0')
6052+
self.gitrepo.cmd('git push --tags')
6053+
6054+
# Step 3 — re-handle the PR; must be NothingToDo, not Queued again.
6055+
with self.assertRaises(exns.NothingToDo):
6056+
self.handle(pr.id, options=self.bypass_all, backtrace=True)
6057+
6058+
# No second q/w branch should have been created (would appear if
6059+
# the PR was incorrectly re-queued with 10.0.0.1).
6060+
qbranches = self.get_qint_branches()
6061+
self.assertFalse(
6062+
any('10.0.0.1' in b for b in qbranches),
6063+
'orphaned 10.0.0.1 queue branch found: %s' % qbranches)
6064+
6065+
# Step 4 — original pre-GA queue branch still builds and merges fine.
6066+
sha1 = self.set_build_status_on_branch_tip(
6067+
'q/w/%d/10.0.0.0/bugfix/TEST-00000' % pr.id, 'SUCCESSFUL')
6068+
with self.assertRaises(exns.Merged):
6069+
self.handle(sha1, options=self.bypass_all, backtrace=True)
6070+
self.assertEqual(self.prs_in_queue(), set())
6071+
60366072
def test_pr_hotfix_alone(self):
60376073
self.gitrepo.cmd('git tag 10.0.0.0')
60386074
self.gitrepo.cmd('git push --tags')

bert_e/workflow/gitwaterflow/queueing.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,22 @@ def already_in_queue(job, wbranches):
126126
127127
"""
128128
pr_id = job.pull_request.id
129-
return any(
130-
get_queue_integration_branch(job, pr_id, w).exists() for w in wbranches
131-
)
129+
if any(get_queue_integration_branch(job, pr_id, w).exists()
130+
for w in wbranches):
131+
return True
132+
# Fallback for hotfix branches: the hfrev embedded in the queue branch
133+
# name may have changed since the PR was queued (pre-GA → post-GA
134+
# transition). Scan by major.minor.micro prefix to detect the existing
135+
# queue branch regardless of which hfrev was in effect when first queued.
136+
if (len(job.git.cascade.dst_branches) == 1 and
137+
isinstance(job.git.cascade.dst_branches[0], HotfixBranch)):
138+
dst = job.git.cascade.dst_branches[0]
139+
prefix = 'origin/q/w/%d/%d.%d.%d.' % (
140+
pr_id, dst.major, dst.minor, dst.micro)
141+
if job.git.repo.cmd(
142+
'git branch -r --list %s*' % prefix).strip():
143+
return True
144+
return False
132145

133146

134147
def add_to_queue(job, wbranches):

0 commit comments

Comments
 (0)