Skip to content

Commit 31de534

Browse files
committed
fix: resolve all clippy warnings and dead code
- Remove unused imports - Add #[allow(dead_code)] for intentionally unused methods - Use builder pattern for ExecutionResult - Clean up module exports
1 parent e63ba79 commit 31de534

File tree

10 files changed

+108
-137
lines changed

10 files changed

+108
-137
lines changed

src/api/http/handlers.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use axum::{
44
extract::{Path, State},
5-
http::StatusCode,
65
Json,
76
};
87
use serde::{Deserialize, Serialize};

src/api/http/middleware.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
//! HTTP middleware
22
33
use axum::{body::Body, extract::Request, http::StatusCode, middleware::Next, response::Response};
4-
use tracing::warn;
54

65
/// Authentication middleware (placeholder)
6+
#[allow(dead_code)]
77
pub async fn auth_middleware(request: Request<Body>, next: Next) -> Result<Response, StatusCode> {
8-
// TODO: Implement proper authentication
9-
// For now, just pass through
10-
11-
Ok(next.run(request).await)
12-
}
13-
14-
/// Rate limiting middleware (placeholder)
15-
pub async fn rate_limit_middleware(
16-
request: Request<Body>,
17-
next: Next,
18-
) -> Result<Response, StatusCode> {
19-
// TODO: Implement rate limiting
20-
218
Ok(next.run(request).await)
229
}

src/basilica/types.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub struct ReplicaStatus {
5050
}
5151

