Repository navigation
ci: fail comment blocks over two lines that a PR adds or edits - #298
Conversation
A comment says the constraint or the reason in at most two lines and links an issue or PR for the backstory. scripts/check_comment_blocks.py enforces the length on the lines a PR adds or changes, as a step of the static job, so existing long blocks pass until a PR edits them. AGENTS.md, REVIEW.md, the Copilot instructions and CONTRIBUTING.md carry the rule. Signed-off-by: Harlow, Jordan <jordan.harlow@intel.com>
There was a problem hiding this comment.
🟢 Approval recommended
The comment-block CI gate changes have no active review issues requiring resolution.
No open issues 🎉
What changed in this PR
0 new findings; nothing to fix.
This PR adds a CI gate enforcing dokimi’s two-line comment-block rule on comments a PR adds or edits, while leaving untouched existing blocks alone.
Changes:
- Adds a diff-aware checker with Python tokenization, rename handling, and exemptions for headers, pragmas, and rulers.
- Integrates the check into the PR-only static CI job and documents the rule and local command.
- Adds tests covering comment detection, changed-line filtering, renames, and invalid refs.
| File | Description |
|---|---|
REVIEW.md |
Adds comment accuracy and concise-comment review guidance. |
dokimi/tests/test_check_comment_blocks.py |
Tests detection rules and Git-diff behavior. |
dokimi/scripts/check_comment_blocks.py |
Implements the changed-comment length gate. |
dokimi/CONTRIBUTING.md |
Documents enforcement and the local command. |
AGENTS.md |
Adds the comment rule to contributor guidance. |
.github/workflows/ci.yml |
Runs the checker in the static job for PRs. |
.github/copilot-instructions.md |
Adds concise-comment guidance for Copilot. |
Review effort: Balanced
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #298 +/- ##
==========================================
- Coverage 93.28% 93.27% -0.01%
==========================================
Files 272 272
Lines 35119 35119
Branches 5964 5964
==========================================
- Hits 32761 32759 -2
- Misses 1544 1546 +2
Partials 814 814 🚀 New features to boost your workflow:
|
|
🔍 OpenCodeReview found 1 issue(s) in this PR. By severity: 1 low
Review details
|
| assert "::error file=a.py,line=2,endLine=4," in capsys.readouterr().out | ||
|
|
||
|
|
||
| def test_main_passes_an_untouched_long_block_and_a_renamed_file(tmp_path, monkeypatch): |
There was a problem hiding this comment.
Nit: the name says main, but the body calls ccb.findings. No test runs main on a passing PR, so a regression in the exit-0 path would go unnoticed. That includes returning 1 or 2 when found is empty, and dropping the success message. Assert ccb.main(["--base", "base", "--head", "HEAD"]) == 0 here as well.
Suggestion:
| def test_main_passes_an_untouched_long_block_and_a_renamed_file(tmp_path, monkeypatch): | |
| assert ccb.findings("base", "HEAD") == [] | |
| assert ccb.main(["--base", "base", "--head", "HEAD"]) == 0 |
Summary
Adds a CI check for a comment rule: a comment states the constraint or the reason in at most two lines, and links an issue or PR when a reader needs the backstory. It is a new
Comment blocksstep inci.yml'sstaticjob, beside the changelog-fragment step, so it needs no runner of its own andmake ci-localruns it too. It reads only the lines a PR adds or changes: the 493 existing blocks over two lines pass until a PR edits one of them.AGENTS.md,REVIEW.md, the Copilot instructions andCONTRIBUTING.mdstate the rule.Changes
scripts/check_comment_blocks.py: for each Python, shell, YAML or TOML file, Makefile or Dockerfile thatorigin/<base>...HEADadds, changes or renames, finds the runs of full-line#comments and fails a run of three or more lines that holds an added or changed line. One::error file=...,line=...,endLine=...per block, exit 1; exit 2 when git cannot diff the refs.tokenize, so a#line inside a string or docstring is not one, and a trailing comment does not join a block.# noqa,# type:,# fmt:and the like). A ruler line (# -----) stays in its block but does not count, so a section banner is one line.tests/fixtures/task_formats/is skipped, as ruff skips it (third-party copies).ci.yml: theComment blocksstep, PR-only and!cancelled()like its neighbours.AGENTS.md: the rule, in the list of what CI holds a PR to.REVIEW.md: a comment that says something the code does not do is a defect; a short comment that tells the backstory instead of the reason is a nit..github/copilot-instructions.md: the rule inline.CONTRIBUTING.md: the local command.Risk
main(each squash commit against its parent), 13 would have failed, on 17 blocks of 3 to 9 lines. All 17 are prose comments, for example the Python 3.13 note atci.yml:45-50and the document-count note atbenchmarks/spec.v1.yaml:75-80. Two-line comments, 726 of them in the tree, pass.scripts/ci_local.py's expression table, asskip-changeloghas; it can follow if a real exception turns up.#line inside a YAML block scalar counts. In workflows that is correct (shell comments inrun:); elsewhere it could count text that is not a comment.Testing
tests/test_check_comment_blocks.py, 23 tests, including temp git repos for a new long block, an untouched one, a rename and an undiffable base. Each rule was mutation-checked: allowing two lines, dropping rename detection, the tokenizer, the line split, the exemptions, the ruler rule or the changed-lines filter each fails a test.ruff check .andzizmor --offline --min-severity medium .github/workflows: clean. The check passes on this PR.test_audit_test_quality.py,test_docs_code_refs.py,test_ci_local.py,test_ci_label_triggers.py,test_text_io_encoding.py,test_docs_links.pyandtest_growth_ratchet.pypass, bar five growth-ratchet tests that callgit init -b, which my git 2.25 does not have. The guidance self-scan reports 0 failures, andpre-commit run --all-filespasses.pytestsuite and the license header check (Docker). mypy does not coverscripts/. CI runs the rest.No changelog fragment: nothing under
dokimi/dokimi/,dokimi/data/or the install tables changes.Revert
Revert the commit. It writes no records and changes no schema.
Checklist
pytestsuite is left to CI (see Testing)ruffpasses; mypy and the schema checks are unaffected (no change underdokimi/dokimi/)AGENTS.md.github/.licenserc.yaml)