Skip to content

fix(uninstall): refuse a still-needed local dependency before any write (#4882) - #4890

Merged
Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-4882-local-shared-descendant-dev
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-4882-local-shared-descendant-dev

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

Stacked on #4870 (Fixes #4833): it contains #4870's commits until that lands, so review only the commits after fa1a547 (this fix and its changelog fragment). Land after #4870.

apm uninstall ./vendor/e, where ./vendor/e is a direct local dependency that another installed package (./vendor/d) still needs, removed only the apm.yml declaration (#4749's declaration-only path). A local lock key includes declaring_parent and anchored_local_path, so the kept row no longer matched the transitive identity install derives (local:vendor/e). apm install --frozen then failed: "local:vendor/e is declared in apm.yml but missing from apm.lock.yaml". A probe found no file deleted or kept wrongly in any follow-up (uninstall/prune, with and without reinstall). The defect was the frozen failure and lock drift.

Ruling (P3, B-safe for 0.38.0): when a still-needed root is LOCAL, uninstall refuses before any write:

[x] ./vendor/e stays: ./vendor/d still needs it; apm.yml and apm.lock.yaml were not changed.
    Uninstall the package that still needs it first, or keep the local declaration in apm.yml.

Exit 1. Remote dependencies keep the declaration-only removal. Full local re-anchoring (re-key the row, ledger owners, receipt re-binding) is tracked in #4889.

Docs:

  • reference/cli/uninstall.md: Behavior step 1.
  • apm-usage commands.md: uninstall row.

Issue and approved scope

Issue: Fixes #4882

Human scope-approval comment: P3 ruling (B-safe) relayed to Intake for the #4882 apm-scope record; see the #4882 comment linking #4889.

Does this PR complete the issue, or what remains? It completes the 0.38.0 scope (refusal). Full local re-anchoring remains in #4889.

apm-spec-waiver: uninstall refuses a still-needed local dependency before any write; no OpenAPM-observable behaviour changes

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)
promise: P-INV-I3 / I7 -- install --frozen keeps passing; a refused command preserves state (source: .agents/skills/apm-lifecycle-tests/SKILL.md)
cell: OP=uninstall SRC=local LOCK=consistent GRAPH=direct ./vendor/e also needed by dev ./vendor/d   owner: commands/uninstall/cli.py (_split_still_needed_packages) on install/orphans.py decision
instrument: today test -> tests/integration/test_uninstall_shared_direct_dependency_lifecycle.py::test_uninstall_refuses_a_local_dependency_another_package_still_needs (extends the module)
oracles: [I3, I7, snapshot-absence]  decisive: exit 1 with the refusal + remedy lines, tree digest unchanged, then install --frozen exit 0
failing-before: CI=true pytest <node> -n 0 -> 1 failed (uninstall exited 0, removed ./vendor/e from apm.yml)
passing-after: CI=true module + test_uninstall_engine_validation + test_uninstall_shared_diamond_dependency + test_uninstall_transitive_cleanup + install/test_orphan_removal_owner + test_uninstall_local_survivor_source_lifecycle, -n 2 -> 65 passed
guard+mutation: n/a     ledger: 4882
hints executed: the remedy is prose (no apm command printed)

Lint chain (local), all clean:

  • ruff check / format --check (0.15.12)
  • lint_architecture_boundaries.py --root .
  • pylint R0801
  • lint-auth-signals
  • complexity ratchet
  • tests.quality.taxonomy --changed
  • check_test_assertions.py
  • tests.lifecycle.generator --check

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

Keeping a direct LOCAL dependency that another installed package still
needs changes its lock identity (local keys include declaring_parent and
anchored_local_path), which uninstall cannot re-key yet; the declaration-
only removal left a lockfile that apm install --frozen rejected. Uninstall
now refuses before any change, names the package that still needs it and
how to proceed. Remote dependencies keep the declaration-only removal
(#4749). Full local re-anchoring is tracked in #4889.

Fixes #4882

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 01:44

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.

🟡 Changes recommended

The uninstall refusal occurs after pre-uninstall hooks, allowing a hook to modify the manifest, lockfile, or deployed files before the command fails and claims the manifest and lockfile were unchanged.

1 open issue
What changed in this PR

This PR adds a safety refusal for uninstalling a local dependency that another installed package still needs, avoiding lock identity drift and subsequent frozen-install failures. It is stacked on #4870, which repairs retained dependencies’ metadata graph-wide; full local re-anchoring remains deferred to #4889.

Changes:

  • Adds a local-dependency refusal with an explanation and recovery guidance, while preserving remote declaration-only removal.
  • Adds regression coverage for unchanged project state and a successful subsequent frozen install.
  • Updates uninstall documentation and records the fixes in changelog fragments and lifecycle bug ledgers.
File Description
tests/​integration/​test_uninstall_shared_direct_dependency_lifecycle.py Adds local-refusal coverage and stacked graph-metadata regressions.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4882.json Records the local-refusal regression and protected properties.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4833.json Records the stacked graph-metadata regressions.
src/​apm_cli/​install/​orphans.py Carries graph-wide metadata repairs from #4870.
src/​apm_cli/​deps/​reachability.py Computes graph-wide shortest depths and parent relationships.
src/​apm_cli/​commands/​uninstall/​cli.py Adds local refusal and applies retained-row metadata repairs.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Documents the local-dependency exception.
docs/​src/​content/​docs/​reference/​cli/​uninstall.md Explains refusal behavior and the removal remedy.
changelog.d/​4890.fixed.md Announces the local-dependency refusal.
changelog.d/​4870.fixed.md Announces the stacked metadata repair.

Review effort: Balanced

Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
…nstall scripts run

The refusal ran after the pre-uninstall lifecycle scripts, so a trusted
script could write before uninstall exited 1 saying nothing changed. The
removal split (and its refusal) now runs before the scripts fire; it
repeats after them, since scripts may edit apm.yml. Red-first cell: a
trusted pre-uninstall script writing a marker; the marker existed before
the fix and the tree is byte-identical after.

Co-authored-by: Copilot App <[email protected]>

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.

🟡 Changes recommended

Uninstall can bypass dependency protection and run hooks when only apm_modules/ is missing, and refusal messages can expose machine-specific parent paths.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Use portable labels for local parent paths

src/​apm_cli/​commands/​uninstall/​cli.py:154

When the surviving local parent was declared with an absolute, Windows-drive, or ~ path, this prints that machine-specific path in the refusal. This bypasses uninstall's path-safe label contract (engine.py:204-218), covered by tests/unit/commands/test_uninstall_atomic_selection.py:233-273. Route the parent through _dependency_public_label so relative declarations remain readable while machine-specific paths use the portable package key.

1 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/commands/uninstall/cli.py Resolved

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.

🟡 Changes recommended

The uninstall refusal exposes machine-specific paths for surviving local parents declared with absolute or home-relative paths, violating the portable diagnostic contract instead of using _dependency_public_label.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
Copilot review on #4890: the still-needed local refusal printed the
absolute local_path of the parent. Use the public dependency label.

Co-authored-by: Copilot App <[email protected]>

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.

🔵 Needs a closer look

Human assessment is needed because a post-hook uninstall refusal can incorrectly claim that apm.yml is unchanged even when the hook edited it.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 22d0017 into main Nov 23, 2026
74 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4882-local-shared-descendant-dev branch November 23, 2026 08:00
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Move the #4678, #4890, #4892, #4912 and #4934 lines into [0.38.1]: they merged before the v0.38.1 tag and shipped in it. [0.38.2] keeps #4920.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants