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.

ci(attribution): enforce the CLA in the contributor-attribution check (#5072)

injaneity20bd35956697
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index 9c419652c5..761e45ec2d 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -85,11 +85,14 @@ GitHub issue form. Longer proposals and diagrams remain in this repository under
### Contributor License Agreement
-Before a pull request can be merged, its author must accept the
-[Contributor License Agreement](../legal/CLA.md) once. The **CI: CLA** check comments on
-your first pull request with instructions; reply with the sentence it gives you
-to sign. The agreement applies to your later contributions, and you keep
-ownership of your work. Maintainers and automation accounts are exempt.
+Contributors accept the [Contributor License Agreement](../legal/CLA.md) once. The
+**CI: CLA** check comments on your first pull request with instructions; reply with
+the sentence it gives you to sign. The agreement applies to your later contributions,
+and you keep ownership of your work. Maintainers and automation accounts are exempt.
+
+The required `contributor-attribution` check enforces the CLA. It fails when a pull
+request touching the Cua Spaces apps or `libs/cua-spacesd` has an unsigned or
+unverifiable contributor, and it only warns elsewhere.
### Agent-Assisted Contributions
diff --git a/.github/scripts/release_attribution.py b/.github/scripts/release_attribution.py
index 08f0fa5dd9..75417fa241 100644
--- a/.github/scripts/release_attribution.py
+++ b/.github/scripts/release_attribution.py
@@ -82,6 +82,17 @@ PERCEPTION_COMPANION_PATHS = (
"libs/cua-driver/rust/Cargo.toml",
"libs/cua-driver/rust/Cargo.lock",
)
+CLA_STRICT_PATHS = (
+ "apps/cua-spaces/",
+ "apps/cua-spaces-desktop/",
+ "apps/cua-spaces-macos/",
+ "apps/cua-spaces-web/",
+ "libs/cua-spacesd/",
+)
+CLA_WORKFLOW = Path(".github/workflows/cla.yml")
+CLA_SIGNATURES_PATH = "signatures/version1/cla.json"
+CLA_SIGNATURES_BRANCH = "cla-signatures"
+CLA_ALLOWLIST_RE = re.compile(r'^\s*allowlist:\s*"(?P<logins>[^"]*)"\s*$', re.MULTILINE)
ALLOWED_TITLE_TYPES = RELEASING_TYPES | {
"build",
"chore",
@@ -105,6 +116,9 @@ class ReleaseError(RuntimeError):
"""A release invariant failed."""
+CLA_LOOKUP_ERRORS = (ReleaseError, OSError, ValueError, KeyError, TypeError)
+
+
@dataclass(frozen=True)
class CommitRecord:
sha: str
@@ -261,6 +275,17 @@ class GitHubClient:
)
return commits
+ def pull_files(self, repository: str, number: int) -> list[str]:
+ paths: list[str] = []
+ for page in range(1, 31):
+ batch = list(
+ self.get(f"repos/{repository}/pulls/{number}/files?per_page=100&page={page}")
+ )
+ paths.extend(str(item.get("filename") or "") for item in batch)
+ if len(batch) < 100:
+ break
+ return paths
+
def file_json(self, repository: str, path: str, ref: str) -> Mapping[str, Any]:
encoded_path = quote(path.strip("/"), safe="/")
payload = self.get(f"repos/{repository}/contents/{encoded_path}?ref={quote(ref, safe='')}")
@@ -608,6 +633,148 @@ def unresolved_coauthor_identities(
return sorted(unresolved.values(), key=lambda item: (item["email"], item["sha"]))
+def resolve_login(
+ config: Mapping[str, Any],
+ name: str,
+ email: str,
+ linked_login: str = "",
+ github: Any = None,
+) -> str | None:
+ return (
+ linked_login
+ or _normalized_map(config, "coauthorOverrides").get(f"{name.strip()} <{email}>".lower())
+ or login_from_email(email, _normalized_map(config, "identityOverrides"))
+ or lookup_email_login(github, email)
+ or None
+ )
+
+
+def unsigned_cla_contributors(
+ *,
+ repository: str,
+ pull: Mapping[str, Any],
+ commits: Sequence[Mapping[str, Any]],
+ config: Mapping[str, Any],
+ signed: set[str],
+ github: GitHubClient,
+) -> list[str]:
+ problems: list[str] = []
+ bots = _normalized_set(config, "bots")
+ ignored = _normalized_set(config, "ignoredCoauthorEmails")
+ unsigned: dict[str, set[int]] = defaultdict(set)
+
+ def add(number: int, name: str, email: str, linked_login: str = "") -> None:
+ email = email.strip().lower()
+ login = resolve_login(config, name, email, linked_login, github)
+ if email in ignored or (login and (is_bot(login, bots) or login.lower() in signed)):
+ return
+ person = f"@{login}" if login else f"{name.strip()} <{email}> (no GitHub login)"
+ unsigned[person].add(number)
+
+ def add_pull(
+ number: int, source: Mapping[str, Any], items: Iterable[Mapping[str, Any]]
+ ) -> set[int]:
+ add(number, "", "", str((source.get("user") or {}).get("login") or ""))
+ sources = set(source_pull_numbers(str(source.get("body") or ""), repository))
+ for item in items:
+ commit = item.get("commit") or {}
+ author = commit.get("author") or {}
+ linked_author = str((item.get("author") or {}).get("login") or "")
+ add(
+ number, str(author.get("name") or ""), str(author.get("email") or ""), linked_author
+ )
+ message = str(commit.get("message") or "")
+ for match in COAUTHOR_RE.finditer(message):
+ add(number, match.group("name"), match.group("email"))
+ sources.update(source_pull_numbers(message, repository))
+ return sources
+
+ pull_number = int(pull.get("number") or 0)
+ for number in sorted(add_pull(pull_number, pull, commits) - {pull_number}):
+ try:
+ source = github.pull(repository, number)
+ items = github.all_pull_commits(repository, {**source, "number": number})
+ except CLA_LOOKUP_ERRORS as error:
+ problems.append(f"could not read source pull request #{number}: {error}")
+ continue
+ add_pull(number, source, items)
+ return problems + [
+ f"{person} has not signed the CLA; sign it on "
+ + " or ".join(f"#{n}" for n in sorted(numbers))
+ for person, numbers in sorted(unsigned.items())
+ ]
+
+
+def validate_pr_cla(*, repository: str, number: int, config_path: Path, github: GitHubClient) -> None:
+ """Enforce the CLA on Spaces paths; warn about every problem elsewhere."""
+ try:
+ paths = github.pull_files(repository, number)
+ except (ReleaseError, OSError, ValueError) as error:
+ raise ReleaseError(
+ f"cannot read the changed files of pull request #{number}; "
+ f"treating it as touching Spaces paths: {error}"
+ ) from error
+ strict = any(path and path.startswith(CLA_STRICT_PATHS) for path in paths)
+ problems: list[str] = []
+ pull = commits = config = None
+ signed: set[str] | None = None
+ try:
+ pull = github.pull(repository, number)
+ expected = pull.get("changed_files")
+ if not isinstance(expected, int) or expected != len(paths) or not all(paths):
+ problems.append(f"changed files of pull request #{number} are incomplete")
+ except CLA_LOOKUP_ERRORS as error:
+ problems.append(f"could not read pull request #{number}: {error}")
+ names: set[str] | None = None
+ try:
+ entries = github.file_json(repository, CLA_SIGNATURES_PATH, CLA_SIGNATURES_BRANCH).get(
+ "signedContributors"
+ )
+ if isinstance(entries, list):
+ names = {
+ str(entry.get("name") or "").lower() for entry in entries if isinstance(entry, Mapping)
+ }
+ else:
+ problems.append(
+ "signatures/version1/cla.json on cla-signatures has no signedContributors list"
+ )
+ except CLA_LOOKUP_ERRORS as error:
+ problems.append(f"signatures/version1/cla.json on cla-signatures could not be read: {error}")
+ allowed: set[str] | None = None
+ try:
+ match = CLA_ALLOWLIST_RE.search(CLA_WORKFLOW.read_text())
+ except (OSError, ValueError):
+ match = None
+ if match:
+ allowed = {login.strip().lower() for login in match.group("logins").split(",")}
+ else:
+ problems.append(".github/workflows/cla.yml has no readable allowlist")
+ try:
+ config = json.loads(config_path.read_text())
+ if pull is not None:
+ commits = github.all_pull_commits(repository, {**pull, "number": number})
+ except CLA_LOOKUP_ERRORS as error:
+ problems.append(f"could not read the pull request commits or attribution config: {error}")
+ if names is not None and allowed is not None:
+ signed = names | allowed
+ if signed is not None and pull is not None and commits is not None and config is not None:
+ problems += unsigned_cla_contributors(
+ repository=repository,
+ pull=pull,
+ commits=commits,
+ config=config,
+ signed=signed,
+ github=github,
+ )
+ if problems and strict:
+ raise ReleaseError(
+ "CLA is not signed or could not be verified on a pull request touching Spaces paths:\n- "
+ + "\n- ".join(problems)
+ )
+ for problem in problems:
+ print(f"::warning::{problem}")
+
+
def is_clean_main_sync(github, repository, sha, parents, main_sha) -> bool:
if len(parents) != 2 or not main_sha:
return False
@@ -651,7 +818,6 @@ def validate_pr_attribution(
opt_out = _normalized_set(base_config, "optOutHandles")
ignored = _normalized_set(base_config, "ignoredCoauthorEmails")
base_overrides = _normalized_map(base_config, "identityOverrides")
- coauthor_overrides = _normalized_map(base_config, "coauthorOverrides")
override_errors = [
f"{email}={login!r} (expected {base_overrides[email]!r})"
@@ -672,22 +838,13 @@ def validate_pr_attribution(
preserved_authors: list[dict[str, Any]] = []
early_errors: list[str] = []
- def resolved_login(name: str, email: str, linked_login: str = "") -> str | None:
- login = (
- linked_login
- or coauthor_overrides.get(f"{name.strip()} <{email}>".lower())
- or login_from_email(email, base_overrides)
- or lookup_email_login(github, email)
- )
- return login or None
-
commit_shas = {str(item.get("sha") or "") for item in commits}
credited_coauthors: set[str] = set()
for item in commits:
message = str((item.get("commit") or {}).get("message") or "")
for match in COAUTHOR_RE.finditer(message):
email = match.group("email").strip().lower()
- login = resolved_login(match.group("name"), email)
+ login = resolve_login(base_config, match.group("name"), email, "", github)
if login and email not in ignored:
credited_coauthors.add(login.lower())
@@ -718,7 +875,7 @@ def validate_pr_attribution(
author_name = str(author.get("name") or "")
author_email = str(author.get("email") or "").strip().lower()
linked_author = str((item.get("author") or {}).get("login") or "").strip()
- author_login = resolved_login(author_name, author_email, linked_author)
+ author_login = resolve_login(base_config, author_name, author_email, linked_author, github)
parents = [str(parent.get("sha") or "") for parent in item.get("parents") or []]
is_base_sync_merge = len(parents) > 1 and any(
parent and parent not in commit_shas for parent in parents[1:]
@@ -774,7 +931,7 @@ def validate_pr_attribution(
for match in COAUTHOR_RE.finditer(message):
name = match.group("name").strip()
email = match.group("email").strip().lower()
- login = resolved_login(name, email)
+ login = resolve_login(base_config, name, email, "", github)
if email in ignored:
continue
if login and (
@@ -1726,17 +1883,21 @@ def report_unresolved_command(args: argparse.Namespace) -> None:
report_unresolved_identities(client, args.repository, identities, config, args.source)
-def validate_pr_command(args: argparse.Namespace) -> None:
+def pull_request_from_event(args: argparse.Namespace) -> tuple[str, int, GitHubClient]:
event = json.loads(args.event.read_text())
event_pull = event.get("pull_request") or {}
repository = str((event.get("repository") or {}).get("full_name") or "")
number = int(event_pull.get("number") or event.get("number") or 0)
if not repository or not number:
raise ReleaseError("event does not identify a repository and pull request")
-
client = GitHubClient(
os.environ.get("GH_TOKEN", ""), os.environ.get("GITHUB_API_URL", "https://api.github.com")
)
+ return repository, number, client
+
+
+def validate_pr_command(args: argparse.Namespace) -> None:
+ repository, number, client = pull_request_from_event(args)
pull = client.pull(repository, number)
head = pull.get("head") or {}
head_repository = str((head.get("repo") or {}).get("full_name") or "")
@@ -1778,10 +1939,15 @@ def validate_pr_command(args: argparse.Namespace) -> None:
def report_pr_attribution(args: argparse.Namespace) -> None:
"""Run the PR attribution validation as information only.
- Attribution is best effort: every finding, and any error while checking,
+ The CLA check runs first and enforces the path policy: it fails on Spaces
+ paths (or an unreadable file list). Attribution is best effort: every finding, and any error while checking,
becomes a warning annotation and step summary. The check always passes so
the required ``contributor-attribution`` status never blocks a merge.
"""
+ repository, number, client = pull_request_from_event(args)
+ validate_pr_cla(
+ repository=repository, number=number, config_path=args.config, github=client
+ )
try:
validate_pr_command(args)
return
diff --git a/.github/scripts/tests/test_ci_gate_workflow.py b/.github/scripts/tests/test_ci_gate_workflow.py
index fb0ee2c7e7..7e34461e4a 100644
--- a/.github/scripts/tests/test_ci_gate_workflow.py
+++ b/.github/scripts/tests/test_ci_gate_workflow.py
@@ -1,3 +1,4 @@
+import json
import os
from pathlib import Path
import subprocess
@@ -38,7 +39,47 @@ def test_gate_wiring():
assert GATE['jobs']['ci-gate']['timeout-minutes'] == 360
assert '.workflow_id != $GITHUB_WORKFLOW_ID' in SCRIPT
assert '(.event == \\"pull_request\\" or .event == \\"pull_request_target\\")' in SCRIPT
- assert 'claude-auto-fix|ci-release-reminder|review-cua-perception-candidates' in SCRIPT
+ assert 'claude-auto-fix|ci-release-reminder|review-cua-perception-candidates|/cla[.]yml($|@)' in SCRIPT
+
+
+def filtered_runs(ignore_re):
+ runs_src = SCRIPT[SCRIPT.index('scope_jq='):]
+ runs_src = runs_src[:runs_src.index('\n}\n') + len('\n}\n')]
+ paths = [
+ ('.github/workflows/cla.yml', 'failure', 'completed'),
+ ('.github/workflows/cla.yml@refs/pull/1/merge', '', 'in_progress'),
+ ('.github/workflows/ci-contributor-attribution.yml', 'failure', 'completed'),
+ ('.github/workflows/claude-auto-fix.yml', 'failure', 'completed'),
+ ('.github/workflows/cla.yml.bak', 'success', 'completed'),
+ ]
+ runs_json = json.dumps({'workflow_runs': [
+ {'workflow_id': i + 1, 'id': 100 + i, 'name': path.rsplit('/', 1)[1], 'path': path,
+ 'event': 'pull_request_target', 'conclusion': conclusion or None, 'status': status}
+ for i, (path, conclusion, status) in enumerate(paths)
+ ]})
+ script = ('api() { jq -r "${@: -1}" <<<"$RUNS_JSON"; }\n' + runs_src + 'runs\n')
+ out = subprocess.run(
+ ['bash', '-e', '-c', script],
+ env={**os.environ, 'RUNS_JSON': runs_json, 'IGNORE_RE': ignore_re,
+ 'GITHUB_WORKFLOW_ID': '0', 'sha': 'abc', 'GITHUB_REPOSITORY': 'test/repo'},
+ capture_output=True, text=True, timeout=10, check=True,
+ ).stdout
+ return out.strip().splitlines()
+
+
[email protected]('ignore_re', ['', 'unrelated-area[.]yml'])
+def test_gate_never_waits_on_the_cla_workflow(ignore_re):
+ rows = filtered_runs(ignore_re)
+ assert [row.split('\t')[2] for row in rows] == [
+ 'ci-contributor-attribution.yml', 'cla.yml.bak',
+ ]
+ failing = run_gate('\n'.join(rows))
+ assert failing.returncode == 1, failing.stderr
+ assert 'ci-contributor-attribution.yml: fail' in failing.stdout
+ passing = run_gate('\n'.join(
+ row.replace('\tfailure\t', '\tsuccess\t') for row in rows
+ ))
+ assert passing.returncode == 0, passing.stderr
MOCK = '''
diff --git a/.github/scripts/tests/test_pr_attribution_command.py b/.github/scripts/tests/test_pr_attribution_command.py
index 09a288ba3c..16a4f16880 100644
--- a/.github/scripts/tests/test_pr_attribution_command.py
+++ b/.github/scripts/tests/test_pr_attribution_command.py
@@ -17,13 +17,31 @@ CONFIG = ".github/release-attribution-config.json"
ANCESTOR = "a" * 40
HEAD = "b" * 40
KNOWN = {"[email protected]": "known-author"}
+SIGNED = ("landing-author", "known-author")
+MESSAGE = "docs: update guide\n\nCo-authored-by: Known <[email protected]>"
+SPACES = ("apps/cua-spaces/src/main.ts",)
+UNSET = object()
+
+
+def encoded(value):
+ data = json.dumps(value).encode()
+ return {"encoding": "base64", "content": base64.b64encode(data).decode()}
def contents(overrides):
if overrides is None:
return None
- data = json.dumps({"identityOverrides": overrides}).encode()
- return {"encoding": "base64", "content": base64.b64encode(data).decode()}
+ return encoded({"identityOverrides": overrides})
+
+
+def signatures(logins):
+ if logins is None:
+ return None
+ if isinstance(logins, dict):
+ return encoded(logins)
+ return encoded(
+ {"signedContributors": [{"name": login, "id": i} for i, login in enumerate(logins)]}
+ )
@pytest.fixture
@@ -70,10 +88,27 @@ def validate_command(tmp_path, github_api):
["git", *args], cwd=tmp_path, env=env, text=True
).strip()
- def validate(*, ancestor, head, body="", merge_base_sha=ANCESTOR, commit=None):
+ def validate(
+ *,
+ ancestor,
+ head,
+ body="",
+ merge_base_sha=ANCESTOR,
+ commit=None,
+ message=MESSAGE,
+ files=("libs/cua-driver/src/lib.rs",),
+ changed_files=UNSET,
+ signed=SIGNED,
+ allowlist="maintainer,dependabot[bot]",
+ pull_author="landing-author",
+ ):
config = tmp_path / CONFIG
config.parent.mkdir()
config.write_text(json.dumps({"identityOverrides": KNOWN}))
+ workflow = tmp_path / ".github/workflows/cla.yml"
+ workflow.parent.mkdir()
+ if allowlist is not None:
+ workflow.write_text(f' with:\n allowlist: "{allowlist}"\n')
git("init", "-q", "--template=")
git("add", CONFIG)
git(
@@ -88,8 +123,13 @@ def validate_command(tmp_path, github_api):
}))
responses.update({
"/repos/trycua/cua/pulls/50": {
+ **(
+ {}
+ if changed_files is None
+ else {"changed_files": len(files or ()) if changed_files is UNSET else changed_files}
+ ),
"number": 50,
- "user": {"login": "landing-author"},
+ "user": {"login": pull_author},
"body": body,
"commits": 1,
"base": {"sha": ANCESTOR},
@@ -103,9 +143,15 @@ def validate_command(tmp_path, github_api):
"name": "Landing Author",
"email": "[email protected]",
},
- "message": "docs: update guide\n\nCo-authored-by: Known <[email protected]>",
+ "message": message,
},
}],
+ "/repos/trycua/cua/pulls/50/files?per_page=100&page=1": (
+ None if files is None else [{"filename": path} for path in files]
+ ),
+ "/repos/trycua/cua/contents/signatures/version1/cla.json?ref=cla-signatures": (
+ signatures(signed)
+ ),
f"/repos/contributor/cua/contents/{CONFIG}?ref={HEAD}": contents(head),
f"/repos/trycua/cua/compare/{trusted_sha}...{HEAD}?per_page=1": {
"merge_base_commit": {"sha": merge_base_sha},
@@ -231,3 +277,245 @@ def test_unlinked_commit_email_passes_with_a_warning(validate_command):
assert "::warning" in result.stdout
assert "[email protected]" in result.stdout
assert "informational" in result.stdout
+
+
+def test_signed_contributors_pass_on_spaces_paths(validate_command):
+ result = validate_command(ancestor=KNOWN, head=KNOWN, files=SPACES)
+
+ assert result.returncode == 0, result.stdout + result.stderr
+ assert "::warning::" not in result.stdout
+ assert "merge-ready for pull request #50" in result.stdout
+
+
+def test_allowlisted_contributor_passes_without_signature(validate_command):
+ result = validate_command(
+ ancestor=KNOWN,
+ head=KNOWN,
+ files=SPACES,
+ signed=("known-author",),
+ allowlist="maintainer,Landing-Author",
+ )
+
+ assert result.returncode == 0, result.stdout + result.stderr
+ assert "::warning::" not in result.stdout
+
+
+ "signed,message,expected",
+ [
+ (
+ ("landing-author", "known-author"),
+ MESSAGE,
+ "@pull-author has not signed the CLA; sign it on #50",
+ ),
+ (
+ ("known-author", "pull-author"),
+ MESSAGE,
+ "@landing-author has not signed the CLA; sign it on #50",
+ ),
+ (
+ ("landing-author", "pull-author"),
+ MESSAGE,
+ "@known-author has not signed the CLA; sign it on #50",
+ ),
+ (
+ (*SIGNED, "pull-author"),
+ "fix: thing\n\nCo-authored-by: Stranger <[email protected]>",
+ "Stranger <[email protected]> (no GitHub login) has not signed the CLA; "
+ "sign it on #50",
+ ),
+ ],
+ ids=["pull-author", "commit-author", "coauthor", "unmatched-coauthor"],
+)
+def test_unsigned_contributor_fails_on_spaces_paths(validate_command, signed, message, expected):
+ result = validate_command(
+ ancestor=KNOWN,
+ head=KNOWN,
+ files=SPACES,
+ signed=signed,
+ message=message,
+ pull_author="pull-author",
+ )
+
+ assert result.returncode == 1
+ assert "CLA is not signed" in result.stderr
+ assert expected in result.stderr
+ assert "merge-ready" not in result.stdout
+
+
+def source_commit(index, login):
+ return {
+ "sha": f"{index:040x}",
+ "author": {"login": login},
+ "commit": {"author": {"name": login, "email": f"{login}@example.com"}},
+ }
+
+
+ "signed,unsigned",
+ [
+ ((*SIGNED, "source-committer"), "source-author"),
+ ((*SIGNED, "source-author"), "source-committer"),
+ ],
+)
+def test_unsigned_salvaged_pull_contributor_fails_naming_its_pull(
+ validate_command, github_api, signed, unsigned
+):
+ _, responses = github_api
+ responses["/repos/trycua/cua/pulls/12"] = {
+ "number": 12, "user": {"login": "source-author"}, "commits": 1,
+ }
+ responses["/repos/trycua/cua/pulls/12/commits?per_page=100&page=1"] = [
+ source_commit(1, "source-committer"),
+ ]
+ result = validate_command(
+ ancestor=KNOWN, head=KNOWN, files=SPACES, body="Salvaged from #12", signed=signed
+ )
+
+ assert result.returncode == 1
+ assert f"@{unsigned} has not signed the CLA; sign it on #12" in result.stderr
+
+
+def test_unsigned_salvaged_commit_author_past_250_commits_fails(validate_command, github_api):
+ _, responses = github_api
+ source_head = "c" * 40
+ responses["/repos/trycua/cua/pulls/12"] = {
+ "number": 12,
+ "user": {"login": "source-author"},
+ "commits": 260,
+ "base": {"ref": "main"},
+ "head": {"sha": source_head},
+ }
+ commits = [source_commit(i, "source-committer") for i in range(259)]
+ commits.append(source_commit(259, "late-committer"))
+ for page in range(1, 4):
+ responses[f"/repos/trycua/cua/compare/main...{source_head}?per_page=100&page={page}"] = {
+ "total_commits": 260,
+ "commits": commits[(page - 1) * 100 : page * 100],
+ }
+ result = validate_command(
+ ancestor=KNOWN,
+ head=KNOWN,
+ files=SPACES,
+ body="Salvaged from #12",
+ signed=(*SIGNED, "source-author", "source-committer"),
+ )
+
+ assert result.returncode == 1
+ assert "@late-committer has not signed the CLA; sign it on #12" in result.stderr
+ assert "source-committer" not in result.stderr
+
+
+def test_unsigned_contributor_on_other_paths_passes_with_warning(validate_command):
+ result = validate_command(ancestor=KNOWN, head=KNOWN, signed=("known-author",))
+
+ assert result.returncode == 0, result.stdout + result.stderr
+ assert "::warning::@landing-author has not signed the CLA; sign it on #50" in result.stdout
+ assert "merge-ready for pull request #50" in result.stdout
+
+
+def stranger_message():
+ return "fix: thing\n\nCo-authored-by: Stranger <[email protected]>"
+
+
+LOOKUP_PROBLEMS = {
+ "count-mismatch": ({"changed_files": 2}, "incomplete"),
+ "changed-files-missing": ({"changed_files": None}, "incomplete"),
+ "missing-filename": ({"extra_file": True}, "incomplete"),
+ "signatures-unreadable": ({"signed": None}, "cla.json"),
+ "signatures-malformed": ({"signed": {"other": []}}, "signedContributors"),
+ "allowlist-unreadable": ({"allowlist": None}, "cla.yml"),
+ "allowlist-missing-line": ({"no_allowlist_line": True}, "cla.yml"),
+ "source-pull-unreadable": ({"body": "Salvaged from #12"}, "#12"),
+ "unmatched-email": (
+ {"message": stranger_message(), "signed": (*SIGNED,)},
+ "(no GitHub login)",
+ ),
+}
+
+
+def run_lookup_problem(validate_command, github_api, case, files):
+ options, expected = LOOKUP_PROBLEMS[case]
+ options = dict(options)
+ files = tuple(files)
+ if "extra_file" in options:
+ options.pop("extra_file")
+ files += (None,)
+ if options.pop("no_allowlist_line", False):
+ options["allowlist"] = None
+ result = validate_command(
+ ancestor=KNOWN, head=KNOWN, files=files, **options
+ )
+ return result, expected
+
+
[email protected]("case", LOOKUP_PROBLEMS)
+def test_cla_lookup_problem_warns_off_spaces_paths(validate_command, github_api, case):
+ result, expected = run_lookup_problem(
+ validate_command, github_api, case, ("libs/cua-driver/src/lib.rs",)
+ )
+
+ assert result.returncode == 0, result.stdout + result.stderr
+ assert "::warning::" in result.stdout
+ assert expected in result.stdout
+ assert "CLA is not signed" not in result.stderr
+
+
[email protected]("case", LOOKUP_PROBLEMS)
+def test_cla_lookup_problem_fails_on_spaces_paths(validate_command, github_api, case):
+ result, expected = run_lookup_problem(validate_command, github_api, case, SPACES)
+
+ assert result.returncode == 1
+ assert "CLA is not signed" in result.stderr
+ assert expected in result.stderr
+
+
+def test_unreadable_file_list_fails_on_any_path(validate_command):
+ result = validate_command(ancestor=KNOWN, head=KNOWN, files=None, changed_files=1)
+
+ assert result.returncode == 1
+ assert "pulls/50/files" in result.stderr
+ assert "treating it as touching Spaces paths" in result.stderr
+
+
+def test_unreadable_later_file_page_fails(validate_command, github_api):
+ _, responses = github_api
+ responses["/repos/trycua/cua/pulls/50/files?per_page=100&page=2"] = None
+ files = tuple(f"libs/cua-driver/f{i}.rs" for i in range(100))
+ result = validate_command(ancestor=KNOWN, head=KNOWN, files=files)
+
+ assert result.returncode == 1
+ assert "treating it as touching Spaces paths" in result.stderr
+
+
+def test_strict_cla_failure_survives_unreadable_attribution_config(validate_command):
+ result = validate_command(
+ ancestor=KNOWN, head=None, files=SPACES, signed=("known-author",)
+ )
+
+ assert result.returncode == 1
+ assert "CLA is not signed" in result.stderr
+
+
+def test_mixed_paths_are_strict(validate_command):
+ result = validate_command(
+ ancestor=KNOWN,
+ head=KNOWN,
+ files=("libs/cua-driver/src/lib.rs", *SPACES),
+ signed=("known-author",),
+ )
+
+ assert result.returncode == 1
+ assert "CLA is not signed" in result.stderr
+
+
+def test_similar_prefix_is_not_strict(validate_command):
+ result = validate_command(
+ ancestor=KNOWN,
+ head=KNOWN,
+ files=("apps/cua-spaces-extra/x",),
+ signed=("known-author",),
+ )
+
+ assert result.returncode == 0, result.stdout + result.stderr
+ assert "::warning::@landing-author has not signed the CLA" in result.stdout
diff --git a/.github/workflows/ci-gate.yml b/.github/workflows/ci-gate.yml
index 10bce4aa13..9d43f6df5e 100644
--- a/.github/workflows/ci-gate.yml
+++ b/.github/workflows/ci-gate.yml
@@ -65,10 +65,11 @@ jobs:
fi
# IGNORE_RE (from the scope step) names workflow files that belong only to areas this PR
# did not touch. Empty means wait for every run.
+ # contributor-attribution enforces the CLA, so the gate never waits on cla.yml.
scope_jq='(env.IGNORE_RE // "") == "" or ((.path | sub("@.*"; "") | split("/") | last) | test(env.IGNORE_RE) | not)'
runs() {
api --paginate "repos/$GITHUB_REPOSITORY/actions/runs?head_sha=$sha&per_page=100" \
- --jq ".workflow_runs[] | select(.workflow_id != $GITHUB_WORKFLOW_ID and (.event == \"pull_request\" or .event == \"pull_request_target\") and (.path | test(\"claude-auto-fix|ci-release-reminder|review-cua-perception-candidates\") | not) and ($scope_jq)) | [.workflow_id, .id, .name, .conclusion // \"\", .status] | @tsv"
+ --jq ".workflow_runs[] | select(.workflow_id != $GITHUB_WORKFLOW_ID and (.event == \"pull_request\" or .event == \"pull_request_target\") and (.path | test(\"claude-auto-fix|ci-release-reminder|review-cua-perception-candidates|/cla[.]yml($|@)\") | not) and ($scope_jq)) | [.workflow_id, .id, .name, .conclusion // \"\", .status] | @tsv"
}
GITHUB_WORKFLOW_ID=$(api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" --jq .workflow_id) || exit 1
# Two identical listings cannot prove every run has appeared, so no verdict is allowed
diff --git a/docs/contributing/CI.md b/docs/contributing/CI.md
index 1e37c4a340..c9522ab297 100644
--- a/docs/contributing/CI.md
+++ b/docs/contributing/CI.md
@@ -18,7 +18,7 @@ Rules, in order:
1. A changed file that matches a **shared** glob, or matches no area at all, makes the gate wait for every run, as it did before scoping.
2. Any other changed file belongs to the first area (top to bottom in the table) whose globs match it.
3. A workflow listed under an area is required only when one of its areas changed.
-4. A workflow listed under no area (for example the CLA, eMudhra and release-metadata checks) is always required. A new workflow is therefore required until someone maps it.
+4. A workflow listed under no area (for example the eMudhra and release-metadata checks) is always required. A new workflow is therefore required until someone maps it. The gate never waits for **CI: CLA**, because the required `contributor-attribution` check enforces the CLA.
Merge-queue runs (`merge_group`) read the file list of the same pull request through the same API call, so
the queue and the pull request wait on the same set. If the scope step fails for any reason, the gate fails.