fix(env): expand ~ relative to the home directory in resolvePath - #240
Open
shani-singh1 wants to merge 1 commit into
Open
fix(env): expand ~ relative to the home directory in resolvePath#240shani-singh1 wants to merge 1 commit into
shani-singh1 wants to merge 1 commit into
Conversation
resolvePath("~/workspace") returned "/workspace": path.slice(1) of "~/workspace"
is "/workspace", and resolve(home, "/workspace") treats it as an absolute path
and drops home entirely (resolve's right-to-left absolute-segment behavior). So a
~-relative EGO_BROWSER_AGENT_WORKSPACE resolved the agent workspace (and thus
learnings, .env loading, and agent_helpers.js) to the wrong directory on every
platform. ~ survives literally when the var is set in a .env file, which
loadEnvFile reads without shell expansion.
Join the remainder onto home instead of resolving it as a fresh absolute path so
~ stays home-relative.
Adds env.test.mjs covering "~", "~/workspace", and "~/a/b" expansion plus a
non-tilde path.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
resolvePath("~/workspace")returns/workspace(the home directory is dropped) instead of<home>/workspace. The~expansion inenv.tsis broken on every platform, so pointingEGO_BROWSER_AGENT_WORKSPACEat a~-relative path resolves the agent workspace (and therefore learnings,.envloading, andagent_helpers.js) to the wrong directory.Root cause
package/ego-browser/src/env.ts:For
"~/workspace",path.slice(1)is"/workspace".path.resolve(home, "/workspace")treats/workspaceas an absolute path segment, so it returns/workspaceand discardshomeentirely. This ispath.resolve's documented right-to-left absolute-segment behavior.Verified against the built runtime (HOME set to
/home/ego-test):~survives literally whenEGO_BROWSER_AGENT_WORKSPACEis set in a.envfile (loadEnvFiledoes not shell-expand), which is exactly whatresolvePathexists to handle.Fix
Join the remainder to the home directory instead of resolving it as a fresh absolute path, so
~stays home-relative:joinkeeps the leading slash frompath.slice(1)relative ("~" -> home,"~/ws" -> home/ws); the outerresolvenormalizes.Verification
env.test.mjs:resolvePath("~/workspace"),"~", and"~/a/b"now resolve under the home directory; a non-tilde path still resolves to an absolute path. Fails before this change (~/workspace->/workspace), passes after. Cross-platform (uses the current OS home/join).npm test,tsc --noEmit, andprettier --checkare clean.Impact
resolvePath/EGO_BROWSER_AGENT_WORKSPACEwith a~path)