From 598b781771ecc75b421e0a57cddaeade94f29654 Mon Sep 17 00:00:00 2001 From: jay23606 <4602056+jay23606@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:52:32 -0500 Subject: [PATCH 1/2] Add a direct test for icacls error wrapping and success return icacls is Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com> --- packages/sandbox/windows_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/sandbox/windows_test.go b/packages/sandbox/windows_test.go index 87e321ed..2118dcb2 100644 --- a/packages/sandbox/windows_test.go +++ b/packages/sandbox/windows_test.go @@ -41,6 +41,26 @@ func TestWindowsDescribeReportsIcacls(t *testing.T) { } } +// icacls is the one point every deny and cleanup ACL call goes through, so its +// error format is locked in here rather than only through Launch. +func TestWindowsIcaclsWrapsFailureAndReturnsNilOnSuccess(t *testing.T) { + missing := t.TempDir() + `\sg-definitely-missing` + err := icacls(missing, "/deny", `*S-1-1-0:(F)`) + if err == nil { + t.Fatal("icacls on a missing path returned nil, want an error") + } + if !strings.HasPrefix(err.Error(), "icacls: ") { + t.Errorf("icacls error = %q, want prefix %q", err.Error(), "icacls: ") + } + if strings.TrimPrefix(err.Error(), "icacls: ") == "" { + t.Errorf("icacls error = %q, want the captured command output after the prefix", err.Error()) + } + + if err := icacls(t.TempDir()); err != nil { + t.Errorf("icacls on an existing directory = %v, want nil", err) + } +} + func TestSystemBinaryFallsBackToBareNameWhenMissing(t *testing.T) { t.Setenv("SystemRoot", `C:\sg-definitely-not-a-real-root`) got := systemBinary("icacls") From a5f424a68f2e5266cb0f7c33a15c58967ff30f9a Mon Sep 17 00:00:00 2001 From: jay23606 <4602056+jay23606@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:55:52 -0500 Subject: [PATCH 2/2] test(sandbox): assert wrapped icacls diagnostics Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com> --- packages/sandbox/windows_test.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/sandbox/windows_test.go b/packages/sandbox/windows_test.go index 2118dcb2..74ca50df 100644 --- a/packages/sandbox/windows_test.go +++ b/packages/sandbox/windows_test.go @@ -7,6 +7,7 @@ package sandbox import ( "os" + "os/exec" "strings" "testing" ) @@ -45,15 +46,22 @@ func TestWindowsDescribeReportsIcacls(t *testing.T) { // error format is locked in here rather than only through Launch. func TestWindowsIcaclsWrapsFailureAndReturnsNilOnSuccess(t *testing.T) { missing := t.TempDir() + `\sg-definitely-missing` + cmd := exec.Command(systemBinary("icacls"), missing, "/deny", `*S-1-1-0:(F)`) + captured, commandErr := cmd.CombinedOutput() + if commandErr == nil { + t.Fatalf("icacls on a missing path succeeded, want a failure (output %q)", captured) + } + wantOutput := strings.TrimSpace(string(captured)) + if wantOutput == "" { + t.Fatal("icacls on a missing path produced no diagnostic output") + } + err := icacls(missing, "/deny", `*S-1-1-0:(F)`) if err == nil { t.Fatal("icacls on a missing path returned nil, want an error") } - if !strings.HasPrefix(err.Error(), "icacls: ") { - t.Errorf("icacls error = %q, want prefix %q", err.Error(), "icacls: ") - } - if strings.TrimPrefix(err.Error(), "icacls: ") == "" { - t.Errorf("icacls error = %q, want the captured command output after the prefix", err.Error()) + if !strings.HasPrefix(err.Error(), "icacls: ") || !strings.Contains(err.Error(), wantOutput) { + t.Errorf("icacls error = %q, want prefix %q and captured command output %q", err.Error(), "icacls: ", wantOutput) } if err := icacls(t.TempDir()); err != nil {