chore: add cargo fmt check to Rust CI and fix existing violations (#620)

TypeScript CI has prettier --check but Rust CI only runs cargo test.
Add cargo fmt --check to catch formatting issues early, and fix the
8 pre-existing formatting violations on main.
This commit is contained in:
Li Yang
2026-03-06 13:32:26 -06:00
committed by GitHub
parent b7e7a2548e
commit 788ad0e61f
4 changed files with 23 additions and 38 deletions
+5
View File
@@ -64,12 +64,17 @@ jobs:
- name: Setup Rust toolchain - name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Cache Rust build artifacts - name: Cache Rust build artifacts
uses: Swatinem/rust-cache@v2 uses: Swatinem/rust-cache@v2
with: with:
workspaces: cli workspaces: cli
- name: Format check
run: cargo fmt --manifest-path cli/Cargo.toml -- --check
- name: Run Rust tests - name: Run Rust tests
run: cargo test --profile ci --manifest-path cli/Cargo.toml run: cargo test --profile ci --manifest-path cli/Cargo.toml
+2 -7
View File
@@ -533,15 +533,10 @@ pub fn ensure_daemon(session: &str, opts: &DaemonOptions) -> Result<DaemonResult
#[cfg(unix)] #[cfg(unix)]
let endpoint_info = format!( let endpoint_info = format!(
"socket: {}", "socket: {}",
get_socket_dir() get_socket_dir().join(format!("{}.sock", session)).display()
.join(format!("{}.sock", session))
.display()
); );
#[cfg(windows)] #[cfg(windows)]
let endpoint_info = format!( let endpoint_info = format!("port: 127.0.0.1:{}", get_port_for_session(session));
"port: 127.0.0.1:{}",
get_port_for_session(session)
);
Err(format!("Daemon failed to start ({})", endpoint_info)) Err(format!("Daemon failed to start ({})", endpoint_info))
} }
+4 -1
View File
@@ -5181,7 +5181,10 @@ mod tests {
let _guard = EnvGuard::new(&["AGENT_BROWSER_HEADED"]); let _guard = EnvGuard::new(&["AGENT_BROWSER_HEADED"]);
_guard.set("AGENT_BROWSER_HEADED", "1"); _guard.set("AGENT_BROWSER_HEADED", "1");
let opts = launch_options_from_env(); let opts = launch_options_from_env();
assert!(!opts.headless, "AGENT_BROWSER_HEADED=1 should set headless=false"); assert!(
!opts.headless,
"AGENT_BROWSER_HEADED=1 should set headless=false"
);
} }
#[tokio::test] #[tokio::test]
+8 -26
View File
@@ -137,8 +137,8 @@ fn build_chrome_args(options: &LaunchOptions) -> Result<ChromeArgs, String> {
args.push(format!("--user-data-dir={}", expanded)); args.push(format!("--user-data-dir={}", expanded));
None None
} else { } else {
let dir = std::env::temp_dir() let dir =
.join(format!("agent-browser-chrome-{}", uuid::Uuid::new_v4())); std::env::temp_dir().join(format!("agent-browser-chrome-{}", uuid::Uuid::new_v4()));
std::fs::create_dir_all(&dir) std::fs::create_dir_all(&dir)
.map_err(|e| format!("Failed to create temp profile dir: {}", e))?; .map_err(|e| format!("Failed to create temp profile dir: {}", e))?;
args.push(format!("--user-data-dir={}", dir.display())); args.push(format!("--user-data-dir={}", dir.display()));
@@ -209,10 +209,7 @@ pub fn launch_chrome(options: &LaunchOptions) -> Result<ChromeProcess, String> {
format!("Failed to launch Chrome at {:?}: {}", chrome_path, e) format!("Failed to launch Chrome at {:?}: {}", chrome_path, e)
})?; })?;
let stderr = child let stderr = child.stderr.take().ok_or_else(|| {
.stderr
.take()
.ok_or_else(|| {
let _ = child.kill(); let _ = child.kill();
cleanup_temp_dir(&temp_user_data_dir); cleanup_temp_dir(&temp_user_data_dir);
"Failed to capture Chrome stderr".to_string() "Failed to capture Chrome stderr".to_string()
@@ -508,10 +505,7 @@ fn should_disable_sandbox(existing_args: &[String]) -> bool {
// Generic container detection: cgroup contains docker/kubepods/lxc // Generic container detection: cgroup contains docker/kubepods/lxc
if let Ok(cgroup) = std::fs::read_to_string("/proc/1/cgroup") { if let Ok(cgroup) = std::fs::read_to_string("/proc/1/cgroup") {
if cgroup.contains("docker") if cgroup.contains("docker") || cgroup.contains("kubepods") || cgroup.contains("lxc") {
|| cgroup.contains("kubepods")
|| cgroup.contains("lxc")
{
return true; return true;
} }
} }
@@ -655,10 +649,7 @@ mod tests {
#[test] #[test]
fn test_chrome_launch_error_generic() { fn test_chrome_launch_error_generic() {
let lines = vec![ let lines = vec!["info line".to_string(), "another info line".to_string()];
"info line".to_string(),
"another info line".to_string(),
];
let msg = chrome_launch_error("Chrome exited", &lines); let msg = chrome_launch_error("Chrome exited", &lines);
assert!(msg.contains("last 2 lines")); assert!(msg.contains("last 2 lines"));
} }
@@ -679,10 +670,7 @@ mod tests {
}; };
let result = build_chrome_args(&opts).unwrap(); let result = build_chrome_args(&opts).unwrap();
assert!(result.args.iter().any(|a| a == "--headless=new")); assert!(result.args.iter().any(|a| a == "--headless=new"));
assert!(result assert!(result.args.iter().any(|a| a == "--window-size=1280,720"));
.args
.iter()
.any(|a| a == "--window-size=1280,720"));
// Temp dir created when no profile // Temp dir created when no profile
assert!(result.temp_user_data_dir.is_some()); assert!(result.temp_user_data_dir.is_some());
let dir = result.temp_user_data_dir.unwrap(); let dir = result.temp_user_data_dir.unwrap();
@@ -741,14 +729,8 @@ mod tests {
..Default::default() ..Default::default()
}; };
let result = build_chrome_args(&opts).unwrap(); let result = build_chrome_args(&opts).unwrap();
assert!(!result assert!(!result.args.iter().any(|a| a == "--window-size=1280,720"));
.args assert!(result.args.iter().any(|a| a == "--window-size=1920,1080"));
.iter()
.any(|a| a == "--window-size=1280,720"));
assert!(result
.args
.iter()
.any(|a| a == "--window-size=1920,1080"));
if let Some(ref dir) = result.temp_user_data_dir { if let Some(ref dir) = result.temp_user_data_dir {
let _ = std::fs::remove_dir_all(dir); let _ = std::fs::remove_dir_all(dir);
} }