fix(cli): expand "~/" home shorthand on Windows#1055
Open
LukeTheoJohnson wants to merge 1 commit into
Open
Conversation
expandHome only matched `~${path.sep}`, which is `~\` on Windows, so the
portable `~/` home shorthand -- the spelling users and config files write
across platforms -- was returned unexpanded. Callers then treated a literal
`~` as a real path segment (reachable via `--output ~/foo`, `--codex-home`,
`CODEX_HOME`, `OPENCODE_CONFIG_DIR`), creating a bogus `~` directory in the
working tree instead of resolving under the user's home.
Match `~/` in addition to the native separator. POSIX behaviour is unchanged
(`~\foo` still passes through, since backslash is a legal filename character
there); only Windows `~/x` handling changes.
Adds tests/resolve-home.test.ts covering the forward-slash shorthand, the
native-separator form, bare `~`, and the pass-through cases.
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.
Problem
On Windows, the
~/home shorthand is not expanded, so the CLI treats a literal~as a real path segment.expandHome()insrc/utils/resolve-home.tsonly matched`~${path.sep}`. On Windowspath.sepis\, so that check is~\. The portable~/spelling, the one users and config files write across platforms, falls through unmatched and is returned verbatim.Because
expandHomebacksresolveTargetHome/resolveCodexHome, the unexpanded value reachesconvert,install, andcleanupthrough--output,--codex-home,--pi-home,CODEX_HOME, andOPENCODE_CONFIG_DIR. The result is a bogus~directory created in the working tree instead of a path under the user's home.This is Linux/macOS-invisible: there
path.sepis/, so~/already matches. CI runs onubuntu-latestonly, which is why it was not caught.Root cause / evidence
Reproduced with the real function on Windows (
path.sep === "\\",os.homedir() === C:\Users\lukej):Fix
Match
~/in addition to the native separator:Surgical by design: POSIX behaviour is unchanged. On POSIX
~\foostill passes through untouched (backslash is a legal filename character there); only Windows~/xhandling changes.Tests
Adds
tests/resolve-home.test.ts:~/.codexand~/sub/direxpand to a home-joined path on every platform (the regression guard: red on Windows before this change, green after).~still expand.~foo, relative, and absolute paths pass through unchanged.Verification on Windows:
Expected "C:\Users\lukej\.codex",Received "~/.codex") and passes after the fix (4/4).mainvs this branch, per-test timings stripped): 168 pre-existing Windows failures on both sides, zero added, zero removed. The new suite adds four passing tests.Related
Same cross-platform path class as prior Windows fixes in this area: #398 (sanitize colons in skill/agent names for Windows), #226 (Windows NTFS colons), and issues #366 / #48 / #49 (colon-in-path ENOENT on Windows). Windows is a supported target with a history of exactly these Unix-invisible path bugs.