chore: enforce Rust production file size limits - #319
Merged
franciscojavierarceo merged 3 commits intoSep 16, 2026
Merged
franciscojavierarceo merged 3 commits into
franciscojavierarceo merged 3 commits into
Conversation
Signed-off-by: Chuyue Wang <stevenwang0805@outlook.com>
StevenWang-CY
requested review from
bbrowning,
franciscojavierarceo,
haoshan98,
jiahuei,
leseb,
maralbahari,
noobHappylife,
qandrew and
tjtanaa
as code owners
September 15, 2026 22:39
Signed-off-by: Chuyue Wang <stevenwang0805@outlook.com>
There was a problem hiding this comment.
🟡 Changes recommended
Baseline additions or increases can currently bypass the new-file limit and ratchet policy.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds pre-commit enforcement for Rust production file-size limits and the existing oversized-file backlog.
Changes:
- Adds a Tree-sitter-based Rust line counter and policy validator.
- Adds 35 regression tests and pre-commit hooks.
- Documents limits, exclusions, baselines, and exceptions.
File summaries
| File | Description |
|---|---|
.pre-commit-config.yaml |
Registers checker and test hooks. |
.rust-file-sizes.json |
Defines existing oversized-file baselines. |
CONTRIBUTING.md |
Documents the file-size policy. |
scripts/check_rust_file_sizes.py |
Implements counting and enforcement. |
scripts/tests/test_rust_file_sizes.py |
Tests counting and policy behavior. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: Chuyue Wang <stevenwang0805@outlook.com>
franciscojavierarceo
approved these changes
Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #318.
Add a pre-commit guard for the Rust file-size policy in #312. New production files are limited to 500 physical lines, and 18 existing oversized files have explicit caps that must decrease as those files shrink. Every invocation scans all tracked Rust files, including policy-only changes, deletions, and renames.
Validate baseline caps against the prior committed policy so adding a new cap or increasing one alongside file growth cannot bypass the guard. Local hooks compare with
HEAD; CI fetches full history and compares with the PR base, merge-queue base, or previous main revision. Initial caps derive only from existing regular Rust production source at the base. Git-detected renames may retain or lower a cap; copies cannot inherit it. Growth requires an explicit bounded exception with a reason, and unavailable history fails with a diagnostic.Use a pinned Rust syntax parser to count inline test-only code separately, including production after test modules, nested items, inner attributes, conditional match arms/initializers/tuple fields, and mixed physical lines. Document dedicated test/benchmark/example exclusions, exact generated-file exclusions, and exception policy. Reject stale/conflicting entries and report counts and corrective steps. The checker never rewrites its policy, fetches history, or compiles the workspace; pre-commit installs and reuses its parser environment.
Macro expansion and whole-program test reachability remain outside this source-counting policy. Policy changes and exceptions require code review; the checker validates contents and baseline history, not GitHub approval state.
Test Plan
--all-files.790db2f. Six real-hook variants (new/increased baseline × staged/policy-only/committed CI history) passed incorrectly before the correction and are rejected afterward. Reasoned exception controls pass on both versions.efee1fe. Cases include baseline history across commits, bootstrap eligibility, renames/copies, malformed prior policy, symlinks, missing/shallow history, override precedence, syntax, physical-line boundaries, exclusions, and downward cap updates.efee1fe: all 65 script tests, every pre-commit hook, Python compilation, and the full scan of 133 production-path Rust files pass. The 18 baseline counts are unchanged.