Skip to content

refactor(pnpr): extract the bottom layer into four crates - #14202

Merged
zkochan merged 2 commits into
mainfrom
pnpr-core-crate
Aug 26, 2026
Merged

zkochan merged 2 commits into
mainfrom
pnpr-core-crate

Conversation

@zkochan

@zkochan zkochan commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Summary

The last item from the pnpr refactor plan in #14191 — started, not
finished
. See "Why four crates and not all of it" below.

pnpr is one 42k-line crate, even though
pnpr/AGENTS.md has
always specified the pnpr-<short-name> convention for registry-only crates
and none existed.

This starts 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. Each
becomes its own crate:

crate contents
pnpr-error the error type every layer returns, and how it renders as HTTP
pnpr-package-name npm package-name parsing and the tarball names derived from it
pnpr-registry the registry routing table
pnpr-policy access policy gating those routes

The 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 by
cargo rather than by convention.

On naming

An earlier revision of this PR put all four in a single pnpr-core. That was
wrong, and AGENTS.md now records why: the workspace has 77 Rust crates and
not one
named core, common, shared, or utils. Those names describe a
position 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::new becomes pub — the only item that turned out to reach
    across the boundary. The compiler found it.
  • Three methods gained #[must_use]. They are genuinely public API now, so
    clippy's pedantic public-API lints apply where pub(crate) had exempted them.
    A real (small) cost of splitting, worth knowing before the next extraction.
  • Every first-party pnpr* crate needs a deny.toml entry. Their PolyForm
    license text scores 0.74 against cargo-deny's 0.8 confidence threshold, so
    each needs an licenses.exceptions entry and a [[licenses.clarify]]
    block pinning the file by hash — without both, Cargo Deny fails the crate as
    unlicensed. That job is path-filtered on Cargo.lock/deny.toml, so it
    only runs on PRs touching one of them; adding a crate always does. This is
    now documented in AGENTS.md, and cargo deny check passes 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.toml requirement,
and the naming rule. pnpr-config, pnpr-storage, pnpr-auth and
pnpr-resolver can follow the same shape one at a time.

Feature forwarding. pnpr's backend-libsql, backend-mysql and
backend-postgres each enable their pnpr-error counterpart, since
RegistryError is 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 under
pnpr-package-name, 32 under pnpr-registry, 15 under pnpr-policy.

Squash Commit Body

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.

Related to pnpm/pnpm#14191.

Checklist

  • Added or updated tests. — a relocation with no behaviour change; the
    existing suite passes unchanged, with 65 tests now running under the four
    new crates.
  • Updated the documentation if needed. — pnpr/AGENTS.md gains the crate
    layout, the deny.toml requirement for new pnpr-* crates, and the naming
    rule.

Written by an agent (Claude Code, claude-opus-5[1m]).

Summary by CodeRabbit

  • New Features

    • Added clearer handling of registry errors, including appropriate response statuses and safer public error messages.
    • Improved protection by redacting sensitive credentials and server details from exposed errors.
    • Expanded package-name and registry validation for malformed names, paths, patterns, and routing configurations.
    • Made access-list construction available for broader integrations.
  • Refactor

    • Reorganized registry, policy, package-name, and error capabilities into dedicated components without changing existing behavior.

`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`.
Copilot AI lite review requested due to automatic review settings August 26, 2026 21:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 20a1fb03-667d-4636-aae8-07fca3031529

📥 Commits

