Repository navigation
Fix Codex WSL project trust conflating case-distinct Linux paths - #8333
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughProject trust normalization now handles WSL UNC paths by normalizing share aliases, distro casing, separators, and drvfs prefixes while preserving Linux-tail case where required. Revocation lookup uses separate drift-tolerant normalization, and configuration mirroring preserves trusted entries while applying matching revocations. Hook trust lookup and WSL reconciliation use the same normalized path keys. Tests cover Windows, UNC, WSL, drvfs, POSIX, trust, revocation, and mirror behavior. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 6203e718-c282-483a-8a13-6285e6fd03c2
📒 Files selected for processing (2)
src/main/codex/config-toml-trust.test.tssrc/main/codex/config-toml-trust.ts
Follow-up: extended the fix to hook-trust key lookupPer review, Both normalizers now share one helper, Added a win32-gated Not changed — normal UNC ( Full |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/main/codex/codex-config-mirror.ts (1)
292-300: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract shared logic between
getTomlSectionHeaderKeyandgetRevocationTomlSectionHeaderKey.Both functions (Lines 285-289 and 292-299) are structurally identical except for the normalization function passed in. Consolidating into one parameterized helper removes the duplication and prevents the two from drifting out of sync if the header-parsing logic changes later.
♻️ Proposed refactor
+function buildProjectTomlSectionHeaderKey( + header: string, + normalize: (projectPath: string) => string +): string { + const projectPath = parseCodexProjectHeaderPath(header) + return projectPath === null ? header.trim() : `project:${normalize(projectPath)}` +} + function getTomlSectionHeaderKey(header: string): string { - const projectPath = parseCodexProjectHeaderPath(header) - return projectPath === null - ? header.trim() - : `project:${normalizeCodexProjectPathForLookup(projectPath)}` + return buildProjectTomlSectionHeaderKey(header, normalizeCodexProjectPathForLookup) } // Why: configs written before WSL tails compared case-sensitively can hold a // revocation under drifted casing; match it loosely so trust is not resurrected. function getRevocationTomlSectionHeaderKey(header: string): string { - const projectPath = parseCodexProjectHeaderPath(header) - return projectPath === null - ? header.trim() - : `project:${normalizeCodexProjectPathForRevocationLookup(projectPath)}` + return buildProjectTomlSectionHeaderKey(header, normalizeCodexProjectPathForRevocationLookup) }src/main/codex/codex-config-mirror.test.ts (1)
447-497: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winStrengthen assertions to verify header/trust_level pairing, not just presence.
Both new tests check
toContain('trust_level = "trusted"')andtoContain('trust_level = "untrusted"')independently of which[projects...]block they belong to. If the merge logic ever attached the wrong trust level to the wrong block (e.g. swapped trusted/untrusted between the drifted-case and exact-case headers), these assertions would still pass. Test 1 (Lines 425-445) avoids this by usingnot.toContain, but tests 2 and 3 don't pin the value to its header.♻️ Suggested stronger assertion for the re-trust test (Lines 472-476)
const runtimeConfig = readFileSync(getRuntimeConfigPath(), 'utf-8') - expect(runtimeConfig).toContain("[projects.'\\\\wsl$\\Ubuntu\\home\\u\\Repo']") - expect(runtimeConfig).toContain('trust_level = "trusted"') - expect(runtimeConfig).toContain('trust_level = "untrusted"') + const repoIdx = runtimeConfig.indexOf("[projects.'\\\\wsl$\\Ubuntu\\home\\u\\Repo']") + expect(repoIdx).toBeGreaterThanOrEqual(0) + expect(runtimeConfig.slice(repoIdx, repoIdx + 120)).toContain('trust_level = "trusted"') + expect(runtimeConfig).toContain('trust_level = "untrusted"')
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f6fab642-ee8d-4311-91fa-44877dada9b6
📒 Files selected for processing (7)
src/main/codex/codex-config-mirror.test.tssrc/main/codex/codex-config-mirror.tssrc/main/codex/config-toml-trust.test.tssrc/main/codex/config-toml-trust.tssrc/main/codex/hook-service.tssrc/shared/wsl-paths.test.tssrc/shared/wsl-paths.ts
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 <[email protected]>
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 <[email protected]>
- 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).
- 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.
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.
aff1459 to
16b12ce
Compare
…blyai#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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]>
Problem
normalizeCodexProjectPathForLookupinsrc/main/codex/config-toml-trust.tslowercased the entire Windows/UNC-shaped path — including the Linux path segment under\\wsl$\<distro>\.... That correctly merges Windows drive-letter spellings, but it conflated two case-distinct Linux directories under a WSL UNC share (e.g..../Repoand.../repo) onto one project trust key. The mirror dedupe incodex-config-mirror.ts(getTomlSectionHeaderKey) uses that same key, so it inherited the bug.Fix
normalizeCodexProjectPathForLookupnow splits WSL UNC paths at the case-insensitive Windows share prefix (\\wsl$\<distro>/\\wsl.localhost\<distro>):Minimal diff: one function reworked plus a small
matchWslUncSharePrefixhelper.Tests
src/main/codex/config-toml-trust.test.ts:describe('normalizeCodexProjectPathForLookup')proving:C:\repo≡c:/repo;\\wsl$\Ubuntu\home\u\Repo≠\\wsl$\Ubuntu\home\u\repo; separator/distro-casing variants of the same WSL path merge;wsl.localhostbehaves likewsl$; normal UNC still case-folds; POSIX paths untouched.upsertProjectTrustLevelInContentkeeps case-distinct WSL Linux paths as two separate[projects.*]blocks.pnpm vitest run config-toml-trust codex-config-mirror→ 122 passed / 3 skipped. Oxlint clean; typecheck clean (only pre-existing unrelatedtypescript-apimodule errors). CRLF header repair (#8197) and hook-path trust (#8191) tests unaffected.Made with Orca 🐋