@@ -2,58 +2,41 @@ package tools
22
33import (
44 "runtime"
5+ "slices"
56 "testing"
67)
78
89func TestGetSafeReadOnlyCommands(t *testing.T) {
910 commands := getSafeReadOnlyCommands()
10−
11+
1112 // Check that we have some commands
1213 if len(commands) == 0 {
1314 t.Fatal("Expected some safe commands, got none")
1415 }
15−
16+
1617 // Check for cross-platform commands that should always be present
1718 crossPlatformCommands := []string{"echo", "hostname", "whoami", "git status", "go version"}
1819 for _, cmd := range crossPlatformCommands {
19− found := false
20− for _, safeCmd := range commands {
21− if safeCmd == cmd {
22− found = true
23− break
24− }
25− }
20+ found := slices.Contains(commands, cmd)
2621 if !found {
2722 t.Errorf("Expected cross-platform command %q to be in safe commands", cmd)
2823 }
2924 }
30−
25+
3126 if runtime.GOOS == "windows" {
3227 // Check for Windows-specific commands
3328 windowsCommands := []string{"dir", "type", "Get-Process"}
3429 for _, cmd := range windowsCommands {
35− found := false
36− for _, safeCmd := range commands {
37− if safeCmd == cmd {
38− found = true
39− break
40− }
41− }
30+ found := slices.Contains(commands, cmd)
4231 if !found {
4332 t.Errorf("Expected Windows command %q to be in safe commands on Windows", cmd)
4433 }
4534 }
46−
35+
4736 // Check that Unix commands are NOT present on Windows
4837 unixCommands := []string{"ls", "pwd", "ps"}
4938 for _, cmd := range unixCommands {
50− found := false
51− for _, safeCmd := range commands {
52− if safeCmd == cmd {
53− found = true
54− break
55− }
56− }
39+ found := slices.Contains(commands, cmd)
5740 if found {
5841 t.Errorf("Unix command %q should not be in safe commands on Windows", cmd)
5942 }
@@ -62,28 +45,16 @@ func TestGetSafeReadOnlyCommands(t *testing.T) {
6245 // Check for Unix-specific commands
6346 unixCommands := []string{"ls", "pwd", "ps"}
6447 for _, cmd := range unixCommands {
65− found := false
66− for _, safeCmd := range commands {
67− if safeCmd == cmd {
68− found = true
69− break
70− }
71− }
48+ found := slices.Contains(commands, cmd)
7249 if !found {
7350 t.Errorf("Expected Unix command %q to be in safe commands on Unix", cmd)
7451 }
7552 }
76−
53+
7754 // Check that Windows-specific commands are NOT present on Unix
7855 windowsOnlyCommands := []string{"dir", "Get-Process", "systeminfo"}
7956 for _, cmd := range windowsOnlyCommands {
80− found := false
81− for _, safeCmd := range commands {
82− if safeCmd == cmd {
83− found = true
84− break
85− }
86− }
57+ found := slices.Contains(commands, cmd)
8758 if found {
8859 t.Errorf("Windows-only command %q should not be in safe commands on Unix", cmd)
8960 }
@@ -94,10 +65,10 @@ func TestGetSafeReadOnlyCommands(t *testing.T) {
9465func TestPlatformSpecificSafeCommands(t *testing.T) {
9566 // Test that the function returns different results on different platforms
9667 commands := getSafeReadOnlyCommands()
97−
68+
9869 hasWindowsCommands := false
9970 hasUnixCommands := false
100−
71+
10172 for _, cmd := range commands {
10273 if cmd == "dir" || cmd == "Get-Process" || cmd == "systeminfo" {
10374 hasWindowsCommands = true
@@ -106,7 +77,7 @@ func TestPlatformSpecificSafeCommands(t *testing.T) {
10677 hasUnixCommands = true
10778 }
10879 }
109−
80+
11081 if runtime.GOOS == "windows" {
11182 if !hasWindowsCommands {
11283 t.Error("Expected Windows commands on Windows platform")
@@ -122,4 +93,5 @@ func TestPlatformSpecificSafeCommands(t *testing.T) {
12293 t.Error("Expected Unix commands on Unix platform")
12394 }
12495 }
125−}
96+}
97+