Reviewing files that changed from the base of the PR and between 80ed457 and ec7f314.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock, !Cargo.lock
📒 Files selected for processing (51)
  • Cargo.toml
  • deny.toml
  • pnpr/AGENTS.md
  • pnpr/crates/error/Cargo.toml
  • pnpr/crates/error/src/lib.rs
  • pnpr/crates/error/src/tests.rs
  • pnpr/crates/package-name/Cargo.toml
  • pnpr/crates/package-name/src/lib.rs
  • pnpr/crates/package-name/src/tests.rs
  • pnpr/crates/pnpr/Cargo.toml
  • pnpr/crates/pnpr/src/auth.rs
  • pnpr/crates/pnpr/src/auth/libsql_backend.rs
  • pnpr/crates/pnpr/src/auth/sqlx_backend.rs
  • pnpr/crates/pnpr/src/auth/tests.rs
  • pnpr/crates/pnpr/src/config.rs
  • pnpr/crates/pnpr/src/config/tests.rs
  • pnpr/crates/pnpr/src/config/upstream.rs
  • pnpr/crates/pnpr/src/journal.rs
  • pnpr/crates/pnpr/src/journal/tests.rs
  • pnpr/crates/pnpr/src/lib.rs
  • pnpr/crates/pnpr/src/osv.rs
  • pnpr/crates/pnpr/src/publish.rs
  • pnpr/crates/pnpr/src/publish/tests.rs
  • pnpr/crates/pnpr/src/resolver.rs
  • pnpr/crates/pnpr/src/resolver/cache.rs
  • pnpr/crates/pnpr/src/resolver/tests.rs
  • pnpr/crates/pnpr/src/resolver/wire.rs
  • pnpr/crates/pnpr/src/route.rs
  • pnpr/crates/pnpr/src/route/tests.rs
  • pnpr/crates/pnpr/src/s3.rs
  • pnpr/crates/pnpr/src/s3/tests.rs
  • pnpr/crates/pnpr/src/search.rs
  • pnpr/crates/pnpr/src/server.rs
  • pnpr/crates/pnpr/src/server/authentication.rs
  • pnpr/crates/pnpr/src/server/package_mutation.rs
  • pnpr/crates/pnpr/src/server/publishing.rs
  • pnpr/crates/pnpr/src/server/staged.rs
  • pnpr/crates/pnpr/src/server/tests.rs
  • pnpr/crates/pnpr/src/shared_artifacts.rs
  • pnpr/crates/pnpr/src/shared_artifacts/tests.rs
  • pnpr/crates/pnpr/src/storage.rs
  • pnpr/crates/pnpr/src/storage/backend.rs
  • pnpr/crates/pnpr/src/streaming/tests.rs
  • pnpr/crates/pnpr/src/upstream.rs
  • pnpr/crates/pnpr/src/upstream/tests.rs
  • pnpr/crates/policy/Cargo.toml
  • pnpr/crates/policy/src/lib.rs
  • pnpr/crates/policy/src/tests.rs
  • pnpr/crates/registry/Cargo.toml
  • pnpr/crates/registry/src/lib.rs
  • pnpr/crates/registry/src/tests.rs
🚧 Files skipped from review as they are similar to previous changes (18)
  • pnpr/crates/pnpr/src/auth.rs
  • pnpr/crates/pnpr/src/config/upstream.rs
  • pnpr/crates/pnpr/src/resolver/wire.rs
  • pnpr/crates/pnpr/src/storage.rs
  • pnpr/crates/pnpr/src/resolver.rs
  • pnpr/crates/pnpr/src/shared_artifacts/tests.rs
  • pnpr/crates/pnpr/src/search.rs
  • pnpr/crates/pnpr/src/config/tests.rs
  • pnpr/crates/pnpr/src/route/tests.rs
  • pnpr/crates/pnpr/src/resolver/tests.rs
  • pnpr/crates/pnpr/src/server/package_mutation.rs
  • pnpr/crates/pnpr/src/auth/sqlx_backend.rs
  • pnpr/crates/pnpr/src/upstream.rs
  • pnpr/crates/pnpr/src/server/publishing.rs
  • pnpr/crates/pnpr/src/server/tests.rs
  • pnpr/crates/pnpr/src/auth/libsql_backend.rs
  • pnpr/crates/pnpr/src/shared_artifacts.rs
  • pnpr/crates/pnpr/src/route.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change replaces pnpr-core with four dedicated crates: pnpr-error, pnpr-package-name, pnpr-policy, and pnpr-registry. It adds shared contracts and tests, updates workspace wiring, and migrates pnpr imports, exports, and feature flags.

Changes

pnpr shared crate split

