From 4ff456a6111d8553893308a84e9f0e992d4809bf Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 10 Apr 2026 09:48:07 +0300 Subject: processor: return error when markdown pre-scan cannot read .md claimedByMarkdown now wraps os.ReadFile failures instead of skipping, so Run fails fast and avoids wrong image claim state. Add regression test using an unreadable markdown file (Unix). Made-with: Cursor --- internal/processor/markdown_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'internal/processor/markdown_test.go') diff --git a/internal/processor/markdown_test.go b/internal/processor/markdown_test.go index a17b704..2445b53 100644 --- a/internal/processor/markdown_test.go +++ b/internal/processor/markdown_test.go @@ -3,7 +3,10 @@ package processor import ( "os" "path/filepath" + "runtime" "testing" + + "codeberg.org/snonux/snonux/internal/config" ) func TestFindLocalImages(t *testing.T) { @@ -88,3 +91,35 @@ func TestFindLocalImages(t *testing.T) { }) } } + +func TestRun_UnreadableMarkdownPreScanFails(t *testing.T) { + t.Parallel() + if runtime.GOOS == "windows" { + t.Skip("chmod does not reliably deny read for owned files on Windows") + } + + base := t.TempDir() + inputDir := filepath.Join(base, "inbox") + outputDir := filepath.Join(base, "out") + if err := os.MkdirAll(inputDir, 0o755); err != nil { + t.Fatal(err) + } + if err := os.MkdirAll(outputDir, 0o755); err != nil { + t.Fatal(err) + } + + mdPath := filepath.Join(inputDir, "note.md") + if err := os.WriteFile(mdPath, []byte("# x\n"), 0o644); err != nil { + t.Fatal(err) + } + if err := os.Chmod(mdPath, 0); err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = os.Chmod(mdPath, 0o644) }) + + cfg := &config.Config{InputDir: inputDir, OutputDir: outputDir} + _, err := Run(cfg) + if err == nil { + t.Fatal("Run: expected error when markdown pre-scan cannot read a .md file") + } +} -- cgit v1.2.3