From 8a467e850e8c9493f446f618190c9b7c40ab3812 Mon Sep 17 00:00:00 2001 From: "devsy-app[bot]" <277138668+devsy-app[bot]@users.noreply.github.com> Date: Sat, 15 Aug 2026 10:43:43 +0000 Subject: [PATCH 1/3] test(shell): cover emulated shell branches Add tests for three uncovered RunEmulatedShell code paths: malformed command parse error, the /dev/null OpenHandler intercept, and the nil env fallback to os.Environ. pkg/shell had minimal coverage (one test) before this change. --- pkg/shell/shell_test.go | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/pkg/shell/shell_test.go b/pkg/shell/shell_test.go index 14abce4a0..2fbb376df 100644 --- a/pkg/shell/shell_test.go +++ b/pkg/shell/shell_test.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "os" + "strings" "testing" ) @@ -26,3 +27,65 @@ func TestRunEmulatedShell_KillExecutesRealBinary(t *testing.T) { ) } } + +func TestRunEmulatedShell_ParseError(t *testing.T) { + err := RunEmulatedShell( + context.Background(), + "if then fi (((( broken syntax", + nil, + &bytes.Buffer{}, + &bytes.Buffer{}, + os.Environ(), + ) + if err == nil { + t.Fatal("expected parse error for malformed command, got nil") + } + if !strings.Contains(err.Error(), "parse shell command") { + t.Fatalf("expected 'parse shell command' error, got: %v", err) + } +} + +func TestRunEmulatedShell_DevNullRedirect(t *testing.T) { + // The custom OpenHandler intercepts "/dev/null" so redirections to it + // never touch the real filesystem. Output redirected there is discarded + // while subsequent commands still run. + var stdout, stderr bytes.Buffer + err := RunEmulatedShell( + context.Background(), + "echo suppressed > /dev/null; echo visible", + nil, + &stdout, + &stderr, + os.Environ(), + ) + if err != nil { + t.Fatalf("expected nil error, got: %v\nstderr: %s", err, stderr.String()) + } + if stdout.String() != "visible\n" { + t.Fatalf("expected only 'visible' on stdout, got: %q", stdout.String()) + } +} + +func TestRunEmulatedShell_NilEnvFallsBackToSystem(t *testing.T) { + // A nil env slice must fall back to os.Environ() so that referenced + // variables still resolve during emulation. + var stdout, stderr bytes.Buffer + err := RunEmulatedShell( + context.Background(), + "echo $HOME", + nil, + &stdout, + &stderr, + nil, + ) + if err != nil { + t.Fatalf("expected nil error, got: %v\nstderr: %s", err, stderr.String()) + } + home := os.Getenv("HOME") + if home == "" { + t.Skip("HOME not set, cannot verify env fallback") + } + if !strings.Contains(stdout.String(), home) { + t.Fatalf("expected stdout to contain HOME=%q, got: %q", home, stdout.String()) + } +} From d25448a4ef3a9037325c80ef715a71e6935d1482 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Mon, 17 Aug 2026 00:18:49 -0500 Subject: [PATCH 2/3] style: cleanup comments --- pkg/shell/shell_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkg/shell/shell_test.go b/pkg/shell/shell_test.go index 2fbb376df..d103bf26c 100644 --- a/pkg/shell/shell_test.go +++ b/pkg/shell/shell_test.go @@ -46,9 +46,6 @@ func TestRunEmulatedShell_ParseError(t *testing.T) { } func TestRunEmulatedShell_DevNullRedirect(t *testing.T) { - // The custom OpenHandler intercepts "/dev/null" so redirections to it - // never touch the real filesystem. Output redirected there is discarded - // while subsequent commands still run. var stdout, stderr bytes.Buffer err := RunEmulatedShell( context.Background(), @@ -67,8 +64,6 @@ func TestRunEmulatedShell_DevNullRedirect(t *testing.T) { } func TestRunEmulatedShell_NilEnvFallsBackToSystem(t *testing.T) { - // A nil env slice must fall back to os.Environ() so that referenced - // variables still resolve during emulation. var stdout, stderr bytes.Buffer err := RunEmulatedShell( context.Background(), From c241c2c568e02548c82e270db7d492216f551e60 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Mon, 17 Aug 2026 05:33:10 +0000 Subject: [PATCH 3/3] fix: update for latest changes to main Signed-off-by: Samuel K --- pkg/shell/shell_test.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/pkg/shell/shell_test.go b/pkg/shell/shell_test.go index 9dcad3381..781234020 100644 --- a/pkg/shell/shell_test.go +++ b/pkg/shell/shell_test.go @@ -32,11 +32,12 @@ func TestRunEmulatedShell_KillExecutesRealBinary(t *testing.T) { func TestRunEmulatedShell_ParseError(t *testing.T) { err := RunEmulatedShell( context.Background(), - "if then fi (((( broken syntax", - nil, - &bytes.Buffer{}, - &bytes.Buffer{}, - os.Environ(), + &CommandRunner{ + Command: "if then fi (((( broken syntax", + Stdout: &bytes.Buffer{}, + Stderr: &bytes.Buffer{}, + Environ: os.Environ(), + }, ) if err == nil { t.Fatal("expected parse error for malformed command, got nil") @@ -50,11 +51,12 @@ func TestRunEmulatedShell_DevNullRedirect(t *testing.T) { var stdout, stderr bytes.Buffer err := RunEmulatedShell( context.Background(), - "echo suppressed > /dev/null; echo visible", - nil, - &stdout, - &stderr, - os.Environ(), + &CommandRunner{ + Command: "echo suppressed > /dev/null; echo visible", + Stdout: &stdout, + Stderr: &stderr, + Environ: os.Environ(), + }, ) if err != nil { t.Fatalf("expected nil error, got: %v\nstderr: %s", err, stderr.String()) @@ -68,11 +70,12 @@ func TestRunEmulatedShell_NilEnvFallsBackToSystem(t *testing.T) { var stdout, stderr bytes.Buffer err := RunEmulatedShell( context.Background(), - "echo $HOME", - nil, - &stdout, - &stderr, - nil, + &CommandRunner{ + Command: "echo $HOME", + Stdout: &stdout, + Stderr: &stderr, + Environ: nil, + }, ) if err != nil { t.Fatalf("expected nil error, got: %v\nstderr: %s", err, stderr.String())