Layer / File(s) Summary
Workspace and crate wiring
Cargo.toml, deny.toml, pnpr/AGENTS.md
The workspace registers the four crates. License entries and crate-layout guidance are updated.
Shared error contract
pnpr/crates/error/...
pnpr-error adds RegistryError, HTTP status mapping, response rendering, transient classification, URL redaction, and tests.
Package, policy, and registry crates
pnpr/crates/package-name/..., pnpr/crates/policy/..., pnpr/crates/registry/...
Shared package-name, access-policy, and registry-routing code moves into dedicated crates. Public API annotations and focused tests are added.
pnpr integration migration
pnpr/crates/pnpr/Cargo.toml, pnpr/crates/pnpr/src/...
pnpr removes local shared modules, re-exports dedicated-crate types, updates feature propagation, and changes production and test imports.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to ec7f3

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: product: pnpr

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pnpr-core-crate

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Extract pnpr-core and enforce registry layer boundaries

✨ Enhancement ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Extracts error, package-name, routing, and policy modules into pnpr-core.
• Enforces one-way crate layering while preserving pnpr public re-exports.
• Forwards backend features and relocates 65 core tests without behavioral changes.
Diagram

graph TD
  W["Cargo workspace"] --> P["pnpr crate"] --> C["pnpr-core"]
  W --> C --> A["Access policy"] --> R["Registry routing"] --> N["Package names"] --> E["Registry errors"]
  P -. "backend features" .-> C
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. One crate per leaf module
  • ➕ Provides the strongest compile-time isolation between error, names, routing, and policy.
  • ➕ Keeps each crate narrowly scoped.
  • ➖ Adds substantial manifest, release, and dependency-management overhead.
  • ➖ Fragments a cohesive low-level API into several tiny crates.
2. Complete the six-crate split at once
  • ➕ Reaches the planned architecture in one migration.
  • ➕ Avoids temporary mixed ownership between pnpr and sibling crates.
  • ➖ Creates an approximately 40,000-line cross-cutting diff.
  • ➖ Makes review, bisection, and regression isolation significantly harder.

Recommendation: Keep the PR's incremental leaf-cluster extraction. The four modules already form a closed dependency chain, so grouping them establishes a useful compile-time boundary without over-fragmenting the domain or making the broader refactor unreviewable; later config, storage, auth, and resolver extractions can follow the same pattern.

Files changed (49) +217 / -146

Refactor (29) +102 / -109
error.rsMove shared registry errors into pnpr-core +0/-0

Move shared registry errors into pnpr-core

• Relocates 'RegistryError', the shared 'Result' alias, and HTTP error rendering into the new leaf crate without changing behavior.

pnpr/crates/core/src/error.rs

lib.rsExpose pnpr-core domain modules +11/-0

Expose pnpr-core domain modules

• Introduces the core crate root and publicly exports error, package-name, policy, and registry modules.

pnpr/crates/core/src/lib.rs

package_name.rsMove package-name validation into pnpr-core +2/-0

Move package-name validation into pnpr-core

• Relocates package and tarball name validation and marks value-returning accessors as '#[must_use]' for the public API.

pnpr/crates/core/src/package_name.rs

policy.rsMove access policy into pnpr-core +2/-1

Move access policy into pnpr-core

• Relocates identities, access tokens, and package rules. Makes 'AccessList::new' public and '#[must_use]' so 'pnpr' configuration can construct resolved team lists across the crate boundary.

pnpr/crates/core/src/policy.rs

registry.rsMove registry routing into pnpr-core +0/-0

Move registry routing into pnpr-core

• Relocates package patterns, registry graph validation, and route resolution into the new core crate without changing routing behavior.

pnpr/crates/core/src/registry.rs

auth.rsUse pnpr-core errors in authentication +2/-4

Use pnpr-core errors in authentication

• Replaces internal error imports with the extracted 'pnpr_core::error' API.

pnpr/crates/pnpr/src/auth.rs

libsql_backend.rsUse pnpr-core errors in libsql authentication +2/-4

Use pnpr-core errors in libsql authentication

• Rewires the libsql authentication backend to return the shared core error and result types.

pnpr/crates/pnpr/src/auth/libsql_backend.rs

sqlx_backend.rsUse pnpr-core errors across SQL authentication +6/-12

Use pnpr-core errors across SQL authentication

• Updates shared SQLx, PostgreSQL, and MySQL authentication paths to consume core error types.

pnpr/crates/pnpr/src/auth/sqlx_backend.rs

config.rsBuild configuration with pnpr-core domain types +7/-7

Build configuration with pnpr-core domain types

• Imports errors, policies, registries, and path-segment validation from 'pnpr-core', exercising the newly public 'AccessList' constructor across the boundary.

pnpr/crates/pnpr/src/config.rs

upstream.rsUse pnpr-core for upstream policy configuration +1/-1

Use pnpr-core for upstream policy configuration

• Imports registry errors and resolved access rules from the new core crate.

pnpr/crates/pnpr/src/config/upstream.rs

journal.rsUse pnpr-core primitives in journal recovery +5/-3

Use pnpr-core primitives in journal recovery

• Rewires package names, result types, and revision-limit error matching to 'pnpr-core'.

pnpr/crates/pnpr/src/journal.rs

lib.rsReplace internal modules with pnpr-core re-exports +4/-8

Replace internal modules with pnpr-core re-exports

• Removes local declarations for the four extracted modules and re-exports their public error, policy, and registry APIs to preserve the existing 'pnpr' library surface.

pnpr/crates/pnpr/src/lib.rs

osv.rsUse pnpr-core registry errors in OSV handling +2/-1

Use pnpr-core registry errors in OSV handling

• Replaces the former crate-local error import with the shared core type.

pnpr/crates/pnpr/src/osv.rs

publish.rsUse pnpr-core errors during publishing +2/-4

Use pnpr-core errors during publishing

• Routes publish validation failures through the extracted registry error type.

pnpr/crates/pnpr/src/publish.rs

resolver.rsUse pnpr-core identities in resolution +1/-1

Use pnpr-core identities in resolution

• Imports caller identity from the extracted access-policy module.

pnpr/crates/pnpr/src/resolver.rs

cache.rsUse pnpr-core identity in resolver caching +2/-4

Use pnpr-core identity in resolver caching

• Rewires cache access context to the shared core identity type.

pnpr/crates/pnpr/src/resolver/cache.rs

wire.rsUse core package and identity types on the resolver wire path +1/-2

Use core package and identity types on the resolver wire path

• Imports validated package names and caller identity from 'pnpr-core'.

pnpr/crates/pnpr/src/resolver/wire.rs

route.rsUse pnpr-core policy and routing models +2/-2

Use pnpr-core policy and routing models

• Rewires route selection and authorization to the extracted access-policy and registry graph types.

pnpr/crates/pnpr/src/route.rs

s3.rsUse pnpr-core errors and package names in S3 storage +10/-10

Use pnpr-core errors and package names in S3 storage

• Rewires S3 configuration, storage operations, and package addressing to shared core types.

pnpr/crates/pnpr/src/s3.rs

search.rsUse pnpr-core primitives in search +2/-1

Use pnpr-core primitives in search

• Imports validated package names and result types from the new core crate.

pnpr/crates/pnpr/src/search.rs

server.rsRun server flows on pnpr-core domain types +17/-12

Run server flows on pnpr-core domain types

• Rewires server routing, authorization, package validation, and public result signatures to the extracted crate while retaining existing behavior.

pnpr/crates/pnpr/src/server.rs

authentication.rsUse pnpr-core authentication policy types +2/-2

Use pnpr-core authentication policy types

• Imports registry errors, identities, and package rules from the core crate.

pnpr/crates/pnpr/src/server/authentication.rs

package_mutation.rsUse pnpr-core types for package mutations +1/-3

Use pnpr-core types for package mutations

• Rewires mutation authorization, package validation, and failures to the extracted domain types.

pnpr/crates/pnpr/src/server/package_mutation.rs

publishing.rsUse pnpr-core types in publishing endpoints +3/-4

Use pnpr-core types in publishing endpoints

• Imports errors, package names, identities, and registry models from the new core dependency.

pnpr/crates/pnpr/src/server/publishing.rs

staged.rsUse pnpr-core types for staged publishes +1/-2

Use pnpr-core types for staged publishes

• Rewires staged-publish validation and errors to core package-name and registry-error APIs.

pnpr/crates/pnpr/src/server/staged.rs

shared_artifacts.rsUse pnpr-core errors for shared artifacts +2/-4

Use pnpr-core errors for shared artifacts

• Rewires artifact-cache operations to the shared registry error and result types.

pnpr/crates/pnpr/src/shared_artifacts.rs

storage.rsUse pnpr-core storage-facing primitives +5/-7

Use pnpr-core storage-facing primitives

• Imports shared errors, results, and validated package names from the extracted crate.

pnpr/crates/pnpr/src/storage.rs

backend.rsUse pnpr-core types in the storage backend contract +2/-5

Use pnpr-core types in the storage backend contract

• Updates backend trait signatures to use core result and package-name types.

pnpr/crates/pnpr/src/storage/backend.rs

upstream.rsUse pnpr-core primitives for upstream requests +5/-5

Use pnpr-core primitives for upstream requests

• Rewires upstream package validation and failure handling to core package-name, error, and result types.

pnpr/crates/pnpr/src/upstream.rs

Tests (15) +40 / -33
tests.rsMove registry error tests into pnpr-core +0/-0

Move registry error tests into pnpr-core

• Relocates coverage for status mapping, public messages, logging, and backend-specific errors alongside the extracted error module.

pnpr/crates/core/src/error/tests.rs

tests.rsMove package-name safety tests into pnpr-core +0/-0

Move package-name safety tests into pnpr-core

• Relocates coverage for scoped names, traversal rejection, tarball parsing, and platform-specific unsafe path segments.

pnpr/crates/core/src/package_name/tests.rs

tests.rsMove access policy tests into pnpr-core +0/-0

Move access policy tests into pnpr-core

• Relocates coverage for token semantics, identity checks, team membership, and package-rule specificity.

pnpr/crates/core/src/policy/tests.rs

tests.rsMove registry routing tests into pnpr-core +0/-0

Move registry routing tests into pnpr-core

• Relocates coverage for pattern parsing, graph validation, shadow detection, and concrete route resolution.

pnpr/crates/core/src/registry/tests.rs

tests.rsMatch authentication failures through pnpr-core +4/-1

Match authentication failures through pnpr-core

• Updates the corrupt htpasswd assertion to reference the extracted registry error type.

pnpr/crates/pnpr/src/auth/tests.rs

tests.rsUpdate configuration tests for pnpr-core +8/-8

Update configuration tests for pnpr-core

• Repoints policy, registry, identity, resolution, and error assertions to the extracted crate.

pnpr/crates/pnpr/src/config/tests.rs

tests.rsUse core package names in journal tests +1/-1

Use core package names in journal tests

• Updates journal recovery tests to construct package names through 'pnpr-core'.

pnpr/crates/pnpr/src/journal/tests.rs

tests.rsUpdate publish test result types +1/-1

Update publish test result types

• Changes the stream helper's error type to the 'pnpr-core' registry error.

pnpr/crates/pnpr/src/publish/tests.rs

tests.rsUpdate resolver tests for core policies and patterns +4/-4

Update resolver tests for core policies and patterns

• Repoints access-list, package-rule, identity, and registry-pattern setup to 'pnpr-core'.

pnpr/crates/pnpr/src/resolver/tests.rs

tests.rsUpdate route tests for pnpr-core types +5/-7

Update route tests for pnpr-core types

• Repoints access lists, identities, package rules, tokens, and patterns to the core crate.

pnpr/crates/pnpr/src/route/tests.rs

tests.rsUpdate S3 tests for pnpr-core types +4/-3

Update S3 tests for pnpr-core types

• Uses core package names and matches revision-reference limit failures through the extracted error enum.

pnpr/crates/pnpr/src/s3/tests.rs

tests.rsUpdate server tests for pnpr-core APIs +6/-4

Update server tests for pnpr-core APIs

• Repoints shared error, result, policy, identity, and registry-pattern fixtures to the extracted crate.

pnpr/crates/pnpr/src/server/tests.rs

tests.rsUpdate shared-artifact tests for core results +2/-1

Update shared-artifact tests for core results

