chore: clean up dead code, fix broken test
- Remove unused methods: append_response_text, clear_response, has_pending_function_calls, take_function_calls - Add #[allow(dead_code)] for intentionally kept future-use methods and response modification helpers - Remove unused now_unix import from gemini.rs - Fix test_modify_strips_all_tools: tools key is removed entirely when no custom tools provided, not left as empty array - Zero warnings, 32 tests passing
This commit is contained in:
@@ -14,7 +14,7 @@ use tracing::info;
|
||||
|
||||
use super::models::{lookup_model, DEFAULT_MODEL, MODELS};
|
||||
use super::polling::poll_for_response;
|
||||
use super::util::{err_response, now_unix};
|
||||
use super::util::err_response;
|
||||
use super::AppState;
|
||||
use crate::mitm::store::PendingToolResult;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ pub(crate) struct PollResult {
|
||||
/// Available for both Opus (Anthropic) and Gemini models.
|
||||
pub thinking: Option<String>,
|
||||
/// Time the model spent thinking, as reported by the LS (e.g. "0.041999832s").
|
||||
#[allow(dead_code)]
|
||||
pub thinking_duration: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
@@ -635,9 +635,9 @@ mod tests {
|
||||
let modified = modify_request(&bytes, None).unwrap();
|
||||
let result: Value = serde_json::from_slice(&modified).unwrap();
|
||||
|
||||
let tools = result["request"]["tools"].as_array().unwrap();
|
||||
// With no ToolContext, tools should just be stripped (empty)
|
||||
assert!(tools.is_empty(), "all tools should be stripped");
|
||||
// With no ToolContext, tools should be removed entirely
|
||||
assert!(result["request"]["tools"].is_null() || result.pointer("/request/tools").is_none(),
|
||||
"tools should be removed when no custom tools provided");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -734,6 +734,7 @@ mod tests {
|
||||
// ─── Response modification ──────────────────────────────────────────────────
|
||||
|
||||
/// Rewrite an SSE response chunk to replace `functionCall` parts with text,
|
||||
#[allow(dead_code)]
|
||||
/// so the LS doesn't see tool calls for tools it doesn't manage.
|
||||
///
|
||||
/// The MITM intercept layer has already captured the function call data
|
||||
@@ -810,6 +811,7 @@ pub fn modify_response_chunk(chunk: &[u8]) -> Option<Vec<u8>> {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Find the end of a JSON object starting at the given string.
|
||||
/// Returns the index past the closing brace.
|
||||
fn find_json_end(s: &str) -> Option<usize> {
|
||||
@@ -845,6 +847,7 @@ fn find_json_end(s: &str) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Rebuild chunked encoding from a modified response body.
|
||||
/// Takes the full text (which contains old chunk sizes) and rebuilds
|
||||
/// with correct sizes.
|
||||
@@ -881,6 +884,7 @@ fn rechunk_response(text: &str) -> String {
|
||||
///
|
||||
/// Handles both Gemini public API format (`{"candidates":[...]}`) and
|
||||
/// internal LS format (`{"response":{"candidates":[...]}}`).
|
||||
#[allow(dead_code)]
|
||||
fn rewrite_function_calls_in_response(json: &mut Value) -> bool {
|
||||
let mut changed = false;
|
||||
|
||||
|
||||
@@ -281,26 +281,6 @@ impl MitmStore {
|
||||
self.has_active_function_call.store(false, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
/// Check if there are pending function calls for a cascade.
|
||||
pub async fn has_pending_function_calls(&self, cascade_id: &str) -> bool {
|
||||
let pending = self.pending_function_calls.read().await;
|
||||
pending.get(cascade_id).map_or(false, |v| !v.is_empty())
|
||||
}
|
||||
|
||||
/// Take (consume) pending function calls.
|
||||
pub async fn take_function_calls(&self, cascade_id: &str) -> Option<Vec<CapturedFunctionCall>> {
|
||||
let mut pending = self.pending_function_calls.write().await;
|
||||
let calls = pending.remove(cascade_id);
|
||||
let result = if calls.is_none() {
|
||||
pending.remove("_latest")
|
||||
} else {
|
||||
calls
|
||||
};
|
||||
if result.is_some() {
|
||||
self.has_active_function_call.store(false, Ordering::SeqCst);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/// Take any pending function calls (ignoring cascade ID).
|
||||
pub async fn take_any_function_calls(&self) -> Option<Vec<CapturedFunctionCall>> {
|
||||
@@ -381,15 +361,7 @@ impl MitmStore {
|
||||
|
||||
// ── Direct response capture (bypass LS) ──────────────────────────────
|
||||
|
||||
/// Append text to the captured response.
|
||||
pub async fn append_response_text(&self, text: &str) {
|
||||
let mut resp = self.captured_response_text.write().await;
|
||||
if let Some(ref mut existing) = *resp {
|
||||
existing.push_str(text);
|
||||
} else {
|
||||
*resp = Some(text.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Set (replace) the captured response text.
|
||||
pub async fn set_response_text(&self, text: &str) {
|
||||
@@ -416,14 +388,7 @@ impl MitmStore {
|
||||
self.response_complete.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
/// Clear captured response state (call at start of new request).
|
||||
pub fn clear_response(&self) {
|
||||
self.response_complete.store(false, Ordering::SeqCst);
|
||||
// Can't use async in sync fn, so we spawn a task... or just use try_write
|
||||
if let Ok(mut resp) = self.captured_response_text.try_write() {
|
||||
*resp = None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Async version of clear_response.
|
||||
pub async fn clear_response_async(&self) {
|
||||
@@ -458,11 +423,13 @@ impl MitmStore {
|
||||
}
|
||||
|
||||
/// Get the active cascade ID.
|
||||
#[allow(dead_code)]
|
||||
pub async fn get_active_cascade(&self) -> Option<String> {
|
||||
self.active_cascade_id.read().await.clone()
|
||||
}
|
||||
|
||||
/// Clear the active cascade ID (called after response is complete).
|
||||
#[allow(dead_code)]
|
||||
pub async fn clear_active_cascade(&self) {
|
||||
*self.active_cascade_id.write().await = None;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user