Skip to content

Commit 901b997

Browse files
committed
fix: show an AI-only check that ran no rule as skipped, and group the PR title with the description
Under the default ai_attribution = "ignore" the PR description check ran no rule but showed a pass. The title and description now share a Pull request group, so the commit group is no longer split in two.
1 parent 0264f70 commit 901b997

3 files changed

Lines changed: 73 additions & 11 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ click away:
129129
> <summary>Show all 4 checks</summary>
130130
>
131131
> ```text
132-
> Commit message
132+
> Pull request
133133
> ✔ PR title (feat: add login page)
134+
> Commit message
134135
> ✔ Commit 1/2 (d87faca) (feat: add login page)
135136
> ✖ Commit 2/2 (5584f46) (1 failure)
136137
> CC001 message
@@ -172,7 +173,7 @@ names the line to remove:
172173
> | PR description | `Claude Code` | [CC013 ai-attribution](https://commit-check.com/rules/#cc013) |
173174
>
174175
> ```text
175-
> PR description
176+
> Pull request
176177
> ✖ PR description (1 failure)
177178
> CC013 ai-attribution
178179
> value: Claude Code

‎main.py‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,35 @@ def skipped_author_scope(flag: str) -> ScopeResult:
432432
)
433433

434434

435+
#: Why an AI-only scope ran no rule: under the default policy there is none to run.
436+
AI_POLICY_IGNORED = 'ai_attribution is "ignore": set it to "forbid" or "disclose"'
437+
438+
439+
def skip_when_no_ai_rule_ran(scope: ScopeResult) -> ScopeResult:
440+
"""Report an AI-only scope that ran no rule as skipped, not passed.
441+
442+
Under the default ``ai_attribution = "ignore"`` the CLI builds none of
443+
the AI rules, so it returns an empty list of checks. Shown as a pass, that
444+
read as "checked, nothing found" to someone who turned the input on and
445+
forgot the policy.
446+
"""
447+
if scope.checks or scope.raw_text:
448+
return scope
449+
scope.checks = [
450+
{
451+
"rule_id": "CC013",
452+
"check": "ai_attribution",
453+
"status": "skip",
454+
"value": "",
455+
"error": "",
456+
"suggest": "",
457+
"docs_url": "",
458+
"reason": AI_POLICY_IGNORED,
459+
}
460+
]
461+
return scope
462+
463+
435464
def get_pr_title() -> str | None:
436465
"""Read PR title from GitHub event payload."""
437466
if not is_pr_event():
@@ -856,7 +885,7 @@ def run_commit_check() -> tuple[int, list[ScopeResult]]:
856885
)
857886
if PR_BODY_AI_ATTRIBUTION_ENABLED:
858887
name_the_line_changes(scope, pr_body)
859-
results.append(scope)
888+
results.append(skip_when_no_ai_rule_ran(scope))
860889
else:
861890
PR_BODY_AI_TOOLS[:] = scope.ai_tools
862891

@@ -924,7 +953,9 @@ def _rule_markdown_link(check: dict[str, str]) -> str:
924953

925954
def _scope_group(label: str) -> str:
926955
"""Group name for a scope label, used to fold the step log output."""
927-
if label == "PR title" or label.startswith("Commit"):
956+
if label in ("PR title", "PR description"):
957+
return "Pull request"
958+
if label.startswith("Commit"):
928959
return "Commit message"
929960
if label.startswith("Author"):
930961
return "Author"

‎main_test.py‎

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,11 +1735,22 @@ def test_groups_scopes_by_category(self):
17351735
fail_scope("Branch"),
17361736
]
17371737
output = self._run(results)
1738-
# One group for commit-message scopes, one for the branch scope.
1739-
self.assertEqual(output.count("::group::"), 2)
1738+
# One group each for the pull request, the commits and the branch.
1739+
self.assertEqual(output.count("::group::"), 3)
1740+
self.assertIn("::group::Pull request", output)
17401741
self.assertIn("::group::Commit message", output)
17411742
self.assertIn("::group::Branch", output)
17421743

