Fix memory-docs line-count SQL edge case, remove stale tmp-referencing test
Nightly Build / build (push) Successful in 6m46s

- memory_docs list_with_metadata: use SQL substr to detect trailing
  newline instead of counting newlines and adding 1 unconditionally
- list_files: remove meta_smoke tests that referenced a non-existent
  scratchpad directory
This commit is contained in:
2026-07-22 22:34:09 +01:00
parent 7769b6689d
commit aa4f31ec64
2 changed files with 2 additions and 41 deletions
+2 -1
View File
@@ -102,7 +102,8 @@ pub async fn list_with_metadata(pool: &SqlitePool, prefix: &str) -> Result<Vec<M
let rows = sqlx::query_as::<_, MemoryEntryMeta>( let rows = sqlx::query_as::<_, MemoryEntryMeta>(
"SELECT path, "SELECT path,
CASE WHEN content = '' THEN 0 CASE WHEN content = '' THEN 0
ELSE LENGTH(content) - LENGTH(REPLACE(content, char(10), '')) + 1 ELSE LENGTH(content) - LENGTH(REPLACE(content, char(10), ''))
+ CASE WHEN substr(content, -1, 1) = char(10) THEN 0 ELSE 1 END
END AS line_count, END AS line_count,
LENGTH(CAST(content AS BLOB)) AS byte_len LENGTH(CAST(content AS BLOB)) AS byte_len
FROM memory_docs FROM memory_docs
@@ -229,43 +229,3 @@ fn walk(root: &Path, dir: &Path, depth: usize, max_depth: usize, dirs_only: bool
} }
Ok(()) Ok(())
} }
#[cfg(test)]
mod meta_smoke {
use super::*;
const SP: &str = "/private/tmp/claude-501/-Users-dguiducci-projects-skald-circle/1cb4c456-6a62-4c67-abf8-bb93ef73e30c/scratchpad/lf";
#[test]
fn human_size_fmt() {
assert_eq!(human_size(0), "0 B");
assert_eq!(human_size(512), "512 B");
assert_eq!(human_size(18 * 1024), "18 KB");
assert_eq!(human_size(1024 * 1024 + 400 * 1024), "1.4 MB");
}
#[test]
fn line_counts() {
assert_eq!(count_lines(b""), 0);
assert_eq!(count_lines(b"a\nb\nc\n"), 3);
assert_eq!(count_lines(b"no newline"), 1);
}
#[test]
fn entries() {
let t = std::path::Path::new(SP).join("three.txt");
let e = file_entry(&t, "three.txt".into());
println!("three.txt -> {}", serde_json::to_string(&e).unwrap());
assert_eq!(e.line_count, Some(3));
let o = std::path::Path::new(SP).join("one.txt");
let e = file_entry(&o, "one.txt".into());
println!("one.txt -> {}", serde_json::to_string(&e).unwrap());
assert_eq!(e.line_count, Some(1));
let b = std::path::Path::new(SP).join("blob.bin");
let e = file_entry(&b, "blob.bin".into());
println!("blob.bin -> {}", serde_json::to_string(&e).unwrap());
assert_eq!(e.line_count, None); // binary: size only
assert!(e.size.is_some());
}
}