Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/pawan-cli/src/tui/irc_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ mod tests {
#[test]
fn poll_irc_inbox_surfaces_formatted_line() {
let hub = IrcHub::new();
let mut worker = hub.join("worker");
let worker = hub.join("worker");
let (mut app, _cmd_rx) = test_app_with_hub(&hub);

worker.send("main", "ping").expect("deliver");
Expand Down Expand Up @@ -412,7 +412,7 @@ mod tests {
#[test]
fn poll_irc_inbox_drains_multiple_messages() {
let hub = IrcHub::new();
let mut worker = hub.join("worker");
let worker = hub.join("worker");
let (mut app, _cmd_rx) = test_app_with_hub(&hub);

worker.send("main", "one").expect("deliver");
Expand Down
3 changes: 1 addition & 2 deletions crates/pawan-cli/src/tui/model_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn fetch_live_models_from(endpoint_url: &str) -> Option<Vec<ModelInfo>
if models.is_empty() {
None
} else {
models.sort_by(|a, b| b.quality_score.cmp(&a.quality_score));
models.sort_by_key(|b| std::cmp::Reverse(b.quality_score));
Some(models)
}
}
Expand Down Expand Up @@ -688,7 +688,6 @@ mod tests {
#[cfg(test)]
mod integration_tests {
use super::*;
use serde_json;
use wiremock::matchers::{method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};

Expand Down
2 changes: 1 addition & 1 deletion crates/pawan-cli/src/tui/queue_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl QueuePanel {
.collect();

let mut lines: Vec<Vec<String>> = vec![Vec::new()];
let max_lines = (area.height as usize).min(3).max(1);
let max_lines = (area.height as usize).clamp(1, 3);
let budget = area.width as usize;

for piece in pieces {
Expand Down
4 changes: 1 addition & 3 deletions crates/pawan-cli/src/tui/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,6 @@ mod tests {

use super::super::fuzzy_search::{default_command_item_lines, FuzzySearchState};
use super::{markdown_to_lines, parse_inline_markdown};
use insta;
use pawan::agent::session::Session;
use pawan::agent::ToolCallRecord;
use ratatui::style::Modifier;
Expand Down Expand Up @@ -2493,7 +2492,7 @@ mod tests {
reset_theme_for_test();
for name in ["onedark", "gruvbox"] {
let mut app = test_app();
app.input.insert_str(&format!("/theme {name}"));
app.input.insert_str(format!("/theme {name}"));
app.handle_event(Event::Key(crossterm::event::KeyEvent::new(
KeyCode::Enter,
KeyModifiers::NONE,
Expand Down Expand Up @@ -4201,7 +4200,6 @@ mod tests {
use super::FuzzySearchState;
use super::super::super::app::PermissionDialog;
use super::super::super::types::DisplayMessage;
use insta;
use pawan::agent::Role;
use ratatui::backend::TestBackend;
use ratatui::Terminal;
Expand Down
10 changes: 4 additions & 6 deletions crates/pawan-cli/src/tui/slash_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,11 @@ impl<'a> App<'a> {
s.to_string()
} else {
let mut end = 0usize;
let mut count = 0usize;
for (i, _) in s.char_indices() {
for (count, (i, _)) in s.char_indices().enumerate() {
if count == max {
break;
}
end = i + 1;
count += 1;
}
format!("{}…", &s[..end])
}
Expand Down Expand Up @@ -225,7 +223,7 @@ impl<'a> App<'a> {
let parts: Vec<&str> = arg.splitn(3, ' ').collect();
let format_str = parts.get(2).unwrap_or(&"md");
let path = parts.get(1).unwrap_or(&"pawan-session");
(path.to_string(), ExportFormat::from_str(format_str))
(path.to_string(), ExportFormat::parse(format_str))
} else if arg.is_empty() {
("pawan-session.md".to_string(), ExportFormat::Markdown)
} else {
Expand Down Expand Up @@ -617,7 +615,7 @@ impl<'a> App<'a> {
self.messages = Self::messages_from_session(result.messages);
let compacted = self.messages.len();
let pct = if original > 0 {
((original.saturating_sub(compacted)) * 100) / original
((original.saturating_sub(compacted)) * 100).checked_div(original).unwrap_or(0)
} else {
0
};
Expand All @@ -638,7 +636,7 @@ impl<'a> App<'a> {
.iter()
.map(|c| format!("{} — {}", c.name, c.description))
.collect();
lines.sort_by(|a, b| a.to_ascii_lowercase().cmp(&b.to_ascii_lowercase()));
lines.sort_by_key(|a| a.to_ascii_lowercase());
self.messages.push(DisplayMessage::new_text(
Role::System,
lines.join("\n"),
Expand Down
2 changes: 1 addition & 1 deletion crates/pawan-cli/src/tui/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub enum ExportFormat {

impl ExportFormat {
/// Parse format from string, defaulting to Markdown
pub fn from_str(s: &str) -> Self {
pub fn parse(s: &str) -> Self {
match s.to_lowercase().as_str() {
"html" => ExportFormat::Html,
"json" => ExportFormat::Json,
Expand Down
46 changes: 23 additions & 23 deletions crates/pawan-cli/tests/tui_types_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,39 @@ use pawan::agent::{ToolCallRecord, ToolCallRequest};

#[test]
fn test_export_format_from_str_lowercase() {
assert_eq!(ExportFormat::from_str("html"), ExportFormat::Html);
assert_eq!(ExportFormat::from_str("json"), ExportFormat::Json);
assert_eq!(ExportFormat::from_str("txt"), ExportFormat::Txt);
assert_eq!(ExportFormat::from_str("md"), ExportFormat::Markdown);
assert_eq!(ExportFormat::parse("html"), ExportFormat::Html);
assert_eq!(ExportFormat::parse("json"), ExportFormat::Json);
assert_eq!(ExportFormat::parse("txt"), ExportFormat::Txt);
assert_eq!(ExportFormat::parse("md"), ExportFormat::Markdown);
}

#[test]
fn test_export_format_from_str_uppercase() {
assert_eq!(ExportFormat::from_str("HTML"), ExportFormat::Html);
assert_eq!(ExportFormat::from_str("JSON"), ExportFormat::Json);
assert_eq!(ExportFormat::from_str("TXT"), ExportFormat::Txt);
assert_eq!(ExportFormat::from_str("MD"), ExportFormat::Markdown);
assert_eq!(ExportFormat::parse("HTML"), ExportFormat::Html);
assert_eq!(ExportFormat::parse("JSON"), ExportFormat::Json);
assert_eq!(ExportFormat::parse("TXT"), ExportFormat::Txt);
assert_eq!(ExportFormat::parse("MD"), ExportFormat::Markdown);
}

#[test]
fn test_export_format_from_str_mixed_case() {
assert_eq!(ExportFormat::from_str("Html"), ExportFormat::Html);
assert_eq!(ExportFormat::from_str("Json"), ExportFormat::Json);
assert_eq!(ExportFormat::parse("Html"), ExportFormat::Html);
assert_eq!(ExportFormat::parse("Json"), ExportFormat::Json);
}

#[test]
fn test_export_format_from_str_full_words() {
assert_eq!(ExportFormat::from_str("markdown"), ExportFormat::Markdown);
assert_eq!(ExportFormat::from_str("MARKDOWN"), ExportFormat::Markdown);
assert_eq!(ExportFormat::from_str("text"), ExportFormat::Txt);
assert_eq!(ExportFormat::from_str("TEXT"), ExportFormat::Txt);
assert_eq!(ExportFormat::parse("markdown"), ExportFormat::Markdown);
assert_eq!(ExportFormat::parse("MARKDOWN"), ExportFormat::Markdown);
assert_eq!(ExportFormat::parse("text"), ExportFormat::Txt);
assert_eq!(ExportFormat::parse("TEXT"), ExportFormat::Txt);
}

#[test]
fn test_export_format_from_str_unknown_defaults_to_markdown() {
assert_eq!(ExportFormat::from_str("pdf"), ExportFormat::Markdown);
assert_eq!(ExportFormat::from_str(""), ExportFormat::Markdown);
assert_eq!(ExportFormat::from_str("xyz"), ExportFormat::Markdown);
assert_eq!(ExportFormat::parse("pdf"), ExportFormat::Markdown);
assert_eq!(ExportFormat::parse(""), ExportFormat::Markdown);
assert_eq!(ExportFormat::parse("xyz"), ExportFormat::Markdown);
}

#[test]
Expand Down Expand Up @@ -285,7 +285,7 @@ fn test_content_block_text() {
fn test_content_block_text_streaming() {
let block = ContentBlock::Text { content: "streaming".to_string(), streaming: true };
match block {
ContentBlock::Text { content, streaming } => {
ContentBlock::Text { streaming, .. } => {
assert!(streaming);
}
_ => panic!("expected Text variant"),
Expand All @@ -301,7 +301,7 @@ fn test_content_block_tool_call() {
state: Box::new(state),
};
match block {
ContentBlock::ToolCall { name, args_summary, state } => {
ContentBlock::ToolCall { name, state, .. } => {
assert_eq!(name, "bash");
assert!(matches!(*state, ToolBlockState::Running));
}
Expand Down Expand Up @@ -531,10 +531,10 @@ fn test_tool_call_record_failed() {

#[test]
fn test_export_format_case_insensitive_all() {
assert_eq!(ExportFormat::from_str("hTmL"), ExportFormat::Html);
assert_eq!(ExportFormat::from_str("JsOn"), ExportFormat::Json);
assert_eq!(ExportFormat::from_str("TxT"), ExportFormat::Txt);
assert_eq!(ExportFormat::from_str("MaRkDoWn"), ExportFormat::Markdown);
assert_eq!(ExportFormat::parse("hTmL"), ExportFormat::Html);
assert_eq!(ExportFormat::parse("JsOn"), ExportFormat::Json);
assert_eq!(ExportFormat::parse("TxT"), ExportFormat::Txt);
assert_eq!(ExportFormat::parse("MaRkDoWn"), ExportFormat::Markdown);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/pawan-core/src/agent/irc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ mod tests {
#[test]
fn routes_direct_message() {
let hub = IrcHub::new();
let mut main = hub.join("main");
let main = hub.join("main");
let mut worker = hub.join("worker");

main.send("worker", "ping").expect("send");
Expand Down
7 changes: 3 additions & 4 deletions crates/pawan-core/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ pub(crate) fn fence_external_system_messages_for_resume(history: &mut [Message])
}

#[cfg(test)]
use construction::{get_api_key_with_secure_fallback, load_arch_context, probe_local_endpoint, scan_context_file};
use construction::{load_arch_context, probe_local_endpoint, scan_context_file};
#[cfg(test)]
use execute::{summarize_args, truncate_tool_result};
use execute::truncate_tool_result;

#[cfg(test)]
mod tests {
Expand Down Expand Up @@ -1589,10 +1589,9 @@ This is malicious.
#[cfg(test)]
mod coordinator_tests {
use super::*;
use crate::PawanError;
use crate::agent::backend::mock::MockBackend;
use crate::coordinator::{FinishReason, ToolCallingConfig};
use serde_json::{json, Value};
use serde_json::json;
use std::sync::Arc;

/// Test that config default has use_coordinator = false
Expand Down
2 changes: 1 addition & 1 deletion crates/pawan-core/src/subagent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn snapshot_queue(max_age_ms: u64) -> Vec<SubagentRun> {
age < max_age_ms
});
let mut runs: Vec<_> = guard.values().cloned().collect();
runs.sort_by(|a, b| a.started_at.cmp(&b.started_at));
runs.sort_by_key(|a| a.started_at);
runs
}

Expand Down
1 change: 1 addition & 0 deletions crates/pawan-core/src/tools/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ impl TaskTool {
})
}

#[allow(clippy::too_many_arguments)]
async fn run_subagent(
&self,
agent_type: &str,
Expand Down
Loading