Include token counts for Piebald that were accidentally ignored#136
Include token counts for Piebald that were accidentally ignored#136
Conversation
📝 WalkthroughWalkthroughThe changes add tool call count tracking to the Piebald analyzer by introducing a new database query function and integrating per-message tool call counts into the message conversion and statistics pipeline. Changes
Sequence DiagramsequenceDiagram
participant Analyzer as PiebaldAnalyzer
participant Query as query_tool_call_counts()
participant DB as Database
participant Convert as convert_messages()
participant Stats as Stats Struct
Analyzer->>Query: Request tool call counts
Query->>DB: JOIN message_parts with message_part_tool_call
DB-->>Query: Return HashMap<message_id, count>
Query-->>Analyzer: tool_call_counts map
Analyzer->>Convert: Pass messages + tool_call_counts
Convert->>Convert: Lookup count for each message
Convert->>Stats: Populate tool_calls field (default 0 if absent)
Stats-->>Convert: Updated Stats with tool call data
Convert-->>Analyzer: ConversationMessage with tool_calls
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
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.
🧹 Nitpick comments (1)
src/analyzers/piebald.rs (1)
310-366: Consider adding test coverage for tool call count functionality.The existing tests don't cover
query_tool_call_countsor the tool call integration inconvert_messages. While the existing query functions (query_chats,query_messages) also lack direct unit tests, adding an in-memory SQLite test for the new functionality would improve confidence:💡 Optional: Test skeleton for tool call counts
#[test] fn test_convert_messages_with_tool_calls() { let chats = vec![PiebaldChat { id: 1, title: Some("Test".to_string()), model: Some("claude-3".to_string()), current_directory: Some("/test".to_string()), }]; let messages = vec![PiebaldMessage { id: 100, parent_chat_id: 1, role: "assistant".to_string(), model: Some("claude-3".to_string()), input_tokens: Some(50), output_tokens: Some(100), reasoning_tokens: None, cache_read_tokens: None, cache_write_tokens: None, created_at: "2025-12-10T14:30:00Z".to_string(), updated_at: "2025-12-10T14:30:00Z".to_string(), }]; let mut tool_call_counts = HashMap::new(); tool_call_counts.insert(100i64, 3u32); let result = convert_messages(&chats, messages, &tool_call_counts); assert_eq!(result.len(), 1); assert_eq!(result[0].stats.tool_calls, 3); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/analyzers/piebald.rs` around lines 310 - 366, Add unit test coverage for tool-call counting by creating an in-memory test that constructs PiebaldChat and PiebaldMessage instances, builds a HashMap<i64,u32> mapping message IDs to counts (the shape returned by query_tool_call_counts), calls convert_messages(&chats, messages, &tool_call_counts) and asserts the resulting MessageStats.tool_calls equals the provided count; reference PiebaldChat, PiebaldMessage, convert_messages and query_tool_call_counts when locating code to test and place the new test alongside the existing #[cfg(test)] mod tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/analyzers/piebald.rs`:
- Around line 310-366: Add unit test coverage for tool-call counting by creating
an in-memory test that constructs PiebaldChat and PiebaldMessage instances,
builds a HashMap<i64,u32> mapping message IDs to counts (the shape returned by
query_tool_call_counts), calls convert_messages(&chats, messages,
&tool_call_counts) and asserts the resulting MessageStats.tool_calls equals the
provided count; reference PiebaldChat, PiebaldMessage, convert_messages and
query_tool_call_counts when locating code to test and place the new test
alongside the existing #[cfg(test)] mod tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7c59fbc9-6eea-4313-a35d-c22e5aa0641d
📒 Files selected for processing (1)
src/analyzers/piebald.rs
Summary by CodeRabbit