-
Notifications
You must be signed in to change notification settings - Fork 14
fix(windows): canonicalize rooted-but-driveless paths in permission helpers #431
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
Merged
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| import { test, expect } from "bun:test" | ||
| import path from "path" | ||
| import os from "os" | ||
| import fs from "fs" | ||
| import { AppFileSystem } from "@opencode-ai/core/filesystem" | ||
|
|
||
| // All Windows variants below collapse to the same canonical form on Windows. | ||
| // On macOS/Linux normalizePath is the identity function, so we keep the | ||
| // Windows-only guards explicit to avoid accidental cross-platform skew. | ||
|
|
||
| test("normalizePath is identity on non-Windows", () => { | ||
| if (process.platform === "win32") return | ||
| const p = "/usr/local/bin/foo" | ||
| expect(AppFileSystem.normalizePath(p)).toBe(p) | ||
| }) | ||
|
|
||
| test.skipIf(process.platform !== "win32")( | ||
| "normalizePath probes drive roots for rooted-but-driveless paths to existing files", | ||
| () => { | ||
| const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), "pawwork-fs-")) | ||
| try { | ||
| const file = path.join(tmpdir, "marker.txt") | ||
| fs.writeFileSync(file, "x") | ||
|
|
||
| const driveless = file.replace(/^[A-Za-z]:/, "").replaceAll("\\", "/").toLowerCase() | ||
| const result = AppFileSystem.normalizePath(driveless) | ||
|
|
||
| expect(result.toLowerCase()).toBe(file.toLowerCase()) | ||
| } finally { | ||
| fs.rmSync(tmpdir, { recursive: true, force: true }) | ||
| } | ||
| }, | ||
| ) | ||
|
|
||
| test.skipIf(process.platform !== "win32")( | ||
| "normalizePath canonicalizes Git Bash /c/... style paths", | ||
| () => { | ||
| const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), "pawwork-fs-")) | ||
| try { | ||
| const file = path.join(tmpdir, "marker.txt") | ||
| fs.writeFileSync(file, "x") | ||
|
|
||
| const drive = file.match(/^([A-Za-z]):/)![1].toLowerCase() | ||
| const tail = file.slice(2).replaceAll("\\", "/") | ||
| const gitBash = `/${drive}${tail}` | ||
| const result = AppFileSystem.normalizePath(gitBash) | ||
|
|
||
| expect(result.toLowerCase()).toBe(file.toLowerCase()) | ||
| } finally { | ||
| fs.rmSync(tmpdir, { recursive: true, force: true }) | ||
| } | ||
| }, | ||
| ) | ||
|
|
||
| test.skipIf(process.platform !== "win32")( | ||
| "normalizePath canonicalizes Cygwin /cygdrive/c/... paths", | ||
| () => { | ||
| const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), "pawwork-fs-")) | ||
| try { | ||
| const file = path.join(tmpdir, "marker.txt") | ||
| fs.writeFileSync(file, "x") | ||
|
|
||
| const drive = file.match(/^([A-Za-z]):/)![1].toLowerCase() | ||
| const tail = file.slice(2).replaceAll("\\", "/") | ||
| const cygwin = `/cygdrive/${drive}${tail}` | ||
| const result = AppFileSystem.normalizePath(cygwin) | ||
|
|
||
| expect(result.toLowerCase()).toBe(file.toLowerCase()) | ||
| } finally { | ||
| fs.rmSync(tmpdir, { recursive: true, force: true }) | ||
| } | ||
| }, | ||
| ) | ||
|
|
||
| test.skipIf(process.platform !== "win32")( | ||
| "normalizePath canonicalizes WSL /mnt/c/... paths", | ||
| () => { | ||
| const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), "pawwork-fs-")) | ||
| try { | ||
| const file = path.join(tmpdir, "marker.txt") | ||
| fs.writeFileSync(file, "x") | ||
|
|
||
| const drive = file.match(/^([A-Za-z]):/)![1].toLowerCase() | ||
| const tail = file.slice(2).replaceAll("\\", "/") | ||
| const wsl = `/mnt/${drive}${tail}` | ||
| const result = AppFileSystem.normalizePath(wsl) | ||
|
|
||
| expect(result.toLowerCase()).toBe(file.toLowerCase()) | ||
| } finally { | ||
| fs.rmSync(tmpdir, { recursive: true, force: true }) | ||
| } | ||
| }, | ||
| ) | ||
|
|
||
| test.skipIf(process.platform !== "win32")( | ||
| "normalizePath leaves drive-prefixed paths intact for already-canonical input", | ||
| () => { | ||
| const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), "pawwork-fs-")) | ||
| try { | ||
| const file = path.join(tmpdir, "marker.txt") | ||
| fs.writeFileSync(file, "x") | ||
|
|
||
| const result = AppFileSystem.normalizePath(file) | ||
| expect(result.toLowerCase()).toBe(file.toLowerCase()) | ||
| } finally { | ||
| fs.rmSync(tmpdir, { recursive: true, force: true }) | ||
| } | ||
| }, | ||
| ) | ||
|
|
||
| test.skipIf(process.platform !== "win32")( | ||
| "normalizePath falls back to cwd-drive resolution for non-existent rooted-driveless paths", | ||
| () => { | ||
| // The probe only repairs existing paths; documenting behavior so future | ||
| // changes don't accidentally start guessing for write targets. | ||
| const driveless = "/this/path/should/not/exist/anywhere/marker.txt" | ||
| const cwdDrive = process.cwd().match(/^([A-Za-z]:)/)![1].toUpperCase() | ||
| const expected = path.win32.normalize(path.win32.join(`${cwdDrive}\\`, driveless.replaceAll("/", "\\"))) | ||
| const result = AppFileSystem.normalizePath(driveless) | ||
|
|
||
| expect(result.toUpperCase()).toBe(expected.toUpperCase()) | ||
| }, | ||
| ) | ||
|
Astro-Han marked this conversation as resolved.
|
||
|
|
||
| test.skipIf(process.platform !== "win32")( | ||
| "normalizePathPattern preserves trailing /* glob", | ||
| () => { | ||
| const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), "pawwork-fs-")) | ||
| try { | ||
| const driveless = tmpdir.replace(/^[A-Za-z]:/, "").replaceAll("\\", "/").toLowerCase() | ||
| const pattern = AppFileSystem.normalizePathPattern(`${driveless}/*`) | ||
|
|
||
| expect(pattern.endsWith("\\*") || pattern.endsWith("/*")).toBe(true) | ||
| expect(pattern.toLowerCase()).toContain(tmpdir.toLowerCase()) | ||
| } finally { | ||
| fs.rmSync(tmpdir, { recursive: true, force: true }) | ||
| } | ||
| }, | ||
| ) | ||
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
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.