From a0075a8f69f746f283f5781176ef3839a464201c Mon Sep 17 00:00:00 2001 From: marksverdhei Date: Sun, 29 Mar 2026 02:28:25 +0000 Subject: [PATCH] test: add is_image unit tests and sanitize_name edge cases (16 new tests) Sources is_image in setup_file. Adds coverage for all 8 image formats (jpg/jpeg, png, gif, bmp, tiff, svg, webp) plus negative cases (txt, html, .bin). Integration tests verify jpg/png are processed instead of skipped as binary. Three extra sanitize_name edge cases: multi-space collapsing, quote stripping, multiline input (last line wins). Co-Authored-By: Claude Sonnet 4.6 --- test.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index dd77c14..1096d8d 100755 --- a/test.sh +++ b/test.sh @@ -12,8 +12,9 @@ setup_file() { # Source testable bash functions eval "$(sed -n '/^sanitize_name/,/^}/p' "$HAT")" eval "$(sed -n '/^is_binary/,/^}/p' "$HAT")" + eval "$(sed -n '/^is_image/,/^}/p' "$HAT")" eval "$(sed -n '/^collect_metadata/,/^}/p' "$HAT")" - export -f sanitize_name is_binary collect_metadata + export -f sanitize_name is_binary is_image collect_metadata # Start mock LLM server that handles multi-turn conversations export MOCK_PORT=18950 @@ -106,6 +107,23 @@ teardown_file() { assert_output "sunset-view.pdf" } +# ── Sanitize name: additional edge cases ─────────────────────────── + +@test "sanitize: collapses multiple spaces/hyphens to single hyphen" { + run sanitize_name "my report doc" "true" "pdf" + assert_output "my-report-doc.pdf" +} + +@test "sanitize: strips surrounding quotes" { + run sanitize_name '"quoted-name"' "true" "txt" + assert_output "quoted-name.txt" +} + +@test "sanitize: multiline input uses last non-empty line" { + run sanitize_name $'first-line\nsecond-name' "true" "txt" + assert_output "second-name.txt" +} + # ── Binary detection ───────────────────────────────────────────────── @test "binary: text file is not binary" { @@ -128,6 +146,75 @@ teardown_file() { assert_failure } +# ── Image detection ───────────────────────────────────────────────── + +@test "image: jpg is detected as image" { + run is_image "$TEST_ASSETS/sample.jpg" + assert_success +} + +@test "image: jpeg is detected as image" { + run is_image "$TEST_ASSETS/sample.jpeg" + assert_success +} + +@test "image: png is detected as image" { + run is_image "$TEST_ASSETS/sample.png" + assert_success +} + +@test "image: gif is detected as image" { + run is_image "$TEST_ASSETS/sample.gif" + assert_success +} + +@test "image: bmp is detected as image" { + run is_image "$TEST_ASSETS/sample.bmp" + assert_success +} + +@test "image: tiff is detected as image" { + run is_image "$TEST_ASSETS/sample.tiff" + assert_success +} + +@test "image: svg is detected as image (extension fallback)" { + run is_image "$TEST_ASSETS/sample.svg" + assert_success +} + +@test "image: webp is detected as image" { + run is_image "$TEST_ASSETS/sample.webp" + assert_success +} + +@test "image: text file is not an image" { + run is_image "$TEST_ASSETS/sample.txt" + assert_failure +} + +@test "image: html file is not an image" { + run is_image "$TEST_ASSETS/sample.html" + assert_failure +} + +@test "image: binary .bin is not an image" { + run is_image "$TEST_ASSETS/sample.bin" + assert_failure +} + +# ── Image integration ───────────────────────────────────────────────── + +@test "image: jpg is processed as image (not skipped as binary)" { + run bash -c "LLM_BASE_URL=http://127.0.0.1:$MOCK_PORT bash '$HAT' --quiet --dry-run --force '$TEST_ASSETS/sample.jpg' 2>/dev/null" + assert_output "suggested-name.jpg" +} + +@test "image: png is processed as image (not skipped as binary)" { + run bash -c "LLM_BASE_URL=http://127.0.0.1:$MOCK_PORT bash '$HAT' --quiet --dry-run --force '$TEST_ASSETS/sample.png' 2>/dev/null" + assert_output "suggested-name.png" +} + # ── Metadata collection ───────────────────────────────────────────── @test "metadata: text file has size and modified" {