[PR #11897] fix(win32): path handling #13976

Open
opened 2026-02-16 18:18:48 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11897

State: open
Merged: No


~75% of this PR is test code

  • Add @/util/path module that normalizes all paths to POSIX format (/) on Windows
  • Replace native path imports across 126 files
  • Enable full CI test suite on Windows (was previously skipped)
  • Handle Git Bash/MSYS paths (/c/Users/... → C:/Users/...)
  • Add --path-separator=/ to ripgrep for consistent output

From the new architecture tests to help force pit of success down the line:

// Canonical rule: paths are POSIX/Bash-compatible everywhere.
// Why: Windows backslashes caused
// - UI file search/filter mismatches (client query used "\" while indexed paths used "/")
// - server/client path comparisons to fail (drive/UNC edge cases)
// - bash tool arg parsing to mis-handle paths ("\" is an escape in bash)
// Enforcement via import boundaries:
// - opencode/src must use @/util/path (Node wrapper + /tmp mapping)
// - app/ui/web/sdk/desktop/plugin must use @opencode-ai/util/path (browser-safe)
// - native path/node:path imports are disallowed everywhere

For me to manually test each one by one:

Fixes

Core Path Normalization

  • Fixes #11045
    • test/lsp/document-symbol-paths.test.ts → "windows: converts file:// URI to drive-letter path"
    • test/tool/diagnostics-paths.test.ts → "accepts posix diagnostics keys", "windows: accepts canonical diagnostics keys"
  • Fixes #11044
    • test/tool/glob-paths.test.ts → "windows: accepts MSYS-style absolute search paths"
    • test/tool/grep-paths.test.ts → "windows: accepts MSYS-style absolute search paths"
    • test/util/path.test.ts → "converts Git Bash / MSYS paths", "normalize() converts MSYS roots"
  • Fixes #11043
    • test/tool/bash.test.ts → "resolves relative workdir against Instance.directory", "throws on invalid workdir"
    • test/server/pty.test.ts → "throws for invalid cwd"
    • test/tool/bash-paths.test.ts → "converts MSYS paths to drive-letter posix", "preserves UNC shares"
  • Fixes #11042
    • test/tool/external-directory.test.ts → "windows: normalizes MSYS-style absolute targets"
    • test/permission/next.test.ts → "evaluate - matches stored backslash patterns", "evaluate - matches case-insensitively"
  • Fixes #11827
    • test/util/path.test.ts → "normalizes standard paths", "joins with forward slashes", "resolve() output contains no backslashes", "handles mixed slashes"
    • test/util/no-native-path-imports.test.ts → "repo source avoids native path imports"
    • test/worktree/worktree-paths.test.ts → "remove matches worktrees case-insensitively", "reset blocks primary workspace case-insensitively"
  • Fixes #10871
    • test/tool/bash-paths.test.ts → "converts MSYS paths to drive-letter posix"
    • test/util/path.test.ts → "converts Git Bash / MSYS paths"
  • Fixes #10872
    • test/tool/bash.test.ts → "asks for external_directory permission even when PATH is broken"
  • Fixes #10716
    • test/server/session-list.test.ts → "filters by directory with trailing separator"
    • test/project/instance-paths.test.ts → "canonicalizes short and long paths to same directory"
  • Fixes #7279
    • test/permission/next.test.ts → "fromConfig - normalizes windows-style backslashes for path permissions", "fromConfig - normalizes MSYS roots for path permissions", "evaluate - matches stored backslash patterns for path permissions", "evaluate - matches case-insensitively for path permissions"
  • Fixes #8567
    • test/tool/edit-paths.test.ts → "windows: accepts MSYS-style absolute file paths"
    • test/tool/write-paths.test.ts → "windows: accepts MSYS-style absolute file paths"
    • test/tool/multiedit-paths.test.ts → "windows: accepts MSYS-style absolute file paths"

LSP & Ripgrep

  • Fixes #11400
    • test/lsp/document-symbol-paths.test.ts → "windows: converts file:// URI to drive-letter path"
    • test/lsp/index.test.ts → "skips servers with invalid roots"
    • test/tool/diagnostics-paths.test.ts → "accepts posix diagnostics keys", "windows: accepts canonical diagnostics keys"
  • Fixes #5727
    • test/tool/grep-paths.test.ts → "windows: accepts MSYS-style absolute search paths"
    • test/file/ripgrep.test.ts (updated with toPosix)

Glob/File Operations

  • Fixes #11317
    • test/config/config.test.ts → "windows: handles file inclusion substitution with MSYS absolute paths"
    • test/util/filesystem.test.ts → "globUp() returns posix absolute paths on Windows"
  • Fixes #9335
    • test/config/config.test.ts → "windows: loads commands when instance directory is MSYS path"
  • Fixes #11687
    • test/tool/diagnostics-paths.test.ts → "accepts posix diagnostics keys", "windows: accepts canonical diagnostics keys"
    • test/tool/edit-paths.test.ts → "windows: accepts MSYS-style absolute file paths"
  • Fixes #10360
    • test/util/path.test.ts → "windows: converts extended-length drive paths", "windows: converts extended-length UNC paths"
    • test/tool/bash-paths.test.ts → "never returns backslashes"

Permission/Security

  • Fixes #8313
    • test/file/path-traversal.test.ts → "windows: blocks cross-drive paths", "windows: treats UNC shares as distinct roots"
  • Fixes #7876
    • test/permission/next.test.ts → "fromConfig - normalizes windows-style backslashes for path permissions", "fromConfig - normalizes MSYS roots for path permissions", "evaluate - matches stored backslash patterns for path permissions", "evaluate - matches case-insensitively for path permissions"

New Test Files Added (16)

  • test/lsp/document-symbol-paths.test.ts
  • test/lsp/index.test.ts
  • test/project/instance-paths.test.ts
  • test/server/pty.test.ts
  • test/session/prompt.test.ts
  • test/tool/bash-paths.test.ts
  • test/tool/diagnostics-paths.test.ts
  • test/tool/edit-paths.test.ts
  • test/tool/glob-paths.test.ts
  • test/tool/grep-paths.test.ts
  • test/tool/lsp-paths.test.ts
  • test/tool/multiedit-paths.test.ts
  • test/tool/write-paths.test.ts
  • test/util/no-native-path-imports.test.ts
  • test/util/path.test.ts
  • test/worktree/worktree-paths.test.ts
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11897 **State:** open **Merged:** No --- ~75% of this PR is test code - Add @/util/path module that normalizes all paths to POSIX format (/) on Windows - Replace native path imports across 126 files - Enable full CI test suite on Windows (was previously skipped) - Handle Git Bash/MSYS paths (/c/Users/... → C:/Users/...) - Add --path-separator=/ to ripgrep for consistent output From the new architecture tests to help force pit of success down the line: ``` // Canonical rule: paths are POSIX/Bash-compatible everywhere. // Why: Windows backslashes caused // - UI file search/filter mismatches (client query used "\" while indexed paths used "/") // - server/client path comparisons to fail (drive/UNC edge cases) // - bash tool arg parsing to mis-handle paths ("\" is an escape in bash) // Enforcement via import boundaries: // - opencode/src must use @/util/path (Node wrapper + /tmp mapping) // - app/ui/web/sdk/desktop/plugin must use @opencode-ai/util/path (browser-safe) // - native path/node:path imports are disallowed everywhere ``` For me to manually test each one by one: ## Fixes ### Core Path Normalization - [ ] Fixes #11045 - `test/lsp/document-symbol-paths.test.ts` → "windows: converts file:// URI to drive-letter path" - `test/tool/diagnostics-paths.test.ts` → "accepts posix diagnostics keys", "windows: accepts canonical diagnostics keys" - [ ] Fixes #11044 - `test/tool/glob-paths.test.ts` → "windows: accepts MSYS-style absolute search paths" - `test/tool/grep-paths.test.ts` → "windows: accepts MSYS-style absolute search paths" - `test/util/path.test.ts` → "converts Git Bash / MSYS paths", "normalize() converts MSYS roots" - [ ] Fixes #11043 - `test/tool/bash.test.ts` → "resolves relative workdir against Instance.directory", "throws on invalid workdir" - `test/server/pty.test.ts` → "throws for invalid cwd" - `test/tool/bash-paths.test.ts` → "converts MSYS paths to drive-letter posix", "preserves UNC shares" - [ ] Fixes #11042 - `test/tool/external-directory.test.ts` → "windows: normalizes MSYS-style absolute targets" - `test/permission/next.test.ts` → "evaluate - matches stored backslash patterns", "evaluate - matches case-insensitively" - [ ] Fixes #11827 - `test/util/path.test.ts` → "normalizes standard paths", "joins with forward slashes", "resolve() output contains no backslashes", "handles mixed slashes" - `test/util/no-native-path-imports.test.ts` → "repo source avoids native path imports" - `test/worktree/worktree-paths.test.ts` → "remove matches worktrees case-insensitively", "reset blocks primary workspace case-insensitively" - [ ] Fixes #10871 - `test/tool/bash-paths.test.ts` → "converts MSYS paths to drive-letter posix" - `test/util/path.test.ts` → "converts Git Bash / MSYS paths" - [ ] Fixes #10872 - `test/tool/bash.test.ts` → "asks for external_directory permission even when PATH is broken" - [ ] Fixes #10716 - `test/server/session-list.test.ts` → "filters by directory with trailing separator" - `test/project/instance-paths.test.ts` → "canonicalizes short and long paths to same directory" - [ ] Fixes #7279 - `test/permission/next.test.ts` → "fromConfig - normalizes windows-style backslashes for path permissions", "fromConfig - normalizes MSYS roots for path permissions", "evaluate - matches stored backslash patterns for path permissions", "evaluate - matches case-insensitively for path permissions" - [ ] Fixes #8567 - `test/tool/edit-paths.test.ts` → "windows: accepts MSYS-style absolute file paths" - `test/tool/write-paths.test.ts` → "windows: accepts MSYS-style absolute file paths" - `test/tool/multiedit-paths.test.ts` → "windows: accepts MSYS-style absolute file paths" ### LSP & Ripgrep - [ ] Fixes #11400 - `test/lsp/document-symbol-paths.test.ts` → "windows: converts file:// URI to drive-letter path" - `test/lsp/index.test.ts` → "skips servers with invalid roots" - `test/tool/diagnostics-paths.test.ts` → "accepts posix diagnostics keys", "windows: accepts canonical diagnostics keys" - [ ] Fixes #5727 - `test/tool/grep-paths.test.ts` → "windows: accepts MSYS-style absolute search paths" - `test/file/ripgrep.test.ts` (updated with toPosix) ### Glob/File Operations - [ ] Fixes #11317 - `test/config/config.test.ts` → "windows: handles file inclusion substitution with MSYS absolute paths" - `test/util/filesystem.test.ts` → "globUp() returns posix absolute paths on Windows" - [ ] Fixes #9335 - `test/config/config.test.ts` → "windows: loads commands when instance directory is MSYS path" - [ ] Fixes #11687 - `test/tool/diagnostics-paths.test.ts` → "accepts posix diagnostics keys", "windows: accepts canonical diagnostics keys" - `test/tool/edit-paths.test.ts` → "windows: accepts MSYS-style absolute file paths" - [ ] Fixes #10360 - `test/util/path.test.ts` → "windows: converts extended-length drive paths", "windows: converts extended-length UNC paths" - `test/tool/bash-paths.test.ts` → "never returns backslashes" ### Permission/Security - [ ] Fixes #8313 - `test/file/path-traversal.test.ts` → "windows: blocks cross-drive paths", "windows: treats UNC shares as distinct roots" - [ ] Fixes #7876 - `test/permission/next.test.ts` → "fromConfig - normalizes windows-style backslashes for path permissions", "fromConfig - normalizes MSYS roots for path permissions", "evaluate - matches stored backslash patterns for path permissions", "evaluate - matches case-insensitively for path permissions" --- ## New Test Files Added (16) - `test/lsp/document-symbol-paths.test.ts` - `test/lsp/index.test.ts` - `test/project/instance-paths.test.ts` - `test/server/pty.test.ts` - `test/session/prompt.test.ts` - `test/tool/bash-paths.test.ts` - `test/tool/diagnostics-paths.test.ts` - `test/tool/edit-paths.test.ts` - `test/tool/glob-paths.test.ts` - `test/tool/grep-paths.test.ts` - `test/tool/lsp-paths.test.ts` - `test/tool/multiedit-paths.test.ts` - `test/tool/write-paths.test.ts` - `test/util/no-native-path-imports.test.ts` - `test/util/path.test.ts` - `test/worktree/worktree-paths.test.ts`
yindo added the pull-request label 2026-02-16 18:18:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13976