Skip to content

chore: enforce Rust production file size limits - #319

Merged
franciscojavierarceo merged 3 commits into
vllm-project:mainfrom
StevenWang-CY:feat-rust-file-size-guard
Sep 16, 2026
Merged

franciscojavierarceo merged 3 commits into
vllm-project:mainfrom
StevenWang-CY:feat-rust-file-size-guard

Conversation

@StevenWang-CY

@StevenWang-CY StevenWang-CY commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

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

  • Unchanged-main pre-commit accepted both 500- and 501-line fixtures. The new hook accepts 500 and rejects 501; also verified large inline test modules, production following tests, policy-only invocation, and CI-style --all-files.
  • Reproduced both baseline bypasses against published commit 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.
  • The final 51 checker tests produce 17 intended failures on the unchanged published checker and all pass on correction 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.
  • From a clean worktree at 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.
  • All 1,467 Rust workspace tests pass (nine existing ignored tests), with locked all-target/all-feature compilation, strict Clippy, and formatting checks passing on the same exact commit.
  • Local validation ran on macOS. No provider cassette is needed for this isolated developer-tooling change; no live-provider, GPU, or new wheel-build validation is claimed.

Signed-off-by: Chuyue Wang <stevenwang0805@outlook.com>
Signed-off-by: Chuyue Wang <stevenwang0805@outlook.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread scripts/check_rust_file_sizes.py
Signed-off-by: Chuyue Wang <stevenwang0805@outlook.com>
@franciscojavierarceo
franciscojavierarceo merged commit 588d8bd into vllm-project:main Sep 16, 2026
9 checks passed
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.

chore: add Rust file-size pre-commit hook

3 participants