Skip to content

feat: add /check-golf bot verifying statements are unchanged#1355

Open
Vilin97 wants to merge 1 commit into
leanprover-community:masterfrom
Vilin97:check-golf-bot
Open

feat: add /check-golf bot verifying statements are unchanged#1355
Vilin97 wants to merge 1 commit into
leanprover-community:masterfrom
Vilin97:check-golf-bot

Conversation

@Vilin97

@Vilin97 Vilin97 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

What

Adds a /check-golf bot that verifies a PR only golfs proofs: that no declaration statement (its signature/type) changed and only proofs and definition bodies changed. Comment /check-golf on any PR and the bot posts its findings as a single comment, editing that same comment on subsequent runs.

Files

  • scripts/check_golf.py — compares two revisions of the repo. For every named declaration in the changed .lean files it decides whether the statement was preserved and only the proof/body changed. It also renders the Markdown report and upserts it as a PR comment (POST first, PATCH the marked comment afterwards).
  • .github/workflows/check-golf.yml — triggers on an issue_comment containing /check-golf on a PR, resolves the merge-base and head, runs the script, and comments.
  • scripts/README.md — documents the tool and how to run it locally.

How it works

The Lean sources are parsed textually (no build required, so the check is fast):

  • comments and string literals are blanked, whitespace is ignored;
  • top-level declarations are segmented on column-0 command starts (robust even when a proof body contains brackets that cannot be balanced textually, e.g. a by block closed by indentation);
  • each statement is split from its body at the top-level := / where / equation | arm, so := in default binders and by blocks inside a type (⟨x, by omega⟩) do not confuse the split;
  • by proof terms embedded inside a type are treated as proof-irrelevant, so golfing them counts as a proof change, not a statement change.

Anonymous instances and examples are not tracked (they have no stable name).

Testing

Run locally against two revisions:

scripts/check_golf.py --base <merge-base> --head <head-sha>

Validated against a large real golf PR: the checker reports 0 statement changes across 312 changed files, and a name-level cross-check confirms no named declaration is dropped by the parser. The post→edit comment logic is covered by a mocked-API test.

Add scripts/check_golf.py and a check-golf GitHub workflow. When a
`/check-golf` comment is posted on a PR, the bot compares the PR's base
and head, checks that no declaration statement (signature/type) changed
and only proofs/bodies changed, and upserts a single findings comment
(posting it once, editing it on later runs).

The Lean sources are parsed textually (no build): comments and
whitespace are ignored, declarations are segmented on column-0 command
starts, each statement is split from its body at the top-level `:=`,
`where`, or equation `|` arm, and `by` proof terms embedded inside a
type are treated as proof-irrelevant.

Co-authored-by: Claude Opus 4.8 <no-reply+claude-opus-4-8@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vjiv6nckrp5cJT9rpgZaKT
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Thank you for this PR, which will now be reviewed. If submitting to ./Physlib or ./QuantumInfo, please see our review guidelines if you are not familiar with the process. You should expect a back and forth with a reviewer before your PR is merged. See also that link for how to add appropriate labels to your PR. The PR will also go through a number of automated checks. You can learn more about these here, including how to run them locally.

If you are submitting to ./PhyslibAlpha there will be a lighter review process, though your PR must still pass the automated checks.

If you want to bring attention to this PR, please write a message on this thread of the Lean Zulip.

Important: If a reviewer adds an awaiting-author label to your PR, once you have addressed the review comments, please remove that label by adding a comment with -awaiting-author. This helps us keep track of reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant