Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(release): resolve a merging maintainer's GitHub squash co-author trailer (#4566)

ddupont86dcdc14ca74
diff --git a/.github/scripts/release_attribution.py b/.github/scripts/release_attribution.py
index c2766cd3c1..dc7a1d5a51 100644
--- a/.github/scripts/release_attribution.py
+++ b/.github/scripts/release_attribution.py
@@ -890,6 +890,49 @@ def asset_checksums(asset_dir: Path | None) -> list[dict[str, Any]]:
return assets
+def merging_maintainer_squash_coauthor(
+ pull: Mapping[str, Any],
+ name: str,
+ github: GitHubClient,
+ repository: str,
+ internal_handles: set[str],
+) -> str | None:
+ """The internal maintainer behind a GitHub-generated squash co-author trailer.
+
+ When a maintainer pushes commits onto someone else's pull request and then
+ squash-merges it, GitHub writes ``Co-authored-by: <commit author name>
+ <account email>`` using that account's own (often private) email, which no
+ commit in the pull request carries. Such a trailer resolves to the merging
+ account only when every one of these holds:
+
+ - that account merged the pull request;
+ - it is listed in ``internalHandles`` (so no external contributor's credit
+ can be claimed or moved this way); and
+ - one of the pull request's commits is linked by GitHub to that account and
+ its git author name is exactly the trailer's name.
+
+ Anything else stays unresolved and fails closed.
+ """
+ number = int(pull.get("number") or 0)
+ if not number:
+ return None
+ merged_by = pull.get("merged_by")
+ if not merged_by:
+ merged_by = github.pull(repository, number).get("merged_by")
+ merger = str((merged_by or {}).get("login") or "").strip()
+ if not merger or merger.lower() not in internal_handles:
+ return None
+ wanted = name.strip().lower()
+ if not wanted:
+ return None
+ for item in github.pull_commits(repository, number):
+ linked = str((item.get("author") or {}).get("login") or "").strip()
+ author_name = str(((item.get("commit") or {}).get("author") or {}).get("name") or "")
+ if linked.lower() == merger.lower() and author_name.strip().lower() == wanted:
+ return merger
+ return None
+
+
def _change_contributors(
pull: Mapping[str, Any],
commit: CommitRecord,
@@ -929,6 +972,10 @@ def _change_contributors(
continue
identity = f"{match.group('name').strip()} <{email}>".lower()
login = coauthor_overrides.get(identity) or login_from_email(email, overrides)
+ if not login:
+ login = merging_maintainer_squash_coauthor(
+ pull, match.group("name"), github, repository, internal
+ )
if not login:
raise ReleaseError(
f"commit {commit.sha} has unresolved human coauthor {email}; "
diff --git a/.github/scripts/tests/test_release_attribution.py b/.github/scripts/tests/test_release_attribution.py
index d7add6af30..592ea52cea 100644
--- a/.github/scripts/tests/test_release_attribution.py
+++ b/.github/scripts/tests/test_release_attribution.py
@@ -686,6 +686,97 @@ def test_pr_3266_squash_coauthor_resolves_through_verified_identity_override():
]
+class SquashTrailerGitHub:
+ """PR #4500's shape: a maintainer pushed onto a contributor PR and merged it."""
+
+ def __init__(self, merger: str, commits: list[tuple[str, str]]) -> None:
+ self.merger = merger
+ self.commits = commits
+
+ def pull(self, repository: str, number: int):
+ assert (repository, number) == ("trycua/cua", 4500)
+ return {"number": 4500, "merged_by": {"login": self.merger}}
+
+ def pull_commits(self, repository: str, number: int):
+ assert (repository, number) == ("trycua/cua", 4500)
+ return [
+ {"author": {"login": login}, "commit": {"author": {"name": name}}}
+ for login, name in self.commits
+ ]
+
+
+SQUASH_4500 = CommitRecord(
+ "c8edda06",
+ "fix(cua-driver): batch Windows foreground multiline input (#4500)",
+ "Co-authored-by: Dillon DuPont <[email protected]>",
+)
+PULL_4500 = {
+ "number": 4500,
+ "user": {"login": "wszkxlllll"},
+ "author_association": "CONTRIBUTOR",
+ "body": "",
+ "labels": [],
+}
+SQUASH_CONFIG = {
+ "bots": [],
+ "coauthorOverrides": {},
+ "ignoredCoauthorEmails": [],
+ "identityOverrides": {},
+ "internalHandles": ["ddupont808"],
+ "optOutHandles": [],
+}
+
+
+def test_merging_maintainer_squash_trailer_resolves_to_that_maintainer():
+ github = SquashTrailerGitHub(
+ "ddupont808",
+ [("wszkxlllll", "wszkxlllll"), ("ddupont808", "Dillon DuPont")],
+ )
+ contributors, _, _ = _change_contributors(
+ PULL_4500, SQUASH_4500, github, "trycua/cua", SQUASH_CONFIG
+ )
+ assert contributors == [
+ {"login": "wszkxlllll", "role": "author", "external": True},
+ {"login": "ddupont808", "role": "coauthor", "external": False},
+ ]
+
+
+def test_pr_4500_squash_trailer_resolves_with_the_checked_in_config():
+ config = json.loads((REPO_ROOT / ".github/release-attribution-config.json").read_text())
+ github = SquashTrailerGitHub(
+ "ddupont808",
+ [("wszkxlllll", "wszkxlllll"), ("ddupont808", "Dillon DuPont")],
+ )
+ contributors, _, _ = _change_contributors(
+ PULL_4500, SQUASH_4500, github, "trycua/cua", config
+ )
+ assert {"login": "ddupont808", "role": "coauthor", "external": False} in contributors
+
+
+ ("merger", "commits"),
+ [
+ # An external merger cannot claim a trailer this way.
+ ("outsider", [("outsider", "Dillon DuPont")]),
+ # The internal merger never authored a commit under that name.
+ ("ddupont808", [("ddupont808", "Someone Else")]),
+ # The name belongs to a commit GitHub links to a different account.
+ ("ddupont808", [("wszkxlllll", "Dillon DuPont")]),
+ # An unlinked commit carrying the name proves nothing.
+ ("ddupont808", [("", "Dillon DuPont")]),
+ ],
+)
+def test_squash_trailer_without_maintainer_provenance_fails_closed(merger, commits):
+ with pytest.raises(ReleaseError, match="unresolved human coauthor"):
+ _change_contributors(
+ PULL_4500,
+ SQUASH_4500,
+ SquashTrailerGitHub(merger, commits),
+ "trycua/cua",
+ SQUASH_CONFIG,
+ )
+
+
def _commit(root: Path, path: str, content: str, subject: str) -> str:
target = root / path
target.parent.mkdir(parents=True, exist_ok=True)