apm icon indicating copy to clipboard operation
apm copied to clipboard

[BUG] Global install succeeds with empty skill directories when HOME/APM_HOME uses a symlink alias

Open DaveMeadAdjust opened this issue 2 months ago • 3 comments

Describe the bug

A global install can exit successfully while deploying empty skill directories when HOME and APM_HOME use a symlink alias. The source plan authorizes canonical paths, but skill copying uses the original path spelling and excludes the authorized files.

To Reproduce

  1. In a disposable environment, create a local APM package containing .apm/skills/demo/SKILL.md and apm.yml with a name and version.
  2. Create a real temporary home and a symlink pointing to it. Set the child process's HOME to that symlink and APM_HOME to <symlink>/.apm.
  3. Run apm install --global <local-package> --target codex --no-policy --parallel-downloads 0.
  4. The command exits 0, but <real-home>/.agents/skills/demo/SKILL.md is absent. Repeat with canonical home paths: the file is deployed.

Apply only the test hunk below, leaving the implementation unchanged, then run:

uv run --extra dev pytest tests/integration/test_global_audit_deploy_root.py -k reads_home_deployment_root -q

Expected behavior

Equivalent home-directory path spellings should deploy the same skill files.

Environment

  • OS: macOS 26.6.1, Apple Silicon
  • Python Version: 3.14.7
  • APM Version: 0.29.1 and main at 852295c8b74ef60be0bd5e91f00ffa63152700c6

Logs

assert install.exit_code == 0, install.output  # passes
assert (isolated.home / ".agents" / "skills" / "demo" / "SKILL.md").is_file()
E AssertionError: assert False

FAILED test_global_install_audit_reads_home_deployment_root[True]
1 failed, 1 passed, 8 deselected

Additional context

DeployableSourcePlan.create() resolves package_info.install_path. SkillIntegrator.integrate_package_skill() retains its original spelling, which reaches the copy filter. _is_safe_source_path() performs a lexical relative_to(source_root) check; noncanonical candidates fail against the resolved root and are ignored.

The proposed patch canonicalizes the package root on a shallow copy of the metadata, preserving caller metadata and descendant-symlink checks. The regression fails before the fix and passes afterward. The focused security, containment, and global-audit suites pass with the patch (38 tests).

