From abf8feb2297dff759fe7c41a6bec94187fc83024 Mon Sep 17 00:00:00 2001 From: Mortdecai Date: Tue, 7 Apr 2026 20:14:27 -0400 Subject: [PATCH] test: add end-to-end integration test for HTML filter to image extraction --- lib/parse/integration_test.go | 72 +++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lib/parse/integration_test.go diff --git a/lib/parse/integration_test.go b/lib/parse/integration_test.go new file mode 100644 index 0000000..a2a6113 --- /dev/null +++ b/lib/parse/integration_test.go @@ -0,0 +1,72 @@ +// lib/parse/integration_test.go +package parse + +import ( + "io" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" +) + +func TestIntegration_HTMLFilterToExtractImages(t *testing.T) { + // Skip if html-kitty filter or w3m not available + filterPath := filepath.Join(os.Getenv("HOME"), + ".local/libexec/aerc/filters/html-kitty") + if _, err := os.Stat(filterPath); err != nil { + t.Skip("html-kitty filter not found:", err) + } + if _, err := exec.LookPath("w3m"); err != nil { + t.Skip("w3m not found:", err) + } + + // HTML with a data: URI image + html := ` +

Hello World

+tiny red pixel +

Goodbye

+` + + cmd := exec.Command("python3", filterPath) + cmd.Stdin = strings.NewReader(html) + cmd.Env = append(os.Environ(), "COLUMNS=80") + out, err := cmd.Output() + if err != nil { + t.Fatalf("filter failed: %v", err) + } + + // Extract images from filter output + cleaned, images := ExtractImages(strings.NewReader(string(out))) + if len(images) == 0 { + t.Fatal("expected at least 1 image from filter output") + } + + // Verify image file exists on disk + if _, err := os.Stat(images[0].Path); err != nil { + t.Errorf("image file not found: %s", images[0].Path) + } + + // Verify alt text + if images[0].Alt != "tiny red pixel" { + t.Errorf("alt = %q, want 'tiny red pixel'", images[0].Alt) + } + + // Verify cleaned output has placeholder + cleanedBytes, _ := io.ReadAll(cleaned) + cleanedStr := string(cleanedBytes) + if !strings.Contains(cleanedStr, "\x00IMG:0\x00") { + t.Error("cleaned output missing placeholder") + } + + // Verify text content preserved + if !strings.Contains(cleanedStr, "Hello World") { + t.Error("text content 'Hello World' lost") + } + + // Clean up temp files + for _, img := range images { + dir := filepath.Dir(img.Path) + os.RemoveAll(dir) + } +}