Skip to content

fix(lockfile): pass scope-resolved path to MCPIntegrator.update_lockfile#1230

Closed
Aaryan-Dadu wants to merge 2 commits intomicrosoft:mainfrom
Aaryan-Dadu:fix/lockfile
Closed

fix(lockfile): pass scope-resolved path to MCPIntegrator.update_lockfile#1230
Aaryan-Dadu wants to merge 2 commits intomicrosoft:mainfrom
Aaryan-Dadu:fix/lockfile

Conversation

@Aaryan-Dadu
Copy link
Copy Markdown

Description

MCPIntegrator.update_lockfile was using Path.cwd() as the default lockfile location even at --global scope, causing MCP server audit entries to be written to the project-local apm.lock.yaml instead of the user-scope ~/.apm/apm.lock.yaml.

Most caller in the install pipeline omitted the lock_path argument. Since Path.cwd() is always the current project directory (not the user's home), MCP entries for a global install were silently written to the wrong file.

Fix

Thread the already-computed scope-resolved _lock_path (derived from ctx.apm_dir, which is ~/.apm/ for --global and Path.cwd() for project scope) into all four update_lockfile call sites.

Fixes #794

Type of change

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

Testing

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

Copilot AI review requested due to automatic review settings May 9, 2026 20:51
@Aaryan-Dadu
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

This PR fixes a bug where MCP audit entries could be written to the wrong lockfile during apm install --global because MCPIntegrator.update_lockfile() defaulted to Path.cwd() when callers omitted the lock_path argument. The fix threads the already scope-resolved lockfile path into all relevant call sites so global installs update ~/.apm/apm.lock.yaml rather than a project-local lockfile.

Changes:

  • Pass the scope-resolved lockfile path into MCPIntegrator.update_lockfile() from the main install pipeline.
  • Pass the scope-resolved lockfile path into MCPIntegrator.update_lockfile() from the apm install --mcp command path.
  • Add regression tests ensuring the scoped lockfile path is forwarded correctly.

Reviewed changes

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

File Description
tests/unit/test_global_mcp_scope.py Adds regression coverage asserting update_lockfile() is called with the scope-resolved lockfile path.
src/apm_cli/install/mcp/command.py Ensures the --mcp install flow updates the correct lockfile by passing the computed lockfile path explicitly.
src/apm_cli/commands/install.py Ensures the main install pipeline passes the scope-resolved lockfile path to all update_lockfile() call sites.

Comment thread tests/unit/test_global_mcp_scope.py Outdated
Comment thread tests/unit/test_global_mcp_scope.py Outdated
MCPIntegrator.update_lockfile() defaults to get_lockfile_path(Path.cwd()) when no explicit path is passed. At --global scope, this cause MCP server audit entries to be written to the project-local apm.lock.yaml instead of the user-scope lockfile at ~/.apm/apm.lock.yaml.

The caller already computes the scope-correct apm_dir (Path.home() / ".apm" for USER scope, Path.cwd() for PROJECT scope) and derives _lock_path from it. This change threads that path through all four update_lockfile call sites so the write always lands in the right file.

Fixes: microsoft#794
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Three textual conflicts on the same microsoft#794 invariant:

- src/apm_cli/commands/install.py: kept the explanatory comment
  describing why the scope-resolved _lock_path is passed explicitly.
- src/apm_cli/install/mcp/command.py: aligned local var name to
  main's _mcp_lock_path while keeping the microsoft#794 explanatory comment.
- tests/unit/test_global_mcp_scope.py: kept BOTH test classes --
  TestUpdateLockfileScope (behavioral, mocks pipeline + scopes) and
  TestUpdateLockfileGlobalScope (AST contract on call sites). They
  pin the same invariant from different angles (defense in depth).

Lint silent. 709 unit tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danielmeppiel
Copy link
Copy Markdown
Collaborator

Thanks for the fix @Aaryan-Dadu! Closing as superseded -- the same fix landed in #1236 (merged earlier today, closes #794). The diagnosis and call-site routing here matched #1236's approach almost exactly, so the underlying behavior is now correct on main. Really appreciate the contribution -- hope to see you back on another issue!

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: MCPIntegrator.update_lockfile uses Path.cwd() at --global scope, writing MCP audit entries to the wrong lockfile

3 participants