Skip to content

feat(macos): dynamically detect install root and fix flaky model catalog test#402

Open
huangzhir wants to merge 2 commits into
BigPizzaV3:mainfrom
huangzhir:feat/macos-install-root-and-test-fix
Open

feat(macos): dynamically detect install root and fix flaky model catalog test#402
huangzhir wants to merge 2 commits into
BigPizzaV3:mainfrom
huangzhir:feat/macos-install-root-and-test-fix

Conversation

@huangzhir
Copy link
Copy Markdown

📌 Background (修改背景)

  1. macOS 路径自适应检测优化

    • 问题描述:在先前版本中,macOS 平台的安装根路径硬编码为系统级 /Applications 目录。然而在实际使用中,许多环境(如受限的开发集群、普通用户环境)不允许或不方便向系统级 /Applications 目录写入软件。当用户将 .app 包安装或运行在用户主目录下的 ~/Applications 或其他自定义路径时,程序会因为无法动态感知自身的实际运行位置,而抛出“检测不到自身入口”的错误(无法识别静默启动器与管理工具入口)。
    • 优化方案:改为动态检测策略。
      • 优先检查系统级 /Applications 下是否已有已安装的 Codex++ 入口,以保证对系统级安装路径的最大兼容性。
      • 如果系统级没有入口,则动态通过 std::env::current_exe() 溯源当前正在运行的 .app 包所在的真实母目录(如用户级 ~/Applications 或其他位置)。
      • 若两者均不存在,则平滑回退到 /Applications
  2. 修复 Flaky 单元测试 (model_catalog_uses_active_relay_profile_model_list_for_display)

    • 问题描述:上游的 model_catalog 单元测试在部分测试跑测时会出现 Flaky 崩溃。原因是 mock 的 RelayProfile 中设置的 model 字段在序列化时被标记了 #[serde(skip_serializing)]。在 settings load 阶段反序列化时,由于 config_contents 属性为空,导致 model 被清空重置,最终引发断言失败崩溃。
    • 优化方案:在 mock 测试数据中补充匹配的 config_contents 属性,并将 relay_mode 设置为 MixedApi,以契合真实环境的数据还原路径,从根本上解决由于反序列化截断导致的 flaky bug,确保测试 100% 稳定通过。

🔍 Key Changes (修改内容与单一职责规范)

为严格遵守单一职责原则 (Single Responsibility Principle),本 PR 仅包含以下两个最核心文件的修改,不包含任何额外的脚本、打包配置或无关的权限变更:

1. crates/codex-plus-core/src/install/mod.rs

  • 重构 macOS 平台的 default_install_root() 函数,引入对 /Applications 和运行环境路径的双重检索和回退机制。

2. crates/codex-plus-core/tests/model_catalog.rs

  • 在单元测试 model_catalog_uses_active_relay_profile_model_list_for_display 中,补充 mock RelayProfileconfig_contentsrelay_mode 属性,确保反序列化模型不丢失。

🧪 Verification Results (验证结果)

所有核心功能和模型模块的自动化测试套件在本地均已 100% 成功通过:

  • cargo test -p codex-plus-core --test installers (6/6 全部 Pass 🟢)
  • cargo test -p codex-plus-core --test model_catalog (6/6 全部 Pass 🟢)
  • 全局 cargo test 顺利跑通,零编译警告和 Panic。

@BigPizzaV3
Copy link
Copy Markdown
Owner

主要解决了什么呢

@BigPizzaV3
Copy link
Copy Markdown
Owner

测试了吗,我这里没有mac

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.

2 participants