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.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(ci): fail the CLA exemption job on a broken signature file (#1808)
Ömer Taha Öztop3585d0a403ea
diff --git a/.github/workflows/cla-field-report-exempt.yml b/.github/workflows/cla-field-report-exempt.ymlindex 8c1e9bc64..9c8ae6f07 100644--- a/.github/workflows/cla-field-report-exempt.yml+++ b/.github/workflows/cla-field-report-exempt.yml@@ -107,12 +107,28 @@ jobs: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."+ # 0 = the author's own signature (post success), 2 = the diff is+ # `.contributors` alone but the file does not parse (fail loudly),+ # anything else = some other PR (leave the verdict to cla-bot).+ status=0+ python3 scripts/check_cla_coauthors.py --is-self-cla-signature --pr "$PR_NUMBER" \+ --base-sha "$BASE_SHA" --head-sha "$HEAD_SHA" || status=$?+ case "$status" in+ 0)+ 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"+ ;;+ 2)+ # The annotation from the script names the SHA and the repair;+ # this exit makes it impossible to miss. A red gate with no+ # explanation is what this branch exists to stop.+ exit 1+ ;;+ *)+ echo "PR #${PR_NUMBER} is neither field-report-only nor a self-CLA signature; leaving verification/cla-signed to cla-bot."+ ;;+ esacfidiff --git a/scripts/check_cla_coauthors.py b/scripts/check_cla_coauthors.pyindex 3728c76e7..ea72760f2 100755--- a/scripts/check_cla_coauthors.py+++ b/scripts/check_cla_coauthors.py@@ -53,6 +53,10 @@ Usage (CI):the status the CI job posts on --head-sha describes that commit and noother. Used by the same exemption job, because cla-bot reads`.contributors` from `main` and so can never pass a signature PR itself.+ Exits 2 when the diff is `.contributors` alone but the file at the head+ SHA does not parse: that is a broken signature, not a mixed PR, and the+ CI job turns the 2 into a visible failure instead of leaving the verdict+ to cla-bot — a dropped comma used to look exactly like the deadlock.Needs `gh` and GH_TOKEN for --pr; repo comes from GITHUB_REPOSITORY or --repo.Tests: scripts/test_cla_coauthors.py@@ -143,6 +147,23 @@ def _is_login(value):return isinstance(value, str) and _LOGIN_RE.match(value) is not None+def is_contributors_only_change(files):+ """True iff the diff is exactly one *modified* `.contributors`.++ The shape a signature PR must have, on its own: it says nothing about the+ author or the contents, only that `.contributors` is the whole diff. The+ CLI uses it to tell "a signature PR whose file is broken" — worth a loud,+ actionable failure — from "some other PR", which stays cla-bot's call.+ """+ return (+ isinstance(files, list)+ and len(files) == 1+ and isinstance(files[0], dict)+ and files[0].get("filename") == ".contributors"+ and files[0].get("status") == "modified"+ )++def is_self_cla_signature(files,base_contributors,@@ -177,14 +198,9 @@ def is_self_cla_signature(- has no commits, or any commit not authored by the PR author; or- carries a Co-authored-by trailer that is unresolvable or unsigned."""- if not isinstance(files, list) or len(files) != 1:- return False- f = files[0]- if not isinstance(f, dict):+ if not is_contributors_only_change(files):return False- if f.get("filename") != ".contributors" or f.get("status") != "modified":- return False- if f.get("previous_filename"):+ if files[0].get("previous_filename"):return Falseif not _is_login(pr_author):@@ -369,7 +385,23 @@ def _self_cla_signature_main(args):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:+ if head_contributors is None:+ # `.contributors` is the entire diff, so an unreadable head file is a+ # broken signature, not an unrelated PR. Returning 1 here left the+ # contributor with a red gate indistinguishable from the deadlock (#1619).+ if is_contributors_only_change(files):+ print(+ f"::error::.contributors at {args.head_sha} could not be read as JSON, "+ "so this signature PR cannot be judged. Fix the file — valid "+ "JSON, exactly one added login — and push again.",+ file=sys.stderr,+ )+ return 2+ return 1+ if base_contributors is None:+ # The merge base is `main`'s own file: nothing this PR can repair, so+ # the verdict stays with cla-bot instead of failing the contributor's+ # job for a defect outside their diff.return 1ok = is_self_cla_signature(files,diff --git a/scripts/test_cla_coauthors.py b/scripts/test_cla_coauthors.pyindex d91cd7176..d6efe7ee2 100755--- a/scripts/test_cla_coauthors.py+++ b/scripts/test_cla_coauthors.py@@ -10,16 +10,23 @@ buger's #166). These tests pin the trailer-aware behaviour.Run: python3 scripts/test_cla_coauthors.py"""+import argparse+import base64+import contextlib+import ioimport pathlibimport reimport sysimport unittest+from unittest import mocksys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))+import check_cla_coauthorsfrom check_cla_coauthors import (FIELD_REPORT_DIR,check_commits,+ is_contributors_only_change,is_field_report_only,is_self_cla_signature,noreply_login,@@ -217,6 +224,131 @@ class FieldReportExemptionTests(unittest.TestCase):CONTRIB = {"filename": ".contributors", "status": "modified"}+class SelfClaSignatureExitCodeTests(unittest.TestCase):+ """The one branch the workflow's `case` depends on: a `.contributors`-only+ PR whose head file does not parse exits 2 (loud), everything else 1."""++ BASE_SHA = "a" * 40+ HEAD_SHA = "b" * 40++ def _run(self, files, head_contributors, broken_base=False):+ base_contributors = None if broken_base else ["xerj-org", "dependabot[bot]"]+ pr = {+ "head": {"sha": self.HEAD_SHA},+ "state": "open",+ "user": {"login": "todie"},+ }+ cmp = {+ "total_commits": 1,+ "merge_base_commit": {"sha": self.BASE_SHA},+ "commits": [+ {+ "sha": "c" * 40,+ "commit": {"message": "chore: sign the CLA"},+ "author": {"login": "todie"},+ }+ ],+ "files": files,+ }+ args = argparse.Namespace(+ pr=1, base_sha=self.BASE_SHA, head_sha=self.HEAD_SHA, repo="o/r"+ )+ with mock.patch.object(+ check_cla_coauthors, "_gh_api_one", side_effect=[pr, cmp]+ ), mock.patch.object(+ check_cla_coauthors,+ "_fetch_contributors_at",+ side_effect=lambda _repo, sha: (+ base_contributors if sha == self.BASE_SHA else head_contributors+ ),+ ), contextlib.redirect_stderr(io.StringIO()) as err:+ rc = check_cla_coauthors._self_cla_signature_main(args)+ return rc, err.getvalue()++ def test_broken_contributors_on_a_signature_pr_exits_2(self):+ rc, err = self._run([CONTRIB], None)+ self.assertEqual(rc, 2)+ self.assertIn("::error::", err)++ def test_broken_contributors_on_a_mixed_pr_exits_1(self):+ rc, err = self._run(+ [CONTRIB, {"filename": "x", "status": "modified"}], None+ )+ self.assertEqual(rc, 1)+ self.assertNotIn("::error::", err)++ def test_a_valid_signature_exits_0(self):+ rc, _ = self._run([CONTRIB], ["xerj-org", "dependabot[bot]", "todie"])+ self.assertEqual(rc, 0)++ def test_a_broken_base_file_is_not_this_pr_fault(self):+ # The merge base is `main`'s own file: a defect there is not something+ # the contributor's diff can repair, so the job must not fail on it.+ rc, err = self._run(+ [CONTRIB],+ ["xerj-org", "dependabot[bot]", "todie"],+ broken_base=True,+ )+ self.assertEqual(rc, 1)+ self.assertNotIn("::error::", err)+++class ContributorsOnlyChangeTests(unittest.TestCase):+ """The CLI separates "a signature PR whose file is broken" (exit 2, loud)+ from "some other PR" (exit 1, cla-bot's call). That split is this shape+ test, so it has to be exact: one file, `.contributors`, modified."""++ def test_one_modified_contributors_is_the_signature_shape(self):+ self.assertTrue(is_contributors_only_change([CONTRIB]))++ def test_any_second_changed_file_breaks_the_shape(self):+ self.assertFalse(+ is_contributors_only_change(+ [CONTRIB, {"filename": "engine/src/lib.rs", "status": "modified"}]+ )+ )++ def test_another_status_is_not_the_signature_shape(self):+ for status in ("added", "removed", "renamed", "copied"):+ self.assertFalse(+ is_contributors_only_change(+ [{"filename": ".contributors", "status": status}]+ )+ )++ def test_a_malformed_file_list_is_not_the_signature_shape(self):+ for files in (None, [], "x", [".contributors"], [None], {}):+ self.assertFalse(is_contributors_only_change(files))+++class FetchContributorsTests(unittest.TestCase):+ """`_fetch_contributors_at` returning None is what the CLI turns into the+ loud exit 2 when `.contributors` is the whole diff."""++ def _fetch(self, raw):+ item = {+ "encoding": "base64",+ "content": base64.b64encode(raw).decode("ascii"),+ }+ with mock.patch.object(+ check_cla_coauthors, "_gh_api_one", return_value=item+ ):+ return check_cla_coauthors._fetch_contributors_at("o/r", "0" * 40)++ def test_invalid_json_returns_none(self):+ # The #1619 file once a merge resolution dropped the comma.+ self.assertIsNone(self._fetch(b'[\n "a",\n "b"\n "c"\n]'))++ def test_a_json_value_that_is_not_a_list_still_parses(self):+ # Shape is the predicate's business, not the fetcher's: a dict parses+ # and is rejected later, which is exit 1, not exit 2.+ self.assertEqual(self._fetch(b'{"a": 1}'), {"a": 1})++ def test_a_valid_list_round_trips(self):+ self.assertEqual(self._fetch(b'["a", "b"]'), ["a", "b"])+++class SelfClaSignatureTests(unittest.TestCase):"""Self-signing .contributors PRs (e.g. #1375, #1366, #1355, #1342) deadlockon cla-bot because cla-bot reads .contributors from `main`. The narrow