diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-15 22:11:33 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-15 22:11:33 +0200 |
| commit | 77a015b96db8727bb12d0869f180a44d087f6319 (patch) | |
| tree | d6e4e485f4556a676fd92a6792602fec690065be /internal/engine/exclude_test.go | |
| parent | 6b38d302daa54140e4e26ad903297a1bba0cbd41 (diff) | |
| download | krino-77a015b96db8727bb12d0869f180a44d087f6319.tar.gz krino-77a015b96db8727bb12d0869f180a44d087f6319.zip | |
an undecided (stop) rule ends the search for that file
Diffstat (limited to 'internal/engine/exclude_test.go')
| -rw-r--r-- | internal/engine/exclude_test.go | 41 |
1 files changed, 41 insertions, 0 deletions
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) + } +} |