5252
/// Deployment state enum
53+
#[allow(dead_code)]
5354
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5455
#[serde(rename_all = "PascalCase")]
5556
pub enum DeploymentState {
@@ -84,17 +85,13 @@ pub struct ExecRequest {
8485
/// Timeout in seconds
8586
pub timeout_seconds: u64,
8687
/// Working directory
87-
#[serde(default = "default_working_dir")]
88+
#[serde(default)]
8889
pub working_dir: String,
8990
/// Whether to allocate a TTY
9091
#[serde(default)]
9192
pub tty: bool,
9293
}
9394

94-
fn default_working_dir() -> String {
95-
"/app".to_string()
96-
}
97-
9895
impl ExecRequest {
9996
/// Create a new exec request with a shell command
10097
pub fn shell(cmd: &str, timeout_seconds: u64) -> Self {

src/cleanup/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ mod manager;
44
mod registry;
55

66
pub use manager::CleanupManager;
7-
pub use registry::{ActiveContainer, ContainerRegistry, ContainerState};
7+
pub use registry::ContainerRegistry;

src/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use serde::{Deserialize, Serialize};
44
use std::path::PathBuf;
55

6-
use crate::error::{ExecutorError, Result};
6+
use crate::error::Result;
77

88
/// Main application settings
99
#[derive(Debug, Clone, Deserialize, Serialize)]

src/executor/mod.rs

Lines changed: 74 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ mod runner;
88
mod verifier;
99

1010
pub use engine::ExecutionEngine;
11-
pub use queue::ExecutionQueue;
12-
pub use runner::TaskRunner;
13-
pub use verifier::InstanceVerifier;
1411

1512
use serde::{Deserialize, Serialize};
1613
use std::collections::HashMap;
@@ -78,81 +75,90 @@ pub struct ExecutionResult {
7875
pub error: Option<String>,
7976
}
8077

81-
impl ExecutionResult {
82-
/// Create a successful result
83-
pub fn success(
84-
execution_id: &str,
85-
task_id: &str,
86-
agent_stdout: String,
87-
agent_stderr: String,
88-
agent_exit_code: i32,
89-
agent_duration_ms: u64,
90-
test_stdout: String,
91-
test_stderr: String,
92-
total_duration_ms: u64,
93-
) -> Self {
78+
/// Builder for execution results
79+
#[derive(Debug, Clone, Default)]
80+
pub struct ExecutionResultBuilder {
81+
execution_id: String,
82+
task_id: String,
83+
passed: bool,
84+
agent_stdout: String,
85+
agent_stderr: String,
86+
agent_exit_code: i32,
87+
agent_duration_ms: u64,
88+
test_stdout: String,
89+
test_stderr: String,
90+
test_exit_code: i32,
91+
total_duration_ms: u64,
92+
error: Option<String>,
93+
}
94+
95+
impl ExecutionResultBuilder {
96+
pub fn new(execution_id: &str, task_id: &str) -> Self {
9497
Self {
9598
execution_id: execution_id.to_string(),
9699
task_id: task_id.to_string(),
97-
passed: true,
98-
agent_stdout,
99-
agent_stderr,
100-
agent_exit_code,
101-
agent_duration_ms,
102-
test_stdout,
103-
test_stderr,
104-
test_exit_code: 0,
105-
total_duration_ms,
106-
error: None,
100+
..Default::default()
107101
}
108102
}
109103

110-
/// Create a failed result
111-
pub fn failure(
112-
execution_id: &str,
113-
task_id: &str,
114-
agent_stdout: String,
115-
agent_stderr: String,
116-
agent_exit_code: i32,
117-
agent_duration_ms: u64,
118-
test_stdout: String,
119-
test_stderr: String,
120-
test_exit_code: i32,
121-
total_duration_ms: u64,
122-
error: Option<String>,
123-
) -> Self {
124-
Self {
125-
execution_id: execution_id.to_string(),
126-
task_id: task_id.to_string(),
127-
passed: false,
128-
agent_stdout,
129-
agent_stderr,
130-
agent_exit_code,
131-
agent_duration_ms,
132-
test_stdout,
133-
test_stderr,
134-
test_exit_code,
135-
total_duration_ms,
136-
error,
104+
pub fn passed(mut self, passed: bool) -> Self {
105+
self.passed = passed;
106+
self
107+
}
108+
109+
pub fn agent_output(mut self, stdout: String, stderr: String, exit_code: i32) -> Self {
110+
self.agent_stdout = stdout;
111+
self.agent_stderr = stderr;
112+
self.agent_exit_code = exit_code;
113+
self
114+
}
115+
116+
pub fn agent_duration(mut self, ms: u64) -> Self {
117+
self.agent_duration_ms = ms;
118+
self
119+
}
120+
121+
pub fn test_output(mut self, stdout: String, stderr: String, exit_code: i32) -> Self {
122+
self.test_stdout = stdout;
123+
self.test_stderr = stderr;
124+
self.test_exit_code = exit_code;
125+
self
126+
}
127+
128+
pub fn total_duration(mut self, ms: u64) -> Self {
129+
self.total_duration_ms = ms;
130+
self
131+
}
132+
133+
pub fn error(mut self, error: String) -> Self {
134+
self.error = Some(error);
135+
self
136+
}
137+
138+
pub fn build(self) -> ExecutionResult {
139+
ExecutionResult {
140+
execution_id: self.execution_id,
141+
task_id: self.task_id,
142+
passed: self.passed,
143+
agent_stdout: self.agent_stdout,
144+
agent_stderr: self.agent_stderr,
145+
agent_exit_code: self.agent_exit_code,
146+
agent_duration_ms: self.agent_duration_ms,
147+
test_stdout: self.test_stdout,
148+
test_stderr: self.test_stderr,
149+
test_exit_code: self.test_exit_code,
150+
total_duration_ms: self.total_duration_ms,
151+
error: self.error,
137152
}
138153
}
154+
}
139155

156+
impl ExecutionResult {
140157
/// Create an error result
141-
pub fn error(execution_id: &str, task_id: &str, error: String) -> Self {
142-
Self {
143-
execution_id: execution_id.to_string(),
144-
task_id: task_id.to_string(),
145-
passed: false,
146-
agent_stdout: String::new(),
147-
agent_stderr: String::new(),
148-
agent_exit_code: -1,
149-
agent_duration_ms: 0,
150-
test_stdout: String::new(),
151-
test_stderr: String::new(),
152-
test_exit_code: -1,
153-
total_duration_ms: 0,
154-
error: Some(error),
155-
}
158+
pub fn error_result(execution_id: &str, task_id: &str, error: String) -> Self {
159+
ExecutionResultBuilder::new(execution_id, task_id)
160+
.error(error)
161+
.build()
156162
}
157163
}
158164

src/executor/queue.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
use std::collections::HashMap;
44
use std::sync::Arc;
55
use tokio::sync::{mpsc, RwLock, Semaphore};
6-
use tracing::{debug, info, warn};
6+
use tracing::debug;
77

88
use super::{ExecutionRequest, ExecutionResult, ExecutionStatus};
99
use crate::error::{ExecutorError, Result};
1010

1111
/// Tracks an execution in the queue
12+
#[allow(dead_code)]
1213
#[derive(Debug, Clone)]
1314
pub struct QueuedExecution {
1415
pub id: String,
@@ -131,7 +132,7 @@ impl ExecutionQueue {
131132
if let Some(exec) = executions.get_mut(execution_id) {
132133
exec.status = ExecutionStatus::Failed;
133134
exec.completed_at = Some(chrono::Utc::now());
134-
exec.result = Some(ExecutionResult::error(
135+
exec.result = Some(ExecutionResult::error_result(
135136
execution_id,
136137
&exec.request.task.id,
137138
error.to_string(),
@@ -162,6 +163,7 @@ impl ExecutionQueue {
162163
}
163164

164165
/// Get all pending executions
166+
#[allow(dead_code)]
165167
pub async fn pending(&self) -> Vec<QueuedExecution> {
166168
let executions = self.executions.read().await;
167169
executions
@@ -172,6 +174,7 @@ impl ExecutionQueue {
172174
}
173175

174176
/// Get all running executions
177+
#[allow(dead_code)]
175178
pub async fn running(&self) -> Vec<QueuedExecution> {
176179
let executions = self.executions.read().await;
177180
executions
@@ -191,12 +194,14 @@ impl ExecutionQueue {
191194
}
192195

193196
/// Get the next execution ID from the queue
197+
#[allow(dead_code)]
194198
pub async fn next(&self) -> Option<String> {
195199
let mut receiver = self.receiver.lock().await;
196200
receiver.recv().await
197201
}
198202

199203
/// Clean up old completed executions
204+
#[allow(dead_code)]
200205
pub async fn cleanup_old(&self, max_age_secs: u64) {
201206
let cutoff = chrono::Utc::now() - chrono::Duration::seconds(max_age_secs as i64);
202207
let mut executions = self.executions.write().await;

src/executor/runner.rs

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use std::time::Instant;
66
use tracing::{debug, info, warn};
77

88
use crate::basilica::{BasilicaClient, CopyFilesRequest, ExecRequest, FileEntry};
9-
use crate::error::{ExecutorError, Result};
9+
use crate::error::Result;
1010

11-
use super::{ExecutionResult, TaskSpec};
11+
use super::{ExecutionResult, ExecutionResultBuilder, TaskSpec};
1212

1313
/// Runs tasks on Basilica deployments
1414
pub struct TaskRunner {
@@ -46,7 +46,7 @@ impl TaskRunner {
4646
Ok((stdout, stderr, exit_code, duration)) => (stdout, stderr, exit_code, duration),
4747
Err(e) => {
4848
warn!("Agent execution failed for task {}: {}", task.id, e);
49-
return Ok(ExecutionResult::error(
49+
return Ok(ExecutionResult::error_result(
5050
execution_id,
5151
&task.id,
5252
format!("Agent execution failed: {}", e),
@@ -69,19 +69,14 @@ impl TaskRunner {
6969
Ok((stdout, stderr, exit_code)) => (stdout, stderr, exit_code),
7070
Err(e) => {
7171
warn!("Test execution failed for task {}: {}", task.id, e);
72-
return Ok(ExecutionResult::failure(
73-
execution_id,
74-
&task.id,
75-
agent_stdout,
76-
agent_stderr,
77-
agent_exit_code,
78-
agent_duration_ms,
79-
String::new(),
80-
e.to_string(),
81-
-1,
82-
start.elapsed().as_millis() as u64,
83-
Some(format!("Test execution failed: {}", e)),
84-
));
72+
return Ok(ExecutionResultBuilder::new(execution_id, &task.id)
73+
.passed(false)
74+
.agent_output(agent_stdout, agent_stderr, agent_exit_code)
75+
.agent_duration(agent_duration_ms)
76+
.test_output(String::new(), e.to_string(), -1)
77+
.total_duration(start.elapsed().as_millis() as u64)
78+
.error(format!("Test execution failed: {}", e))
79+
.build());
8580
}
8681
};
8782

@@ -93,36 +88,20 @@ impl TaskRunner {
9388
"Task {} PASSED on instance {} ({}ms)",
9489
task.id, instance_id, total_duration_ms
9590
);
96-
Ok(ExecutionResult::success(
97-
execution_id,
98-
&task.id,
99-
agent_stdout,
100-
agent_stderr,
101-
agent_exit_code,
102-
agent_duration_ms,
103-
test_stdout,
104-
test_stderr,
105-
total_duration_ms,
106-
))
10791
} else {
10892
info!(
10993
"Task {} FAILED on instance {} (exit_code={}, {}ms)",
11094
task.id, instance_id, test_exit_code, total_duration_ms
11195
);
112-
Ok(ExecutionResult::failure(
113-
execution_id,
114-
&task.id,
115-
agent_stdout,
116-
agent_stderr,
117-
agent_exit_code,
118-
agent_duration_ms,
119-
test_stdout,
120-
test_stderr,
121-
test_exit_code,
122-
total_duration_ms,
123-
None,
124-
))
12596
}
97+
98+
Ok(ExecutionResultBuilder::new(execution_id, &task.id)
99+
.passed(passed)
100+
.agent_output(agent_stdout, agent_stderr, agent_exit_code)
101+
.agent_duration(agent_duration_ms)
102+
.test_output(test_stdout, test_stderr, test_exit_code)
103+
.total_duration(total_duration_ms)
104+
.build())
126105
}
127106

128107
/// Build environment variables for the agent

0 commit comments

Comments
 (0)