-
Notifications
You must be signed in to change notification settings - Fork 180
fix: prefer APM-managed runtimes over system PATH and warn on codex/GitHub Models incompatibility #1356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
danielmeppiel
merged 3 commits into
microsoft:main
from
sergio-sisternes-epam:issue/605
May 18, 2026
Merged
fix: prefer APM-managed runtimes over system PATH and warn on codex/GitHub Models incompatibility #1356
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """Runtime binary resolution utilities.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import shutil | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from apm_cli.utils.path_security import ( | ||
| PathTraversalError, | ||
| ensure_path_within, | ||
| validate_path_segments, | ||
| ) | ||
|
|
||
|
|
||
| def find_runtime_binary(name: str) -> str | None: | ||
| """Return the resolved path to a runtime binary. | ||
|
|
||
| Priority: | ||
| 1. ~/.apm/runtimes/<name> (APM-managed, executable) | ||
| 2. shutil.which(name) (system PATH fallback) | ||
|
|
||
| On Windows the APM-managed binary may carry a ``.exe`` suffix, so both | ||
| ``name`` and ``name.exe`` are checked under ``~/.apm/runtimes/``. | ||
|
|
||
| Raises | ||
| ------ | ||
| PathTraversalError | ||
| If *name* contains path-traversal sequences (e.g. ``..``, ``/``, | ||
| ``\\``) or is an absolute path. This is a security guard against | ||
| user-supplied input that could escape the ``~/.apm/runtimes/`` | ||
| directory. | ||
| """ | ||
| # Security: reject names containing path-traversal or separator | ||
| # characters before any filesystem path is constructed. | ||
| # Runtime names must be simple identifiers (e.g. "codex", "python"). | ||
| if "/" in name or "\\" in name: | ||
| raise PathTraversalError( | ||
| f"Invalid runtime name '{name}': must be a plain binary name " | ||
| "without path separators ('/' or '\\\\')" | ||
| ) | ||
| validate_path_segments(name, context="runtime name", reject_empty=True) | ||
|
|
||
| apm_runtimes = Path.home() / ".apm" / "runtimes" | ||
|
|
||
| def _safe_executable(candidate: Path) -> bool: | ||
| """Return True iff *candidate* is an executable file within *apm_runtimes*.""" | ||
| if not (candidate.is_file() and os.access(candidate, os.X_OK)): | ||
| return False | ||
| try: | ||
| ensure_path_within(candidate, apm_runtimes) | ||
| except PathTraversalError: | ||
| return False | ||
| return True | ||
|
|
||
| if sys.platform == "win32": | ||
| apm_path_exe = apm_runtimes / f"{name}.exe" | ||
| if _safe_executable(apm_path_exe): | ||
| return str(apm_path_exe) | ||
|
|
||
| apm_path = apm_runtimes / name | ||
| if _safe_executable(apm_path): | ||
| return str(apm_path) | ||
|
|
||
| return shutil.which(name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Unit tests for runtime modules.""" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.