Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(agent-tools): satisfy clippy under -D warnings

thinhlpg05589113faec
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs
index 05a36eab4..5f2618e1f 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs
@@ -354,6 +354,7 @@ impl WorkspaceScope {
// `read_only_project` is a folder the user attached read-only. It is validated
// here rather than trusted: an unusable one is an error, never a silent drop,
// or the agent would work against a folder it believes is attached and is not.
+#[allow(clippy::too_many_arguments)]
pub async fn execute_tool(
data_folder: String,
thread_id: String,
@@ -591,6 +592,10 @@ mod tests {
use super::*;
use serde_json::json;
use std::sync::atomic::{AtomicUsize, Ordering};
+ use std::sync::{Arc, Mutex};
+
+ /// The output sink test's shared ledger: what was sent, tagged with call id.
+ type Seen = Arc<Mutex<Vec<(u64, Option<String>, String)>>>;
static COUNTER: AtomicUsize = AtomicUsize::new(0);
@@ -760,6 +765,7 @@ mod tests {
/// spelled `/tmp/...` where it is bound over the sandbox's `/tmp` and by its
/// real path where nothing is mounted there.
#[tokio::test]
+ #[allow(clippy::await_holding_lock)]
async fn escaping_writes_are_refused() {
let data = unique_data_folder();
let df = data.to_string_lossy().to_string();
@@ -1446,8 +1452,7 @@ mod tests {
/// and what matters here is the ordering, correlation and the byte budget.
#[test]
fn the_output_sink_numbers_chunks_and_tags_them_with_the_call() {
- use std::sync::{Arc, Mutex};
- let seen: Arc<Mutex<Vec<(u64, Option<String>, String)>>> = Arc::new(Mutex::new(Vec::new()));
+ let seen: Seen = Arc::new(Mutex::new(Vec::new()));
let sink = test_sink(seen.clone(), Some("call-7".into()));
sink("one".into());
@@ -1466,8 +1471,7 @@ mod tests {
/// tool result.
#[test]
fn the_output_sink_stops_at_the_byte_cap_and_says_so() {
- use std::sync::{Arc, Mutex};
- let seen: Arc<Mutex<Vec<(u64, Option<String>, String)>>> = Arc::new(Mutex::new(Vec::new()));
+ let seen: Seen = Arc::new(Mutex::new(Vec::new()));
let sink = test_sink(seen.clone(), None);
sink("x".repeat(MAX_STREAMED_BYTES + 1));
@@ -1481,10 +1485,7 @@ mod tests {
/// Mirrors `output_sink`'s accounting without a `Channel`, which cannot be
/// constructed outside a webview.
- fn test_sink(
- seen: std::sync::Arc<std::sync::Mutex<Vec<(u64, Option<String>, String)>>>,
- call_id: Option<String>,
- ) -> crate::tools::OutputSink {
+ fn test_sink(seen: Seen, call_id: Option<String>) -> crate::tools::OutputSink {
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering};
use std::sync::Arc;
let seq = Arc::new(AtomicU64::new(0));
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs
index 3bfcba850..9a420022b 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs
@@ -131,6 +131,7 @@ pub enum Decision {
/// session grant > capability rules. Reads inside the project are silently
/// allowed; reads that escape the project, and all writes/exec, prompt (unless
/// already granted this session or pre-approved in agent.toml).
+#[allow(clippy::too_many_arguments)]
pub fn resolve_decision(
tool: &BuiltinTool,
args: &serde_json::Value,
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rs
index d6d813099..d5560f6eb 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rs
@@ -3537,6 +3537,7 @@ mod tests {
/// Renders for real when a browser is present, and returns an image part
/// rather than a data URL buried in the text.
#[tokio::test]
+ #[allow(clippy::await_holding_lock)]
async fn screenshot_returns_an_image_part_when_chrome_is_present() {
if chrome_binary().is_none() {
return;
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/jail.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/jail.rs
index 3662a67a2..f0b71bf49 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/jail.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/jail.rs
@@ -1069,13 +1069,8 @@ mod enforcement_tests {
fn temp_dir() -> PathBuf {
let tmp = std::env::temp_dir();
#[cfg(target_os = "macos")]
- {
- return tmp.canonicalize().unwrap_or(tmp);
- }
- #[cfg(not(target_os = "macos"))]
- {
- tmp
- }
+ let tmp = tmp.canonicalize().unwrap_or(tmp);
+ tmp
}
fn workspace() -> PathBuf {
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/workspace.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/workspace.rs
index 0691d7b6c..36075ae33 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/workspace.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/workspace.rs
@@ -544,6 +544,7 @@ mod tests {
/// by age. Nothing else in the temp dir is touched, and a fresh scratch
/// survives the real 24h threshold.
#[tokio::test]
+ #[allow(clippy::await_holding_lock)]
async fn stale_scratch_dirs_are_swept_and_fresh_ones_are_not() {
let session = format!("sweep-stale-{}", std::process::id());
let _guard = lock_scratch_namespace();