返回 DeepSeek-Reasonix
write_paths_test.go
根目录 / internal / shellsafe / write_paths_test.go
1 package shellsafe
2
3 import "testing"
4
5 func TestStaticWritePathsRejectsIncompleteScopes(t *testing.T) {
6 for _, command := range []string{`echo x > a`, `printf '%s' x >> 'a b'`} {
7 if paths, ok := StaticWritePaths(command); !ok || len(paths) != 1 {
8 t.Fatalf("literal scope: %s %v %v", command, paths, ok)
9 }
10 }
11 for _, command := range []string{`echo $(rm a) > b`, `echo x > "$TARGET"`, `echo x > a; rm b`, `printf -v var x`, `echo x > a &`, `python write.py`, `echo x > a 2>&1`, `echo x > *.txt`} {
12 if paths, ok := StaticWritePaths(command); ok {
13 t.Fatalf("unproven scope: %s %v", command, paths)
14 }
15 }
16 }
17
18 func TestGitNoPagerRetainsEffectClassification(t *testing.T) {
19 for _, command := range []string{`git --no-pager diff --stat`, `git -C repo --no-pager status`, `git --no-pager -C repo log --oneline`} {
20 got := ClassifyBash(command)
21 if got.Certainty != EffectKnown || got.Writes != 0 {
22 t.Fatalf("reader misclassified: %s %+v", command, got)
23 }
24 }
25 for _, command := range []string{`git --no-pager diff --output=out`, `git --no-pager -c core.pager=evil log`, `git --no-pager diff --ext-diff`, `git --no-pager status; rm file`} {
26 got := ClassifyBash(command)
27 if got.Certainty == EffectKnown && got.Writes == 0 {
28 t.Fatalf("writer classified read-only: %s %+v", command, got)
29 }
30 }
31 }
32
32 lines GO