chore: fix clippy warnings, add embedding/omni_patch, update telemetry, and ignore temp files

This commit is contained in:
Riz Ashraf committed 2026-09-29 06:42:29 +01:00
1 parent 495304f3fa
commit 98a1716ac8
23 files changed
+2253 -75

No files matched your search

+105
View File
@@ -65,3 +65,108 @@ pub async fn nvim_telemetry_handler(
axum::Json(serde_json::json!({"status": "ok"}))
}
use crate::models::TerminalHistory;
pub async fn get_terminal_history_handler(
State(state): State<Arc<AppState>>,
) -> impl axum::response::IntoResponse {
let history_json = state.handler.state.terminal_history.read_with(|h| serde_json::to_string(h).unwrap_or_else(|_| "[]".to_string()));
([(axum::http::header::CONTENT_TYPE, "application/json")], history_json)
}
pub async fn terminal_telemetry_handler(
State(state): State<Arc<AppState>>,
axum::Json(payload): axum::Json<TerminalHistory>,
) -> impl axum::response::IntoResponse {
state.handler.state.terminal_history.modify(|history| {
history.push_front(payload.clone());
if history.len() > 100 {
history.pop_back();
}
});
let ws_msg = serde_json::json!({
"type": "terminal_telemetry",
"data": payload
});
let msg_str = ws_msg.to_string();
let senders: Vec<_> = state
.clients
.read()
.unwrap_or_else(|e| e.into_inner())
.values()
.cloned()
.collect();
for tx in senders {
let _ = tx.try_send(msg_str.clone());
}
axum::Json(serde_json::json!({"status": "ok"}))
}
#[cfg(test)]
mod tests {
use super::*;
use crate::router::MemoryHandler;
use crate::state::MemoryState;
use axum::http::Request;
use tower::ServiceExt;
use std::collections::HashMap;
use std::sync::atomic::AtomicUsize;
use tempfile::tempdir;
use axum::routing::post;
use axum::routing::get;
#[tokio::test]
async fn test_terminal_history() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let app_state = Arc::new(AppState {
handler: Arc::new(MemoryHandler::new(state.clone())),
clients: std::sync::RwLock::new(HashMap::new()),
next_id: AtomicUsize::new(1),
});
let app = axum::Router::new()
.route("/api/terminal/history", get(get_terminal_history_handler))
.route("/terminal/telemetry", post(terminal_telemetry_handler))
.with_state(app_state.clone());
// Create a fake terminal telemetry payload
let payload = TerminalHistory {
command: "echo test".to_string(),
exit_code: 0,
timestamp: 12345,
};
// Post the telemetry
let req = Request::builder()
.method("POST")
.uri("/terminal/telemetry")
.header("content-type", "application/json")
.body(axum::body::Body::from(serde_json::to_string(&payload).unwrap()))
.unwrap();
let response = app.clone().oneshot(req).await.unwrap();
assert_eq!(response.status(), 200);
// Get the telemetry
let req2 = Request::builder()
.method("GET")
.uri("/api/terminal/history")
.body(axum::body::Body::empty())
.unwrap();
let response2 = app.oneshot(req2).await.unwrap();
assert_eq!(response2.status(), 200);
let body_bytes = axum::body::to_bytes(response2.into_body(), usize::MAX).await.unwrap();
let history: Vec<TerminalHistory> = serde_json::from_slice(&body_bytes).unwrap();
assert_eq!(history.len(), 1);
assert_eq!(history[0].command, "echo test");
}
}