Add optional Polonius support to generated projects - #78
Conversation
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 16 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (32)
SummaryAdd optional Polonius support to generated Rust projects through the
WalkthroughAdd optional Polonius support to generated projects. Configure Cargo, Makefile, CI, coverage, and release workflows. Generate policy documentation. Validate enabled and disabled outputs through rendering, contract, snapshot, and compilation tests. ChangesPolonius template support
Sequence Diagram(s)sequenceDiagram
participant Copier
participant Templates
participant GeneratedProject
participant ContractTests
Copier->>Templates: Set enable_polonius
Templates->>GeneratedProject: Render flags, toolchains, and documentation
GeneratedProject->>GeneratedProject: Run build and workflow commands
ContractTests->>GeneratedProject: Inspect generated configuration
ContractTests->>ContractTests: Validate enabled and disabled contracts
Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 20✅ Passed checks (20 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Reviewer's GuideAdds an optional enable_polonius Copier choice and wires Polonius (-Zpolonius=next) coherently through Cargo, Makefile, coverage, CI, and release workflows, plus documentation and tests, with different defaults for app vs lib flavours and a dedicated tooling contract helper. Sequence diagram for make test with Polonius enabledsequenceDiagram
actor Developer
participant Makefile
participant Cargo
participant RustCompiler
Developer->>Makefile: make test
Makefile->>Makefile: RUST_FLAGS := -D warnings RUST_FLAGS
Makefile->>Makefile: POLONIUS_FLAGS := -Zpolonius=next
Makefile->>Makefile: DEV_RUST_FLAGS := RUST_FLAGS + POLONIUS_FLAGS + DEV_LINKER_FLAGS
Makefile->>Cargo: CARGO TEST_CMD TEST_FLAGS BUILD_JOBS
note right of Makefile: RUSTFLAGS=DEV_RUST_FLAGS
Cargo->>RustCompiler: compile tests with -Zpolonius=next
Makefile->>Cargo: cargo test --doc --workspace --all-features
note right of Makefile: RUSTFLAGS=DEV_RUST_FLAGS
Cargo->>RustCompiler: compile doc-tests with -Zpolonius=next
RustCompiler-->>Developer: tests and doc-tests built under Polonius
Flow diagram for optional Polonius configuration propagationflowchart LR
Copier[Copier template]
Choice[enable_polonius choice]
CargoConfig[template/.cargo/config.toml.jinja]
Makefile[template/Makefile.jinja]
Workflows[template/.github/workflows ci.yml.jinja, coverage-main.yml.jinja, release.yml.jinja]
Toolchain[template/rust-toolchain.toml.jinja]
Docs[template/docs/polonius.md.jinja, AGENTS.md.jinja]
Copier --> Choice
Choice -->|true| CargoConfig
Choice -->|true| Makefile
Choice -->|true| Workflows
Choice -->|true| Toolchain
Choice -->|true| Docs
Choice -->|false| CargoConfig
Choice -->|false| Makefile
Choice -->|false| Workflows
Choice -->|false| Toolchain
Choice -->|false| Docs
CargoConfig -->|build.rustflags, target rustflags| RustBuild[Rust build commands]
Makefile -->|POLONIUS_FLAGS, DEV_RUST_FLAGS, COVERAGE_RUST_FLAGS| RustBuild
Workflows -->|RUSTFLAGS env| RustBuild
Toolchain -->|nightly rust_nightly_date| RustBuild
Docs -->|policy and guidance| Contributors[Project contributors]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/helpers/rendering.py`:
- Line 26: Replace the public helper’s one-line docstring with a complete
NumPy-style docstring, documenting every parameter, the return value, and the
behavior of the `None` option versus a Boolean override for `enable_polonius`.
Keep the documentation aligned with the helper’s existing signature and
behavior.
In `@tests/helpers/tooling_contracts/polonius.py`:
- Around line 106-123: Update _assert_release_workflow to parse the
[toolchain].channel value from rust_toolchain and require the enabled release
setup toolchain to equal that channel instead of merely starting with
“nightly-20”. Also assert the build command uses cross +<toolchain> with the
same parsed channel, while preserving the existing stable and RUSTFLAGS checks.
- Around line 125-143: Expand the docstring of the public
assert_polonius_toolchain_contracts helper with NumPy-style Parameters and
Raises sections, documenting every argument as its rendered project surface and
stating that AssertionError is raised when the selected Polonius state does not
match.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 0fc3accc-6a75-402e-9a5d-74f051a53094
📒 Files selected for processing (29)
.gitignoreREADME.mdcopier.yamldocs/developers-guide.mddocs/users-guide.mdtemplate/.cargo/config.toml.jinjatemplate/.github/workflows/ci.yml.jinjatemplate/.github/workflows/coverage-main.yml.jinjatemplate/.github/workflows/{% if flavour == 'app' %}release.yml{% endif %}.jinjatemplate/AGENTS.md.jinjatemplate/Makefile.jinjatemplate/README.md.jinjatemplate/docs/contents.md.jinjatemplate/docs/developers-guide.md.jinjatemplate/docs/repository-layout.md.jinjatemplate/docs/users-guide.md.jinjatemplate/docs/{% if enable_polonius %}polonius.md{% endif %}.jinjatemplate/rust-toolchain.toml.jinjatemplate/typos.local.tomltemplate/typos.tomltests/helpers/rendering.pytests/helpers/tooling_contracts/__init__.pytests/helpers/tooling_contracts/polonius.pytests/test_template/__snapshots__/test_snapshots.ambrtests/test_template/test_basic_rendering.pytests/test_template/test_compilation.pytests/test_template/test_tooling_contracts.pytypos.local.tomltypos.toml
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
leynos/whitaker(auto-detected)
|
@coderabbitai resume |
✅ Action performedReviews resumed. |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/adr-004-optional-polonius-support.md`:
- Around line 19-29: Rewrite the Decision paragraph in
docs/adr-004-optional-polonius-support.md without first-person or second-person
pronouns. Replace the awkward “decided for ... and against ...” construction
with direct statements covering the enable_polonius defaults, propagation,
toolchain-contract rationale, and dated-nightly/RUSTFLAGS constraints, using
en-GB-oxendict spelling and grammar.
In `@template/.cargo/config.toml.jinja`:
- Around line 1-8: Propagate Polonius settings to rustdoc: in
template/.cargo/config.toml.jinja, add rustdocflags to the enabled [build]
block; in template/Makefile.jinja at lines 54-55 and 69-70, define RUSTDOC_FLAGS
with POLONIUS_FLAGS as its default and pass RUSTDOCFLAGS="$(RUSTDOC_FLAGS)" to
both cargo test --doc and cargo doc.
In `@tests/helpers/tooling_contracts/polonius.py`:
- Around line 85-94: Extend the Makefile validation in the existing
compile-recipe test to inspect the coverage recipe body and directly assert it
contains RUSTFLAGS="$(COVERAGE_RUST_FLAGS)". Keep the current compile_lines
filtering and composed-flag assertions unchanged, and use the existing makefile
content variable rather than broadening the filter.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 5891a8c2-8fef-4738-93d5-1584c8763dfe
📒 Files selected for processing (31)
.gitignoreREADME.mdcopier.yamldocs/adr-004-optional-polonius-support.mddocs/developers-guide.mddocs/execplans/rust-project-enhancements.mddocs/users-guide.mdtemplate/.cargo/config.toml.jinjatemplate/.github/workflows/ci.yml.jinjatemplate/.github/workflows/coverage-main.yml.jinjatemplate/.github/workflows/{% if flavour == 'app' %}release.yml{% endif %}.jinjatemplate/AGENTS.md.jinjatemplate/Makefile.jinjatemplate/README.md.jinjatemplate/docs/contents.md.jinjatemplate/docs/developers-guide.md.jinjatemplate/docs/repository-layout.md.jinjatemplate/docs/users-guide.md.jinjatemplate/docs/{% if enable_polonius %}polonius.md{% endif %}.jinjatemplate/rust-toolchain.toml.jinjatemplate/typos.local.tomltemplate/typos.tomltests/helpers/rendering.pytests/helpers/tooling_contracts/__init__.pytests/helpers/tooling_contracts/polonius.pytests/test_template/__snapshots__/test_snapshots.ambrtests/test_template/test_basic_rendering.pytests/test_template/test_compilation.pytests/test_template/test_tooling_contracts.pytypos.local.tomltypos.toml
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
leynos/whitaker(auto-detected)
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@copier.yaml`:
- Around line 116-119: Update the rust_nightly_date validator to use a strict
full-string regex that rejects trailing newlines, replacing the current
regex_search pattern’s end anchor with an end-of-string match. Add a regression
test covering a value ending in “2025-06-10\n” and assert that validation raises
ValueError.
In `@docs/migrations/0.2.0.md`:
- Line 22: Update the migration documentation sentence containing
`-Zpolonius=next` by removing the comma before the essential “because” clause,
preserving the surrounding wording and en-GB-oxendict grammar.
In `@tests/helpers/tooling_contracts/polonius.py`:
- Line 81: Update the four contract assertions in the relevant test function to
include descriptive failure messages: the RUSTDOC_FLAGS inheritance check,
coverage recipe check, rustdoc recipe count check, and all-rustdoc-lines check.
Preserve the existing assertion conditions and use the proposed context-specific
messages, including rendered line data for the count and all-lines assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 2a7a898d-2f94-4a14-a3a5-aef723d41030
📒 Files selected for processing (10)
README.mdcopier.yamldocs/adr-004-optional-polonius-support.mddocs/migrations/0.2.0.mddocs/users-guide.mdtemplate/.cargo/config.toml.jinjatemplate/Makefile.jinjatests/helpers/tooling_contracts/polonius.pytests/test_template/__snapshots__/test_snapshots.ambrtests/test_template/test_basic_rendering.py
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
leynos/whitaker(auto-detected)
|
@coderabbitai resume |
✅ Action performedReviews resumed. |
Default Polonius on for applications and off for libraries while allowing an explicit override. Preserve the compiler flag through Cargo target configuration, Make compile paths, coverage, and release workflows so Cranelift, mold, and lld remain coherent. Generate borrow-checker policy documentation and agent guidance. Exercise both configurations and compile a single-lookup borrow-returning accessor. Ignore the local GrepAI index used during semantic exploration.
Bind release workflows to the exact generated toolchain channel and add a render-only property test over the complete flavour, option, and target class matrix. Document the helper contracts and record the optional Polonius decision, risks, progress, and outcome in ADR-004 and the completed tooling plan.
Carry the Polonius flag through rustdoc and directly verify the coverage and documentation recipes that override compiler flags. Reject unsafe nightly-date answers before rendering release shell commands, and document the 0.2.0 migration path and refined architectural decision.
Reject nightly dates with trailing newlines using a strict end-of-string match and retain regression coverage for the validation boundary. Add actionable messages to rustdoc and coverage contract assertions, and correct the migration guide's essential `because` clause.
Restore Ruff's required top-level spacing after Weave combines the scheduled mutation-testing changes with the Polonius property contract.
a350198 to
40108c6
Compare
Summary
This branch adds an optional
enable_poloniusCopier choice so generatedapplications can adopt borrow-centric internal APIs by default, while generated
libraries retain wider compiler compatibility unless maintainers opt in. It
preserves
-Zpolonius=nextacross Cargo, Make, coverage and release buildsbecause explicit
RUSTFLAGSand target-specific linker flags otherwisesupersede Cargo's build-level settings.
The implementation adapts the toolchain policy from the
Netsuke Polonius migration
and its
Cranelift and mold integration
to the template's optional application/library contract.
Review walkthrough
copier.yamlfor the application-recommended default and explicit override.
template/.cargo/config.toml.jinjaand
template/Makefile.jinjafor the Polonius, Cranelift, mold and lld flag-precedence contract.
template/.github/workflows/ci.yml.jinja,template/.github/workflows/coverage-main.yml.jinjaand the
application release workflow template.
template/AGENTS.md.jinjaand the
generated Polonius policy.
tests/helpers/tooling_contracts/polonius.py,tests/test_template/test_tooling_contracts.pyand
tests/test_template/test_compilation.pyfor explicit mode coverage and the compiler-verified single-lookup accessor.
Validation
make test: passed; 70 tests passed and the optional Act test was skipped.make check-fmt: passed; 28 files were already formatted.make lint: passed; Ruff reported no issues.make typecheck: passed; mypy reported no issues in 28 source files.make spelling: passed with the regenerated Oxford spelling configuration.make all: passed with their recommendedPolonius defaults.
make markdownlint: passed.git diff --check origin/main...HEAD: passed.Notes
This branch is not linked to a GitHub issue or roadmap task. It does not
implement an ExecPlan; the repository's existing
Rust tooling import ExecPlan
is complete and predates this extension.
Summary by Sourcery
Add an optional Polonius borrow-checker mode to generated Rust projects and ensure tooling preserves its compiler flags consistently across local builds and CI.
New Features:
Enhancements:
Tests: