Skip to content

Make package publication immutable#4

Merged
loreste merged 1 commit into
loreste:mainfrom
attahn:fix/immutable-package-publish
Jul 19, 2026
Merged

Make package publication immutable#4
loreste merged 1 commit into
loreste:mainfrom
attahn:fix/immutable-package-publish

Conversation

@attahn

@attahn attahn commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Published versions could previously be replaced in place. This rejects republishing the same name and version, stages package contents before an atomic rename, validates registry coordinates, isolates scoped package names, and rejects symlinked sources. Tests: cargo test --bin mako passes.

Summary by CodeRabbit

  • New Features

    • Local registry packages now use collision-safe storage for scoped package names.
    • Registry dependencies resolve correctly for both scoped and unscoped package names.
  • Bug Fixes

    • Published package versions are now immutable; changing content under an existing name and version is rejected.
    • Invalid package names and versions are rejected during publication.
    • Unsafe package sources, including symlinks, are blocked from publication.
  • Documentation

    • Clarified registry publishing rules, naming constraints, SemVer requirements, and cache layout.

@attahn

attahn commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@attahn, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a8dcf6d6-be34-4b49-a841-7c7ee295c6df

📥 Commits

Reviewing files that changed from the base of the PR and between 4a62e22 and 4b4a807.

📒 Files selected for processing (6)
  • docs/CLI.md
  • docs/GUIDE.md
  • docs/book/src/ch10-packages.md
  • src/main.rs
  • src/pkg.rs
  • src/tooling.rs
📝 Walkthrough

Walkthrough

The local registry now validates publication coordinates, stages allowed package contents, prevents overwriting published versions, and stores registry entries using cache-derived keys. Registry resolution and documentation reflect the updated layout, including scoped package encoding.

Changes

Local registry publication

Layer / File(s) Summary
Validate and finalize immutable publications
src/pkg.rs, src/main.rs, docs/CLI.md
Publication validates package names and SemVer versions, rejects symlinked sources, stages allowed contents, and finalizes versions without overwriting existing entries.
Resolve cache-keyed registry entries
src/pkg.rs, src/tooling.rs, docs/GUIDE.md, docs/book/src/ch10-packages.md
Registry lookup and dependency installation use dep_cache_key, with scoped names encoded into single directory segments and covered by resolution tests.

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

Sequence Diagram(s)

sequenceDiagram
  participant PublishCommand
  participant pkg_publish
  participant PublishStaging
  participant LocalRegistry
  PublishCommand->>pkg_publish: publish package name and version
  pkg_publish->>pkg_publish: validate publication coordinates
  pkg_publish->>PublishStaging: copy allowed package contents
  PublishStaging->>LocalRegistry: rename staged version
  LocalRegistry-->>pkg_publish: reject existing version
Loading

Suggested reviewers: loreste

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: making package publication immutable.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 59 minutes.

@coderabbitai coderabbitai Bot 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.

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 `@src/pkg.rs`:
- Around line 1500-1501: Update copy_package_for_publish to inspect the manifest
with symlink_metadata before fs::copy and reject it when it is a symlink,
preserving the existing copy error handling for regular files. Add a test
covering a symlinked mako.toml manifest, including the corresponding failure
behavior.
- Around line 1463-1469: Update valid_registry_version to require strict,
canonical SemVer rather than relying solely on parse_semver, rejecting
abbreviated, prefixed, and extra-component forms such as 1, v1.2.3, and 1.2.3.4
while preserving valid canonical versions. Extend the coordinate test covering
this validation to assert these rejected cases.

In `@src/tooling.rs`:
- Around line 2455-2457: Validate registry names with valid_registry_name before
deriving cache keys or performing lookups. In src/tooling.rs lines 2455-2457,
reject invalid name values before registry_root and dep_cache_key; apply the
same validation to the effective/external registry lookup in src/pkg.rs lines
552-553, and ensure only the validated name reaches the project dependency cache
path in src/pkg.rs lines 719-722.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8aec9acf-cbd9-4733-b030-43da71b20885

📥 Commits

Reviewing files that changed from the base of the PR and between 4a62e22 and 4b4a807.

📒 Files selected for processing (6)
  • docs/CLI.md
  • docs/GUIDE.md
  • docs/book/src/ch10-packages.md
  • src/main.rs
  • src/pkg.rs
  • src/tooling.rs

Comment thread src/pkg.rs
Comment thread src/pkg.rs
Comment on lines +1500 to +1501
fn copy_package_for_publish(project: &Path, manifest: &Path, dest: &Path) -> Result<(), String> {
fs::copy(manifest, dest.join("mako.toml")).map_err(|e| format!("copy toml: {e}"))?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Reject a symlinked mako.toml before copying it.

The manifest is copied directly with fs::copy, which follows symlinks, whereas the test only covers links inside src/. Check symlink_metadata(manifest) before copying and add a manifest-symlink case.

Proposed fix
 fn copy_package_for_publish(project: &Path, manifest: &Path, dest: &Path) -> Result<(), String> {
+    let manifest_kind = fs::symlink_metadata(manifest)
+        .map_err(|e| format!("inspect {}: {e}", manifest.display()))?;
+    if manifest_kind.file_type().is_symlink() {
+        return Err(format!("refusing to publish symlink {}", manifest.display()));
+    }
     fs::copy(manifest, dest.join("mako.toml")).map_err(|e| format!("copy toml: {e}"))?;

Also applies to: 2305-2335

🤖 Prompt for 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.

In `@src/pkg.rs` around lines 1500 - 1501, Update copy_package_for_publish to
inspect the manifest with symlink_metadata before fs::copy and reject it when it
is a symlink, preserving the existing copy error handling for regular files. Add
a test covering a symlinked mako.toml manifest, including the corresponding
failure behavior.

Comment thread src/tooling.rs
@loreste
loreste merged commit 8a13941 into loreste:main Jul 19, 2026
4 of 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.

2 participants