From 77a015b96db8727bb12d0869f180a44d087f6319 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Tue, 15 Sep 2026 22:11:33 +0200 Subject: an undecided (stop) rule ends the search for that file --- internal/engine/exclude_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'internal/engine/exclude_test.go') diff --git a/internal/engine/exclude_test.go b/internal/engine/exclude_test.go index 7069623..7d9ce2a 100644 --- a/internal/engine/exclude_test.go +++ b/internal/engine/exclude_test.go @@ -576,3 +576,44 @@ func TestDuplicateExcludeFailsClosed(t *testing.T) { } } } + +// TestUndecidedStopRuleStops: a (stop) rule whose condition cannot be +// decided ends the search for that file, so a later rule does not act on a +// file the stop rule was written to keep (plan 12). +func TestUndecidedStopRuleStops(t *testing.T) { + big := "confidential " + strings.Repeat("x", 2048) + h, dl := excludeTree(t, map[string]string{"big.txt": big, "small.txt": "nothing"}) + main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": ` +(path "~/dl") +(max-read 1K) +(rule "keep" (when (content "confidential")) (stop)) +(rule "all" (move "Out")) +`}) + e, errs := Load(main) + if len(errs) > 0 { + t.Fatal(errs) + } + r, err := e.Match(context.Background(), e.Dirs[0]) + if err != nil { + t.Fatal(err) + } + for _, fm := range append(append([]FileMatch{}, r.Matched...), r.Unmatched...) { + switch fm.File.Rel { + case "big.txt": + if len(fm.Rules) != 0 || len(fm.Warnings) == 0 { + t.Errorf("big.txt: rules %d, warnings %v; want no rule and the warning", len(fm.Rules), fm.Warnings) + } + case "small.txt": + if len(fm.Rules) != 1 { + t.Errorf("small.txt: rules %d; want the move", len(fm.Rules)) + } + } + } + x, err := e.Explain(context.Background(), filepath.Join(dl, "big.txt")) + if err != nil { + t.Fatal(err) + } + if len(x.Rules) != 2 || x.Rules[1].Stopped != "stopped by rule keep, which could not be decided" { + t.Errorf("explain rules = %+v; want all stopped by the undecided keep", x.Rules) + } +} -- cgit v1.3