Skip to content

fix(prune): preserve case-equivalent GitHub dependencies (supersedes #3158) - #3241

Merged
Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-publish-prune-fix-successor
Oct 15, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-publish-prune-fix-successor

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

fix(prune): preserve case-equivalent GitHub dependencies

Description

TL;DR

Prune now keeps an installed GitHub dependency when only its owner/repository casing changes in apm.yml, without renaming its directory. Distinct repositories under case-variant owner prefixes remain valid; genuinely duplicate complete paths stop cleanup with a path-specific error. This supersedes #3158, preserving Shaurya Saria (@icecold009)'s original fix and adding scoped diagnostic, regression, documentation, and review follow-ups.

Important

Original contributor commit c347ee3d5dbea58b2ad984b90af96d5559d536af is preserved unchanged, not squashed or recreated. #3158 remains open pending a separate maintainer handoff decision. This PR does not authorize a merge.

Problem (WHY)

The issue and human review are the canonical task evidence. Validation below follows the Agent Skills guidance to "Read agent execution traces, not just final outputs.", rather than treating the earlier advisory or passing eligibility check as runtime proof.

Approach (WHAT)

  • Opt only prune into complete-path matching within the existing host-aware materialization owner; retain strict prefix checks for relocation.
  • Use the same expected-path calculation for declarations and lock-retained transitive dependencies.
  • Preserve host-sensitive, alias, local-path, and in-repository path casing rules.
  • Report MaterializationPathCollisionError separately and refuse cleanup before any removal.
  • Carry forward contributor history, add provenance credit, and append the authorized bounded review fold without rewriting commits.

Implementation (HOW)

File Change
src/apm_cli/commands/_helpers.py Add an opt-in expected-path lookup using the cached reader and complete-path selection; default consumers are unchanged.
src/apm_cli/commands/prune.py Enable that lookup for prune and surface ambiguity without the manifest-parse prefix.
src/apm_cli/models/dependency/materialization.py Opt-in traversal advances matching prefixes to complete candidates, then reuses the existing selection/collision authority. Strict default traversal is unchanged.
tests/helpers/prune_casing.py Share package/orphan fixtures, byte snapshots, and an explicitly simulated case-sensitive reader.
tests/unit/test_prune_casing.py Exercise casing directions, dry-run/real cleanup, lock/no-lock, transitives, opt-in behavior, casing boundaries, and collision diagnostics.
tests/integration/test_prune_casing_cli.py Run both modes through the isolated installed-Python CLI, including native case-distinct directories; schedule all six cases in required Linux lifecycle smoke.
tests/unit/models/test_dependency_materialization.py Protect strict default collision behavior and cached directory reads in both lookup modes.
docs/src/content/docs/reference/cli/prune.md Explain case-preserving matching, unchanged boundaries, and ambiguity recovery.
packages/apm-guide/.apm/skills/apm-usage/commands.md Keep the packaged prune command description consistent with the reference.

No CHANGELOG edit is carried; this remains the approved #3034 bug-fix scope.

Diagram

Complete-path lookup preserves spelling and accepts distinct repositories; duplicate full paths stop orphan cleanup. Dashed nodes mark the changed behavior.

flowchart LR
    subgraph Selection["Expected installed paths"]
        P["prune"] --> E["_build_expected_install_paths<br/>preserve_installed_case=True"]
        E --> G{"No alias and case-insensitive repo identity?"}
        G -->|Yes| M["Canonical materialization matcher<br/>match_complete_path=True"]
        G -->|No| D["Declared install path"]
        M -->|"Unique existing path"| C["Preserve installed spelling"]
        M -->|"No existing path"| D
    end
    subgraph Outcome["Prune outcome"]
        C --> O["_find_orphaned_packages"]
        D --> O
        O --> R["Preview or remove only orphan roots"]
        M -->|"Duplicate full paths"| X["Report MaterializationPathCollisionError<br/>exit 1 before cleanup"]
    end
    classDef added stroke-dasharray: 5 5;
    class E,M,X added;
Loading

Trade-offs

  • Prune-specific complete-path opt-in rather than global lowercasing or relaxing install relocation: aliases, local paths, case-sensitive hosts, and virtual suffixes retain their contracts.
  • Preserve original commits rather than squash or replay them: attribution remains auditable, at the cost of carrying faithful main-merge commits and one empty provenance-credit commit.
  • Portable coverage uses an explicitly simulated reader. Four native cases skip on ordinary macOS storage; all six CLI cases also passed on a dedicated case-sensitive HFS+ volume and in required Linux lifecycle smoke.
  • Fresh functional evidence uses the installed Python CLI, not a frozen binary. Earlier panel/mutation results remain historical; the bounded review fold has its own regression and mutation evidence.

Benefits

  1. Both GitHub casing directions retain package bytes and manifest content.
  2. Real prune still deletes an actual orphan, while dry-run preserves it.
  3. Different repositories sharing case-variant owner names do not block orphan removal; genuine duplicate paths exit nonzero before changing package bytes, manifest or lockfile.

Issue and approved scope

Fixes #3034. Supersedes #3158.

Human scope-approval comment: #3034 (comment)

This completes the approved host-aware prune correction, regression fixtures, actual-orphan behavior, case-sensitive boundaries, and affected documentation. Review contact: Daniel Meppiel (@danielmeppiel).

The renewed approval preserves the original scope verbatim. Global lowercasing, case-sensitive-host identity changes, unrelated prune redesign, and removal of user-managed files are outside this change.

Original implementation: Shaurya Saria (@icecold009), commit c347ee3d5dbea58b2ad984b90af96d5559d536af. Prepared follow-up: 3bfede3d54a65a58924348816ff05204eaa47bf2. Both remain unchanged ancestors of this branch.

Type of change

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

Testing

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

Validation

Publication head: b5ec1acd45e32ed7b8220ccbba85966c3696b21d, integrated with main 2a8213ac39d6ba862fca6eddd28c7f4653950bfb.
The full suite and frozen-binary suite were not run locally. All six exact-head technical workflows passed: CI, CodeQL, spec conformance, docs, NOTICE, and Merge Gate.
Windows attempt 1 had one gh.exe --version timeout in unchanged discovery code (786 passed, 1 failed, 2 skipped). The single failed-job rerun passed 787 tests with 2 skips; the dependent check also passed on rerun. No code or policy was changed for recovery.

uv run --frozen --extra dev pytest -p no:cacheprovider -q -rs tests/unit/models/test_dependency_materialization.py tests/unit/test_command_helpers.py tests/unit/test_prune_command.py tests/unit/test_prune_casing.py tests/integration/test_prune_casing_cli.py tests/quality/test_ci_topology.py --junitxml=/Users/danielmeppiel/.copilot/session-state/be82c181-49dd-4b8f-9e95-fca488acafe1/files/fold-final-tests.xml — passed:

SKIPPED [4] tests/integration/test_prune_casing_cli.py:44: Filesystem does not support distinct case-only directory names
225 passed, 4 skipped in 169.15s (0:02:49)

The JUnit report proves exact-head local execution; it does not relabel the four skipped native cases as passes.

The separate native HFS+ JUnit receipt fold-native-restored-tests.xml records 6 passed in 31.32s after restoring both mutation probes. The temporary case-sensitive volume was removed afterward.

Required Linux lifecycle execution ran uv run --extra dev pytest -p no:cacheprovider -q --strict-markers -n 4 --dist loadgroup -m 'lifecycle_smoke and not lifecycle_merge_group' tests/integration: 244 passed, 1 skipped. The sole skip is the selected remote-marketplace metadata-outage test, whose required APM_RUN_INTEGRATION_TESTS=1 is absent. This accounts for every skip, proving all six selected prune CLI nodes passed, including the four native case-sensitive cases. The workflow emits no per-node JUnit; the receipt retains this explicit outcome-accounting proof rather than inventing one.

Exact lint and static-check commands and results

Each command below exited 0 on the publication head:

Command Result
uv run --frozen --extra dev ruff check src/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ scripts/windows_native_symlink_probe_entry.py Passed: All checks passed!
uv run --frozen --extra dev ruff format --check src/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ scripts/windows_native_symlink_probe_entry.py Passed: 1940 files already formatted
uv run --frozen --extra dev python -m pylint --disable=all --enable=R0801 --min-similarity-lines=10 --fail-on=R0801 src/apm_cli/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ scripts/windows_native_symlink_probe_entry.py Passed: no duplication diagnostics
bash scripts/lint-auth-signals.sh Passed
bash scripts/lint-architecture-boundaries.sh Passed
uv run --frozen python scripts/check_test_assertions.py Passed
uv run --frozen python scripts/check_exact_test_duplicates.py Passed
git diff --check Passed
git diff --check 2a8213ac39d6ba862fca6eddd28c7f4653950bfb...HEAD Passed

The YAML-I/O, 2100-line, and raw str(relative_to) CI predicates also passed. The two GNU-grep predicates were executed as equivalent line-based Python regular expressions on macOS; their original exclusions and failure conditions were retained.

The deterministic owner gate detected two existing owners: dependency identity/materialization and orphan selection. Version-2 evidence was schema-validated and semantically checked against fresh base/head detection and seven actual passing JUnit nodes, including both CLI modes, portable positive/negative cases and strict-default refusal.

Scenario Evidence

Types below use the repository's actual module-level behavioral markers.

# Scenario (user promise) Principle(s) Test(s) proving it Type
1 Changing GitHub owner/repository casing retains declared bytes; dry-run changes nothing and real prune removes the actual orphan. Portability by manifest; DevX (pragmatic as npm) tests/unit/test_prune_casing.py::test_prune_preserves_casing_equivalent_github_package (regression-trap for #3034) component
2 A lock-retained transitive dependency remains installed across casing differences. Governed by policy tests/unit/test_prune_casing.py::test_prune_retains_case_equivalent_transitive_dependency component
3 Case-sensitive hosts, aliases, local paths, and paths inside repositories keep their existing spelling rules. Vendor-neutral tests/unit/test_prune_casing.py::test_prune_does_not_casefold_sensitive_materialization, ::test_prune_does_not_preserve_case_changed_unknown_host_package, ::test_prune_preserves_virtual_path_case component
4 Conflicting case variants fail before cleanup and identify the actual directory problem. Secure by default; DevX (pragmatic as npm) tests/unit/test_prune_casing.py::test_prune_ambiguous_casing_fails_before_cleanup component
5 The installed CLI preserves the declared dependency and removes only the orphan outside dry-run. DevX (pragmatic as npm) tests/integration/test_prune_casing_cli.py::test_prune_casing_real_cli e2e
6 Different complete repositories coexist; genuine duplicates stop both modes with byte preservation. Secure by default; Portability by manifest tests/unit/test_prune_casing.py::test_prune_complete_paths_with_portable_reader_seam component
7 The same positive/negative behavior is exercised on native case-sensitive directories. Portability by manifest tests/integration/test_prune_casing_cli.py::test_prune_complete_paths_on_case_sensitive_filesystem (four passes on native HFS+ and required Linux; ordinary macOS capability skips remain separately reported) e2e
Retained review and mutation evidence, with revision boundary

The prior lean advisory on #3158 was ship_with_followups. It is historical, not a new independent review of this publication head.

Both recommendations are implemented in retained commit 3bfede3d54a65a58924348816ff05204eaa47bf2: collision-specific reporting with stronger assertions, and packaged command documentation.

At that retained revision, removing the collision handler caused 2 failures; disabling the case-preserving prune opt-in caused 13 failures with 7 unaffected cases passing. Restoring both produced 20 passing cases. A broader retained run recorded 286 passed and 1 skipped.

Review fold bff4acf844e09e1615a7e466aad0f0048e6d6dae adds the complete-path opt-in. Before the fix, four new positive regressions failed. Disabling genuine-duplicate refusal made all four negative cases fail; relaxing the strict default made its dedicated regression fail. Each guard was restored. The final main merge left these guarded source/test files unchanged, and the exact merged-head suite passed above.

No second broad code panel ran. The genuine bounded delta review ran supply-chain, test-coverage and Python-architecture specialists with zero findings, followed by actual CEO synthesis returning ship_now. The inline finding is resolved. Historical review/test results are not relabeled as executions of this head.

How to test

  • Run uv sync --frozen --extra dev to prepare the source-installed CLI environment.
  • Run the focused pytest command above (choose a local JUnit output path); expect 225 passes and four capability skips on a case-insensitive filesystem, or 229 passes on a case-sensitive filesystem.
  • In a disposable project with microsoft/apm already installed, change only its declaration to Microsoft/APM; run uv run apm prune --dry-run and confirm the declared package is not reported as an orphan.
  • Run real prune in that disposable fixture with an unrelated orphan; verify only the orphan disappears, the declared directory keeps its spelling, and its bytes remain unchanged.
  • Run uv run --frozen --extra dev pytest -q -m 'lifecycle_smoke and not lifecycle_merge_group' tests/integration/test_prune_casing_cli.py on Linux; expect all six native CLI cases to pass.

Spec conformance (OpenAPM v0.1)

If this PR changes behaviour that an OpenAPM v0.1 req-XXX covers,
confirm the three-step ritual in the
development guide:

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • 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.

This repairs prune's use of existing host-aware identity and materialization rules; it adds no normative requirement or format. Spec-conformance CI remains part of the successor's technical verification.

Co-authored-by: Copilot [email protected]

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f79e464c-180e-4be3-9056-0773aa679a1a
Address the PR 3158 panel follow-ups and human review by reporting materialization collisions without blaming a valid manifest. Cover dry-run and real prune with a mutation-proven diagnostic regression and synchronize the packaged usage guide.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f79e464c-180e-4be3-9056-0773aa679a1a
Preserve the retained PR 3158 history and incorporate current main without changing the scoped implementation.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: be82c181-49dd-4b8f-9e95-fca488acafe1
Publish the retained work from #3158 as a successor for #3034. Original contributor commit c347ee3 and subsequent scoped follow-up remain unchanged. This commit changes no files.

Co-authored-by: Shaurya Saria <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: be82c181-49dd-4b8f-9e95-fca488acafe1
Retain the scoped prune implementation and original contributor history while integrating the newly merged MCP changes.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: be82c181-49dd-4b8f-9e95-fca488acafe1

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 lookup treats case-equivalent owner prefixes as collisions even when complete package paths are distinct, blocking valid prune operations.

1 open finding
What changed in this PR

Fixes #3034 by making prune preserve GitHub dependencies after owner/repository casing changes, without renaming installed directories.

Changes:

  • Opts prune into host-aware installed-path matching.
  • Adds collision-specific diagnostics and regression coverage.
  • Updates prune reference and packaged usage documentation.
File Description
tests/​unit/​test_prune_casing.py Covers casing preservation, boundaries, and collisions.
tests/​integration/​test_prune_casing_cli.py Exercises dry-run and actual CLI cleanup.
tests/​helpers/​prune_casing.py Shares package and orphan fixtures.
src/​apm_cli/​commands/​prune.py Enables matching and handles collisions separately.
src/​apm_cli/​commands/​_helpers.py Adds opt-in case-preserving path lookup.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Updates packaged prune guidance.
docs/​src/​content/​docs/​reference/​cli/​prune.md Documents casing behavior and collision recovery.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/apm_cli/commands/_helpers.py Resolved
…ollisions

Fold review 4284092621 within the approved #3034 scope. Reuse canonical full-path selection only for prune; preserve strict relocation defaults and genuine duplicate refusal. Add portable reader-seam and required Linux native-filesystem regressions for both prune modes.

Co-authored-by: Shaurya Saria <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: be82c181-49dd-4b8f-9e95-fca488acafe1
Retain the scoped prune correction alongside the #3100 and #3222 changes.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: be82c181-49dd-4b8f-9e95-fca488acafe1
Preserve #3237 linked-resource lifetime guidance without changing the scoped prune correction.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: be82c181-49dd-4b8f-9e95-fca488acafe1
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_now

Prune-casing successor extends materialization with opt-in complete-path traversal, preserves strict defaults, and closes the false-collision bug; all three delta specialists report zero findings.

panel-mode=delta; personas=supply-chain-security-expert,test-coverage-expert,python-architect,apm-ceo
cc Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

All three delta panelists -- supply-chain-security-expert, test-coverage-expert, and python-architect (ad-hoc addition for the newly extended materialization owner) -- returned zero findings on the corrective commit bff4acf and the final head b5ec1ac. There is no dissent to resolve. The prior lean panel on predecessor #3158 recommended ship_with_followups; both recommended follow-ups (separate MaterializationPathCollisionError handling and packaged usage-command documentation) were folded in retained commit 3bfede3, which is an unchanged ancestor of this successor. The one legitimate inline finding (4284092621, reader-mode matcher rejecting at owner prefix before checking complete repository paths) was independently reproduced, corrected in bff4, and the thread awaits the orchestrator's evidence reply. This delta review is a materially different assessment of the corrective successor, not a carried-forward stance from the historical panel.

The evidence stack is thorough and honestly bounded. All six standard technical workflows succeeded on the final head: CI, CodeQL, spec conformance, docs deploy, NOTICE drift check, and the dependent aggregate technical check. CI attempt 1 had one transient runner/tool failure (gh.exe --version timed out on Windows in unchanged trusted-executable discovery; 786 passed, 1 failed, 2 skipped); the evidence-backed rerun on the same unchanged head recovered cleanly (787 passed, 2 skipped in 453.07s) with no code or policy change. Native Linux lifecycle smoke (job 116485573123) passed 244 tests with 1 deterministically identified skip (test_remote_metadata_outage_never_certifies_degraded_marketplace, gated by APM_RUN_INTEGRATION_TESTS=1 absent from the recorded environment). All six prune CLI nodes passed on Linux, including the four genuine case-sensitive-filesystem cases. Separately, a dedicated macOS HFS+ case-sensitive volume ran all six CLI cases (31.32s) and both positive/negative native mutation probes failed as expected. Targeted source mutations confirmed every guard is load-bearing. Owner verification identified two existing owners with no new authority, centralization, or split-authority repair.

Strategically, this PR delivers on the declared prune promise from issue #3034: still-declared dependencies survive casing-only changes while real orphans remain removable and case-sensitive hosts retain their rules. The opt-in design -- match_complete_path defaults to False -- respects the strict-default principle and does not alter prepare_materialization_path. No positioning, naming, or breaking-change concern is raised. The validated base is 2a8213a; main has since advanced (reported f65ac26), so the maintainer's landing decision should include a fresh mergeability check against latest main, distinguishing the tested base from later main pins not executed by this review. This panel does not own that landing decision.

Aligned with: Secure by default, Portable by manifest, Multi-harness / multi-host

Panel summary

Persona B R N Takeaway
Supply Chain Security 0 0 0 Complete-path opt-in preserves containment, collision detection, and write-path isolation; no supply-chain surface regression at b5ec1ac.
Test Coverage 0 0 0 All critical prune-casing surfaces have regression traps at floor tier; portable seam, native HFS+ e2e, and six targeted mutations confirm every path is load-bearing; ship.
Python Architect 0 0 0 Owner extension is structurally clean: opt-in complete-path traversal reuses existing policy primitives; strict default relocation unchanged; no split authority introduced.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Recommendation

All three delta specialists returned zero findings on the corrective successor head. The one legitimate inline finding was corrected in bff4. Six standard workflows succeeded; targeted mutations, native Linux lifecycle smoke, and macOS HFS+ execution all confirm the change is load-bearing and sound. Owner verification shows two existing owners with no new authority. The validated base is 2a8213a; main has since advanced to f65ac26, so a fresh mergeability preview against latest main is warranted before landing, but no code, security, or architecture concern remains from this panel.


Full per-persona findings

Python Architect

No findings.

Supply Chain Security

No findings.

Test Coverage

No findings.

This panel is advisory. It does not block merge. Re-apply the panel-review label after addressing feedback to re-run.


Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 4037af1 into main Oct 15, 2026
35 of 37 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-publish-prune-fix-successor branch October 15, 2026 15:15
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.

[BUG] prune marks a declared GitHub package orphaned after a casing-only manifest change

3 participants