Skip to content

fix(codex): use relative filename for model_catalog_json#3614

Merged
farion1231 merged 2 commits into
farion1231:mainfrom
steponeerror:fix/wsl-codex-model-catalog-path
Jun 3, 2026
Merged

fix(codex): use relative filename for model_catalog_json#3614
farion1231 merged 2 commits into
farion1231:mainfrom
steponeerror:fix/wsl-codex-model-catalog-path

Conversation

@steponeerror

@steponeerror steponeerror commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Closes #3573
Related: #3569

Problem / 问题描述

When cc-switch runs on Windows and the Codex config directory is a WSL path (e.g. \\wsl.localhost\Ubuntu\home\user\.codex), the generated config.toml contains a Windows UNC path in model_catalog_json:

当 cc-switch 在 Windows 上运行,且 Codex 配置目录是 WSL 路径时,生成的 config.tomlmodel_catalog_json 字段包含 Windows UNC 路径:

model_catalog_json = '\\wsl.localhost\Ubuntu\home\user\.codex\cc-switch-model-catalog.json'

Codex CLI runs inside WSL and cannot resolve UNC paths. Additionally, users who symlink their .codex directory across Windows/WSL (e.g. ln -s /mnt/c/Users/xxx/.codex ~/.codex) will break with any absolute path format.

Codex CLI 在 WSL 中运行,无法解析 UNC 路径。此外,通过符号链接跨系统共享 .codex 目录的用户,无论使用 Linux 还是 Windows 绝对路径,都会在某一端失效。

Summary / 方案概述

Write only the filename cc-switch-model-catalog.json (relative path) to config.toml. Since config.toml and the catalog file always reside in the same directory (~/.codex/), Codex CLI correctly resolves relative paths from the config directory.

仅写入文件名 cc-switch-model-catalog.json(相对路径)到 config.toml。由于 config.toml 和 catalog 文件始终在同一目录下,Codex CLI 会从配置目录解析相对路径。

This eliminates the need for platform-specific path translation and makes the config portable across Windows, WSL, and symlinked directories.

这消除了平台特定路径转换的需求,使配置在 Windows、WSL 和符号链接目录之间可移植。

Key Changes / 主要变更

  • set_codex_model_catalog_json_field(): Some arm writes only CC_SWITCH_CODEX_MODEL_CATALOG_FILENAME instead of the full absolute path

  • resolve_cc_switch_catalog_path(): Removed dead string-equality comparison that never matched on WSL

  • set_codex_model_catalog_json_field() None arm: Ownership is now determined solely by filename match

  • Deleted wsl_unc_to_linux_path() helper and all its tests (no longer needed)

  • set_codex_model_catalog_json_field()Some 分支仅写入 CC_SWITCH_CODEX_MODEL_CATALOG_FILENAME 而非完整绝对路径

  • resolve_cc_switch_catalog_path():移除了在 WSL 上永远不匹配的字符串相等比较

  • set_codex_model_catalog_json_field() None 分支:所有权判断仅通过文件名匹配

  • 删除了 wsl_unc_to_linux_path() 辅助函数及其所有测试(不再需要)

Test Plan / 测试计划

  • model_catalog_json_field_writes_relative_filename — verifies relative output / 验证相对路径输出
  • set_catalog_json_field_writes_filename_for_any_path — verifies any input path produces filename / 验证任意输入路径生成文件名
  • set_catalog_json_field_writes_filename_ignoring_unc_path — Windows-only, verifies UNC path input / 仅 Windows,验证 UNC 路径输入
  • set_catalog_json_none_removes_cc_switch_owned_by_filename — backward compat with absolute paths / 向后兼容绝对路径
  • set_catalog_json_none_removes_relative_path — verifies removal of new relative path format / 验证移除新的相对路径格式
  • set_catalog_json_none_preserves_user_owned_catalog — verifies user catalogs untouched / 验证用户自有 catalog 不受影响
  • resolve_catalog_finds_relative_filename — verifies read path handles relative / 验证读取路径处理相对路径
  • resolve_catalog_ignores_user_owned_relative — verifies user catalogs ignored / 验证用户自有 catalog 被忽略
  • All existing tests pass with no regressions / 所有现有测试通过,无回归
  • Manual verification on Windows+WSL / 在 Windows+WSL 环境手动验证

