Skip to content

fix(uninstall): refuse before any change when a file lacks deletion evidence (#3701) - #4294

Merged
Daniel Meppiel (danielmeppiel) merged 719 commits into
mainfrom
danielmeppiel-uninstall-evidence-refusal
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 719 commits into
mainfrom
danielmeppiel-uninstall-evidence-refusal

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Steward ruling on the #4049 uninstall behavior: the refusal is intended and keeps exit 1, because an edited lock must never authorize deleting user bytes. This PR meets the ruling's conditions.

  1. Nothing changes on refusal. Uninstall used to discover a missing-evidence file during target cleanup, after removing package sources and while rewriting apm.lock.yaml. It now asks the evidence owner up front. Right after preparing deletion evidence, and before touching apm_modules/, apm.yml or apm.lock.yaml, _refuse_uninstall_without_evidence lists every file the uninstall would delete: claims of the removed packages and projected orphans, minus files survivors still claim, root-local files and preserved profile values. It then calls DeploymentEvidence.refusals(). Any file without evidence (edited, unproven or unreadable) stops the uninstall with exit 1; staged local refreshes are cleaned up and nothing else is written. The existing post-cleanup abort stays as a backstop for races.

  2. The message names every file and the reason, plus two runnable remedies. Both are defined once in the cleanup owner (refusal_reason, uninstall_evidence_remedies):

    No force flag exists on apm uninstall, so per the ruling no flag is added. The explicit consent path for offline sources is a 0.38 follow-up for the PM to file.

  3. Installed-CLI tests.

    • test_uninstall_refusal_changes_nothing_and_its_remedy_runs creates receipts through the CLI and seeds a user edit. It evicts machine state and makes the source unreachable, then asserts the refusal leaves the whole tree byte-identical, including apm_modules/, apm.yml and apm.lock.yaml, and that it names every file and both remedies.
    • The same test then EXECUTES remedy (a): it restores the source, runs apm install, then apm uninstall. The edited file is still refused and named "edited since APM deployed it", with nothing changed. After the documented manual step (move it aside), uninstall completes and the user's bytes survive.
    • Updated to the new contract: test_pre_receipt_uninstall[unavailable], test_unhashed_lock_claims_never_delete_user_files, and test_refused_uninstall_lock_claims_only_files_on_disk. The last one now asserts lock, manifest and tree are unchanged on refusal; the old contract dropped removed files from the lock.
  4. Docs. The CHANGELOG gains an upgrade note ("After upgrading, apm uninstall needs deployment evidence..."). The uninstall reference and the apm-guide commands.md row are updated.

Issue and approved scope

Issue: Fixes #4451, fixes #4467; Refs #3701 (Part of #3701)

Human scope-approval comment: #3701 (comment). The steward ruling was relayed by the 0.37 Hardening PM.

Does this PR complete the issue, or what remains? Remaining: the 0.38 consent flag for offline or deleted sources (to be filed by the PM).

Type of change

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

Testing

  • Tested locally. Static gates only: ruff, architecture linter (--root ., clean), complexity ratchet (clean), pylint R0801 (10.00), auth-signal lint. This host runs no tests; the full-integration label is requested.
  • All existing tests pass (CI)
  • Added tests for new functionality (if applicable)

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md (upgrade notes).

Spec conformance (OpenAPM v0.1)

  • N/A -- the behavior is req-lk-024's existing "kept with a diagnostic" outcome. Only the refusal moves earlier, and no requirement text changes.

#4451 fold

DeploymentEvidence.refusals also refuses a member of a claimed directory that was replaced by a symlink. Cleanup keeps such a directory, so without this check uninstall removed the package's apm_modules copy and then exited 1. Managed final symlinks outside claimed directories keep their unlink rule (unit: test_refusals_name_a_symlinked_member_of_a_claimed_directory).

The installed-CLI test_integrity_row[I|path-containment|uninstall-prune|disk-or-cache] was a strict expected failure on main and is now required. It asserts:

  • exit 1;
  • the "replaced by a symbolic link" reason and the printed next step;
  • apm_modules, apm.yml, the lockfile and the skill directory are byte-identical.

Local: test_integrity 89 passed, 15 xfailed.

#4467 and train-2 delta (head 6807592)

Local: lint chain clean (ruff 0.15.12 check and format, pylint R0801 10.00, auth signals, complexity ratchet). Both uninstall-prune cells pass. The remedy test passes.

Agent note, not authored by Daniel.

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

Evidence preflight occurs after potentially mutating steps and omits shrinking survivor selections and hash-tracked skill assets, allowing uninstall to remove files or rewrite apm.yml before detecting missing evidence or edits.

3 open issues
What changed in this PR

This PR moves uninstall’s deployment-evidence check earlier to prevent partial removal when tracked files cannot safely be deleted, supporting the cleanup protections introduced for #3701.

Changes:

  • Adds an evidence preflight with per-file refusal reasons and recovery instructions.
  • Expands installed-CLI tests to check unchanged files on refusal and exercise recovery steps.
  • Documents the intended refusal behavior and upgrade implications.
File Description
tests/​integration/​test_uninstall_refusal_lockfile_truth_lifecycle.py Asserts manifest, lockfile, and tree remain unchanged on refusal.
tests/​integration/​test_stale_cleanup_hash_authority_lifecycle.py Updates the expected refusal message.
tests/​integration/​test_cleanup_deployment_evidence_lifecycle.py Adds unchanged-state and recovery lifecycle coverage.
src/​apm_cli/​integration/​cleanup.py Adds evidence refusal queries, reasons, and remedies.
src/​apm_cli/​commands/​uninstall/​cli.py Checks deletion evidence before package removal.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Updates the uninstall behavior reference.
docs/​src/​content/​docs/​reference/​cli/​uninstall.md Documents early refusal and recovery options.
CHANGELOG.md Adds an uninstall deployment-evidence upgrade note.

Review effort: Balanced

Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
Comment thread src/apm_cli/integration/cleanup.py Resolved
…pack line

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

# Conflicts:
#	tests/fixtures/lifecycle_bug_ledger.json
…ns; name every credential tried

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

# Conflicts:
#	src/apm_cli/core/auth.py
#	src/apm_cli/marketplace/version_pins.py
#	tests/fixtures/lifecycle_bug_ledger.json
…oject and user scope

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…le lacks deletion evidence (#3701)

Co-authored-by: Copilot App <[email protected]>
…er match without a local receipt; cleanup retains files the install kept

Co-authored-by: Copilot App <[email protected]>
The pre-download frozen MCP check stays silent (the hydrated check and the
MCP phase report parked servers); the commit gate does not repeat the org
policy discovery notice. An install refuses a symlinked lockfile only
when it adds or removes a dependency or updates refs, so an unchanged
install still reads through it.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Register update's provenance re-verification write as a commit site of the
lockfile write authority, and name the install-writes-lockfile decision in
one helper the preflight guard reads.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…touched (#4318)

apm update refreshes apm.yml dependencies only. With a local bundle
installed it now names the bundle (from its hook ownership markers and
compile staging slugs, else its file count) and gives the runnable next
step: apm install <newer-bundle-file>. The lifecycle generator's strict
cell rule|U8|update-leaves-a-local-bundle-untouched becomes required.

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

`apm install --frozen --global` now checks each locked native plugin root
against its recorded fingerprint in the frozen hash verification, before any
write. A mismatch exits 1 naming the plugin, the expected and observed
digests and `apm install --global`, as `apm audit --ci` reports it; nothing
is written. A plain install that restores a changed root prints a [!] line.

The lifecycle I1 oracle treats a path under a native_plugin root as recorded
only when the same lock records that root, the observation is user scope and
the tree carries the record's fingerprint. Four gate cells become required;
six org-policy cells stay strict under #3703.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…hor citations (#3701)

test_integrity's git-skill-hash uninstall-prune/disk-or-cache cell now
expects the preflight refusal (exit 1, nothing removed). The symlinked
member cell (path-containment) stays strict: the preflight skips final
symlinks by design, so that uninstall still removes package sources
before refusing. Generator citations follow uninstall/cli.py.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…--ci, install, --frozen and update

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

# Conflicts:
#	tests/integration/test_trust_integrity_consistency_lifecycle.py
…pies that match the lock

Co-authored-by: Copilot App <[email protected]>
A parked local bundle's record (#4221) lives under apm_modules/; prune now
reads a directory without packages as empty. The needle for the bundle
approval-key guard follows the key's helper, and the strict cells for
#4169 and #4214 are removed now that both hold.

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

# Conflicts:
#	src/apm_cli/commands/install.py
#	src/apm_cli/install/phases/resolve.py
#	tests/fixtures/lifecycle_bug_ledger.json
#	tests/lifecycle/generator/rules.py
#	tests/quality/lifecycle_obligations.json
#	tests/utils/lifecycle_evidence.py
generated_obligations.json drifted when journey known cells were dropped
without --write. Regenerate it and add a test that runs the witnesses
check, so a stale file fails CI.

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

# Conflicts:
#	src/apm_cli/install/service.py
#	tests/fixtures/lifecycle_bug_ledger.json
…robe cannot read the config (#4390)

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

# Conflicts:
#	tests/fixtures/lifecycle_bug_ledger.json
At user scope the install gate discovers org policy from APM_HOME, never
from the HOME repository's remote (#4087). The frozen stale-decision check
and the retired-hook naming discovered from the deploy root (HOME), so a
HOME remote's org-deny made --frozen refuse a hook the gate still deployed
(GATE user spine). Both now discover from manifest_root, as the gate does.
E01 step 4's check count follows exec-status-current.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…; one row re-keyed to #4443

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

# Conflicts:
#	tests/quality/generated_obligations.json
… on a terminal and honors NO_COLOR

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

# Conflicts:
#	tests/fixtures/lifecycle_bug_ledger.json
#	tests/utils/lifecycle_evidence.py
…fusals as [x] errors

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

# Conflicts:
#	src/apm_cli/commands/update.py
#	tests/lifecycle/generator/rules.py
…acts module

tests/quality/test_generated_obligations.py is not in any CI job's file
list; test_promise_obligations.py runs in Architecture Ratchet Contracts.

Co-authored-by: Copilot App <[email protected]>
native.py keeps every strict cell still failing on the merged tree: the
re-keyed #4444/#4445/#4446/#4447 rows and the train #3703 native-plugin
rows; the #4154 and #4225 cells whose fixes are in are dropped (35 native
rows: 23 pass, 12 strict xfail).

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot App <[email protected]>

# Conflicts:
#	tests/lifecycle/machines/test_m_source.py
#	tests/lifecycle/security/gate_slices/bin.py
…ble next step

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

# Conflicts:
#	tests/quality/generated_obligations.json
…nt promise ids

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

# Conflicts:
#	tests/quality/generated_obligations.json
…link (#4451)

Cleanup keeps a claimed skill directory that holds a symlink, so
uninstall removed the package's apm_modules copy and then exited 1. The
evidence preflight (DeploymentEvidence.refusals) now refuses a symlinked
member of a claimed directory up front, naming it and the next step.
Managed final symlinks outside claimed directories keep their unlink
rule. test_integrity's path-containment uninstall cell flips to
required: exit 1, the reason and next step, and apm_modules, apm.yml,
the lockfile and the skill directory byte-identical.

Fixes #4451

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

# Conflicts:
#	tests/fixtures/lifecycle_bug_ledger.json
#	tests/lifecycle/generator/rules.py
#	tests/lifecycle/security/test_integrity.py
#	tests/unit/integration/test_cleanup_helper.py
Train-2 merged and resolved (integrity cells use the refusal oracle;
both sides of cleanup_helper tests kept). Open: test_integrity on the
merged tree showed 6 failures and 6 strict XPASS in train-2 cells
(bundle hook retire, policy cache pin) not yet triaged.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
With #4360 on the base, install keeps an edited managed file instead of
rewriting it, so remedy (a) no longer needs to move files aside first.
The remedy test executes it as printed: install keeps and names the
edited file (exit 1), uninstall still refuses only that file and changes
nothing, and after the documented manual step uninstall completes with
the user's bytes intact. Docs and the apm-guide row follow.

Co-authored-by: Copilot App <[email protected]>
Steward ruling: a printed remedy must converge when executed literally.
Install keeps an edited file (#4360) and exits 1, so remedy (a) moves files
holding edits aside first; the remedy test runs it in printed order (move
aside, install exit 0, uninstall exit 0, user bytes preserved).

This reverts commit 6807592.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit b8e2416 into main Nov 21, 2026
4 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-uninstall-evidence-refusal branch November 21, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-integration Run the full integration suite (ci-integration.yml) on this PR before merge

Projects

None yet

2 participants