chore: turn clippy on for test code (#4817)
This commit is contained in:
@@ -97,41 +97,3 @@ pub fn get_valid_sorted_sessions(sort_order: SortOrder) -> Result<Vec<SessionInf
|
||||
|
||||
Ok(session_infos)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::session::SessionMetadata;
|
||||
use std::fs;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[test]
|
||||
fn test_get_valid_sorted_sessions_with_corrupted_files() {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let session_dir = temp_dir.path().join("sessions");
|
||||
fs::create_dir_all(&session_dir).unwrap();
|
||||
|
||||
// Create a valid session file
|
||||
let valid_session = session_dir.join("valid_session.jsonl");
|
||||
let metadata = SessionMetadata::default();
|
||||
let metadata_json = serde_json::to_string(&metadata).unwrap();
|
||||
fs::write(&valid_session, format!("{}\n", metadata_json)).unwrap();
|
||||
|
||||
// Create a corrupted session file (invalid JSON)
|
||||
let corrupted_session = session_dir.join("corrupted_session.jsonl");
|
||||
fs::write(&corrupted_session, "invalid json content").unwrap();
|
||||
|
||||
// Create another valid session file
|
||||
let valid_session2 = session_dir.join("valid_session2.jsonl");
|
||||
fs::write(&valid_session2, format!("{}\n", metadata_json)).unwrap();
|
||||
|
||||
// Mock the session directory by temporarily setting it
|
||||
// Note: This is a simplified test - in practice, we'd need to mock the session::list_sessions function
|
||||
// For now, we'll just verify that the function handles errors gracefully
|
||||
|
||||
// The key improvement is that get_valid_sorted_sessions should not fail completely
|
||||
// when encountering corrupted sessions, but should skip them and continue with valid ones
|
||||
|
||||
// This test verifies the logic changes we made to handle corrupted sessions gracefully
|
||||
assert!(true, "Test passes - the function now handles corrupted sessions gracefully by skipping them instead of failing completely");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1364,7 +1364,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_corruption_recovery() -> Result<()> {
|
||||
let test_cases = vec![
|
||||
let test_cases = [
|
||||
// Case 1: Unclosed quotes
|
||||
(
|
||||
r#"{"role":"user","content":[{"type":"text","text":"Hello there}]"#,
|
||||
@@ -1665,7 +1665,10 @@ mod tests {
|
||||
let file_path = dir.path().join("metadata.jsonl");
|
||||
|
||||
let mut metadata = SessionMetadata::default();
|
||||
metadata.description = "Description with\nnewline and \"quotes\" and 🦆".to_string();
|
||||
#[allow(clippy::field_reassign_with_default)]
|
||||
{
|
||||
metadata.description = "Description with\nnewline and \"quotes\" and 🦆".to_string();
|
||||
}
|
||||
|
||||
let messages = Conversation::new_unvalidated(vec![Message::user().with_text("test")]);
|
||||
|
||||
@@ -1702,7 +1705,7 @@ mod tests {
|
||||
let mut lines: Vec<String> = contents.lines().map(String::from).collect();
|
||||
lines[0] = lines[0].replace(
|
||||
&get_home_dir().to_string_lossy().into_owned(),
|
||||
&invalid_dir.to_string_lossy().into_owned(),
|
||||
&invalid_dir.to_string_lossy(),
|
||||
);
|
||||
fs::write(&file_path, lines.join("\n"))?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user