• Uses the 'pnpr-core' result alias in artifact-cache test helpers.

pnpr/crates/pnpr/src/shared_artifacts/tests.rs

tests.rsUse core package names in streaming tests +2/-1

Use core package names in streaming tests

• Updates tarball-streaming test setup to construct package names through 'pnpr-core'.

pnpr/crates/pnpr/src/streaming/tests.rs

tests.rsUpdate upstream tests for pnpr-core +3/-2

Update upstream tests for pnpr-core

• Repoints package-name, registry-error, and default package-rule usage to the extracted crate.

pnpr/crates/pnpr/src/upstream/tests.rs

Documentation (1) +7 / -1
AGENTS.mdDocument the pnpr-core crate layout +7/-1

Document the pnpr-core crate layout

• Replaces the sibling-crate placeholder with the new core crate and its four domain modules.

pnpr/AGENTS.md

Other (4) +68 / -3
Cargo.lockLock the new pnpr-core workspace package +23/-0

Lock the new pnpr-core workspace package

• Adds 'pnpr-core' to 'pnpr''s resolved dependencies and records the new crate's feature-dependent dependency set.

Cargo.lock

Cargo.tomlRegister pnpr-core in workspace dependencies +1/-0

Register pnpr-core in workspace dependencies

• Adds the new 'pnpr/crates/core' package to the shared workspace dependency table.

Cargo.toml

Cargo.tomlDefine the pnpr-core crate and backend features +40/-0

Define the pnpr-core crate and backend features

• Creates the non-published core package, declares its workspace dependencies, and exposes optional libsql, MySQL, and PostgreSQL feature gates.

pnpr/crates/core/Cargo.toml

Cargo.tomlDepend on pnpr-core and forward backend features +4/-3

Depend on pnpr-core and forward backend features

• Adds the core dependency and maps each 'pnpr' backend feature to its matching 'pnpr-core' feature while retaining local backend dependencies.

pnpr/crates/pnpr/Cargo.toml

@greptile-apps

greptile-apps Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The 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

greptile-apps[bot]
greptile-apps Bot previously approved these changes Aug 26, 2026
@qodo-code-review

qodo-code-review Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can start a comment with 'qodo' or '@qodo' to chat about any finding

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit ec7f314 ⚖️ Balanced

Results up to commit 80ed457 ⚖️ Balanced


No changes from previous review

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@github-actions

github-actions Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.05     17.3±1.37ms    21.7 MB/sec    1.00     16.4±0.85ms    22.9 MB/sec
packument/parse                                  1.08     49.0±3.61µs  1354.4 MB/sec    1.00     45.4±1.12µs  1462.2 MB/sec
tarball/download_dependency                      1.00      5.8±1.18ms   752.0 KB/sec    1.57      9.1±2.21ms   478.4 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.18   357.3±60.21ms 44.8 KElem/sec    1.00   304.1±26.04ms 52.6 KElem/sec
workspace_resolution/hoist_heavy                 1.00   538.0±49.38ms        ? ?/sec    1.23   660.9±78.94ms        ? ?/sec
workspace_sort/chained_projects                  1.00     27.3±3.75ms        ? ?/sec    1.03     28.2±6.72ms        ? ?/sec

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 26, 2026
`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.
Copilot AI review requested due to automatic review settings August 26, 2026 21:22
@greptile-apps
greptile-apps Bot dismissed their stale review August 26, 2026 21:22

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan zkochan changed the title refactor(pnpr): extract pnpr-core refactor(pnpr): extract the bottom layer into four crates Aug 26, 2026
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit ec7f314

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.35%. Comparing base (03b8525) to head (ec7f314).

Files with missing lines Patch % Lines
pnpr/crates/pnpr/src/server.rs 85.71% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zkochan
zkochan merged commit 49ad901 into main Aug 26, 2026
35 checks passed
@zkochan
zkochan deleted the pnpr-core-crate branch August 26, 2026 21:51
zkochan added a commit that referenced this pull request Aug 26, 2026
)

## 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.
@zkochan zkochan mentioned this pull request Aug 26, 2026
2 tasks done
zkochan added a commit that referenced this pull request Aug 27, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpr reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants