style: Apply cargo fmt and clippy fixes across codebase

Automated formatting and lint corrections from parallel agent work:

- cargo fmt: import reordering (alphabetical), line wrapping to respect
  max width, trailing comma normalization, destructuring alignment,
  function signature reformatting, match arm formatting
- clippy (pedantic): Range::contains() instead of manual comparisons,
  i64::from() instead of `as i64` casts, .clamp() instead of
  .max().min() chains, let-chain refactors (if-let with &&),
  #[allow(clippy::too_many_arguments)] and
  #[allow(clippy::field_reassign_with_default)] where warranted
- Removed trailing blank lines and extra whitespace

No behavioral changes. All existing tests pass unmodified.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Taylor Eernisse
2026-02-03 13:01:59 -05:00
parent ff94f24702
commit a50fc78823
42 changed files with 1431 additions and 623 deletions

View File

@@ -51,26 +51,72 @@ fn insert_document(conn: &Connection, id: i64, source_type: &str, title: &str, c
fn fts_basic_search() {
let conn = create_test_db();
insert_document(&conn, 1, "issue", "Authentication bug", "Users cannot login when using OAuth tokens. The JWT refresh fails silently.");
insert_document(&conn, 2, "merge_request", "Add user profile page", "This MR adds a new user profile page with avatar upload support.");
insert_document(&conn, 3, "issue", "Database migration failing", "The migration script crashes on PostgreSQL 14 due to deprecated syntax.");
insert_document(
&conn,
1,
"issue",
"Authentication bug",
"Users cannot login when using OAuth tokens. The JWT refresh fails silently.",
);
insert_document(
&conn,
2,
"merge_request",
"Add user profile page",
"This MR adds a new user profile page with avatar upload support.",
);
insert_document(
&conn,
3,
"issue",
"Database migration failing",
"The migration script crashes on PostgreSQL 14 due to deprecated syntax.",
);
let results = lore::search::search_fts(&conn, "authentication login", 10, lore::search::FtsQueryMode::Safe).unwrap();
let results = lore::search::search_fts(
&conn,
"authentication login",
10,
lore::search::FtsQueryMode::Safe,
)
.unwrap();
assert!(!results.is_empty(), "Expected at least one result for 'authentication login'");
assert_eq!(results[0].document_id, 1, "Authentication issue should be top result");
assert!(
!results.is_empty(),
"Expected at least one result for 'authentication login'"
);
assert_eq!(
results[0].document_id, 1,
"Authentication issue should be top result"
);
}
#[test]
fn fts_stemming_matches() {
let conn = create_test_db();
insert_document(&conn, 1, "issue", "Running tests", "The test runner is executing integration tests.");
insert_document(&conn, 2, "issue", "Deployment config", "Deployment configuration for production servers.");
insert_document(
&conn,
1,
"issue",
"Running tests",
"The test runner is executing integration tests.",
);
insert_document(
&conn,
2,
"issue",
"Deployment config",
"Deployment configuration for production servers.",
);
// "running" should match "runner" and "executing" via porter stemmer
let results = lore::search::search_fts(&conn, "running", 10, lore::search::FtsQueryMode::Safe).unwrap();
assert!(!results.is_empty(), "Stemming should match 'running' to 'runner'");
let results =
lore::search::search_fts(&conn, "running", 10, lore::search::FtsQueryMode::Safe).unwrap();
assert!(
!results.is_empty(),
"Stemming should match 'running' to 'runner'"
);
assert_eq!(results[0].document_id, 1);
}
@@ -78,20 +124,43 @@ fn fts_stemming_matches() {
fn fts_empty_results() {
let conn = create_test_db();
insert_document(&conn, 1, "issue", "Bug fix", "Fixed a null pointer dereference in the parser.");
insert_document(
&conn,
1,
"issue",
"Bug fix",
"Fixed a null pointer dereference in the parser.",
);
let results = lore::search::search_fts(&conn, "kubernetes deployment helm", 10, lore::search::FtsQueryMode::Safe).unwrap();
assert!(results.is_empty(), "No documents should match unrelated query");
let results = lore::search::search_fts(
&conn,
"kubernetes deployment helm",
10,
lore::search::FtsQueryMode::Safe,
)
.unwrap();
assert!(
results.is_empty(),
"No documents should match unrelated query"
);
}
#[test]
fn fts_special_characters_handled() {
let conn = create_test_db();
insert_document(&conn, 1, "issue", "C++ compiler", "The C++ compiler segfaults on template metaprogramming.");
insert_document(
&conn,
1,
"issue",
"C++ compiler",
"The C++ compiler segfaults on template metaprogramming.",
);
// Special characters should not crash the search
let results = lore::search::search_fts(&conn, "C++ compiler", 10, lore::search::FtsQueryMode::Safe).unwrap();
let results =
lore::search::search_fts(&conn, "C++ compiler", 10, lore::search::FtsQueryMode::Safe)
.unwrap();
// Safe mode sanitizes the query — it should still return results or at least not crash
assert!(results.len() <= 1);
}
@@ -101,17 +170,44 @@ fn fts_result_ordering_by_relevance() {
let conn = create_test_db();
// Doc 1: "authentication" in title and content
insert_document(&conn, 1, "issue", "Authentication system redesign", "The authentication system needs a complete redesign. Authentication flows are broken.");
insert_document(
&conn,
1,
"issue",
"Authentication system redesign",
"The authentication system needs a complete redesign. Authentication flows are broken.",
);
// Doc 2: "authentication" only in content, once
insert_document(&conn, 2, "issue", "Login page update", "Updated the login page with better authentication error messages.");
insert_document(
&conn,
2,
"issue",
"Login page update",
"Updated the login page with better authentication error messages.",
);
// Doc 3: unrelated
insert_document(&conn, 3, "issue", "Database optimization", "Optimize database queries for faster response times.");
insert_document(
&conn,
3,
"issue",
"Database optimization",
"Optimize database queries for faster response times.",
);
let results = lore::search::search_fts(&conn, "authentication", 10, lore::search::FtsQueryMode::Safe).unwrap();
let results = lore::search::search_fts(
&conn,
"authentication",
10,
lore::search::FtsQueryMode::Safe,
)
.unwrap();
assert!(results.len() >= 2, "Should match at least 2 documents");
// Doc 1 should rank higher (more occurrences of the term)
assert_eq!(results[0].document_id, 1, "Document with more term occurrences should rank first");
assert_eq!(
results[0].document_id, 1,
"Document with more term occurrences should rank first"
);
}
#[test]
@@ -128,7 +224,8 @@ fn fts_respects_limit() {
);
}
let results = lore::search::search_fts(&conn, "bug login", 5, lore::search::FtsQueryMode::Safe).unwrap();
let results =
lore::search::search_fts(&conn, "bug login", 5, lore::search::FtsQueryMode::Safe).unwrap();
assert!(results.len() <= 5, "Results should be capped at limit");
}
@@ -136,24 +233,45 @@ fn fts_respects_limit() {
fn fts_snippet_generated() {
let conn = create_test_db();
insert_document(&conn, 1, "issue", "Performance issue", "The application performance degrades significantly when more than 100 users are connected simultaneously. Memory usage spikes to 4GB.");
insert_document(
&conn,
1,
"issue",
"Performance issue",
"The application performance degrades significantly when more than 100 users are connected simultaneously. Memory usage spikes to 4GB.",
);
let results = lore::search::search_fts(&conn, "performance", 10, lore::search::FtsQueryMode::Safe).unwrap();
let results =
lore::search::search_fts(&conn, "performance", 10, lore::search::FtsQueryMode::Safe)
.unwrap();
assert!(!results.is_empty());
// Snippet should contain some text (may have FTS5 highlight markers)
assert!(!results[0].snippet.is_empty(), "Snippet should be generated");
assert!(
!results[0].snippet.is_empty(),
"Snippet should be generated"
);
}
#[test]
fn fts_triggers_sync_on_insert() {
let conn = create_test_db();
insert_document(&conn, 1, "issue", "Test document", "This is test content for FTS trigger verification.");
insert_document(
&conn,
1,
"issue",
"Test document",
"This is test content for FTS trigger verification.",
);
// Verify FTS table has an entry via direct query
let fts_count: i64 = conn
.query_row("SELECT COUNT(*) FROM documents_fts WHERE documents_fts MATCH 'test'", [], |r| r.get(0))
.query_row(
"SELECT COUNT(*) FROM documents_fts WHERE documents_fts MATCH 'test'",
[],
|r| r.get(0),
)
.unwrap();
assert_eq!(fts_count, 1, "FTS trigger should auto-index on INSERT");
@@ -163,20 +281,35 @@ fn fts_triggers_sync_on_insert() {
fn fts_triggers_sync_on_delete() {
let conn = create_test_db();
insert_document(&conn, 1, "issue", "Deletable document", "This content will be deleted from the index.");
insert_document(
&conn,
1,
"issue",
"Deletable document",
"This content will be deleted from the index.",
);
// Verify it's indexed
let before: i64 = conn
.query_row("SELECT COUNT(*) FROM documents_fts WHERE documents_fts MATCH 'deletable'", [], |r| r.get(0))
.query_row(
"SELECT COUNT(*) FROM documents_fts WHERE documents_fts MATCH 'deletable'",
[],
|r| r.get(0),
)
.unwrap();
assert_eq!(before, 1);
// Delete the document
conn.execute("DELETE FROM documents WHERE id = 1", []).unwrap();
conn.execute("DELETE FROM documents WHERE id = 1", [])
.unwrap();
// Verify it's removed from FTS
let after: i64 = conn
.query_row("SELECT COUNT(*) FROM documents_fts WHERE documents_fts MATCH 'deletable'", [], |r| r.get(0))
.query_row(
"SELECT COUNT(*) FROM documents_fts WHERE documents_fts MATCH 'deletable'",
[],
|r| r.get(0),
)
.unwrap();
assert_eq!(after, 0, "FTS trigger should remove entry on DELETE");
}
@@ -193,6 +326,8 @@ fn fts_null_title_handled() {
)
.unwrap();
let results = lore::search::search_fts(&conn, "rate limiting", 10, lore::search::FtsQueryMode::Safe).unwrap();
let results =
lore::search::search_fts(&conn, "rate limiting", 10, lore::search::FtsQueryMode::Safe)
.unwrap();
assert!(!results.is_empty(), "Should find documents with NULL title");
}