Skip to content

Commit 8d25170

Browse files
committed
fix: resolve clippy warnings in cortex-cli crate
1 parent ac24885 commit 8d25170

17 files changed

Lines changed: 61 additions & 109 deletions

File tree

src/cortex-cli/src/agent_cmd/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ mod tests {
253253
#[test]
254254
fn test_agent_mode_clone() {
255255
let mode = AgentMode::Subagent;
256-
let cloned = mode.clone();
256+
let cloned = mode;
257257
assert_eq!(mode, cloned);
258258
}
259259

src/cortex-cli/src/agent_cmd/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ pub fn matches_pattern(name: &str, pattern: &str) -> bool {
7777
// *pattern* - contains
7878
let inner = &pattern[1..pattern.len() - 1];
7979
name.contains(inner)
80-
} else if pattern.starts_with('*') {
80+
} else if let Some(suffix) = pattern.strip_prefix('*') {
8181
// *pattern - ends with
82-
name.ends_with(&pattern[1..])
82+
name.ends_with(suffix)
8383
} else if pattern.ends_with('*') {
8484
// pattern* - starts with
8585
name.starts_with(&pattern[..pattern.len() - 1])

src/cortex-cli/src/cli/handlers.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,6 @@ pub async fn run_resume(resume_cli: ResumeCommand) -> Result<()> {
648648
// Start TUI with the session
649649
#[cfg(feature = "cortex-tui")]
650650
{
651-
let config = config;
652651
// The TUI would need to support session resumption
653652
cortex_tui::run(config, None).await?;
654653
}
@@ -698,6 +697,7 @@ pub async fn run_delete(delete_cli: DeleteCommand) -> Result<()> {
698697
}
699698

700699
/// List sessions.
700+
#[allow(clippy::too_many_arguments)]
701701
pub async fn list_sessions(
702702
all: bool,
703703
_days: Option<u32>,
@@ -884,10 +884,10 @@ pub async fn list_features() -> Result<()> {
884884
pub async fn run_serve(serve_cli: ServeCommand) -> Result<()> {
885885
use cortex_app_server::ServerConfig;
886886

887-
let mut config = ServerConfig::default();
888-
889-
// Set listen address from host and port
890-
config.listen_addr = format!("{}:{}", serve_cli.host, serve_cli.port);
887+
let mut config = ServerConfig {
888+
listen_addr: format!("{}:{}", serve_cli.host, serve_cli.port),
889+
..Default::default()
890+
};
891891

892892
// Set authentication if provided
893893
if let Some(token) = serve_cli.auth_token {
@@ -967,7 +967,6 @@ pub async fn run_history(history_cli: HistoryCommand) -> Result<()> {
967967

968968
#[cfg(test)]
969969
mod tests {
970-
use super::*;
971970
use clap_complete::Shell;
972971
use std::io::{self, ErrorKind, Write};
973972

src/cortex-cli/src/compact_cmd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use anyhow::{Context, Result};
1717
use clap::Parser;
1818
use serde::Serialize;
19-
use std::path::PathBuf;
19+
use std::path::{Path, PathBuf};
2020

2121
/// Compact CLI command.
2222
#[derive(Debug, Parser)]
@@ -277,7 +277,7 @@ fn count_orphaned_history(sessions_dir: &PathBuf, history_dir: &PathBuf) -> usiz
277277
}
278278

279279
/// Check if compaction lock is held.
280-
fn is_lock_held(data_dir: &PathBuf) -> bool {
280+
fn is_lock_held(data_dir: &Path) -> bool {
281281
let lock_path = data_dir.join(".compaction.lock");
282282
if lock_path.exists()
283283
&& let Ok(metadata) = std::fs::metadata(&lock_path)

src/cortex-cli/src/completion_setup.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::fs;
88
use std::io::{self, IsTerminal, Write};
9-
use std::path::PathBuf;
9+
use std::path::{Path, PathBuf};
1010

1111
use clap_complete::Shell;
1212

@@ -37,12 +37,12 @@ fn get_cortex_home() -> Option<PathBuf> {
3737
}
3838

3939
/// Check if completion setup has already been offered.
40-
fn completion_already_offered(cortex_home: &PathBuf) -> bool {
40+
fn completion_already_offered(cortex_home: &Path) -> bool {
4141
cortex_home.join(COMPLETION_OFFERED_MARKER).exists()
4242
}
4343

4444
/// Mark that completion setup has been offered.
45-
fn mark_completion_offered(cortex_home: &PathBuf) -> io::Result<()> {
45+
fn mark_completion_offered(cortex_home: &Path) -> io::Result<()> {
4646
// Ensure the directory exists
4747
fs::create_dir_all(cortex_home)?;
4848

src/cortex-cli/src/exec_cmd/autonomy.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! Controls what operations the agent can perform without user approval.
44
5-
use std::path::PathBuf;
5+
use std::path::Path;
66

77
use clap::ValueEnum;
88
use cortex_protocol::{AskForApproval, SandboxPolicy};
@@ -55,17 +55,17 @@ impl AutonomyLevel {
5555
}
5656

5757
/// Convert to sandbox policy.
58-
pub fn to_sandbox_policy(&self, cwd: &PathBuf) -> SandboxPolicy {
58+
pub fn to_sandbox_policy(&self, cwd: &Path) -> SandboxPolicy {
5959
match self {
6060
AutonomyLevel::ReadOnly => SandboxPolicy::ReadOnly,
6161
AutonomyLevel::Low | AutonomyLevel::Medium => SandboxPolicy::WorkspaceWrite {
62-
writable_roots: vec![cwd.clone()],
62+
writable_roots: vec![cwd.to_path_buf()],
6363
network_access: *self == AutonomyLevel::Medium,
6464
exclude_tmpdir_env_var: false,
6565
exclude_slash_tmp: false,
6666
},
6767
AutonomyLevel::High => SandboxPolicy::WorkspaceWrite {
68-
writable_roots: vec![cwd.clone()],
68+
writable_roots: vec![cwd.to_path_buf()],
6969
network_access: true,
7070
exclude_tmpdir_env_var: false,
7171
exclude_slash_tmp: false,

src/cortex-cli/src/exec_cmd/helpers.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Helper functions for exec mode flags.
22
3-
use std::path::PathBuf;
3+
use std::path::{Path, PathBuf};
44

55
use anyhow::{Context, Result, bail};
66

@@ -59,15 +59,7 @@ pub fn read_clipboard() -> Result<String> {
5959

6060
/// Fetch content from a URL.
6161
pub async fn fetch_url_content(url: &str) -> Result<String> {
62-
// Use reqwest if available, otherwise fall back to curl
63-
#[cfg(feature = "reqwest")]
64-
{
65-
let response = reqwest::get(url).await?;
66-
let text = response.text().await?;
67-
Ok(text)
68-
}
69-
70-
#[cfg(not(feature = "reqwest"))]
62+
// Use curl for fetching
7163
{
7264
use std::process::Command;
7365
let output = Command::new("curl")
@@ -85,7 +77,7 @@ pub async fn fetch_url_content(url: &str) -> Result<String> {
8577
}
8678

8779
/// Get git diff from the working directory.
88-
pub fn get_git_diff(cwd: &PathBuf) -> Result<String> {
80+
pub fn get_git_diff(cwd: &Path) -> Result<String> {
8981
use std::process::Command;
9082

9183
let output = Command::new("git")
@@ -109,7 +101,7 @@ pub fn get_git_diff(cwd: &PathBuf) -> Result<String> {
109101

110102
/// Collect files matching include/exclude patterns.
111103
pub fn collect_files_by_pattern(
112-
cwd: &PathBuf,
104+
cwd: &Path,
113105
include_patterns: &[String],
114106
exclude_patterns: &[String],
115107
) -> Result<String> {
@@ -323,7 +315,7 @@ mod tests {
323315
fn test_validate_path_environment() {
324316
// This test just checks that the function doesn't panic
325317
let warnings = validate_path_environment();
326-
// Warnings may or may not be present depending on the environment
327-
assert!(warnings.len() >= 0);
318+
// Just verify we got a result (warnings may or may not be present)
319+
let _ = warnings;
328320
}
329321
}

src/cortex-cli/src/github_cmd.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub struct InstallArgs {
5353
/// - Analyze code changes for bugs, security issues, and best practices
5454
/// - Suggest improvements with inline comments
5555
/// - Respond to review comments and questions
56+
///
5657
/// Triggered by: pull_request (opened, synchronize, reopened)
5758
#[arg(long, default_value_t = true)]
5859
pub pr_review: bool,
@@ -904,8 +905,6 @@ mod tests {
904905

905906
#[tokio::test]
906907
async fn test_install_accepts_valid_directory() {
907-
use std::io::Write;
908-
909908
// Create a temporary directory
910909
let temp_dir = std::env::temp_dir().join(format!("cortex_test_dir_{}", std::process::id()));
911910
std::fs::create_dir_all(&temp_dir).expect("Failed to create temp dir");

src/cortex-cli/src/import_cmd.rs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use anyhow::{Context, Result, bail};
66
use clap::Parser;
77
use std::collections::HashSet;
8-
use std::path::PathBuf;
8+
use std::path::{Path, PathBuf};
99

1010
use crate::styled_output::{print_info, print_success, print_warning};
1111
use cortex_engine::rollout::recorder::{RolloutRecorder, SessionMeta};
@@ -238,33 +238,7 @@ impl ImportCommand {
238238

239239
/// Fetch content from a URL.
240240
async fn fetch_url(url: &str) -> Result<String> {
241-
// Use reqwest if available, otherwise fall back to curl
242-
#[cfg(feature = "reqwest")]
243-
{
244-
let response = reqwest::get(url).await?;
245-
if !response.status().is_success() {
246-
bail!("Failed to fetch URL: HTTP {}", response.status());
247-
}
248-
249-
// Check content-type header to warn about non-JSON content
250-
if let Some(content_type) = response.headers().get(reqwest::header::CONTENT_TYPE) {
251-
let content_type_str = content_type.to_str().unwrap_or("");
252-
if !content_type_str.contains("application/json")
253-
&& !content_type_str.contains("text/plain")
254-
&& !content_type_str.is_empty()
255-
{
256-
print_warning(&format!(
257-
"URL returned Content-Type '{}', expected 'application/json'.",
258-
content_type_str
259-
));
260-
print_info("The import may fail if the content is not valid JSON.");
261-
}
262-
}
263-
264-
Ok(response.text().await?)
265-
}
266-
267-
#[cfg(not(feature = "reqwest"))]
241+
// Use curl for fetching
268242
{
269243
// Simple curl-based fallback
270244
use std::process::Command;
@@ -452,7 +426,7 @@ fn validate_export_messages(messages: &[ExportMessage]) -> Result<()> {
452426
}
453427

454428
/// Convert an export message to a protocol event.
455-
fn message_to_event(message: &ExportMessage, turn_id: &mut u64, cwd: &PathBuf) -> Result<Event> {
429+
fn message_to_event(message: &ExportMessage, turn_id: &mut u64, cwd: &Path) -> Result<Event> {
456430
let event_msg = match message.role.as_str() {
457431
"user" => {
458432
*turn_id += 1;
@@ -475,7 +449,7 @@ fn message_to_event(message: &ExportMessage, turn_id: &mut u64, cwd: &PathBuf) -
475449
call_id: message.tool_call_id.clone().unwrap_or_default(),
476450
turn_id: turn_id.to_string(),
477451
command: vec!["imported_tool".to_string()],
478-
cwd: cwd.clone(),
452+
cwd: cwd.to_path_buf(),
479453
parsed_cmd: vec![ParsedCommand {
480454
program: "imported_tool".to_string(),
481455
args: vec![],

src/cortex-cli/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ mod tests {
369369
// Initially should be false unless something panicked
370370
// We can't reset this, but we can verify the function works
371371
let has_panic = has_background_panic();
372-
// Just verify we can call the function
373-
assert!(has_panic == true || has_panic == false);
372+
// Just verify we can call the function and it returns a valid boolean
373+
let _ = has_panic;
374374
}
375375

376376
#[test]

0 commit comments

Comments
 (0)