Proposed patch and regression
diff --git a/src/apm_cli/integration/skill_integrator.py b/src/apm_cli/integration/skill_integrator.py
--- a/src/apm_cli/integration/skill_integrator.py
+++ b/src/apm_cli/integration/skill_integrator.py
@@ -1457,6 +1457,13 @@ class SkillIntegrator(BaseIntegrator):
         Returns:
             SkillIntegrationResult: Results of the integration operation
         """
+        # Match the canonical root used by DeployableSourcePlan without
+        # changing caller metadata or resolving links within the package.
+        from copy import copy
+
+        package_info = copy(package_info)
+        package_info.install_path = package_info.install_path.resolve()
+
         enforce_agent_plugin_deployment_boundary(package_info)
 
         # Check if package type allows skill installation (T4 routing)
diff --git a/tests/integration/test_global_audit_deploy_root.py b/tests/integration/test_global_audit_deploy_root.py
--- a/tests/integration/test_global_audit_deploy_root.py
+++ b/tests/integration/test_global_audit_deploy_root.py
@@ -47,12 +47,23 @@ def _tree_snapshot(
     return directories, files
 
 
[email protected]("aliased_home", [False, True])
 def test_global_install_audit_reads_home_deployment_root(
+    aliased_home: bool,
     tmp_path: Path,
     monkeypatch: pytest.MonkeyPatch,
 ) -> None:
     isolated = IsolatedApmEnvironment.create(tmp_path / "global-audit", base_env=os.environ)
     environment = isolated.subprocess_env()
+    if aliased_home:
+        alias = isolated.root / "home-alias"
+        try:
+            alias.symlink_to(isolated.home, target_is_directory=True)
+        except (OSError, NotImplementedError):
+            pytest.skip("directory symlinks unavailable")
+        environment["HOME"] = str(alias)
+        environment["USERPROFILE"] = str(alias)
+        environment["APM_HOME"] = str(alias / ".apm")
     environment["APM_NO_CACHE"] = "1"
     for name, value in environment.items():
         monkeypatch.setenv(name, value)

DaveMeadAdjust avatar Sep 07 '26 05:09 DaveMeadAdjust

Triage decision

accept

Proposed labels

theme/security
area/content-security
type/bug
status/accepted

Milestone

null -- open-milestone read failed (401 from milestones API); no milestone assigned this run.

Suggested next action

Apply the proposed patch canonicalizing package_info.install_path on a shallow copy in SkillIntegrator.integrate_package_skill() before the _is_safe_source_path() containment check, and merge the included aliased-home regression test.

Suggested issue comment

Excellent report -- root cause, patch, and regression test are all included and verified (38 focused tests pass with the patch). Accepting directly: a symlinked HOME/APM_HOME must deploy the same files as the canonical path, and the fix is narrowly scoped to canonicalizing the package root before the containment check without weakening it. No milestone assigned yet (milestone read failed this run).

Per-lens notes (collapsed)

DevX UX Expert -- User-Need Reviewer

A successful exit (code 0) that silently deploys empty skill directories on a common macOS/Linux setup (symlinked home) is exactly the kind of silent failure that erodes trust in the install command's reported outcome.

Supply Chain Security Expert -- Risk-Surface Reviewer

This sits directly on the containment boundary (_is_safe_source_path's relative_to(source_root) check) -- theme/security is required. The proposed patch is reassuring: it canonicalizes the comparison root rather than loosening the check, and preserves descendant-symlink containment, so it strengthens rather than relaxes the boundary.

OSS Growth Hacker -- Contributor-Tone Reviewer

Not activated -- DaveMeadAdjust has 3 prior issues on this repo and the report includes a fully verified patch plus regression test, indicating an experienced contributor; standard tone applies.

Python Architect -- Architecture Reviewer

Not activated -- the proposed patch is a narrow, well-contained fix (shallow-copy canonicalization at one call site) with no new interface or cross-cutting contract change.

Doc Writer -- Documentation Reviewer

Not activated -- no user-facing documentation implication; this is an internal path-canonicalization fix.

APM CEO -- Triage Arbiter

Model bug report: reproducible, root-caused, patched, and regression-tested. Accept as type/bug, theme/security, area/content-security.

{
  "decision": "accept",
  "decision_detail": "",
  "theme": "theme/security",
  "areas": ["area/content-security"],
  "type": "type/bug",
  "status": "status/accepted",
  "priority": null,
  "preserved_labels": [],
  "milestone": null,
  "next_action": "Apply the proposed patch canonicalizing package_info.install_path on a shallow copy in SkillIntegrator.integrate_package_skill() before the _is_safe_source_path() containment check, and merge the included aliased-home regression test.",
  "comment_markdown": "Excellent report -- root cause, patch, and regression test are all included and verified (38 focused tests pass with the patch). Accepting directly: a symlinked HOME/APM_HOME must deploy the same files as the canonical path, and the fix is narrowly scoped to canonicalizing the package root before the containment check without weakening it. No milestone assigned yet (milestone read failed this run)."
}

Triage status: agentic proposal pending human ratification. Silence is approval. Maintainers can:

  • Override any label or milestone above by editing it directly -- human edits are authoritative and will not be reverted on subsequent runs.
  • Re-trigger triage by applying the status/needs-triage label, or by removing status/triaged to enroll the issue in the next daily sweep.

Posted by the Triage Panel workflow. See packages/apm-triage-panel for the panel skill.

Generated by Triage Panel · copilot · auto · 165.9 AIC · ⌖ 21.2 AIC · ⊞ 14.1K · ◷

github-actions[bot] avatar Sep 09 '26 12:09 github-actions[bot]

Triage decision

accept

Proposed labels

theme/security
area/content-security
type/bug
status/accepted

Milestone

null

Suggested next action

Canonicalize HOME/APM_HOME path spellings before authorizing and copying skill files, so a symlink alias resolves to the same authorized set as the canonical path, and land the provided regression test.

Suggested issue comment

Confirmed and well-isolated -- when `HOME`/`APM_HOME` is a symlink alias, the source plan authorizes canonical paths but the copy step uses the original (symlinked) path spelling, so authorized files don't match what gets copied and the install silently deploys empty directories while still exiting 0. This is accepted; the fix should canonicalize both sides of the authorization/copy boundary consistently. Thanks for including the exact regression test (`test_global_audit_deploy_root.py -k reads_home_deployment_root`) -- that will anchor the fix directly.

Per-lens notes (collapsed)

DevX UX Expert -- User-Need Reviewer

Silent success with empty deployed skill directories is a serious trust failure -- exit code 0 should mean the install actually happened. The reporter isolated this precisely to symlinked HOME/APM_HOME path spelling, which is common on macOS where /tmp and some home setups are symlinked.

Supply Chain Security Expert -- Risk-Surface Reviewer

This is a path-canonicalization mismatch between the authorization plan and the file-copy step -- a content-security/integrity boundary. theme/security and area/content-security are required since authorized-vs-copied path mismatches are exactly the kind of divergence that can mask incomplete or incorrect deployments.

OSS Growth Hacker -- Contributor-Tone Reviewer

Not activated -- author_association is NONE but the report includes a precise repro, exact environment details, and a ready-to-run regression test; standard courteous, technical tone is appropriate without special first-timer framing.

Python Architect -- Architecture Reviewer

Not activated -- this is a bounded canonicalization fix at the authorization/copy boundary, not a new interface or schema change.

Doc Writer -- Documentation Reviewer

Not activated -- internal correctness fix; no user-facing doc surface change implied.

APM CEO -- Triage Arbiter

Precise, reproducible security-adjacent bug with a ready-made regression test. Accepting as theme/security, area/content-security, type/bug.

{
  "decision": "accept",
  "decision_detail": "",
  "theme": "theme/security",
  "areas": ["area/content-security"],
  "type": "type/bug",
  "status": "status/accepted",
  "priority": null,
  "preserved_labels": [],
  "milestone": null,
  "next_action": "Canonicalize HOME/APM_HOME path spellings before authorizing and copying skill files, so a symlink alias resolves to the same authorized set as the canonical path, and land the provided regression test.",
  "comment_markdown": "Confirmed and well-isolated -- when HOME/APM_HOME is a symlink alias, the source plan authorizes canonical paths but the copy step uses the original (symlinked) path spelling, so authorized files don't match what gets copied and the install silently deploys empty directories while still exiting 0. This is accepted; the fix should canonicalize both sides of the authorization/copy boundary consistently. Thanks for including the exact regression test -- that will anchor the fix directly."
}

Triage status: agentic proposal pending human ratification. Silence is approval. Maintainers can:

  • Override any label or milestone above by editing it directly -- human edits are authoritative and will not be reverted on subsequent runs.
  • Re-trigger triage by applying the status/needs-triage label, or by removing status/triaged to enroll the issue in the next daily sweep.

Posted by the Triage Panel workflow. See packages/apm-triage-panel for the panel skill.

Generated by Triage Panel · copilot · auto · 76.9 AIC · ⌖ 22.5 AIC · ⊞ 14.1K · ◷

github-actions[bot] avatar Sep 10 '26 12:09 github-actions[bot]

At the lead maintainer's direction, the current acceptance of this item is withdrawn as part of APM's roadmap and contribution reset. Previous acceptance labels or comments must not be treated as approval to start or continue substantive implementation for inclusion in APM.

Thank you for the work and ideas already contributed. Our small maintainer team needs to agree supported scope and review capacity before inviting more implementation. This is not a rejection of the proposal or a judgment of your work, and it does not undo completed work or erase its history.

Please follow the contribution rules: a responsible human maintainer needs to record the bounded scope, acceptance criteria and review contact on the issue before substantive work resumes. Existing issue discussion, assignments and contributions remain available for that decision. Trivial typo and broken-link corrections retain their standing preapproval.

danielmeppiel avatar Sep 12 '26 00:09 danielmeppiel