test(codex_cli): build session paths component by component so hashes match on Windows - #226
Conversation
📝 WalkthroughWalkthroughThe Codex CLI tests now cover Codex data-directory resolution, root-aware model configuration cases, and platform-native session paths for stable archive hash comparisons. ChangesCodex CLI test coverage
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
2d6c39a to
74d6080
Compare
… match on Windows
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/analyzers/tests/codex_cli.rs (2)
562-572: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert precedence over an existing home config.
The test creates only the custom config. It therefore proves that the custom path is read, not that it overrides
~/.codex/config.toml. Write a different model to the home config to cover the precedence rule.💚 Proposed test strengthening
fn test_fallback_model_respects_codex_home() { let dir = tempfile::tempdir().unwrap(); + let home_codex = dir.path().join(".codex"); + std::fs::create_dir(&home_codex).unwrap(); + std::fs::write(home_codex.join("config.toml"), "model = \"gpt-5-mini\"\n").unwrap(); let custom = dir.path().join("custom-codex");🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/analyzers/tests/codex_cli.rs` around lines 562 - 572, Strengthen test_fallback_model_respects_codex_home by creating a different model configuration in the home-root config.toml before calling get_fallback_model_with_roots. Keep the custom Codex home configuration set to "gpt-5.5" and assert it is selected over the conflicting home configuration.
514-558: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSimplify the fixture writes and consider a table-driven form.
Each case creates, writes, and drops a
Fileonly to replaceconfig.toml.std::fs::writetruncates and closes in one call, and Line 566 already uses it. A table of(contents, expected)pairs would also remove the repeated assertion blocks.♻️ Proposed refactor
- // Test case 2: empty config file - let mut file = std::fs::File::create(&config_path).unwrap(); - file.write_all(b"").unwrap(); - drop(file); - let model = get_fallback_model_with_roots(None, Some(dir.path())); - assert_eq!(model, "gpt-5"); - - // Test case 3: model configured in config file - let mut file = std::fs::File::create(&config_path).unwrap(); - file.write_all(b"model = \"gpt-5.5\"\n").unwrap(); - drop(file); - let model = get_fallback_model_with_roots(None, Some(dir.path())); - assert_eq!(model, "gpt-5.5"); + // Contents of config.toml mapped to the expected fallback model. + for (contents, expected) in [ + ("", "gpt-5"), // empty file + ("model = \"gpt-5.5\"\n", "gpt-5.5"), // configured model + ("model = \"\"\n", "gpt-5"), // empty value + ("model = \" \"\n", "gpt-5"), // whitespace-only value + ("model = \n", "gpt-5"), // invalid TOML + ("other_key = \"value\"\n", "gpt-5"), // model key omitted + ] { + std::fs::write(&config_path, contents).unwrap(); + assert_eq!( + get_fallback_model_with_roots(None, Some(dir.path())), + expected, + "unexpected model for config {contents:?}" + ); + }Keep case 1 before the loop and case 5 after it, because neither uses a config file.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/analyzers/tests/codex_cli.rs` around lines 514 - 558, Simplify the repeated config-file test setup in get_fallback_model_with_roots tests by replacing each File::create/write_all/drop sequence with std::fs::write. Consolidate cases 2–4 and 6–8 into a table-driven loop of contents and expected models, keeping case 1 before the loop and the None home-directory case after it. Preserve all existing inputs and assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/analyzers/tests/codex_cli.rs`:
- Around line 562-572: Strengthen test_fallback_model_respects_codex_home by
creating a different model configuration in the home-root config.toml before
calling get_fallback_model_with_roots. Keep the custom Codex home configuration
set to "gpt-5.5" and assert it is selected over the conflicting home
configuration.
- Around line 514-558: Simplify the repeated config-file test setup in
get_fallback_model_with_roots tests by replacing each
File::create/write_all/drop sequence with std::fs::write. Consolidate cases 2–4
and 6–8 into a table-driven loop of contents and expected models, keeping case 1
before the loop and the None home-directory case after it. Preserve all existing
inputs and assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b780dd40-e10f-4053-9a71-22fbd3c8086a
📒 Files selected for processing (1)
src/analyzers/tests/codex_cli.rs
Closes #225.
test_message_hashes_remain_stable_after_archivingbuilt the active sessiondirectory with a single
join(".codex/sessions/2026/07/22"). On Windows thoseforward slashes stay inside the path string, while
canonical_session_pathrebuilds the archived path one component at a time and gets native separators.
conversation_hashhashes the string form of the path, so the two sides hasheddifferent strings and the assertion failed.
Both paths are now built component by component, which produces the same string
on either platform. The comment above them says why, so the next person editing
this fixture does not undo it.
The other nine
joincalls in this file that embed slashes are left alone. Theyonly create directories, and Windows accepts forward slashes there, so changing
them would widen the diff without fixing anything.
Verification. 409 passed, 0 failed on both
ubuntu-latestandwindows-latest,on the same tree as this branch plus a temporary workflow that is not part of the
change: https://github.com/NickAme03/splitrail/actions/runs/30660532341
The failure this fixes is visible in the run reported in #225, taken on
mainbefore this branch existed: 404 passed and 1 failed, with Windows the only red
job. https://github.com/NickAme03/splitrail/actions/runs/30655673828
This is a test fixture fix. It does not change any counting behaviour, and the
production path stays as it was:
WalkDiralready yields native separators onboth sides, which is why the numbers splitrail reports were never affected.
One thing this does not do, since it belongs to you and not to a fix:
checks.ymlruns only on
ubuntu-latestand never runscargo test, so nothing in CI wouldhave caught this and nothing will catch the next one. I am happy to add a Windows
test job in a separate pull request if you want it.