Skip to content

Commit 776f2ed

Browse files
authored
fixes creation of cache directory panic when path already exists (#2857)
1 parent 697dc64 commit 776f2ed

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

crates/chat-cli/src/cli/agent/root_command_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl AgentArgs {
147147
Some(AgentSubcommands::Edit { name }) => {
148148
let _agents = Agents::load(os, None, true, &mut stderr, mcp_enabled).await.0;
149149
let (_agent, path_with_file_name) = Agent::get_agent_by_name(os, &name).await?;
150-
150+
151151
let editor_cmd = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());
152152
let mut cmd = std::process::Command::new(editor_cmd);
153153

crates/chat-cli/src/cli/chat/cli/profile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl AgentSubcommand {
252252
let (_agent, path_with_file_name) = Agent::get_agent_by_name(os, &name)
253253
.await
254254
.map_err(|e| ChatError::Custom(Cow::Owned(e.to_string())))?;
255-
255+
256256
let editor_cmd = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());
257257
let mut cmd = std::process::Command::new(editor_cmd);
258258

crates/chat-cli/src/cli/chat/tools/execute/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ mod tests {
494494
use crate::cli::agent::Agent;
495495

496496
let os = Os::new().await.unwrap();
497-
497+
498498
// Test read-only command with default settings (allow_read_only = false)
499499
let readonly_cmd = serde_json::from_value::<ExecuteCommand>(serde_json::json!({
500500
"command": "ls -la",
@@ -519,15 +519,16 @@ mod tests {
519519

520520
#[tokio::test]
521521
async fn test_eval_perm_allow_read_only_enabled() {
522+
use std::collections::HashMap;
523+
522524
use crate::cli::agent::{
523525
Agent,
524526
ToolSettingTarget,
525527
};
526-
use std::collections::HashMap;
527528

528529
let os = Os::new().await.unwrap();
529530
let tool_name = if cfg!(windows) { "execute_cmd" } else { "execute_bash" };
530-
531+
531532
let agent = Agent {
532533
name: "test_agent".to_string(),
533534
tools_settings: {
@@ -566,15 +567,16 @@ mod tests {
566567

567568
#[tokio::test]
568569
async fn test_eval_perm_allow_read_only_with_denied_commands() {
570+
use std::collections::HashMap;
571+
569572
use crate::cli::agent::{
570573
Agent,
571574
ToolSettingTarget,
572575
};
573-
use std::collections::HashMap;
574576

575577
let os = Os::new().await.unwrap();
576578
let tool_name = if cfg!(windows) { "execute_cmd" } else { "execute_bash" };
577-
579+
578580
let agent = Agent {
579581
name: "test_agent".to_string(),
580582
tools_settings: {
@@ -599,7 +601,9 @@ mod tests {
599601

600602
let res = denied_readonly_cmd.eval_perm(&os, &agent);
601603
// Should deny even read-only commands if they're in denied list
602-
assert!(matches!(res, PermissionEvalResult::Deny(ref commands) if commands.contains(&"\\Als .*\\z".to_string())));
604+
assert!(
605+
matches!(res, PermissionEvalResult::Deny(ref commands) if commands.contains(&"\\Als .*\\z".to_string()))
606+
);
603607

604608
// Test different read-only command not in denied list
605609
let allowed_readonly_cmd = serde_json::from_value::<ExecuteCommand>(serde_json::json!({

crates/chat-cli/src/mcp_client/oauth_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ async fn get_auth_manager(
289289
};
290290
let reg_as_str = serde_json::to_string_pretty(&reg)?;
291291
let reg_parent_path = reg_full_path.parent().ok_or(OauthUtilError::MalformDirectory)?;
292-
tokio::fs::create_dir(reg_parent_path).await?;
292+
tokio::fs::create_dir_all(reg_parent_path).await?;
293293
tokio::fs::write(reg_full_path, &reg_as_str).await?;
294294

295295
Ok(am)

0 commit comments

Comments
 (0)