Skip to content

[0.38] feat(uninstall): --trust-lockfile consent path for offline or deleted sources (#4295) - #4603

Closed
Daniel Meppiel (danielmeppiel) wants to merge 4 commits into
danielmeppiel-fuzzy-fishstickfrom
danielmeppiel-fuzzy-fishstick-4295
Closed

Daniel Meppiel (danielmeppiel) wants to merge 4 commits into
danielmeppiel-fuzzy-fishstickfrom
danielmeppiel-fuzzy-fishstick-4295

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

Stacked on #4588 (#4313). The base branch is danielmeppiel-fuzzy-fishstick until #4588 lands; then this PR rebases onto main. Both PRs extend _refuse_uninstall_without_evidence.

This PR adds apm uninstall --trust-lockfile, an explicit, per-invocation consent path for when deployment evidence is missing because no locked render can be produced (the source is offline, private or deleted, and the checkout and cache are gone) and no receipt exists.

  • One decision, in the canonical owner. DeploymentEvidence.lockfile_consentable (src/apm_cli/integration/cleanup.py, owner file-level-deploy-sync-cleanup) is true only when all four hold:

    • receipt state was read without error and holds no receipt for the file;
    • no render of its owning locked package could be produced (_rendered_roots is empty);
    • its compute_file_hash (req-lk-012 domain) equals the single hash apm.lock.yaml records for that path under its owners (ledger rows plus deployed_file_hashes; none or conflicting means keep);
    • the file is a regular, readable, non-symlinked file.

    verdict() consults it only after consent_to_lockfile_hashes(), so the same decision drives the refusal check (refusals) and both deletion sites. It is rechecked at removal, and install and prune never call it.

  • Without the flag, the exit code and filesystem effects are exactly 0.37's. The refusal now marks each file --trust-lockfile would delete it or kept even with --trust-lockfile. It offers UNINSTALL_EVIDENCE_TRUST_LOCKFILE (src/apm_cli/core/remediation.py) as a third remedy only when at least one file is deletable.

  • With the flag, every refused file that is not consentable is kept and named by the existing kept-file warnings. _abort_if_retained_target_cleanup_paths ignores those kept files and the skill directories holding them, so kept files do not fail the command; every existing failure exit still applies. Each consented deletion prints Deleted <path> (matched its apm.lock.yaml hash; --trust-lockfile).

  • Spec: proposed amendment OpenAPM 0.1.75 revises req-lk-024 in place with the per-invocation consent exception and adds no statement. It is in its own commit (spec(openapm): 0.1.75 ...). It touches Section 5.2, Section 10.7, Appendix C, Appendix D, the requirements manifest, tests/spec_conformance/test_deletion_evidence_reqs.py and CONFORMANCE. It needs normal spec review: run the apm-spec-guardian advisory panel.

Issue and approved scope

Issue: Fixes #4295

Human scope-approval comment: #4295 (comment) (the amended record, which supersedes #4295 (comment)). Governance eligibility: record-present, contact_confirmation_needed: false.

Does this PR complete the issue? Yes. It does not cover the following, which are out of scope: changing the default refusal, a lockfile hash authorizing deletion without the flag or over contrary evidence, apm prune and install cleanup, an interactive prompt, a --dry-run preview, a config or env equivalent, and deleting files the lockfile does not record. --yes and --force never imply the flag: uninstall has neither option, and only --trust-lockfile calls consent_to_lockfile_hashes().

Decisions (taken as recommended defaults, per rule S15):

Type of change

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

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Done-when: new module tests/integration/test_uninstall_trust_lockfile_lifecycle.py.

  • It runs at project scope and at user scope (-g). After install, the receipts are removed, the checkout and cache are removed, and the origin repository is moved away.
  • apm uninstall pkg refuses with exit 1, changes nothing (apm.yml, apm.lock.yaml and the skills tree are byte-identical) and previews each file. The flag is offered as the last remedy.
  • --trust-lockfile exits 0, deletes and prints beta and gamma, keeps and names the edited alpha, and removes the package from apm.yml and apm.lock.yaml. apm audit --ci then passes or reports only the kept file.
  • Negative controls:
    • With the source reachable, a lockfile row claiming a user-authored file with its matching hash keeps the file.
    • A file whose receipt and render both differ is kept.
    • Unreadable receipt state deletes nothing.

Red on main: on origin/main f8c31a5 the project cell fails at the refusal preview assertion (no --trust-lockfile marks; all three files refused as unproven), and every --trust-lockfile invocation fails with click's no-such-option error. Green on head: APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm uv run --frozen --extra dev pytest tests/integration/test_uninstall_trust_lockfile_lifecycle.py gives 5 passed.

Local evidence:

  • uv run --frozen --extra dev pytest tests/unit/integration/test_cleanup_helper.py -k trust_lockfile: 4 passed (single matching hash, conflicting hashes, no hash, unreadable receipt state, and a recheck after edit).
  • uv run --frozen --extra dev pytest tests/spec_conformance/test_deletion_evidence_reqs.py: 9 passed (req-lk-024 consent exception oracles).
  • tests/unit/core remediation catalog and block proofs: passed. tests/lifecycle/generator/test_generator_rules.py: 28 passed (line anchors updated).
  • Gates passed: ruff check and ruff format --check, pylint R0801, lint-auth-signals, lint_architecture_boundaries.py --root . (exit 0), complexity ratchet vs origin/main, check_test_assertions, tests.quality.taxonomy --changed (6 modules carry their marker and promise), check_taxonomy_allowances, spec orphan_check (151 aligned), the Mode B detector (spec-concurrent edit; orphan_check owns it), and gen_statement (CONFORMANCE committed in the spec commit).
  • uv run --frozen --extra dev pytest -n 2 tests/quality tests/integration/test_architecture_owner_rule_mutations.py: 1725 passed. One xdist worker crashed under memory pressure on transport-platform-credential-report-owner; that case passes when rerun alone.
  • tests/quality/test_cli_docs_surface.py: 12 passed.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md:
    user-visible effect first, 25 words or fewer, ending with (#PR);
    breaking changes only under upgrade notes; no Highlights; see
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated (req-lk-024 prose, Section 10.7, Appendix C note, Appendix D 0.1.75 row).
  • Manifest edit: docs/public/specs/manifests/openapm-v0.1.requirements.yml updated (req-lk-024 notes).
  • Test edit: @pytest.mark.req("req-lk-024") cases added in tests/spec_conformance/test_deletion_evidence_reqs.py.
  • CONFORMANCE.{md,json} regenerated via uv run --extra dev python -m tests.spec_conformance.gen_statement and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

…evidence (#4295)

When no receipt exists and no locked render can be produced (source
offline, private or deleted; checkout and cache gone), `apm uninstall
--trust-lockfile` deletes a refused file only when its bytes equal the
single hash apm.lock.yaml records for it under its owner, prints each
deleted path, and keeps and names every other file without failing.
It never overrides a differing receipt or render, a render lacking the
path, conflicting or missing recorded hashes, unreadable receipt state,
unreadable or symlinked files.

One decision in DeploymentEvidence (lockfile_consentable) drives the
refusal preview and the deletion, rechecked at removal. Without the flag
the exit code and filesystem effects are unchanged; the refusal now marks
each file as deletable or kept under the flag and offers the flag only
when at least one file is deletable.

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

Proposed amendment 0.1.75 revises req-lk-024 in place: on an uninstall the
user explicitly consents to, a file with no local deployment record (read
without error) and no producible render of its owning locked dependency
MAY be deleted when its req-lk-012 content hash equals the single hash the
lockfile records for that path under its owner, rechecked before removal,
and each deletion is named. Contrary or missing evidence always keeps the
file; consent is never implied by another option or configuration. Adds no
statement. Sections 10.7, Appendix C and D, the requirements manifest,
conformance tests and CONFORMANCE are updated.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-fuzzy-fishstick-4295 branch from e9bbf14 to f41c4d4 Compare November 21, 2026 12:34
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…evidence (#4295)

When no receipt exists and no locked render can be produced (source
offline, private or deleted; checkout and cache gone), `apm uninstall
--trust-lockfile` deletes a refused file only when its bytes equal the
single hash apm.lock.yaml records for it under its owner, prints each
deleted path, and keeps and names every other file without failing.
It never overrides a differing receipt or render, a render lacking the
path, conflicting or missing recorded hashes, unreadable receipt state,
unreadable or symlinked files.

One decision in DeploymentEvidence (lockfile_consentable) drives the
refusal preview and the deletion, rechecked at removal. Without the flag
the exit code and filesystem effects are unchanged; the refusal now marks
each file as deletable or kept under the flag and offers the flag only
when at least one file is deletable.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…eption (#4295)

Proposed amendment 0.1.75 revises req-lk-024 in place: on an uninstall the
user explicitly consents to, a file with no local deployment record (read
without error) and no producible render of its owning locked dependency
MAY be deleted when its req-lk-012 content hash equals the single hash the
lockfile records for that path under its owner, rechecked before removal,
and each deletion is named. Contrary or missing evidence always keeps the
file; consent is never implied by another option or configuration. Adds no
statement. Sections 10.7, Appendix C and D, the requirements manifest,
conformance tests and CONFORMANCE are updated.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…evidence (#4295)

When no receipt exists and no locked render can be produced (source
offline, private or deleted; checkout and cache gone), `apm uninstall
--trust-lockfile` deletes a refused file only when its bytes equal the
single hash apm.lock.yaml records for it under its owner, prints each
deleted path, and keeps and names every other file without failing.
It never overrides a differing receipt or render, a render lacking the
path, conflicting or missing recorded hashes, unreadable receipt state,
unreadable or symlinked files.

One decision in DeploymentEvidence (lockfile_consentable) drives the
refusal preview and the deletion, rechecked at removal. Without the flag
the exit code and filesystem effects are unchanged; the refusal now marks
each file as deletable or kept under the flag and offers the flag only
when at least one file is deletable.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…eption (#4295)

Proposed amendment 0.1.75 revises req-lk-024 in place: on an uninstall the
user explicitly consents to, a file with no local deployment record (read
without error) and no producible render of its owning locked dependency
MAY be deleted when its req-lk-012 content hash equals the single hash the
lockfile records for that path under its owner, rechecked before removal,
and each deletion is named. Contrary or missing evidence always keeps the
file; consent is never implied by another option or configuration. Adds no
statement. Sections 10.7, Appendix C and D, the requirements manifest,
conformance tests and CONFORMANCE are updated.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…4295)

0.1.75 is claimed by #4001 (req-pl-022) and 0.1.74 by #4559.

Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Superseded by #4650 (same commits ported, spec amendment renumbered to 0.1.76, changelog moved to changelog.d).

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…evidence (#4295)

When no receipt exists and no locked render can be produced (source
offline, private or deleted; checkout and cache gone), `apm uninstall
--trust-lockfile` deletes a refused file only when its bytes equal the
single hash apm.lock.yaml records for it under its owner, prints each
deleted path, and keeps and names every other file without failing.
It never overrides a differing receipt or render, a render lacking the
path, conflicting or missing recorded hashes, unreadable receipt state,
unreadable or symlinked files.

One decision in DeploymentEvidence (lockfile_consentable) drives the
refusal preview and the deletion, rechecked at removal. Without the flag
the exit code and filesystem effects are unchanged; the refusal now marks
each file as deletable or kept under the flag and offers the flag only
when at least one file is deletable.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…eption (#4295)

Proposed amendment 0.1.75 revises req-lk-024 in place: on an uninstall the
user explicitly consents to, a file with no local deployment record (read
without error) and no producible render of its owning locked dependency
MAY be deleted when its req-lk-012 content hash equals the single hash the
lockfile records for that path under its owner, rechecked before removal,
and each deletion is named. Contrary or missing evidence always keeps the
file; consent is never implied by another option or configuration. Adds no
statement. Sections 10.7, Appendix C and D, the requirements manifest,
conformance tests and CONFORMANCE are updated.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…4295)

0.1.75 is claimed by #4001 (req-pl-022) and 0.1.74 by #4559.

Supersedes: #4603
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
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.

1 participant