From 0f108fd8ac6e01f41b66d166e676b475ec37f8dd Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 12 Nov 2026 01:03:54 +0100 Subject: [PATCH] internal/apply: a test of the places a module is placed in follows no link on the machine it runs on Builds: design 47 G A-95 (the owed hang of TestAModulesOwnPlacesAreStillPlaced on real mounts) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h --- internal/apply/placement_guard.go | 6 +++++- internal/apply/placement_guard_test.go | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/apply/placement_guard.go b/internal/apply/placement_guard.go index 248dda54..09662a6e 100644 --- a/internal/apply/placement_guard.go +++ b/internal/apply/placement_guard.go @@ -386,11 +386,15 @@ func below(path, dir string) bool { // atOrBelow says whether path is dir or below it. func atOrBelow(path, dir string) bool { return path == dir || below(path, dir) } +// evalSymlinks follows the links of an existing path; a variable so a test judges paths whose machine it does not touch (a mount +// of the machine it runs on may not answer). +var evalSymlinks = filepath.EvalSymlinks + // resolved is a path with every link in it followed, as far as the path exists, and the rest as declared. func resolved(path string) string { rest := "" for p := path; ; p = filepath.Dir(p) { - if real, err := filepath.EvalSymlinks(p); err == nil { + if real, err := evalSymlinks(p); err == nil { return filepath.Clean(filepath.Join(real, rest)) } if filepath.Dir(p) == p { diff --git a/internal/apply/placement_guard_test.go b/internal/apply/placement_guard_test.go index 8bff411d..869dddd9 100644 --- a/internal/apply/placement_guard_test.go +++ b/internal/apply/placement_guard_test.go @@ -178,6 +178,11 @@ func TestAFoundDirectoryIsUsedAsFound(t *testing.T) { // The module's own directories keep being placed: below /var/lib, below /etc as root's, a container's mount of // the machine's docker socket. func TestAModulesOwnPlacesAreStillPlaced(t *testing.T) { + // The paths below are judged as written: no link of them is followed on the machine the test runs on, whose mounts of them + // (a share that does not answer) it does not depend on. + was := evalSymlinks + evalSymlinks = func(p string) (string, error) { return p, nil } + t.Cleanup(func() { evalSymlinks = was }) for _, path := range []string{"/var/lib/notes/data", "/etc/systemd/logind.conf.d", "/var/run/fail2ban", "/srv/notes", "/mnt/plex/config", "/storage/media", "/var/lib/mesh/registry"} { if err := refusePath(path, placingDirectory, "notes", ""); err != nil {