Supersedes #3574 (that approach used UNC-to-Linux path translation instead of relative paths)
取代 #3574(该方案使用 UNC 转 Linux 路径翻译,而非相对路径)

Instead of writing an absolute path (which breaks on WSL/symlink setups),
write only the filename "cc-switch-model-catalog.json" to config.toml.
Codex CLI resolves relative paths from the config directory, and both
files always reside in the same directory (~/.codex/).

This eliminates the need for UNC-to-Linux path translation and makes
the config portable across Windows, WSL, and symlinked directories.

Also simplifies ownership checks in resolve_cc_switch_catalog_path()
and set_codex_model_catalog_json_field() by removing dead string-equality
comparisons that never matched on WSL.

Closes farion1231#3573
Related: farion1231#3569
@steponeerror
steponeerror force-pushed the fix/wsl-codex-model-catalog-path branch 2 times, most recently from 36d75d7 to 438a72d Compare June 2, 2026 15:10
@farion1231

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Wrap a >100-col UNC-path line and remove a trailing blank line that broke 'cargo fmt --check' in Backend CI. Style-only, no logic change.

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢您的贡献!

@farion1231
farion1231 merged commit 7811383 into farion1231:main Jun 3, 2026
3 checks passed
AnXiYiZhi pushed a commit to AnXiYiZhi/DevCLaw-old that referenced this pull request Jun 9, 2026
…3614)

* fix(codex): use relative filename for model_catalog_json

Instead of writing an absolute path (which breaks on WSL/symlink setups),
write only the filename "cc-switch-model-catalog.json" to config.toml.
Codex CLI resolves relative paths from the config directory, and both
files always reside in the same directory (~/.codex/).

This eliminates the need for UNC-to-Linux path translation and makes
the config portable across Windows, WSL, and symlinked directories.

Also simplifies ownership checks in resolve_cc_switch_catalog_path()
and set_codex_model_catalog_json_field() by removing dead string-equality
comparisons that never matched on WSL.

Closes farion1231#3573
Related: farion1231#3569

* style(codex): fix rustfmt violations in model_catalog tests

Wrap a >100-col UNC-path line and remove a trailing blank line that broke 'cargo fmt --check' in Backend CI. Style-only, no logic change.

---------

Co-authored-by: steponeerror <[email protected]>
Co-authored-by: Jason <[email protected]>
gfunc pushed a commit to gfunc/cc-switch that referenced this pull request Jun 19, 2026
…3614)

* fix(codex): use relative filename for model_catalog_json

Instead of writing an absolute path (which breaks on WSL/symlink setups),
write only the filename "cc-switch-model-catalog.json" to config.toml.
Codex CLI resolves relative paths from the config directory, and both
files always reside in the same directory (~/.codex/).

This eliminates the need for UNC-to-Linux path translation and makes
the config portable across Windows, WSL, and symlinked directories.

Also simplifies ownership checks in resolve_cc_switch_catalog_path()
and set_codex_model_catalog_json_field() by removing dead string-equality
comparisons that never matched on WSL.

Closes farion1231#3573
Related: farion1231#3569

* style(codex): fix rustfmt violations in model_catalog tests

Wrap a >100-col UNC-path line and remove a trailing blank line that broke 'cargo fmt --check' in Backend CI. Style-only, no logic change.

---------

Co-authored-by: steponeerror <[email protected]>
Co-authored-by: Jason <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Codex model_catalog_json uses Windows UNC path when config dir is in WSL

2 participants