@@ -87,10 +87,10 @@ func TestRunContinuity(t *testing.T) {
88func TestShellTypeDetection(t *testing.T) {
88func TestShellTypeDetection(t *testing.T) {
89 shell := &PersistentShell{}
89 shell := &PersistentShell{}
91 tests := []struct {
91 tests := []struct {
92− command string
92+ command string
93− expected ShellType
93+ expected ShellType
94 windowsOnly bool
94 windowsOnly bool
96 // Windows-specific commands
96 // Windows-specific commands
@@ -100,14 +100,14 @@ func TestShellTypeDetection(t *testing.T) {
100 {"del file.txt", ShellTypeCmd, true},
100 {"del file.txt", ShellTypeCmd, true},
101 {"md newdir", ShellTypeCmd, true},
101 {"md newdir", ShellTypeCmd, true},
102 {"tasklist", ShellTypeCmd, true},
102 {"tasklist", ShellTypeCmd, true},
104 // PowerShell commands
104 // PowerShell commands
105 {"Get-Process", ShellTypePowerShell, true},
105 {"Get-Process", ShellTypePowerShell, true},
106 {"Get-ChildItem", ShellTypePowerShell, true},
106 {"Get-ChildItem", ShellTypePowerShell, true},
107 {"Set-Location C:\\", ShellTypePowerShell, true},
107 {"Set-Location C:\\", ShellTypePowerShell, true},
108 {"Get-Content file.txt | Where-Object {$_ -match 'pattern'}", ShellTypePowerShell, true},
108 {"Get-Content file.txt | Where-Object {$_ -match 'pattern'}", ShellTypePowerShell, true},
109 {"$files = Get-ChildItem", ShellTypePowerShell, true},
109 {"$files = Get-ChildItem", ShellTypePowerShell, true},
111 // Unix/cross-platform commands
111 // Unix/cross-platform commands
112 {"ls -la", ShellTypePOSIX, false},
112 {"ls -la", ShellTypePOSIX, false},
113 {"cat file.txt", ShellTypePOSIX, false},
113 {"cat file.txt", ShellTypePOSIX, false},
@@ -116,11 +116,11 @@ func TestShellTypeDetection(t *testing.T) {
116 {"git status", ShellTypePOSIX, false},
116 {"git status", ShellTypePOSIX, false},
117 {"go build", ShellTypePOSIX, false},
117 {"go build", ShellTypePOSIX, false},
120 for _, test := range tests {
120 for _, test := range tests {
121 t.Run(test.command, func(t *testing.T) {
121 t.Run(test.command, func(t *testing.T) {
122 result := shell.determineShellType(test.command)
122 result := shell.determineShellType(test.command)
124 if test.windowsOnly && runtime.GOOS != "windows" {
124 if test.windowsOnly && runtime.GOOS != "windows" {
125 // On non-Windows systems, everything should use POSIX
125 // On non-Windows systems, everything should use POSIX
126 if result != ShellTypePOSIX {
126 if result != ShellTypePOSIX {
@@ -140,12 +140,12 @@ func TestWindowsCDHandling(t *testing.T) {
140 if runtime.GOOS != "windows" {
140 if runtime.GOOS != "windows" {
141 t.Skip("Windows CD handling test only runs on Windows")
141 t.Skip("Windows CD handling test only runs on Windows")
144 shell := &PersistentShell{
144 shell := &PersistentShell{
145 cwd: "C:\\Users",
145 cwd: "C:\\Users",
146 env: []string{},
146 env: []string{},
149 tests := []struct {
149 tests := []struct {
150 command string
150 command string
151 expectedCwd string
151 expectedCwd string
@@ -156,12 +156,12 @@ func TestWindowsCDHandling(t *testing.T) {
156 {"cd C:\\Windows", "C:\\Windows", false},
156 {"cd C:\\Windows", "C:\\Windows", false},
157 {"cd", "", true}, // Missing argument
157 {"cd", "", true}, // Missing argument
160 for _, test := range tests {
160 for _, test := range tests {
161 t.Run(test.command, func(t *testing.T) {
161 t.Run(test.command, func(t *testing.T) {
162 originalCwd := shell.cwd
162 originalCwd := shell.cwd
163 stdout, stderr, err := shell.handleWindowsCD(test.command)
163 stdout, stderr, err := shell.handleWindowsCD(test.command)
165 if test.shouldError {
165 if test.shouldError {
166 if err == nil {
166 if err == nil {
167 t.Errorf("Command %q should have failed", test.command)
167 t.Errorf("Command %q should have failed", test.command)
@@ -174,7 +174,7 @@ func TestWindowsCDHandling(t *testing.T) {
174 t.Errorf("Command %q: expected cwd %q, got %q", test.command, test.expectedCwd, shell.cwd)
174 t.Errorf("Command %q: expected cwd %q, got %q", test.command, test.expectedCwd, shell.cwd)
178 // Reset for next test
178 // Reset for next test
179 shell.cwd = originalCwd
179 shell.cwd = originalCwd
180 _ = stdout
180 _ = stdout
@@ -187,17 +187,17 @@ func TestCrossPlatformExecution(t *testing.T) {
187 shell := newPersistentShell(".")
187 shell := newPersistentShell(".")
188 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
188 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
189 defer cancel()
189 defer cancel()
191 // Test a simple command that should work on all platforms
191 // Test a simple command that should work on all platforms
192 stdout, stderr, err := shell.Exec(ctx, "echo hello")
192 stdout, stderr, err := shell.Exec(ctx, "echo hello")
193 if err != nil {
193 if err != nil {
194 t.Fatalf("Echo command failed: %v, stderr: %s", err, stderr)
194 t.Fatalf("Echo command failed: %v, stderr: %s", err, stderr)
197 if stdout == "" {
197 if stdout == "" {
198 t.Error("Echo command produced no output")
198 t.Error("Echo command produced no output")
201 // The output should contain "hello" regardless of platform
201 // The output should contain "hello" regardless of platform
202 if !strings.Contains(strings.ToLower(stdout), "hello") {
202 if !strings.Contains(strings.ToLower(stdout), "hello") {
203 t.Errorf("Echo output should contain 'hello', got: %q", stdout)
203 t.Errorf("Echo output should contain 'hello', got: %q", stdout)
@@ -208,17 +208,17 @@ func TestWindowsNativeCommands(t *testing.T) {
208 if runtime.GOOS != "windows" {
208 if runtime.GOOS != "windows" {
209 t.Skip("Windows native command test only runs on Windows")
209 t.Skip("Windows native command test only runs on Windows")
212 shell := newPersistentShell(".")
212 shell := newPersistentShell(".")
213 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
213 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
214 defer cancel()
214 defer cancel()
216 // Test Windows dir command
216 // Test Windows dir command
217 stdout, stderr, err := shell.Exec(ctx, "dir")
217 stdout, stderr, err := shell.Exec(ctx, "dir")
218 if err != nil {
218 if err != nil {
219 t.Fatalf("Dir command failed: %v, stderr: %s", err, stderr)
219 t.Fatalf("Dir command failed: %v, stderr: %s", err, stderr)
222 if stdout == "" {
222 if stdout == "" {
223 t.Error("Dir command produced no output")
223 t.Error("Dir command produced no output")