Skip to content

fix(install): scope local content scan to ~/.apm/ at user scope (#830)#850

Open
guwenqing wants to merge 3 commits intomicrosoft:mainfrom
guwenqing:fix/830-global-install-home-glob
Open

fix(install): scope local content scan to ~/.apm/ at user scope (#830)#850
guwenqing wants to merge 3 commits intomicrosoft:mainfrom
guwenqing:fix/830-global-install-home-glob

Conversation

@guwenqing
Copy link
Copy Markdown

@guwenqing guwenqing commented Apr 22, 2026

fix: scope link-resolver discovery to ~/.apm/ at user scope (#830)

Fixes #830

At user scope (--global), project_root is Path.home(). integrate_local_content() passes this as install_path, and BaseIntegrator.init_link_resolver() calls discover_primitives(install_path) — which recursive-globs the entire home directory. This causes multi-minute hangs and triggers macOS privacy dialogs (Downloads, Desktop, etc.).

Root cause: Feature #626 (local .apm/ auto-discovery, v0.8.12) was not tested with -g where project_root = ~/ (feature #452, v0.8.6).

Fix: In BaseIntegrator.init_link_resolver(), when install_path == Path.home(), scope discover_primitives() to ~/.apm/ instead of ~/. This keeps PackageInfo.install_path as project_root so integrators still find primitives at <project_root>/.apm// correctly.

Before: apm install -g hangs indefinitely After: apm install -g completes in ~4 seconds

Changes

  • src/apm_cli/integration/base_integrator.py — scope discover_primitives() scan root in init_link_resolver() when install_path is $HOME
  • tests/unit/integration/test_base_integrator.py — add tests for home-directory scoping
  • tests/unit/test_local_content_install.py — verify install_path stays project_root at user scope

Type of change

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

Testing

  • Tested locally
  • All existing tests pass (93 passed)
  • Added tests for new functionality

…osoft#830)

At user scope (`--global`), `project_root` is `Path.home()`.
`integrate_local_content()` passed this directly as `install_path`,
causing `discover_primitives()` to recursive-glob the entire home
directory.  This caused multi-minute hangs and triggered macOS privacy
dialogs (Downloads, Desktop, etc.).

Root cause: feature microsoft#626 (local `.apm/` auto-discovery, v0.8.12) was
not tested with `-g` where `project_root = ~/` (feature microsoft#452, v0.8.6).

Fix: when `scope is InstallScope.USER`, set `install_path` to
`project_root / ".apm"` so only `~/.apm/` is scanned.

Before: `apm install -g` hangs indefinitely
After:  `apm install -g` completes in ~4 seconds

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 22, 2026 18:51
@guwenqing
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a user-scope (apm install -g/--global) performance hang where local primitive discovery could recursively scan the entire home directory by changing how the synthetic “local” package’s scan root is chosen during local-content integration.

Changes:

  • Adjust integrate_local_content() to set the synthetic local package install_path/package_path to ~/.apm when scope=InstallScope.USER.
  • Add a unit test asserting the user-scope synthetic PackageInfo.install_path is <project_root>/.apm rather than <project_root>.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/apm_cli/install/services.py Changes synthetic local package roots at user scope to avoid scanning $HOME.
tests/unit/test_local_content_install.py Adds coverage asserting the new user-scope install_path behavior.

Comment thread src/apm_cli/install/services.py Outdated
Comment thread tests/unit/test_local_content_install.py
…not install_path

Address Copilot review feedback: changing install_path to ~/.apm/
broke integrator file discovery (they look under <install_path>/.apm/<type>/).

Move the fix to BaseIntegrator.init_link_resolver() instead: when
install_path == $HOME, scope discover_primitives() to ~/.apm/ to
avoid recursive-globbing the entire home directory.

- Revert services.py install_path change (keep project_root)
- Fix base_integrator.py init_link_resolver to scope scan root
- Update test to verify install_path stays project_root at user scope
- Add tests for init_link_resolver home-directory scoping

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@guwenqing guwenqing force-pushed the fix/830-global-install-home-glob branch from 8307ff8 to de46eb2 Compare April 22, 2026 19:03
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.

User-scope install (--global) unexpectedly enters local .apm integration and can spend a long time scanning $HOME

2 participants