Repository navigation
Expand file tree
/
Copy pathtest_cla_coauthors.py
More file actions
executable file
·690 lines (578 loc) · 26.7 KB
/
Copy pathtest_cla_coauthors.py
File metadata and controls
executable file
·690 lines (578 loc) · 26.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
#!/usr/bin/env python3
"""Regression tests for the Co-authored-by CLA check (issue #269).
Before this check existed, cla-bot matched only commit *authors* against
.contributors, so a maintainer re-land of a fork PR — commits authored
xerj-org, contributor credited via a Co-authored-by trailer — went green
without the contributor ever signing (live instance: PR #248 re-landing
buger's #166). These tests pin the trailer-aware behaviour.
Run: python3 scripts/test_cla_coauthors.py
"""
import argparse
import base64
import contextlib
import io
import pathlib
import re
import subprocess
import sys
import unittest
from
6870
unittest import mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
import check_cla_coauthors
from check_cla_coauthors import (
FIELD_REPORT_DIR,
check_commits,
is_contributors_only_change,
is_field_report_only,
is_self_cla_signature,
noreply_login,
parse_coauthors,
)
REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent
# The shape of PR #248: maintainer-authored re-land, real attribution
# carried only by the trailer.
RELAND_COMMITS = [
{
"sha": "c337eb8f",
"message": "perf(autoindex): reuse the phase-A PDF extraction\n\n"
"Body text.\n\nCo-authored-by: Leonid Bugaev <leonsbox@gmail.com>",
},
{
"sha": "81c64883",
"message": "docs(changelog): record the change\n\n"
"Co-authored-by: Leonid Bugaev <leonsbox@gmail.com>",
},
]
def no_network(email):
raise AssertionError(f"unexpected network resolution for {email!r}")
class ParseTests(unittest.TestCase):
def test_extracts_name_and_email(self):
got = parse_coauthors(RELAND_COMMITS[0]["message"])
self.assertEqual(got, [("Leonid Bugaev", "leonsbox@gmail.com")])
def test_trailer_key_is_case_insensitive(self):
# git trailers are case-insensitive; GitHub emits "Co-authored-by".
msg = "subject\n\nCO-AUTHORED-BY: A B <a@b.c>\nco-authored-by: C D <c@d.e>"
self.assertEqual(
parse_coauthors(msg), [("A B", "a@b.c"), ("C D", "c@d.e")]
)
def test_no_trailers(self):
self.assertEqual(parse_coauthors("fix: something\n\nplain body"), [])
class NoreplyTests(unittest.TestCase):
def test_modern_noreply(self):
self.assertEqual(
noreply_login("1234567+buger@users.noreply.github.com"), "buger"
)
def test_legacy_noreply(self):
self.assertEqual(noreply_login("buger@users.noreply.github.com"), "buger")
def test_bot_noreply(self):
self.assertEqual(
noreply_login("49699333+dependabot[bot]@users.noreply.github.com"),
"dependabot[bot]",
)
def test_ordinary_email_is_not_a_login(self):
self.assertIsNone(noreply_login("leonsbox@gmail.com"))
class GateTests(unittest.TestCase):
def test_unsigned_coauthor_fails_the_gate(self):
# THE regression for issue #269: every commit author is signed, the
# co-author is not — the old gate said green here.
problems = check_commits(
RELAND_COMMITS,
contributors=["xerj-org", "dependabot[bot]"],
resolve=lambda email: "buger",
)
self.assertTrue(problems, "gate passed a re-land with an unsigned co-author")
self.assertTrue(any("buger" in p for p in problems), problems)
def test_unresolvable_coauthor_fails_the_gate(self):
# An identity the gate cannot attribute is exactly what it exists to
# flag — unresolvable must fail, not silently pass.
problems = check_commits(
RELAND_COMMITS,
contributors=["xerj-org", "dependabot[bot]"],
resolve=lambda email: None,
)
self.assertTrue(problems, "gate passed an unresolvable co-author")
def test_signed_coauthor_passes(self):
problems = check_commits(
RELAND_COMMITS,
contributors=["xerj-org", "dependabot[bot]", "buger"],
resolve=lambda email: "buger",
)
self.assertEqual(problems, [])
def test_login_match_is_case_insensitive(self):
# GitHub logins are case-insensitive; a case mismatc
8000
h between the
# resolved login and the .contributors entry must not flag a signer.
problems = check_commits(
RELAND_COMMITS,
contributors=["xerj-org", "Buger"],
resolve=lambda email: "buger",
)
self.assertEqual(problems, [])
def test_noreply_coauthor_needs_no_network(self):
commits = [
{
"sha": "abc12345",
"message": "subject\n\n"
"Co-authored-by: B <99+buger@users.noreply.github.com>",
}
]
problems = check_commits(
commits, contributors=["buger"], resolve=no_network
)
self.assertEqual(problems, [])
def test_no_trailers_needs_no_network(self):
commits = [{"sha": "abc12345", "message": "fix: plain commit"}]
self.assertEqual(
check_commits(commits, contributors=["xerj-org"], resolve=no_network), []
)
def test_duplicate_emails_resolved_once(self):
calls = []
def counting(email):
calls.append(email)
return "buger"
check_commits(RELAND_COMMITS, contributors=["buger"], resolve=counting)
self.assertEqual(calls, ["leonsbox@gmail.com"])
class FieldReportExemptionTests(unittest.TestCase):
"""The narrow carve-out: a field-report-only diff is exempt; anything else
is not. Bundling a code change with a field report must NOT bypass the gate
— that would be a security hole, so the mixed case is asserted explicitly."""
def _report(self, name):
return f"{FIELD_REPORT_DIR}{name}"
def test_single_field_report_is_exempt(self):
self.assertTrue(
is_field_report_only([self._report("2026-08-18-reference-coding.md")])
)
def test_several_field_reports_are_exempt(self):
self.assertTrue(
is_field_report_only(
[
self._report("2026-08-18-a.md"),
self._report("2026-08-18-b.md"),
]
)
)
def test_field_report_plus_code_is_NOT_exempt(self):
# THE security case: a code change riding along with a field report must
# get the full gate, never the exemption.
self.assertFalse(
is_field_report_only(
[
self._report("2026-08-18-a.md"),
"engine/crates/xerj-server/src/main.rs",
]
)
)
def test_field_report_plus_other_docs_is_NOT_exempt(self):
self.assertFalse(
is_field_report_only([self._report("2026-08-18-a.md"), "README.md"])
)
def test_the_folder_readme_is_NOT_a_field_report(self):
self.assertFalse(is_field_report_only([self._report("README.md")]))
def test_a_nested_path_is_NOT_a_field_report(self):
self.assertFalse(is_field_report_only([self._report("sub/2026-08-18-a.md")]))
def test_a_non_markdown_file_in_the_folder_is_NOT_exempt(self):
self.assertFalse(is_field_report_only([self._report("2026-08-18-a.txt")]))
def test_an_empty_diff_is_NOT_exempt(self):
# "nothing changed" must never read as "exempt".
self.assertFalse(is_field_report_only([]))
self.assertFalse(is_field_report_only([""]))
def test_a_lookalike_prefix_outside_the_folder_is_NOT_exempt(self):
# A path that merely starts with the folder name but is not inside it.
self.assertFalse(
is_field_report_only(["user-feedback/16-agent-field-reports-notes.md"])
)
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, merge_parent=None,
ancestry=None):
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,
}
if merge_parent is not None:
cmp["commits"].append({
"sha": self.HEAD_SHA,
"commit": {"message": "Merge main"},
"author": {"login": "xerj-org"},
"parents": [{"sha": "c" * 40}, {"sha": merge_parent}],
})
cmp["total_commits"] += 1
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, ancestry]
), 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_signature_with_maintainer_base_merge_exits_0(self):
rc, _ = self._run([CONTRIB], ["xerj-org", "dependabot[bot]", "todie"],
merge_parent=self.BASE_SHA)
self.assertEqual(rc, 0)
def test_foreign_branch_merge_does_not_get_a_success_status(self):
rc, _ = self._run([CONTRIB], ["xerj-org", "dependabot[bot]", "todie"],
merge_parent="d" * 40,
ancestry={"status": "diverged"})
self.assertEqual(rc, 1)
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 BaseMergeProofTests(unittest.TestCase):
BASE = "a" * 40
PARENT = "b" * 40
COMMIT = {"parents": [{"sha": "c" * 40}, {"sha": PARENT}]}
def test_exact_pinned_base_needs_no_lookup(self):
with mock.patch.object(check_cla_coauthors, "_gh_api_one") as api:
self.assertTrue(check_cla_coauthors._merges_pinned_base(
"o/r", self.COMMIT, self.PARENT))
api.assert_not_called()
def test_ancestor_is_proven_with_pinned_comparison(self):
result = {"status": "ahead", "merge_base_commit": {"sha": self.PARENT}}
with mock.patch.object(check_cla_coauthors, "_gh_api_one", return_value=result) as api:
self.assertTrue(check_cla_coauthors._merges_pinned_base(
"o/r", self.COMMIT, self.BASE))
api.assert_called_once_with(f"repos/o/r/compare/{self.PARENT}...{self.BASE}")
def test_non_ancestor_and_missing_proof_refuse(self):
for result in (None, {}, {"status": "ahead"},
{"status": "ahead", "merge_base_commit": {"sha": self.BASE}},
{"status": "diverged", "merge_base_commit": {"sha": self.PARENT}},
{"status": "behind", "merge_base_commit": {"sha": self.PARENT}}):
with self.subTest(result=result), mock.patch.object(
check_cla_coauthors, "_gh_api_one", return_value=result):
self.assertFalse(check_cla_coauthors._merges_pinned_base(
"o/r", self.COMMIT, self.BASE))
def test_bad_parent_metadata_never_gets_an_exception(self):
for parents in (None, [], [{"sha": self.PARENT}], self.COMMIT["parents"] * 2,
[None, {"sha": self.BASE}], [{"sha": self.BASE}, {"sha": "main"}]):
with self.subTest(parents=parents), mock.patch.object(
check_cla_coauthors, "_gh_api_one") as api:
self.assertFalse(check_cla_coauthors._merges_pinned_base(
"o/r", {"parents": parents}, self.BASE))
api.assert_not_called()
def test_lookup_error_refuses(self):
with mock.patch.object(check_cla_coauthors, "_gh_api_one",
side_effect=subprocess.CalledProcessError(1, "gh")):
self.assertFalse(check_cla_coauthors._merges_pinned_base(
"o/r", self.COMMIT, self.BASE))
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) 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(
files=[CONTRIB],
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(
files=[CONTRIB],
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(
files=[CONTRIB, {"filename": "engine/src/lib.rs", "status": "modified"}],
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(
files=[CONTRIB],
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(
files=[CONTRIB],
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(
files=[CONTRIB],
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(
files=[CONTRIB],
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 <99+unsigned@users.noreply.github.com>",
"author_login": "todie",
}
]
self.assertFalse(
is_self_cla_signature(
files=[CONTRIB],
base_contributors=self.BASE,
head_contributors=self.BASE + ["todie"],
pr_author="todie",
commits=commits,
resolve=no_network,
)
)
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_signed_base_merge_preserves_the_contributors_signature(self):
merge = dict(sha="deadbeef", message="Merge main to resolve signature conflict",
author_login="xerj-org", merges_base=True)
self.assertTrue(self._ok(commits=self.COMMITS + [merge]))
def test_base_merge_cannot_replace_the_contributors_own_commit(self):
merge = dict(sha="deadbeef", message="Merge main",
author_login="xerj-org", merges_base=True)
self.assertFalse(self._ok(commits=[merge]))
def test_base_merge_exception_still_requires_a_signed_author(self):
merge = dict(sha="deadbeef", message="Merge main",
author_login="unsigned", merges_base=True)
self.assertFalse(self._ok(commits=self.COMMITS + [merge]))
def test_signed_author_without_proven_base_merge_is_rejected(self):
merge = dict(sha="deadbeef", message="Merge main",
author_login="xerj-org")
for proof in (None, False, "true", 1):
self.assertFalse(self._ok(commits=self.COMMITS + [dict(merge, merges_base=proof)]))
def test_base_merge_does_not_exempt_mixed_diff_or_unsigned_trailers(self):
merge = dict(sha="deadbeef", message="Merge main",
author_login="xerj-org", merges_base=True)
self.assertFalse(self._ok(
commits=self.COMMITS + [merge],
files=[CONTRIB, {"filename": "x.rs", "status": "modified"}]))
merge["message"] += "\n\nCo-authored-by: Unsigned <unsigned@users.noreply.github.com>"
self.assertFalse(self._ok(commits=self.COMMITS + [merge]))
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)."""
def _ci(self):
return (REPO_ROOT / ".github" / "workflows" / "ci.yml").read_text()
def _cla_job(self):
ci = self._ci()
m = re.search(r"\n cla-config:\n(.*?)(?=\n \S)", ci, re.S)
self.assertIsNotNone(m, "cla-config job missing from ci.yml")
return m.group(1)
def test_ci_runs_the_coauthor_check(self):
self.assertIn("check_cla_coauthors.py", self._cla_job())
def test_ci_runs_these_tests(self):
self.assertIn("test_cla_coauthors.py", self._cla_job())
def test_cla_config_computes_changed_files_for_the_carveout(self):
# The carve-out only works if the job actually passes the PR's changed
# files to the checker — otherwise every PR runs the full gate.
self.assertIn("--changed-files", self._cla_job())
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 (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)
# 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)
if __name__ == "__main__":
unittest.main()