Skip to content

Commit bf85ed8

Browse files
committed
test(engine): cover cachedGitignore filepath.Abs error fallback
The filepath.Abs error branch (triggered when os.Getwd fails) was not exercised. Add a Linux-only test that removes the process cwd so filepath.Abs fails on a relative path, driving the filepath.Clean fallback. Brings runner_cache.go cachedGitignore to 100% coverage. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F2S14pCS1WAv6p7n8ZHHb2
1 parent 43fd9ea commit bf85ed8

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

internal/engine/runner_coverage_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"os"
66
"path/filepath"
7+
"runtime"
78
"testing"
89

910
"github.com/jeduden/mdsmith/internal/config"
@@ -46,6 +47,35 @@ func TestCachedGitignore_CacheHit(t *testing.T) {
4647

4748
// (dead test removed — filepath.Join(dir, ".") normalizes to dir, so both args are identical)
4849

50+
// TestCachedGitignore_AbsPathFallback covers the filepath.Abs error branch by
51+
// removing the process cwd (only possible on Linux) so os.Getwd fails when
52+
// given a relative path. Must not run in parallel — mutates the process cwd.
53+
func TestCachedGitignore_AbsPathFallback(t *testing.T) {
54+
if runtime.GOOS != "linux" {
55+
t.Skip("deleting cwd only works on Linux")
56+
}
57+
orig, err := os.Getwd()
58+
require.NoError(t, err)
59+
60+
dir, err := os.MkdirTemp("", "engine-cwd-test-*")
61+
require.NoError(t, err)
62+
63+
require.NoError(t, os.Chdir(dir))
64+
t.Cleanup(func() {
65+
_ = os.Chdir(orig)
66+
_ = os.RemoveAll(dir)
67+
})
68+
69+
// Removing the cwd makes os.Getwd (and hence filepath.Abs) fail for
70+
// relative paths while leaving the process still operational.
71+
require.NoError(t, os.Remove(dir))
72+
73+
runner := &Runner{Config: &config.Config{}}
74+
// Relative path triggers filepath.Abs → os.Getwd error → Clean fallback.
75+
m := runner.cachedGitignore(".")
76+
require.NotNil(t, m, "expected non-nil matcher even when Abs fails")
77+
}
78+
4979
func TestCachedGitignore_InitializesNilCache(t *testing.T) {
5080
runner := &Runner{
5181
Config: &config.Config{},

0 commit comments

Comments
 (0)