test(rust): use shared fixture macro#1161
Conversation
Replaces handwritten temporary directory setup across Rust tests with the shared fs_fixture! macro. This keeps fixture construction consistent, removes manual cleanup, and lets assert_fs own temporary directory lifetimes. The change also narrows test-only imports and guard structs where directory cleanup is now handled by the fixture helper.
Adds the missing create-pr guidance for cases where the user explicitly asks for merge completion. The new reference keeps merge gated on CodeRabbit review, passing required CI, and normal GitHub mergeability instead of treating PR readiness as the final step.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughReplace many tests' manual temp-dir setup with ChangesPR workflow documentation
Test infrastructure migration to fs_fixture
🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Suggested labels:
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
@coderabbitai please review this PR. The latest push replaces handwritten Rust test fixture setup with the shared fs_fixture! macro and adds the missing merge guidance to the create-pr skill. |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
ccusage-guide | c45ce85 | Commit Preview URL Branch Preview URL |
May 25 2026, 08:28 PM |
|
Review of
|
Merges origin/main to resolve the PR merge conflict after upstream Claude sidechain dedupe changes landed. The conflict resolution keeps the new upstream sidechain tests while retaining the fs_fixture! conversion for Claude usage file discovery tests.
|
@coderabbitai please review the latest push. I merged origin/main to resolve the PR conflict, kept the new upstream Claude sidechain tests, retained the fs_fixture! conversion, and reran format, full tests, and clippy. |
|
✅ Actions performedReview triggered.
|
Updates the test-support fixture test to create the root through fs_fixture! while still calling Fixture::write_file directly. This addresses CodeRabbit feedback without reintroducing handwritten temporary directory setup.
|
@coderabbitai I addressed your fixture-support observation in the latest push: the incremental fixture test now creates the root with fs_fixture!({}) and still calls Fixture::write_file directly, preserving direct API coverage without handwritten temp setup. I reran format, full tests, and clippy. |
|
Tip For best results, initiate chat on the files or code changes.
🐇 ✨ |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@rust/crates/ccusage/src/adapter/gemini/loader.rs`:
- Around line 48-54: The test sets GEMINI_DATA_DIR_ENV then removes it manually,
which leaks the env var if the test panics; wrap the env change in a panic-safe
guard: capture the previous value with std::env::var_os(GEMINI_DATA_DIR_ENV),
set the env var, then create a small RAII drop guard (or use a scoped restore
pattern) that on Drop restores the previous value (or removes the var if None).
Apply this around the SharedArgs creation / call to load_entries and
PricingMap::load_embedded so GEMINI_DATA_DIR_ENV is always restored even if
load_entries or the test panics.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8ab5e42c-cf75-48a2-869e-f51ac5c7c4e8
📒 Files selected for processing (26)
.agents/skills/create-pr/SKILL.md.agents/skills/create-pr/references/merge.mdrust/crates/ccusage-test-support/src/lib.rsrust/crates/ccusage/src/adapter/amp/parser.rsrust/crates/ccusage/src/adapter/claude/mod.rsrust/crates/ccusage/src/adapter/codebuff/loader.rsrust/crates/ccusage/src/adapter/codex/loader.rsrust/crates/ccusage/src/adapter/codex/mod.rsrust/crates/ccusage/src/adapter/copilot/loader.rsrust/crates/ccusage/src/adapter/droid/loader.rsrust/crates/ccusage/src/adapter/gemini/loader.rsrust/crates/ccusage/src/adapter/gemini/paths.rsrust/crates/ccusage/src/adapter/goose/loader.rsrust/crates/ccusage/src/adapter/goose/paths.rsrust/crates/ccusage/src/adapter/hermes/loader.rsrust/crates/ccusage/src/adapter/kilo/loader.rsrust/crates/ccusage/src/adapter/kimi/loader.rsrust/crates/ccusage/src/adapter/kimi/parser.rsrust/crates/ccusage/src/adapter/kimi/paths.rsrust/crates/ccusage/src/adapter/openclaw/loader.rsrust/crates/ccusage/src/adapter/opencode/loader.rsrust/crates/ccusage/src/adapter/pi/parser.rsrust/crates/ccusage/src/adapter/qwen/mod.rsrust/crates/ccusage/src/cli.rsrust/crates/ccusage/src/commands/mod.rsrust/crates/ccusage/src/main.rs
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
rust/crates/ccusage/src/adapter/claude/mod.rs (1)
241-279:⚠️ Potential issue | 🟠 Major | ⚡ Quick winRefresh dedupe indexes after cross-key replacement
On Line 266, replacements can now occur after sidechain fallback matching, but only new insertions (Line 275+) update
deduped_indexes. When replacement happens with a different exact(message_id, request_id)hash, later duplicates for that exact key can bypass dedupe and be appended.💡 Proposed fix
- if let Some((_, Some(index))) = dedupe_lookup { + if let Some((hash, Some(index))) = dedupe_lookup { if should_replace_deduped_entry(&entry.data, &deduped[index].data) { deduped[index] = entry; + push_deduped_index(deduped_indexes, hash, index); + if let Some(message_id) = deduped[index].data.message.id.as_deref() { + push_deduped_index(deduped_indexes, usage_dedupe_hash(message_id, None), index); + } } return; }🤖 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 `@rust/crates/ccusage/src/adapter/claude/mod.rs` around lines 241 - 279, When replacing an existing deduped entry (the block handling Some((_, Some(index))) where you call should_replace_deduped_entry and then set deduped[index] = entry) you must also refresh deduped_indexes for the new entry keys so future lookups for the exact (message_id, request_id) or message-only hash don't miss duplicates; after assigning deduped[index] = entry, compute the new exact hash via usage_dedupe_hash using the new entry's message.id and request_id and call push_deduped_index(deduped_indexes, new_hash, index), and likewise if the new entry has a message.id call push_deduped_index with usage_dedupe_hash(message_id, None); use the existing symbols deduped_indexes, deduped, entry, index, usage_dedupe_hash, push_deduped_index and message.id.as_deref() to locate and update the code.
🤖 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.
Outside diff comments:
In `@rust/crates/ccusage/src/adapter/claude/mod.rs`:
- Around line 241-279: When replacing an existing deduped entry (the block
handling Some((_, Some(index))) where you call should_replace_deduped_entry and
then set deduped[index] = entry) you must also refresh deduped_indexes for the
new entry keys so future lookups for the exact (message_id, request_id) or
message-only hash don't miss duplicates; after assigning deduped[index] = entry,
compute the new exact hash via usage_dedupe_hash using the new entry's
message.id and request_id and call push_deduped_index(deduped_indexes, new_hash,
index), and likewise if the new entry has a message.id call push_deduped_index
with usage_dedupe_hash(message_id, None); use the existing symbols
deduped_indexes, deduped, entry, index, usage_dedupe_hash, push_deduped_index
and message.id.as_deref() to locate and update the code.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 02fa7b98-97b9-4359-a486-36154f09987b
📒 Files selected for processing (9)
rust/crates/ccusage-test-support/src/lib.rsrust/crates/ccusage/src/adapter/amp/parser.rsrust/crates/ccusage/src/adapter/claude/mod.rsrust/crates/ccusage/src/adapter/codebuff/loader.rsrust/crates/ccusage/src/adapter/copilot/loader.rsrust/crates/ccusage/src/adapter/droid/loader.rsrust/crates/ccusage/src/adapter/kimi/parser.rsrust/crates/ccusage/src/adapter/pi/parser.rsrust/crates/ccusage/src/main.rs
Apply cargo fmt to the Rust tests changed in the fixture macro refactor. The CI lint-check runs nix flake check, which includes ccusage-rust-fmt. The previous local format pass did not cover the Rust workspace formatting shape used by that check, so this commit keeps the follow-up limited to rustfmt output.
|
@coderabbitai I pushed a rustfmt-only follow-up after CI reported ccusage-rust-fmt differences. Please review the latest commit as well. |
|
✅ Actions performedReview triggered.
|
ccusage
@ccusage/ccusage-darwin-arm64
@ccusage/ccusage-darwin-x64
@ccusage/ccusage-linux-arm64
@ccusage/ccusage-linux-x64
@ccusage/ccusage-win32-arm64
@ccusage/ccusage-win32-x64
commit: |
ccusage performance comparisonPR SHA: This compares the PR package against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the Rust PR release binary against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the PR package against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the Rust PR release binary against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the PR package against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the Rust PR release binary against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
Restore GEMINI_DATA_DIR with a panic-safe guard in Gemini tests so the environment is not leaked when a test panics. Refresh Claude dedupe indexes when a parent usage entry replaces a sidechain replay with a different request id, and cover the replacement path so later exact duplicates continue to dedupe.
|
@coderabbitai I addressed the remaining actionable findings: Gemini tests now restore GEMINI_DATA_DIR with a panic-safe guard, and Claude dedupe replacement refreshes indexes with a regression test. Please review the latest push. |
|
✅ Actions performedReview triggered.
|
ccusage performance comparisonPR SHA: This compares the PR package against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the Rust PR release binary against the configured base package on the same CI runner. Package runner startupExecution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one
Cached bunx execution performanceRuns the same large fixture through Fixtures: Claude
Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
Replaces handwritten Rust test fixture setup with the shared fs_fixture! macro across loader, parser, CLI, and command tests.
This removes manual temp directory creation and cleanup in tests while keeping runtime behavior unchanged. It also documents the missing create-pr merge step for explicit merge requests.
Testing:
Summary by cubic
Standardized Rust tests on the shared
fs_fixture!macro and added explicit merge guidance for thecreate-prskill. Also fixed Claude dedupe index refresh when replacing sidechain replays to keep later duplicates deduping correctly.Refactors
ccusage_test_support::fs_fixture!.GeminiDataDirEnvGuardto restoreGEMINI_DATA_DIRin tests.Fixture::write_filecoverage while creating the root via the macro.references/merge.mdand updatedSKILL.mdto require explicit user-requested merges.Bug Fixes
Written for commit c45ce85. Summary will update on new commits. Review in cubic
Summary by CodeRabbit
Documentation
Tests