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.

fix(cla): bind the self-signature exemption to the head SHA and close bypasses

xerj-org42ac75622bbd
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6e1438482..82b63de7f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -64,7 +64,9 @@ jobs:
# (and nothing else). Any code/CI/other-docs change re-arms the full gate.
# The binding `verification/cla-signed` status for a field-report-only PR
# is provided separately (.github/workflows/cla-field-report-exempt.yml),
- # because cla-bot cannot path-scope itself.
+ # because cla-bot cannot path-scope itself. A rename also emits its source
+ # path (previous_filename), so renaming a code file into the field-report
+ # folder cannot hide its deletion from the carve-out.
- name: Co-authored-by trailers resolve to signed contributors
if: github.event_name == 'pull_request'
env:
@@ -72,7 +74,7 @@ jobs:
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
- FILES="$(gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/files" --jq '.[].filename')"
+ FILES="$(gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/files" --jq '.[] | .filename, (.previous_filename // empty)')"
python3 scripts/check_cla_coauthors.py --pr "$PR_NUMBER" --changed-files "$FILES"
reference-coding:
diff --git a/.github/workflows/cla-field-report-exempt.yml b/.github/workflows/cla-field-report-exempt.yml
index bcc3d59f9..8c1e9bc64 100644
--- a/.github/workflows/cla-field-report-exempt.yml
+++ b/.github/workflows/cla-field-report-exempt.yml
@@ -1,34 +1,45 @@
name: CLA field-report exemption
-# Provides the required `verification/cla-signed` status for a pull request whose
-# ENTIRE diff is agent field reports — markdown files under
-# user-feedback/16-agent-field-reports/ — and ONLY such a pull request.
+# Provides the required `verification/cla-signed` status for exactly two kinds of
+# pull request, and ONLY those:
+#
+# 1. A field-report-only PR: its ENTIRE diff is agent field reports — markdown
+# files under user-feedback/16-agent-field-reports/.
+# 2. A self-CLA-signature PR: its ENTIRE diff is `.contributors` gaining ONE
+# entry, the PR author's own login, with every commit authored by that
+# author (scripts/check_cla_coauthors.py --is-self-cla-signature).
#
# Why a separate job at all: `verification/cla-signed` is normally posted by the
# external cla-bot GitHub App, which matches commit AUTHORS against .contributors
# and CANNOT path-scope itself. The agent field-report loop exists so any agent
# can file one short report; gating that behind a CLA signature is the friction
# that kept the folder empty (see demo/playbooks/AGENT_CONTRIBUTION_LOOP_2026-08-18.md).
-# This job scopes the exemption: it fires only when EVERY changed path is a field
-# report, so a mixed pull request (a field report plus any code/CI/other change)
-# is left entirely to cla-bot and gets the full gate. The predicate is the same
-# one the internal trailer gate uses (scripts/check_cla_coauthors.py
-# --is-field-report-only), so the two cannot drift.
+# And cla-bot reads .contributors from `main`, so the very PR that signs the CLA
+# can never pass cla-bot before it is merged (issue: the signature deadlock,
+# e.g. #1375). A mixed PR (either kind plus any other change) is left entirely
+# to cla-bot and gets the full gate. The predicates are the same code the
+# internal trailer gate uses, so they cannot drift.
#
# Why pull_request_target, not pull_request: only that event's token can write a
-# commit status on a fork pull request, and field reports come from exactly those
+# commit status on a fork pull request, and both kinds come from exactly those
# forks. This job is safe under the elevated token because it NEVER checks out or
# runs the pull request's code — it checks out the trusted base ref, reads the
-# changed FILE LIST from the API, and posts a status. Do not add a checkout of the
-# PR head here.
+# changed FILE LIST, commits and `.contributors` contents from the API as data,
+# and posts a status. Do not add a checkout of the PR head here.
+#
+# Binding to the head SHA: every input is read pinned to
+# compare/<base.sha>...<head.sha> (and contents?ref=<sha>), and the status is
+# posted on that same head.sha — so a force-push after the check cannot inherit
+# a verdict about a different commit. A rename lists its source path too
+# (previous_filename), so a rename into an exempt path cannot hide a deletion.
#
-# Honest limitation (stated plainly, per the task): posting this status races
-# cla-bot's own status for the same context — GitHub keeps the last writer per
-# context. Because this job never fires on a mixed PR, cla-bot stays authoritative
-# everywhere it matters, but the fully robust fix for field-report-only PRs is an
-# admin-level branch-protection or .clabot change, which lives outside this repo.
-# The status post is non-fatal (`|| echo`) so a token that cannot write it never
-# reddens the PR; cla-bot simply remains authoritative in that case.
+# Honest limitation: GitHub keeps the last writer per status context, so this
+# races cla-bot's own status. The job waits (bounded) for cla-bot's first status
+# on the head SHA before posting, which covers the normal ordering; a later
+# `@cla-bot check` re-run can still overwrite it with cla-bot's verdict. Because
+# this job never fires on a mixed PR, cla-bot stays authoritative everywhere it
+# matters. The status post is non-fatal (`|| echo`) so a token that cannot write
+# it never reddens the PR; cla-bot simply remains authoritative in that case.
on:
pull_request_target:
@@ -54,31 +65,54 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
+ persist-credentials: false
- 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 }}
+ BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
REPO: ${{ github.repository }}
run: |
- FILES="$(gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/files" --jq '.[].filename')"
- if python3 scripts/check_cla_coauthors.py --is-field-report-only --changed-files "$FILES"; then
- echo "PR #${PR_NUMBER} is field-report-only; posting verification/cla-signed=success."
- gh api -X POST "repos/${REPO}/statuses/${HEAD_SHA}" \
- -f context=verification/cla-signed \
- -f state=success \
- -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."
+ set -euo pipefail
+ # Changed paths of EXACTLY head.sha (pinned compare, not the moving
+ # pulls/N/files list). A rename also emits its source path. The compare
+ # API caps the file list at 300, so a list that long is untrustworthy
+ # and emits a sentinel that no predicate accepts.
+ FILES="$(gh api "repos/${REPO}/compare/${BASE_SHA}...${HEAD_SHA}" --jq '
+ if (.files | length) >= 300 then "<truncated-file-list>"
+ else .files[] | .filename, (.previous_filename // empty) end')" \
+ || FILES="<compare-failed>" # unknown diff: no predicate accepts it
+
+ post_success() {
+ # Let cla-bot's first status for this SHA land first (last writer
+ # wins per context), bounded so a missing cla-bot never hangs us.
+ for _ in $(seq 1 20); do
+ n="$(gh api "repos/${REPO}/commits/${HEAD_SHA}/statuses" \
+ --jq '[.[] | select(.context == "verification/cla-signed" and .creator.login == "cla-bot[bot]")] | length' || echo 0)"
+ [ "${n:-0}" -gt 0 ] && break
+ sleep 15
+ done
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" \
+ -f description="$1" \
+ -f target_url="$2" \
|| echo "note: could not post the status (insufficient token permissions?). cla-bot remains authoritative."
+ }
+
+ if python3 scripts/check_cla_coauthors.py --is-field-report-only --changed-files "$FILES"; then
+ echo "PR #${PR_NUMBER} @ ${HEAD_SHA} is field-report-only; posting verification/cla-signed=success."
+ post_success \
+ "Field-report-only PR: CLA gate waived for user-feedback/16-agent-field-reports/*.md" \
+ "https://github.com/${REPO}/blob/main/user-feedback/16-agent-field-reports/README.md"
+ elif python3 scripts/check_cla_coauthors.py --is-self-cla-signature --pr "$PR_NUMBER" \
+ --base-sha "$BASE_SHA" --head-sha "$HEAD_SHA"; then
+ echo "PR #${PR_NUMBER} @ ${HEAD_SHA} is its author's own CLA signature; posting verification/cla-signed=success."
+ post_success \
+ "CLA signature PR: the author adds only their own login to .contributors" \
+ "https://github.com/${REPO}/blob/main/CLA.md"
else
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 fd8d80bd8..3728c76e7 100755
--- a/scripts/check_cla_coauthors.py
+++ b/scripts/check_cla_coauthors.py
@@ -40,17 +40,20 @@ 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.
- 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.
+ 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 <n> --base-sha <sha> --head-sha <sha>
+ Exits 0 iff the PR, evaluated at exactly --head-sha, is a CLA signature by
+ its own author: the only change is `.contributors` gaining the author's own
+ login, every commit is authored by the PR author, and no Co-authored-by
+ trailer names an unsigned contributor. Everything (changed files, commits,
+ both `.contributors` versions) is read pinned to --base-sha...--head-sha, so
+ the status the CI job posts on --head-sha describes that commit and no
+ other. Used by the same exemption job, because cla-bot reads
+ `.contributors` from `main` and so can never pass a signature PR itself.
+ Needs `gh` and GH_TOKEN for --pr; repo comes from GITHUB_REPOSITORY or --repo.
Tests: scripts/test_cla_coauthors.py
"""
@@ -125,66 +128,95 @@ def is_field_report_only(paths):
return True
+# A GitHub login: ASCII alphanumerics and single hyphens, at most 39 chars.
+# Deliberately ASCII-only — str.lower() folds some non-ASCII code points onto
+# ASCII letters (e.g. KELVIN SIGN U+212A -> "k"), which must not count as a
+# case-insensitive match for a real login.
+_LOGIN_RE = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$")
+
+# A signature PR has one or a handful of commits. Anything bigger is not what
+# this exemption is for, and a cap keeps the commit list provably complete.
+MAX_SIGNATURE_COMMITS = 20
+
+
+def _is_login(value):
+ return isinstance(value, str) and _LOGIN_RE.match(value) is not None
+
+
def is_self_cla_signature(
- paths,
+ files,
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.
+ """True iff the PR is its own author signing the CLA, and nothing else.
+
+ cla-bot reads `.contributors` from `main`, so a PR whose sole purpose is
+ signing the CLA (adding the PR author's own login to `.contributors`) can
+ never pass cla-bot before it is merged. This predicate lets the trusted
+ `pull_request_target` job satisfy `verification/cla-signed` for exactly
+ that PR shape.
+
+ files: the PR's changed-file entries, as GitHub's compare/files API returns
+ them ({"filename", "status", "previous_filename"?}), pinned to the head
+ SHA being judged.
+ base_contributors / head_contributors: parsed `.contributors` at the merge
+ base and at the head SHA.
+ commits: [{"sha", "message", "author_login"}] — every commit in the PR.
+
+ Rejects a PR that:
+ - changes any file other than `.contributors`, or reaches it by a rename
+ or copy (which would hide the deletion of the source path), or adds or
+ deletes it rather than modifying it;
+ - removes or alters any existing `.contributors` entry;
+ - adds anything other than exactly ONE entry, that entry being a valid
+ GitHub login equal (ASCII case-insensitively) to the PR author;
+ - comes from an author who is already signed (nothing to sign);
+ - has no commits, or any commit not authored by the PR author; or
+ - carries a Co-authored-by trailer that is unresolvable or unsigned.
"""
- clean_paths = [p.strip() for p in paths if p.strip()]
- if clean_paths != [".contributors"]:
+ if not isinstance(files, list) or len(files) != 1:
return False
- if not isinstance(pr_author, str) or not pr_author.strip():
+ f = files[0]
+ if not isinstance(f, dict):
return False
- author_lower = pr_author.strip().lower()
- if not isinstance(base_contributors, list) or not isinstance(head_contributors, list):
+ if f.get("filename") != ".contributors" or f.get("status") != "modified":
return False
- if not all(isinstance(c, str) and c.strip() for c in base_contributors):
+ if f.get("previous_filename"):
return False
- if not all(isinstance(c, str) and c.strip() for c in head_contributors):
+
+ if not _is_login(pr_author):
return False
+ author = pr_author.lower()
+
+ for lst in (base_contributors, head_contributors):
+ if not isinstance(lst, list) or not all(isinstance(c, str) for c in lst):
+ return False
if "dependabot[bot]" not in head_contributors:
return False
- base_counts = {}
+ if any(c.lower() == author for c in base_contributors):
+ return False # already signed: there is nothing to sign
+
+ # head must be exactly base plus one entry (multiset), entries untouched.
+ remaining = list(head_contributors)
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:
+ try:
+ remaining.remove(c)
+ except ValueError:
+ return False # an existing entry was removed or altered
+ if len(remaining) != 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):
+ added = remaining[0]
+ if not _is_login(added) or added.lower() != author:
return False
- if not commits:
+
+ if not commits or len(commits) > MAX_SIGNATURE_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:
+ login = commit.get("author_login")
+ if not _is_login(login) or login.lower() != author:
return False
if check_commits(commits, head_contributors, resolve):
return False
@@ -266,21 +298,90 @@ 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)."""
+def _gh_api_one(path):
+ """A single (non-paginated) API response object."""
+ out = subprocess.run(
+ ["gh", "api", path], check=True, capture_output=True, text=True
+ ).stdout
+ return json.loads(out)
+
+
+def _fetch_contributors_at(repo, sha):
+ """`.contributors` at commit `sha`, parsed as pure JSON data via the
+ contents API (never checking out or executing PR code). None on any
+ failure, including a file over the contents API's inline size limit."""
try:
- items = _gh_api(
- f"repos/{repo}/contents/.contributors?ref={urllib.parse.quote(head_sha)}"
+ item = _gh_api_one(
+ f"repos/{repo}/contents/.contributors?ref={urllib.parse.quote(sha)}"
)
- if not items or not isinstance(items[0], dict):
+ if not isinstance(item, dict) or item.get("encoding") != "base64":
return None
- raw = base64.b64decode(items[0]["content"]).decode("utf-8")
+ raw = base64.b64decode(item["content"]).decode("utf-8")
return json.loads(raw)
- except ( subprocess.CalledProcessError, KeyError, ValueError, TypeError):
+ except (subprocess.CalledProcessError, KeyError, ValueError, TypeError):
return None
+_SHA_RE = re.compile(r"^[0-9a-f]{40}$")
+
+
+def _self_cla_signature_main(args):
+ """--is-self-cla-signature: judge the PR at exactly args.head_sha."""
+ if args.pr is None or not args.base_sha or not args.head_sha:
+ print("--is-self-cla-signature needs --pr, --base-sha and --head-sha",
+ file=sys.stderr)
+ return 2
+ if not (_SHA_RE.match(args.base_sha) and _SHA_RE.match(args.head_sha)):
+ return 1
+ try:
+ pr_info = _gh_api_one(f"repos/{args.repo}/pulls/{args.pr}")
+ # A stale event (the PR was pushed again since): its own run judges
+ # the new head. Never post a verdict about a SHA we did not read.
+ if (pr_info.get("head") or {}).get("sha") != args.head_sha:
+ print("PR head moved since this event; not judging a stale SHA.")
+ return 1
+ if pr_info.get("state") != "open":
+ return 1
+ pr_author = (pr_info.get("user") or {}).get("login") or ""
+
+ # Pinned to base...head: the files and commits are those of head_sha,
+ # not whatever the PR points at by the time the API is read.
+ cmp = _gh_api_one(
+ f"repos/{args.repo}/compare/{args.base_sha}...{args.head_sha}"
+ )
+ raw_commits = cmp.get("commits") or []
+ if cmp.get("total_commits") != len(raw_commits):
+ return 1 # truncated list: cannot prove every commit was checked
+ merge_base = (cmp.get("merge_base_commit") or {}).get("sha") or ""
+ if not _SHA_RE.match(merge_base):
+ return 1
+ files = cmp.get("files")
+ commits = [
+ {
+ "sha": c["sha"],
+ "message": c["commit"]["message"],
+ "author_login": (c.get("author") or {}).get("login"),
+ }
+ for c in raw_commits
+ ]
+ except (subprocess.CalledProcessError, KeyError, ValueError, TypeError):
+ return 1
+
+ base_contributors = _fetch_contributors_at(args.repo, merge_base)
+ head_contributors = _fetch_contributors_at(args.repo, args.head_sha)
+ if base_contributors is None or head_contributors is None:
+ return 1
+ ok = is_self_cla_signature(
+ files,
+ base_contributors,
+ head_contributors,
+ pr_author,
+ commits,
+ resolve=make_repo_resolver(args.repo),
+ )
+ return 0 if ok else 1
+
+
def main():
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--pr", type=int, help="pull request number")
@@ -303,9 +404,11 @@ def main():
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.",
+ help="predicate mode: exit 0 iff the PR, at --head-sha, only adds the PR "
+ "author's own login to .contributors, else 1. Used by the exemption CI job.",
)
+ ap.add_argument("--base-sha", help="PR base SHA (--is-self-cla-signature)")
+ ap.add_argument("--head-sha", help="PR head SHA to judge (--is-self-cla-signature)")
args = ap.parse_args()
paths = _split_paths(args.changed_files)
@@ -315,35 +418,7 @@ def main():
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
+ return _self_cla_signature_main(args)
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 7ce04b20b..d91cd7176 100755
--- a/scripts/test_cla_coauthors.py
+++ b/scripts/test_cla_coauthors.py
@@ -214,6 +214,9 @@ class FieldReportExemptionTests(unittest.TestCase):
)
+CONTRIB = {"filename": ".contributors", "status": "modified"}
+
+
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
@@ -232,7 +235,7 @@ class SelfClaSignatureTests(unittest.TestCase):
def test_valid_self_signature_passes(self):
self.assertTrue(
is_self_cla_signature(
- paths=[".contributors"],
+ files=[CONTRIB],
base_contributors=self.BASE,
head_contributors=self.BASE + ["todie"],
pr_author="todie",
@@ -244,7 +247,7 @@ class SelfClaSignatureTests(unittest.TestCase):
def test_case_insensitive_author_match_passes(self):
self.assertTrue(
is_self_cla_signature(
- paths=[".contributors"],
+ files=[CONTRIB],
base_contributors=self.BASE,
head_contributors=self.BASE + ["todie"],
pr_author="Todie",
@@ -256,7 +259,7 @@ class SelfClaSignatureTests(unittest.TestCase):
def test_touching_any_other_file_is_rejected(self):
self.assertFalse(
is_self_cla_signature(
- paths=[".contributors", "engine/src/lib.rs"],
+ files=[CONTRIB, {"filename": "engine/src/lib.rs", "status": "modified"}],
base_contributors=self.BASE,
head_contributors=self.BASE + ["todie"],
pr_author="todie",
@@ -268,7 +271,7 @@ class SelfClaSignatureTests(unittest.TestCase):
def test_adding_another_user_is_rejected(self):
self.assertFalse(
is_self_cla_signature(
- paths=[".contributors"],
+ files=[CONTRIB],
base_contributors=self.BASE,
head_contributors=self.BASE + ["someone-else"],
pr_author="todie",
@@ -280,7 +283,7 @@ class SelfClaSignatureTests(unittest.TestCase):
def test_adding_self_plus_another_user_is_rejected(self):
self.assertFalse(
is_self_cla_signature(
- paths=[".contributors"],
+ files=[CONTRIB],
base_contributors=self.BASE,
head_contributors=self.BASE + ["todie", "someone-else"],
pr_author="todie",
@@ -292,7 +295,7 @@ class SelfClaSignatureTests(unittest.TestCase):
def test_removing_existing_contributor_is_rejected(self):
self.assertFalse(
is_self_cla_signature(
- paths=[".contributors"],
+ files=[CONTRIB],
base_contributors=self.BASE,
head_contributors=["xerj-org", "dependabot[bot]", "todie"],
pr_author="todie",
@@ -311,7 +314,7 @@ class SelfClaSignatureTests(unittest.TestCase):
]
self.assertFalse(
is_self_cla_signature(
- paths=[".contributors"],
+ files=[CONTRIB],
base_contributors=self.BASE,
head_contributors=self.BASE + ["todie"],
pr_author="todie",
@@ -331,7 +334,7 @@ class SelfClaSignatureTests(unittest.TestCase):
]
self.assertFalse(
is_self_cla_signature(
- paths=[".contributors"],
+ files=[CONTRIB],
base_contributors=self.BASE,
head_contributors=self.BASE + ["todie"],
pr_author="todie",
@@ -341,6 +344,76 @@ class SelfClaSignatureTests(unittest.TestCase):
)
+ def _ok(self, **kw):
+ args = dict(
+ files=[CONTRIB],
+ base_contributors=self.BASE,
+ head_contributors=self.BASE + ["todie"],
+ pr_author="todie",
+ commits=self.COMMITS,
+ resolve=no_network,
+ )
+ args.update(kw)
+ return is_self_cla_signature(**args)
+
+ def test_baseline_helper_passes(self):
+ self.assertTrue(self._ok())
+
+ def test_rename_onto_contributors_is_rejected(self):
+ # A rename lists only the NEW path; the deleted source would be hidden.
+ renamed = dict(CONTRIB, status="renamed", previous_filename="engine/x.rs")
+ self.assertFalse(self._ok(files=[renamed]))
+ sneaky = dict(CONTRIB, previous_filename="engine/x.rs")
+ self.assertFalse(self._ok(files=[sneaky]))
+
+ def test_added_or_removed_contributors_file_is_rejected(self):
+ self.assertFalse(self._ok(files=[dict(CONTRIB, status="added")]))
+ self.assertFalse(self._ok(files=[dict(CONTRIB, status="removed")]))
+ self.assertFalse(self._ok(files=[]))
+
+ def test_altering_an_existing_entry_is_rejected(self):
+ # Same count, same author added, but an existing entry rewritten.
+ head = ["xerj-org", "dependabot[bot]", "Buger", "todie"]
+ self.assertFalse(self._ok(head_contributors=head))
+
+ def test_non_ascii_lookalike_login_is_rejected(self):
+ # KELVIN SIGN U+212A lowercases to ASCII "k" under str.lower().
+ self.assertFalse(
+ self._ok(head_contributors=self.BASE + ["\u212aate"], pr_author="kate",
+ commits=[dict(self.COMMITS[0], author_login="kate")])
+ )
+
+ def test_whitespace_padded_entry_is_rejected(self):
+ self.assertFalse(self._ok(head_contributors=self.BASE + [" todie "]))
+ self.assertFalse(self._ok(head_contributors=self.BASE + ["todie\n"]))
+
+ def test_already_signed_author_is_rejected(self):
+ base = self.BASE + ["Todie"]
+ self.assertFalse(self._ok(base_contributors=base, head_contributors=base + ["todie"]))
+
+ def test_malformed_contributors_is_rejected(self):
+ self.assertFalse(self._ok(head_contributors={"todie": True}))
+ self.assertFalse(self._ok(head_contributors=self.BASE + ["todie", 1]))
+ self.assertFalse(self._ok(head_contributors=None))
+ self.assertFalse(self._ok(head_contributors=["xerj-org", "buger", "todie"]))
+
+ def test_commit_with_no_linked_github_user_is_rejected(self):
+ self.assertFalse(self._ok(commits=[dict(self.COMMITS[0], author_login=None)]))
+ self.assertFalse(self._ok(commits=[]))
+
+ def test_one_foreign_commit_among_own_commits_is_rejected(self):
+ commits = self.COMMITS + [dict(self.COMMITS[0], sha="deadbeef", author_login="mallory")]
+ self.assertFalse(self._ok(commits=commits))
+
+ def test_too_many_commits_is_rejected(self):
+ self.assertFalse(self._ok(commits=self.COMMITS * 21))
+
+ def test_invalid_pr_author_is_rejected(self):
+ self.assertFalse(self._ok(pr_author=""))
+ self.assertFalse(self._ok(pr_author="todie[bot]",
+ head_contributors=self.BASE + ["todie[bot]"]))
+
+
class WiringTests(unittest.TestCase):
"""A checker CI never runs is not a gate (cf. the #207 lesson)."""
@@ -374,6 +447,13 @@ class WiringTests(unittest.TestCase):
self.assertIn("verification/cla-signed", text)
self.assertIn("--is-field-report-only", text)
self.assertIn("--is-self-cla-signature", text)
+ # Both verdicts must be judged on the exact SHA the status is posted to.
+ self.assertIn("compare/${BASE_SHA}...${HEAD_SHA}", text)
+ self.assertIn('--head-sha "$HEAD_SHA"', text)
+ # A rename must expose its source path to the path predicates.
+ self.assertIn("previous_filename", text)
+ self.assertIn("persist-credentials: false", text)
+ self.assertNotIn("head.ref", 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)