From fdf1ff757c27384a834203590f08f155dbdb2f0d Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 22 Nov 2026 16:52:06 +0000 Subject: [PATCH] fix(update): label an updater PR found as a duplicate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CodeRabbit on PR 2552 (pr.sh:150): since the label step runs after gh pr create, a failed label call left the PR unlabeled, and every later run matched it as a duplicate and exited before labeling. The duplicate path now runs the same label CLI on the matched PR, so the next run heals a missing label. test_pr.py logs every call of its gh stub and asserts the POST of both labels on the duplicate; against the old pr.sh it fails (negative control). Tests: test_pr.py, the update CLI suite and the Python repository lints, 116 passed; ruff and shellcheck clean. 🎯 Fix: 92 % 💥 Break: 4 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 88 🚦 Gate: ⏳ quality-high not run on this head, gates run on main Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- scripts/github/update/open/pr.sh | 1 + .../scripts/github/update/open/test_pr.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/github/update/open/pr.sh b/scripts/github/update/open/pr.sh index 85bd915771..d380385af2 100755 --- a/scripts/github/update/open/pr.sh +++ b/scripts/github/update/open/pr.sh @@ -104,6 +104,7 @@ done if [[ -n "${DUPLICATE_PR}" ]]; then echo "Open PR #${DUPLICATE_PR} already carries this exact change. Skipping push and PR creation." + python3 -m cli.contributing.update.label --repo "${REPO}" --pr "${DUPLICATE_PR}" --level "${UPDATE_LEVEL}" exit 0 fi diff --git a/tests/unit/python/scripts/github/update/open/test_pr.py b/tests/unit/python/scripts/github/update/open/test_pr.py index bf7f47b3c0..4c08d8336b 100644 --- a/tests/unit/python/scripts/github/update/open/test_pr.py +++ b/tests/unit/python/scripts/github/update/open/test_pr.py @@ -1,16 +1,20 @@ from __future__ import annotations import os +import re import subprocess import tempfile import unittest from pathlib import Path -from utils.cache.files import PROJECT_ROOT +from cli.contributing.update.label import UPDATE +from cli.contributing.update.label.__main__ import LEVEL_OF_NAME +from utils.cache.files import PROJECT_ROOT, read_text SCRIPT = PROJECT_ROOT / "scripts" / "github" / "update" / "open" / "pr.sh" PINNED_FILE = "pin.txt" GH_STUB = """#!/usr/bin/env bash +printf '%s\\n' "$*" >> "${GH_STUB_LOG}" if [[ "$1 $2" == "pr list" ]]; then printf '7\\t%s\\t%s\\n' "${GH_STUB_CROSS_REPO}" "${GH_STUB_BRANCH}" fi @@ -32,10 +36,12 @@ class UpdatePrFixture: stub = stub_dir / "gh" stub.write_text(GH_STUB) stub.chmod(0o755) + self.gh_log = Path(tmp) / "gh.log" inherited = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")} self.env = { **inherited, "PATH": f"{stub_dir}{os.pathsep}{os.environ['PATH']}", + "GH_STUB_LOG": str(self.gh_log), "GIT_CONFIG_GLOBAL": os.devnull, "GIT_ALLOW_PROTOCOL": "file", "GH_TOKEN": "unused", @@ -100,7 +106,7 @@ class UpdatePrFixture: class TestUpdatePrDedupe(unittest.TestCase): - def test_edited_branch_of_the_same_proposal_is_a_duplicate(self) -> None: + def test_edited_branch_of_the_same_proposal_is_a_labelled_duplicate(self) -> None: with tempfile.TemporaryDirectory() as tmp: fixture = UpdatePrFixture(tmp) branch = f"update/pins-20251231-{fixture.fingerprint()[:7]}" @@ -108,6 +114,14 @@ class TestUpdatePrDedupe(unittest.TestCase): self.assertEqual(result.returncode, 0, result.stdout + result.stderr) self.assertIn("Open PR #7 already carries this exact change", result.stdout) self.assertNotIn("Pushing change to branch", result.stdout) + level = re.search(r"^Update level: (\w+)$", result.stdout, re.MULTILINE) + self.assertIsNotNone(level, result.stdout) + self.assertIn( + "api --method POST repos/acme/widgets/issues/7/labels" + f" -f labels[]={UPDATE.name}" + f" -f labels[]={LEVEL_OF_NAME[level.group(1)].name}", + read_text(str(fixture.gh_log)).splitlines(), + ) def test_fork_branch_with_the_same_suffix_is_not_a_duplicate(self) -> None: with tempfile.TemporaryDirectory() as tmp: