Skip to content

Fix Cargo hosted workspace redirects - #256

Open
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
codex/cargo-hosted-workspace-fixes
Open

Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
codex/cargo-hosted-workspace-fixes

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Codex:gpt-6-astra

Hosted Cargo patches incorrectly reject workspace-inherited dependency aliases and can mistake an editable local package for a different version outside the project. Quoted dependency values and annotated registry tables also bypass parts of the rewriter, leaving declarations unpatched or producing duplicate TOML tables on reruns.

Root Cause

Workspace references were filtered by their local alias before resolving the root definition. The lockfile ownership guard compared only package names. Several source-preserving TOML readers recognized fewer valid string and table-header forms than Cargo accepts.

Fix

  • Resolve workspace aliases before matching the patched crate, including normal, dev, build, and target declarations.
  • Match local lockfile owners by name and version, including inherited workspace versions and Cargo's default version.
  • Validate proposed manifests against parsed TOML and refuse any matching declaration left unpinned, including legal root/target/workspace dotted and inline forms.
  • Recognize literal-string dependency aliases and quoted or annotated registry tables; preserve healthy configuration on repeated application.

Testing

  • Regression tests added.
  • 73 Cargo redirect Rust unit tests passed.
  • CLI built with cargo build --locked -p socket-patch-cli.
  • Full workspace Clippy passed with cargo clippy --workspace --all-features -- -D warnings.
  • Real depscan converter, PostgreSQL, object store, registry server, and API end-to-end tests passed: direct and workspace projects across hosted, vendored service, and vendored build modes.
  • Fresh Cargo caches, locked offline execution of a patch-only function, byte-exact hosted downloads, idempotence, quoted/commented configuration, revert, tampered archive rejection, outside-path refusal, and legacy rows without index metadata all passed.
  • Changed Rust file passes rustfmt and diff whitespace checks.

Public Changelog

Hosted Cargo patches now handle inherited workspace aliases and annotated registry configuration correctly, and safely refuse dependencies outside the editable project.

Checklist

  • Is PR safe to revert (yes/no)?: Yes.

Companion to SocketDev/depscan#26792. Based on the current main commit 2390c5ff784d2a0fbca5fd13f9dff83752b7615a.


Note

Medium Risk
Changes core Cargo.toml/Cargo.lock rewrite logic for hosted patches; mistakes could block valid redirects or still miss edge-case declarations, but failures are fail-closed with warnings rather than silent partial writes.

Overview
Hosted Cargo registry redirects are tightened so workspace aliases, lockfile ownership, and TOML edge cases no longer produce partial or wrong pins.

After plan_cargo_toml, a new validate_cargo_toml_pins pass parses the planned manifest and refuses the whole dependency if any matching declaration (root dotted forms, target.*, workspace.dependencies, workspace-inherited keys) is still unpinned—replacing behavior that could skip garbage lines and leave a partial redirect.

Workspace inheritance is resolved by alias/key before deciding whether an entry targets the patched crate (CargoWorkspaceEntry::OtherPackage, NeedsWorkspacePin for workspace = true in table blocks). Lock transitive checks now treat “pinned” local packages as (name, version) via cargo_manifest_package_id, including workspace-inherited versions and Cargo’s default 0.0.0.

TOML handling moves from narrow regexes to toml_edit-based string/inline parsing for registry pins, renames, and .cargo/config registry blocks (quoted headers, single-quoted values, comments). Malformed manifests that fail validation now emit redirect_cargo_toml_dep_unrewritable instead of best-effort partial rewrites.

Extensive regression tests cover partial-redirect refusal, renamed workspace deps, literal-string forms, and name+version lock matching.

Reviewed by Cursor Bugbot for commit a156d87. Configure here.

Resolve inherited dependency aliases through their workspace definitions
and match local lockfile owners by both package name and version. This
allows valid workspace patches while refusing consumers outside the
editable project.

Read quoted dependency values and annotated registry tables consistently
so repeated application cannot leave an alias unpatched or create an
invalid duplicate TOML table.

Validated with 70 Cargo redirect unit tests and real service-backed
hosted, vendored service, and vendored build installs using fresh Cargo
caches, locked offline builds, integrity rejection, and revert.

Assisted-by: Codex:gpt-6-astra
Validate planned dependency pins against parsed TOML before writing any
files. Legal root and target dotted or inline declarations that the
source-preserving editor cannot rewrite now refuse the entire patch
instead of leaving a mixture of original and patched sources.

Validate unchanged member manifests too, while preserving workspace
inheritance and declarations for other package versions. Malformed TOML
is refused without changing the project.

Validated with 73 Cargo unit tests and the real converter/API/CLI matrix,
including an actual Cargo build proving the dotted manifest is valid
and remains byte-identical after refusal.

Assisted-by: Codex:gpt-6-astra
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Claude (@claude) review

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

BugBot review

Combine identical refusal branches for dotted dependencies without
changing which declarations are refused. Full workspace Clippy and all
73 Cargo redirect tests pass.

Assisted-by: Codex:gpt-6-astra

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a156d87. Configure here.

This branch has not been deployed

No deployments
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