Fix Codex WSL project trust conflating case-distinct Linux paths (#8333)
* Fix Codex WSL project trust conflating case-distinct Linux paths normalizeCodexProjectPathForLookup lowercased the entire Windows/UNC path, including the case-sensitive Linux portion under \\wsl$\<distro>. Two distinct WSL project dirs (.../Repo vs .../repo) collapsed onto one trust key, and the mirror dedupe (codex-config-mirror) inherited it. Preserve case for the Linux path after the case-insensitive \\wsl$\<distro> / \\wsl.localhost\<distro> share prefix; true Windows drive letters and normal UNC shares still case-fold as before. Co-authored-by: Orca <help@stably.ai> * Apply the same WSL case-fold fix to hook-trust key lookup normalizeHookTrustKeyForLookup had the identical latent bug: on a win32 host it lowercased the whole Windows-shaped path, folding the case-sensitive Linux tail of a \\wsl$\<distro> UNC hook path — contrary to its own comment that WSL sources stay case-sensitive. Extract foldWindowsCaseInsensitivePath (shared with the project-path normalizer): fold only the case-insensitive drive/\\wsl$ share prefix, preserve the Linux tail. Existing suffix (event:group:handler) is already lowercase, so behavior is unchanged there. Co-authored-by: Orca <help@stably.ai> * Fix Codex WSL trust revocation and hook-key case folding - Case-drifted or share-spelling-varied WSL revocations were being ignored on merge, letting stale "trusted" entries survive; fold revocation lookups fully so matching errs toward revoked. - Hook-trust key folding was gated on process.platform === 'win32', so WSL/SSH-remote hook sources weren't folded when Orca itself ran on macOS/Linux; fold by path shape instead, via the new shared foldWslUncPathCaseInsensitiveParts helper (also covers /mnt drvfs automounts and wsl$/wsl.localhost share aliasing). * Fix Codex WSL trust key case-folding regressions - Don't fold case-variant `/MNT` dirs as if they were the drvfs automount; only literal lowercase `/mnt/<drive>` folds. - Preserve an exact-cased trusted project entry in ~/.codex during runtime merge instead of letting a loosely-matched, case-drifted revocation clobber a user's re-granted trust on every mirror pass. - Minor cleanup: inline foldWindowsCaseInsensitivePath and hoist the repeated normalizeHookTrustKeyForLookup call in findTrustBlockRanges. * Refactor case-fold WSL trust test to assert real serializer output Extract path variables and assert against escapeTomlString(incomingPath) instead of a hardcoded escaped string literal, so the fixture can't silently drift from the actual TOML header serialization. --------- Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { isWslUncPath, parseWslUncPath } from './wsl-paths'
|
||||
import { foldWslUncPathCaseInsensitiveParts, isWslUncPath, parseWslUncPath } from './wsl-paths'
|
||||
|
||||
describe('wsl path helpers', () => {
|
||||
it('parses modern and legacy WSL UNC paths without platform checks', () => {
|
||||
@@ -18,3 +18,35 @@ describe('wsl path helpers', () => {
|
||||
expect(isWslUncPath('/home/jin/repo')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('foldWslUncPathCaseInsensitiveParts', () => {
|
||||
it('folds share spelling, distro casing, and separators but not the Linux tail', () => {
|
||||
expect(foldWslUncPathCaseInsensitiveParts('\\\\WSL$\\Ubuntu\\home\\jin\\Repo')).toBe(
|
||||
'//wsl.localhost/ubuntu/home/jin/Repo'
|
||||
)
|
||||
expect(foldWslUncPathCaseInsensitiveParts('//wsl.localhost/UBUNTU/home/jin/Repo')).toBe(
|
||||
'//wsl.localhost/ubuntu/home/jin/Repo'
|
||||
)
|
||||
})
|
||||
|
||||
it('folds drvfs automount tails but not other /mnt entries', () => {
|
||||
expect(foldWslUncPathCaseInsensitiveParts('\\\\wsl$\\Ubuntu\\mnt\\C\\Users\\Jin')).toBe(
|
||||
'//wsl.localhost/ubuntu/mnt/c/users/jin'
|
||||
)
|
||||
expect(foldWslUncPathCaseInsensitiveParts('\\\\wsl$\\Ubuntu\\mnt\\wsl\\Data')).toBe(
|
||||
'//wsl.localhost/ubuntu/mnt/wsl/Data'
|
||||
)
|
||||
})
|
||||
|
||||
it('does not treat a case-variant /MNT dir as the drvfs automount', () => {
|
||||
expect(foldWslUncPathCaseInsensitiveParts('\\\\wsl$\\Ubuntu\\MNT\\c\\Repo')).toBe(
|
||||
'//wsl.localhost/ubuntu/MNT/c/Repo'
|
||||
)
|
||||
})
|
||||
|
||||
it('returns null for non-WSL paths', () => {
|
||||
expect(foldWslUncPathCaseInsensitiveParts('C:\\Users\\jin')).toBeNull()
|
||||
expect(foldWslUncPathCaseInsensitiveParts('//server/share/x')).toBeNull()
|
||||
expect(foldWslUncPathCaseInsensitiveParts('/home/jin')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -19,3 +19,18 @@ export function parseWslUncPath(path: string): WslUncPathInfo | null {
|
||||
export function isWslUncPath(path: string): boolean {
|
||||
return parseWslUncPath(path) !== null
|
||||
}
|
||||
|
||||
// Why: Windows folds the share (\\wsl$ aliases \\wsl.localhost), the distro, and
|
||||
// drvfs /mnt/<drive> tails case-insensitively; the rest of the Linux path is not.
|
||||
export function foldWslUncPathCaseInsensitiveParts(path: string): string | null {
|
||||
const parsed = parseWslUncPath(path)
|
||||
if (!parsed) {
|
||||
return null
|
||||
}
|
||||
// Why: the drvfs automount is literally lowercase /mnt — a case-variant like
|
||||
// /MNT is an ordinary case-sensitive Linux dir and must not be folded.
|
||||
const linuxPath = /^\/mnt\/[a-zA-Z](?:\/|$)/.test(parsed.linuxPath)
|
||||
? parsed.linuxPath.toLowerCase()
|
||||
: parsed.linuxPath
|
||||
return `//wsl.localhost/${parsed.distro.toLowerCase()}${linuxPath === '/' ? '' : linuxPath}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user