1744+
def test_title_and_description_share_one_group(self):
1745+
"""The commits come after both, so the commit group is not split."""
1746+
results = [
1747+
pass_scope("PR title"),
1748+
pass_scope("PR description"),
1749+
pass_scope("Commit 1/1"),
1750+
]
1751+
groups = [name for name, _ in main._grouped(results)]
1752+
self.assertEqual(groups, ["Pull request", "Commit message"])
1753+
17431754
def test_raw_text_fallback_is_printed(self):
17441755
scope = main.ScopeResult(label="Branch", raw_text="unexpected output")
17451756
output = self._run([scope])
@@ -1801,8 +1812,9 @@ def test_success_golden_output(self):
18011812
"<summary>Show all 4 checks</summary>\n"
18021813
"\n"
18031814
"```text\n"
1804-
"Commit message\n"
1815+
"Pull request\n"
18051816
" ✔ PR title (feat: add login page)\n"
1817+
"Commit message\n"
18061818
" ✔ Commit 1/2 (feat: add user auth)\n"
18071819
" ✔ Commit 2/2 (fix: resolve timeout)\n"
18081820
"Branch\n"
@@ -1839,8 +1851,9 @@ def test_failure_golden_output(self):
18391851
"<summary>Show all 3 checks</summary>\n"
18401852
"\n"
18411853
"```text\n"
1842-
"Commit message\n"
1854+
"Pull request\n"
18431855
" ✔ PR title (feat: add login page)\n"
1856+
"Commit message\n"
18441857
" ✖ Commit 2/2 (1 failure)\n"
18451858
" CC001 message\n"
18461859
" value: bad message\n"
@@ -1890,8 +1903,9 @@ def test_failure_golden_output_with_commits(self):
18901903
"<summary>Show all 5 checks</summary>\n"
18911904
"\n"
18921905
"```text\n"
1893-
"Commit message\n"
1906+
"Pull request\n"
18941907
" ✔ PR title (feat: Add login page)\n"
1908+
"Commit message\n"
18951909
" ✖ Commit 1/3 (d87faca) (1 failure)\n"
18961910
" CC001 message\n"
18971911
" value: bad message\n"
@@ -2950,8 +2964,9 @@ def test_all_skipped_golden_output(self):
29502964
"<summary>Show all 2 checks</summary>\n"
29512965
"\n"
29522966
"```text\n"
2953-
"Commit message\n"
2967+
"Pull request\n"
29542968
" ⊘ PR title (skipped)\n"
2969+
"Commit message\n"
29552970
" ⊘ Commit 1/1 (skipped)\n"
29562971
"```\n"
29572972
"\n"
@@ -3198,7 +3213,7 @@ def test_warning_only_golden_output(self):
31983213
"<summary>Show all 2 checks</summary>\n"
31993214
"\n"
32003215
"```text\n"
3201-
"Commit message\n"
3216+
"Pull request\n"
32023217
" ✔ PR title (feat: add login page)\n"
32033218
"Branch\n"
32043219
" ⚠ Branch (1 warning)\n"
@@ -3720,6 +3735,21 @@ def test_pr_body_is_a_scope_checked_with_the_ai_rules_only(self):
37203735
)
37213736
self.assertEqual([r.label for r in results], ["PR description"])
37223737

3738+
def test_no_ai_rule_ran_reads_as_skipped_not_passed(self):
3739+
"""Under ai_attribution = "ignore" the CLI runs no rule on the description."""
3740+
results, _ = self._run(True, "false")
3741+
self.assertEqual(results[0].status, "skip")
3742+
self.assertEqual(results[0].skip_reason, main.AI_POLICY_IGNORED)
3743+
3744+
def test_a_rule_that_ran_keeps_its_verdict(self):
3745+
checks = [{"rule_id": "CC013", "check": "ai_attribution", "status": "pass"}]
3746+
scope = main.ScopeResult(label="PR description", checks=list(checks))
3747+
self.assertEqual(main.skip_when_no_ai_rule_ran(scope).checks, checks)
3748+
3749+
def test_unparsable_output_still_fails(self):
3750+
scope = main.ScopeResult(label="PR description", raw_text="Error: bad config")
3751+
self.assertEqual(main.skip_when_no_ai_rule_ran(scope).status, "fail")
3752+
37233753
def test_ai_label_alone_reads_it_but_reports_no_scope(self):
37243754
results, mock_scope = self._run(False, "true")
37253755
mock_scope.assert_called_once()

0 commit comments

Comments
 (0)