Skip to content

Refresh or diagnose stale nested Cargo.lock files before publish preflight #61

Description

@leynos

Summary

lading publish can fail during preflight when a workspace contains tracked nested Cargo.lock files that become stale after lading bump updates package versions.

The observed failure came from rstest-bdd after bumping workspace packages from 0.5.0 to 0.6.0-beta1.

Error

Updating crates.io index                                                                                                
error: cannot update the lock file /data/leynos/Projects/rstest-bdd/crates/rstest-bdd/tests/ui_lints/Cargo.lock because 
--locked was passed to prevent this                                                                                     
help: to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.      

Cause

lading publish runs cargo test --workspace --all-targets as source-workspace preflight before staging.

In rstest-bdd, one integration test shells out to:

cargo clippy --locked --manifest-path tests/ui_lints/Cargo.toml                                                         

tests/ui_lints is a nested Cargo workspace with its own tracked Cargo.lock. After lading bump updates path dependency versions, that nested lockfile still contains the old path package versions, so Cargo needs to rewrite it. The nested test passes --locked, so Cargo aborts.

A scratch refresh showed the nested lockfile needed to update the internal path crates from 0.5.0 to 0.6.0-beta1 and add the new tracing dependency set.

Expected Behaviour

Lading should either:

  • refresh tracked lockfiles after manifest version/dependency rewrites, including nested lockfiles; or
  • fail before the full publish preflight with a targeted diagnostic naming the stale lockfile and the exact repair command.

Proposed Fix

Add lockfile handling to lading:

  1. After lading bump, discover tracked Cargo.lock files under the workspace excluding target.

  2. For each lockfile whose parent has a Cargo.toml, run:

    cargo generate-lockfile --manifest-path <parent>/Cargo.toml                                                          
    
  3. In lading publish, add a lockfile freshness validation phase before cargo test:

    cargo metadata --locked --manifest-path <parent>/Cargo.toml --format-version=1                                       
    
  4. If Cargo reports that a lockfile cannot be updated because --locked was passed, raise a PublishPreflightError with the lockfile path and the corresponding cargo generate-lockfile --manifest-path ... command.

Further Investigation

lading publish currently runs preflight before staging and patch stripping. That means preflight does not validate the exact tree later used for cargo package and cargo publish.

Investigate whether publish should be split into:

  1. verify source git cleanliness;
  2. plan and stage the workspace;
  3. apply publish-time manifest changes;
  4. refresh or validate staged lockfiles;
  5. run cargo preflight in the staged workspace;
  6. package and publish from the same staged workspace.

This would let dry-run publish repair staged lockfiles without mutating the source checkout.

No code changes were made in either repository during this investigation. The only commands with side effects were in / tmp scratch copies/logs, plus Cargo may have downloaded dependencies while checking the root metadata because the root
lockfile was already locally modified before this investigation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions