Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

ci(cla): exempt self-signed .contributors PRs from clabot deadlock

Christian M. Todieebae5448307e
diff --git a/.github/workflows/cla-field-report-exempt.yml b/.github/workflows/cla-field-report-exempt.yml
index a1ab74465..bcc3d59f9 100644
--- a/.github/workflows/cla-field-report-exempt.yml
+++ b/.github/workflows/cla-field-report-exempt.yml
@@ -55,7 +55,7 @@ jobs:
with:
ref: ${{ github.event.pull_request.base.sha }}
- - name: Provide verification/cla-signed for a field-report-only PR
+ - name: Provide verification/cla-signed for a field-report-only or self-CLA-signature PR
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
@@ -71,6 +71,14 @@ jobs:
-f description="Field-report-only PR: CLA gate waived for user-feedback/16-agent-field-reports/*.md" \
-f target_url="https://github.com/${REPO}/blob/main/user-feedback/16-agent-field-reports/README.md" \
|| echo "note: could not post the status (insufficient token permissions?). cla-bot remains authoritative."
+ elif python3 scripts/check_cla_coauthors.py --is-self-cla-signature --pr "$PR_NUMBER" --changed-files "$FILES"; then
+ echo "PR #${PR_NUMBER} is a valid self-CLA signature in .contributors; posting verification/cla-signed=success."
+ gh api -X POST "repos/${REPO}/statuses/${HEAD_SHA}" \
+ -f context=verification/cla-signed \
+ -f state=success \
+ -f description="CLA signature PR: author added own login to .contributors per CLA.md" \
+ -f target_url="https://github.com/${REPO}/blob/main/CLA.md" \
+ || echo "note: could not post the status (insufficient token permissions?). cla-bot remains authoritative."
else
- echo "PR #${PR_NUMBER} touches non-field-report paths; leaving verification/cla-signed to cla-bot."
+ echo "PR #${PR_NUMBER} is neither field-report-only nor a self-CLA signature; leaving verification/cla-signed to cla-bot."
fi
diff --git a/scripts/check_cla_coauthors.py b/scripts/check_cla_coauthors.py
index b713a3ce7..fd8d80bd8 100755
--- a/scripts/check_cla_coauthors.py
+++ b/scripts/check_cla_coauthors.py
@@ -40,16 +40,23 @@ Usage (CI):
check_cla_coauthors.py --pr <number> [--changed-files "<paths>"]
Runs the trailer gate. If --changed-files is a field-report-only set, the
gate is skipped (exempt) and this exits 0 without a network lookup.
- check_cla_coauthors.py --is-field-report-only --changed-files "<paths>"
- Prints nothing; exits 0 iff the paths are a field-report-only set, else 1.
- Used by the separate CI job that provides `verification/cla-signed` for
- strictly field-report-only pull requests.
- Needs `gh` and GH_TOKEN for --pr; repo comes from GITHUB_REPOSITORY or --repo.
+ check_cla_coauthors.py --is-field-report-only --changed-files "<paths>"
+ Prints nothing; exits 0 iff the paths are a field-report-only set, else 1.
+ Used by the separate CI job that provides `verification/cla-signed` for
+ strictly field-report-only pull requests.
+ check_cla_coauthors.py --is-self-cla-signature --pr <number> --changed-files "<paths>"
+ Prints nothing; exits 0 iff the PR only modifies `.contributors` to add the
+ PR author's own GitHub login (preserving all existing entries, with all
+ commits authored by the PR author and no unsigned Co-authored-by trailers).
+ Used by the separate CI job so `.contributors` signature PRs do not deadlock
+ on cla-bot reading `.contributors` from `main`.
+ Needs `gh` and GH_TOKEN for --pr; repo comes from GITHUB_REPOSITORY or --repo.
Tests: scripts/test_cla_coauthors.py
"""
import argparse
+import base64
import json
import os
import pathlib
@@ -118,6 +125,72 @@ def is_field_report_only(paths):
return True
+def is_self_cla_signature(
+ paths,
+ base_contributors,
+ head_contributors,
+ pr_author,
+ commits,
+ resolve=lambda _email: None,
+):
+ """True iff the PR exclusively adds `pr_author` to `.contributors` and every
+ commit is authored by `pr_author` with no unsigned Co-authored-by trailers.
+
+ cla-bot always reads `https://raw.githubusercontent.com/<repo>/main/.contributors`,
+ so a PR whose sole purpose is signing the CLA (adding the PR author's own
+ GitHub login to `.contributors`) fails cla-bot's check until it is merged.
+ This predicate lets the trusted `pull_request_target` workflow satisfy
+ `verification/cla-signed` for strictly self-signing `.contributors` PRs
+ while rejecting any PR that:
+ - touches any file other than `.contributors`,
+ - removes or modifies any existing `.contributors` entry (including
+ `dependabot[bot]`),
+ - adds any login other than `pr_author`,
+ - contains any commit not authored by `pr_author`, or
+ - carries an unresolvable or unsigned `Co-authored-by` trailer.
+ """
+ clean_paths = [p.strip() for p in paths if p.strip()]
+ if clean_paths != [".contributors"]:
+ return False
+ if not isinstance(pr_author, str) or not pr_author.strip():
+ return False
+ author_lower = pr_author.strip().lower()
+ if not isinstance(base_contributors, list) or not isinstance(head_contributors, list):
+ return False
+ if not all(isinstance(c, str) and c.strip() for c in base_contributors):
+ return False
+ if not all(isinstance(c, str) and c.strip() for c in head_contributors):
+ return False
+ if "dependabot[bot]" not in head_contributors:
+ return False
+ base_counts = {}
+ for c in base_contributors:
+ base_counts[c] = base_counts.get(c, 0) + 1
+ head_counts = {}
+ for c in head_contributors:
+ head_counts[c] = head_counts.get(c, 0) + 1
+ for c, count in base_counts.items():
+ if head_counts.get(c, 0) < count:
+ return False
+ if len(head_contributors) > len(base_contributors) + 1:
+ return False
+ for c, count in head_counts.items():
+ added = count - base_counts.get(c, 0)
+ if added > 0 and c.strip().lower() != author_lower:
+ return False
+ if not any(c.strip().lower() == author_lower for c in head_contributors):
+ return False
+ if not commits:
+ return False
+ for commit in commits:
+ commit_author = commit.get("author_login")
+ if not isinstance(commit_author, str) or commit_author.strip().lower() != author_lower:
+ return False
+ if check_commits(commits, head_contributors, resolve):
+ return False
+ return True
+
+
def check_commits(commits, contributors, resolve):
"""Return a list of problem strings; empty means the gate passes.
@@ -193,6 +266,21 @@ def _split_paths(raw):
return [] if raw is None else raw.split()
+def _fetch_head_contributors(repo, head_sha):
+ """Fetch and parse `.contributors` at `head_sha` as pure JSON data via the
+ GitHub contents API (never checking out or executing the PR head)."""
+ try:
+ items = _gh_api(
+ f"repos/{repo}/contents/.contributors?ref={urllib.parse.quote(head_sha)}"
+ )
+ if not items or not isinstance(items[0], dict):
+ return None
+ raw = base64.b64decode(items[0]["content"]).decode("utf-8")
+ return json.loads(raw)
+ except ( subprocess.CalledProcessError, KeyError, ValueError, TypeError):
+ return None
+
+
def main():
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--pr", type=int, help="pull request number")
@@ -212,6 +300,12 @@ def main():
help="predicate mode: exit 0 iff --changed-files is a field-report-only "
"set, else 1. Prints nothing; used by the exemption CI job.",
)
+ ap.add_argument(
+ "--is-self-cla-signature",
+ action="store_true",
+ help="predicate mode: exit 0 iff the PR exclusively adds the PR author's "
+ "own GitHub login to .contributors, else 1. Used by the exemption CI job.",
+ )
args = ap.parse_args()
paths = _split_paths(args.changed_files)
@@ -220,6 +314,37 @@ def main():
if args.is_field_report_only:
return 0 if is_field_report_only(paths) else 1
+ if args.is_self_cla_signature:
+ if args.pr is None:
+ ap.error("--pr is required with --is-self-cla-signature")
+ if [p.strip() for p in paths if p.strip()] != [".contributors"]:
+ return 1
+ base_contributors = json.loads((REPO_ROOT / ".contributors").read_text())
+ pr_info = _gh_api(f"repos/{args.repo}/pulls/{args.pr}")[0]
+ pr_author = (pr_info.get("user") or {}).get("login") or ""
+ head_sha = (pr_info.get("head") or {}).get("sha") or ""
+ head_contributors = _fetch_head_contributors(args.repo, head_sha)
+ if head_contributors is None:
+ return 1
+ raw = _gh_api(f"repos/{args.repo}/pulls/{args.pr}/commits?per_page=100")
+ commits = [
+ {
+ "sha": c["sha"],
+ "message": c["commit"]["message"],
+ "author_login": (c.get("author") or {}).get("login"),
+ }
+ for c in raw
+ ]
+ ok = is_self_cla_signature(
+ paths,
+ base_contributors,
+ head_contributors,
+ pr_author,
+ commits,
+ resolve=make_repo_resolver(args.repo),
+ )
+ return 0 if ok else 1
+
if args.pr is None:
ap.error("--pr is required unless --is-field-report-only is given")
diff --git a/scripts/test_cla_coauthors.py b/scripts/test_cla_coauthors.py
index 04e442415..7ce04b20b 100755
--- a/scripts/test_cla_coauthors.py
+++ b/scripts/test_cla_coauthors.py
@@ -21,6 +21,7 @@ from check_cla_coauthors import (
FIELD_REPORT_DIR,
check_commits,
is_field_report_only,
+ is_self_cla_signature,
noreply_login,
parse_coauthors,
)
@@ -213,6 +214,133 @@ class FieldReportExemptionTests(unittest.TestCase):
)
+class SelfClaSignatureTests(unittest.TestCase):
+ """Self-signing .contributors PRs (e.g. #1375, #1366, #1355, #1342) deadlock
+ on cla-bot because cla-bot reads .contributors from `main`. The narrow
+ self-signature predicate satisfies `verification/cla-signed` only when a PR
+ exclusively adds its own author to .contributors."""
+
+ BASE = ["xerj-org", "dependabot[bot]", "buger"]
+ COMMITS = [
+ {
+ "sha": "9bd098c0",
+ "message": "chore: add todie to .contributors (CLA signature)",
+ "author_login": "todie",
+ }
+ ]
+
+ def test_valid_self_signature_passes(self):
+ self.assertTrue(
+ is_self_cla_signature(
+ paths=[".contributors"],
+ base_contributors=self.BASE,
+ head_contributors=self.BASE + ["todie"],
+ pr_author="todie",
+ commits=self.COMMITS,
+ resolve=no_network,
+ )
+ )
+
+ def test_case_insensitive_author_match_passes(self):
+ self.assertTrue(
+ is_self_cla_signature(
+ paths=[".contributors"],
+ base_contributors=self.BASE,
+ head_contributors=self.BASE + ["todie"],
+ pr_author="Todie",
+ commits=self.COMMITS,
+ resolve=no_network,
+ )
+ )
+
+ def test_touching_any_other_file_is_rejected(self):
+ self.assertFalse(
+ is_self_cla_signature(
+ paths=[".contributors", "engine/src/lib.rs"],
+ base_contributors=self.BASE,
+ head_contributors=self.BASE + ["todie"],
+ pr_author="todie",
+ commits=self.COMMITS,
+ resolve=no_network,
+ )
+ )
+
+ def test_adding_another_user_is_rejected(self):
+ self.assertFalse(
+ is_self_cla_signature(
+ paths=[".contributors"],
+ base_contributors=self.BASE,
+ head_contributors=self.BASE + ["someone-else"],
+ pr_author="todie",
+ commits=self.COMMITS,
+ resolve=no_network,
+ )
+ )
+
+ def test_adding_self_plus_another_user_is_rejected(self):
+ self.assertFalse(
+ is_self_cla_signature(
+ paths=[".contributors"],
+ base_contributors=self.BASE,
+ head_contributors=self.BASE + ["todie", "someone-else"],
+ pr_author="todie",
+ commits=self.COMMITS,
+ resolve=no_network,
+ )
+ )
+
+ def test_removing_existing_contributor_is_rejected(self):
+ self.assertFalse(
+ is_self_cla_signature(
+ paths=[".contributors"],
+ base_contributors=self.BASE,
+ head_contributors=["xerj-org", "dependabot[bot]", "todie"],
+ pr_author="todie",
+ commits=self.COMMITS,
+ resolve=no_network,
+ )
+ )
+
+ def test_commit_by_different_author_is_rejected(self):
+ commits = [
+ {
+ "sha": "9bd098c0",
+ "message": "chore: add todie to .contributors",
+ "author_login": "other-user",
+ }
+ ]
+ self.assertFalse(
+ is_self_cla_signature(
+ paths=[".contributors"],
+ base_contributors=self.BASE,
+ head_contributors=self.BASE + ["todie"],
+ pr_author="todie",
+ commits=commits,
+ resolve=no_network,
+ )
+ )
+
+ def test_unsigned_coauthor_trailer_is_rejected(self):
+ commits = [
+ {
+ "sha": "9bd098c0",
+ "message": "chore: add todie to .contributors\n\n"
+ "Co-authored-by: Unsigned <[email protected]>",
+ "author_login": "todie",
+ }
+ ]
+ self.assertFalse(
+ is_self_cla_signature(
+ paths=[".contributors"],
+ base_contributors=self.BASE,
+ head_contributors=self.BASE + ["todie"],
+ pr_author="todie",
+ commits=commits,
+ resolve=no_network,
+ )
+ )
+
+
class WiringTests(unittest.TestCase):
"""A checker CI never runs is not a gate (cf. the #207 lesson)."""
@@ -238,13 +366,14 @@ class WiringTests(unittest.TestCase):
def test_a_separate_job_provides_the_field_report_status(self):
# cla-bot cannot path-scope itself, so the required `verification/cla-signed`
- # status for a strictly field-report-only PR is provided by a dedicated
- # workflow, guarded by the same predicate.
+ # status for a strictly field-report-only PR (or a self-CLA signature PR)
+ # is provided by a dedicated workflow, guarded by the same predicates.
wf = REPO_ROOT / ".github" / "workflows" / "cla-field-report-exempt.yml"
self.assertTrue(wf.exists(), "field-report exemption workflow missing")
text = wf.read_text()
self.assertIn("verification/cla-signed", text)
self.assertIn("--is-field-report-only", text)
+ self.assertIn("--is-self-cla-signature", text)
# It must never run the PR's own code under the elevated token.
self.assertIn("pull_request_target", text)
self.assertIn("base.sha", text)