Repository navigation
refactor(pnpr): extract the bottom layer into four crates - #14202
Conversation
`pnpr` was one 42k-line crate, though `pnpr/AGENTS.md` has always specified the `pnpr-<short-name>` convention for registry-only crates and none existed. Start the split at the bottom, where the boundary is already closed: `error` depends on nothing, `package_name` on `error`, `registry` on `package_name`, `policy` on `registry`, and no member reaches back up. Those four modules move to `pnpr/crates/core` as `pnpr-core`, byte-for-byte apart from one item. Consumers name `pnpr_core::` instead of `crate::`, which is the point — the layering is now checked by cargo rather than by convention, and nothing can quietly grow an edge from `error` back into `server`. The backend features forward: `pnpr`'s `backend-libsql`, `backend-mysql`, and `backend-postgres` each enable their `pnpr-core` counterpart, since the error type is what names those backends. Two consequences worth noting. `AccessList::new` becomes `pub` — it is the one item the crate boundary caught as reaching across. And three methods gained `#[must_use]`: they are now genuinely public API, so clippy's pedantic public-API lints apply where `pub(crate)` had exempted them. All four feature combinations build; the suite is unchanged at 714, of which 65 now run under `pnpr-core`.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (51)
🚧 Files skipped from review as they are similar to previous changes (18)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change replaces Changespnpr shared crate split
Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: ⚪ Minimal · up to This refactor separates the pnpr layers into dedicated crates without an identified behavior or integration issue. No actionable merge-blocking risk remains beyond normal checks and review. Suggested labels: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoExtract pnpr-core and enforce registry layer boundaries
AI Description
Diagram
High-Level Assessment
Files changed (49)
|
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains in the eligible follow-up review scope. No blocking failure remains. Reviews (2): Last reviewed commit: "refactor(pnpr): extract the bottom layer..." | Re-trigger Greptile |
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can start a comment with 'qodo' or '@qodo' to chat about any finding |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Micro-Benchmark ResultsLinux |
`pnpr` was one 42k-line crate, though `pnpr/AGENTS.md` has always specified the `pnpr-<short-name>` convention for registry-only crates and none existed. Start at the bottom of the module graph, where the boundary is already closed: `error` depends on nothing, `package_name` on `error`, `registry` on `package_name`, `policy` on `registry`, and no member reaches back up. Those four become `pnpr-error`, `pnpr-package-name`, `pnpr-registry`, and `pnpr-policy` — one crate each, named for what it holds. The workspace has 77 Rust crates and not one named `core`, `common`, `shared`, or `utils`; such a name describes a position in the graph rather than a subject, which is what lets it collect anything. `AGENTS.md` now says so, so the next extraction doesn't have to relearn it. Consumers name `pnpr_error::` and friends instead of `crate::`, so the layering is checked by cargo rather than by convention. The backend features forward to `pnpr-error`, which is the crate that names those backends. Three things the crate boundary surfaced. `AccessList::new` becomes `pub` — the one item reaching across. Three methods gained `#[must_use]`, since pedantic public-API lints apply where `pub(crate)` had exempted them. And every first-party `pnpr*` crate needs a `deny.toml` exception plus a `licenses.clarify` block, because their PolyForm license text scores below cargo-deny's confidence threshold; without both, `Cargo Deny` fails the crate as unlicensed. All four feature combinations build, `cargo deny check` passes, and the suite is unchanged at 714 — 65 of which now run under the four new crates.
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|
Code review by qodo was updated up to the latest commit ec7f314 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #14202 +/- ##
=======================================
Coverage 88.35% 88.35%
=======================================
Files 690 690
Lines 119122 119120 -2
=======================================
+ Hits 105247 105249 +2
+ Misses 13875 13871 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
) ## Summary Continues the crate split from #14191, after #14202 (the bottom layer) and #14204 (`pnpr-config`). The three modules that depended only on `pnpr-config` become crates. They are independent of each other, so this is one *tier* rather than a chain: | crate | contents | tests | | --- | --- | --- | | `pnpr-auth` | the user and token stores: htpasswd, SQLite, networked SQL backends | 43 | | `pnpr-route` | classifies a fetch route public or private, so a shared resolution never leaks private data | 25 | | `pnpr-upstream` | the upstream registry proxy client: packument/tarball fetches, cache validators, circuit breaker | 31 | Nine items the boundaries caught as reaching across become `pub`, and seven gained `#[must_use]` as newly public API. Three doc links pointed at items that are private or at a crate no longer in scope; they are now plain code spans rather than links. ## Two things the boundaries exposed, both silent **`pnpr-auth`'s backend features did not forward.** They enable its own `libsql`/`sqlx`, but the matching `RegistryError` variants are gated in `pnpr-error`, so `cargo check -p pnpr-auth --features backend-libsql` failed to compile with 57 errors. It only ever worked *through* `pnpr`, which forwards to both. Now `pnpr-auth`'s features forward to `pnpr-error` as well. **The justfile's two test recipes had drifted.** `test-pacquet` runs the workspace minus `pnpr` and `pnpr-fixtures`; `test-pnpr` runs the rest. The intent is clear — pacquet crates in one job, pnpr crates in the other — but the excludes were written when `pnpr` was one crate. Every new `pnpr-*` crate has been landing in the *pacquet* job, and building bare there: `pnpr-auth` would have reported 28 tests instead of 43, **dropping its 14 libsql backend tests from CI without failing anything.** Both recipes now name every `pnpr-*` crate: excluded from `test-pacquet`, selected together in `test-pnpr` so cargo's feature unification gives them the backends `pnpr` itself defaults to. `just test-pnpr` covers all ten crates at **732 tests**, and `just test-pacquet` is unchanged at 8606. That drift is worth knowing for the remaining extractions — it is the kind of coverage loss that shows up as a green build.
## Summary Continues the crate split from #14191, after #14202, #14204 and #14207. `storage`, `s3`, `streaming`, `journal` and `publish` move together as **one** crate. That is not a shortcut — the graph says they are one subsystem: ``` storage → journal → publish → streaming → storage (a 4-cycle) s3 ↔ storage (another) ``` Splitting them further would mean inventing seams the code does not have. The crate they form is coherent on its own terms: where packages live, how bytes get into that store, and the journal that makes a publish survive a crash. The two thin edges are `Storage::publish_journal()` (a convenience constructor) and `streaming`'s use of `TarballWrite` — either could be cut, but doing so to manufacture crate boundaries would make the code worse, not better. ### What the boundary caught Fifteen items become `pub`, plus the `HostedPackumentForUpdate` fields the server reads — I had initially guessed that type was crate-internal and the compiler corrected me. `HostedBackend` deliberately stays `pub(crate)`: the trait is implemented and dispatched only inside this crate, so it is the one part of the backend contract that is nobody else's business. The re-export is split by visibility to say so. One over-publish caught on review of my own diff: `revision_ref_owner` exists twice — a method and a free function — and the compiler only needed the method. The free function is back to private. Four doc links pointed at `crate::serve`, `crate::s3` or private items that no longer resolve from the new crate root; those are plain code spans now. `just test-pnpr` covers eleven crates at **733 tests**, unchanged. All feature combinations build and `cargo deny check` passes.
Summary
The last item from the pnpr refactor plan in #14191 — started, not
finished. See "Why four crates and not all of it" below.
pnpris one 42k-line crate, even thoughpnpr/AGENTS.mdhasalways specified the
pnpr-<short-name>convention for registry-only cratesand none existed.
This starts at the bottom of the module graph, where the boundary is already
closed:
errordepends on nothing,package_nameonerror,registryonpackage_name,policyonregistry— and no member reaches back up. Eachbecomes its own crate:
pnpr-errorpnpr-package-namepnpr-registrypnpr-policyThe files move byte-for-byte apart from one item. Consumers name
pnpr_error::and friends instead of
crate::, which is the point: the layering is checked bycargo rather than by convention.
On naming
An earlier revision of this PR put all four in a single
pnpr-core. That waswrong, and
AGENTS.mdnow records why: the workspace has 77 Rust crates andnot one named
core,common,shared, orutils. Those names describe aposition in the dependency graph rather than a subject, which is exactly what
lets them accumulate unrelated things. Crates here are named for what they hold.
Sizes range from 95 to 7,584 lines already, so four crates of 150–1,120 lines
are unremarkable.
Three things the crate boundary surfaced
AccessList::newbecomespub— the only item that turned out to reachacross the boundary. The compiler found it.
#[must_use]. They are genuinely public API now, soclippy's pedantic public-API lints apply where
pub(crate)had exempted them.A real (small) cost of splitting, worth knowing before the next extraction.
pnpr*crate needs adeny.tomlentry. Their PolyFormlicense text scores 0.74 against cargo-deny's 0.8 confidence threshold, so
each needs an
licenses.exceptionsentry and a[[licenses.clarify]]block pinning the file by hash — without both,
Cargo Denyfails the crate asunlicensed. That job is path-filtered onCargo.lock/deny.toml, so itonly runs on PRs touching one of them; adding a crate always does. This is
now documented in
AGENTS.md, andcargo deny checkpasses locally(
advisories ok, bans ok, licenses ok, sources ok).Why four crates and not all of it
The plan sketched six crates covering the whole tree. Doing that in one PR is a
~40k-line diff touching every module at once — not reviewable, not bisectable.
This extracts the leaf-most layer and establishes everything the rest needs:
crate layout, workspace wiring, feature forwarding, the
deny.tomlrequirement,and the naming rule.
pnpr-config,pnpr-storage,pnpr-authandpnpr-resolvercan follow the same shape one at a time.Feature forwarding.
pnpr'sbackend-libsql,backend-mysqlandbackend-postgreseach enable theirpnpr-errorcounterpart, sinceRegistryErroris what names those backends. All four combinations(
--no-default-features, each SQL backend alone,--all-features) build.The suite is unchanged at 714 tests: 12 now under
pnpr-error, 6 underpnpr-package-name, 32 underpnpr-registry, 15 underpnpr-policy.Squash Commit Body
Checklist
existing suite passes unchanged, with 65 tests now running under the four
new crates.
pnpr/AGENTS.mdgains the cratelayout, the
deny.tomlrequirement for newpnpr-*crates, and the namingrule.
Written by an agent (Claude Code, claude-opus-5[1m]).
Summary by CodeRabbit
New Features
Refactor