on main help sign in
fix: fmt files
aa0fb4cRaphael Amorim
internal/llm/tools/shell/comparison_test.go+5−5
@@ -28,7 +28,7 @@ func TestShellPerformanceComparison(t *testing.T) {
28 assert.Equal(t, 0, exitCode)
28 assert.Equal(t, 0, exitCode)
29 assert.Contains(t, stdout, "hello")
29 assert.Contains(t, stdout, "hello")
30 assert.Empty(t, stderr)
30 assert.Empty(t, stderr)
31−
31+
32 t.Logf("Quick command took: %v", duration)
32 t.Logf("Quick command took: %v", duration)
33}
33}
34
34
@@ -48,13 +48,13 @@ func TestShellCPUUsageComparison(t *testing.T) {
48 start := time.Now()
48 start := time.Now()
49 _, stderr, exitCode, _, err := shell.Exec(context.Background(), "sleep 0.1", 1000)
49 _, stderr, exitCode, _, err := shell.Exec(context.Background(), "sleep 0.1", 1000)
50 duration := time.Since(start)
50 duration := time.Since(start)
51−
51+
52 runtime.ReadMemStats(&m2)
52 runtime.ReadMemStats(&m2)
53
53
54 require.NoError(t, err)
54 require.NoError(t, err)
55 assert.Equal(t, 0, exitCode)
55 assert.Equal(t, 0, exitCode)
56 assert.Empty(t, stderr)
56 assert.Empty(t, stderr)
57−
57+
58 memGrowth := m2.Alloc - m1.Alloc
58 memGrowth := m2.Alloc - m1.Alloc
59 t.Logf("Sleep 0.1s command took: %v", duration)
59 t.Logf("Sleep 0.1s command took: %v", duration)
60 t.Logf("Memory growth during polling: %d bytes", memGrowth)
60 t.Logf("Memory growth during polling: %d bytes", memGrowth)
@@ -72,7 +72,7 @@ func BenchmarkShellPolling(b *testing.B) {
72
72
73 b.ResetTimer()
73 b.ResetTimer()
74 b.ReportAllocs()
74 b.ReportAllocs()
75−
75+
76 for i := 0; i < b.N; i++ {
76 for i := 0; i < b.N; i++ {
77 // Use a short sleep to measure polling overhead
77 // Use a short sleep to measure polling overhead
78 _, _, exitCode, _, err := shell.Exec(context.Background(), "sleep 0.02", 500)
78 _, _, exitCode, _, err := shell.Exec(context.Background(), "sleep 0.02", 500)
@@ -80,4 +80,4 @@ func BenchmarkShellPolling(b *testing.B) {
80 b.Fatalf("Command failed: %v, exit code: %d", err, exitCode)
80 b.Fatalf("Command failed: %v, exit code: %d", err, exitCode)
81 }
81 }
82 }
82 }
83−}
83+}
internal/llm/tools/shell/shell.go+3−3
@@ -192,10 +192,10 @@ echo $EXEC_EXIT_CODE > %s
192 // Use exponential backoff polling
192 // Use exponential backoff polling
193 pollInterval := 1 * time.Millisecond
193 pollInterval := 1 * time.Millisecond
194 maxPollInterval := 100 * time.Millisecond
194 maxPollInterval := 100 * time.Millisecond
195−
195+
196 ticker := time.NewTicker(pollInterval)
196 ticker := time.NewTicker(pollInterval)
197 defer ticker.Stop()
197 defer ticker.Stop()
198−
198+
199 for {
199 for {
200 select {
200 select {
201 case <-ctx.Done():
201 case <-ctx.Done():
@@ -219,7 +219,7 @@ echo $EXEC_EXIT_CODE > %s
219 return
219 return
220 }
220 }
221 }
221 }
222−
222+
223 // Exponential backoff to reduce CPU usage for longer-running commands
223 // Exponential backoff to reduce CPU usage for longer-running commands
224 if pollInterval < maxPollInterval {
224 if pollInterval < maxPollInterval {
225 pollInterval = time.Duration(float64(pollInterval) * 1.5)
225 pollInterval = time.Duration(float64(pollInterval) * 1.5)
internal/llm/tools/shell/shell_test.go+3−3
@@ -28,7 +28,7 @@ func TestShellPerformanceImprovement(t *testing.T) {
28 assert.Equal(t, 0, exitCode)
28 assert.Equal(t, 0, exitCode)
29 assert.Contains(t, stdout, "hello world")
29 assert.Contains(t, stdout, "hello world")
30 assert.Empty(t, stderr)
30 assert.Empty(t, stderr)
31−
31+
32 // Quick commands should complete very fast with our exponential backoff
32 // Quick commands should complete very fast with our exponential backoff
33 assert.Less(t, duration, 50*time.Millisecond, "Quick command should complete fast with exponential backoff")
33 assert.Less(t, duration, 50*time.Millisecond, "Quick command should complete fast with exponential backoff")
34}
34}
@@ -44,11 +44,11 @@ func BenchmarkShellQuickCommands(b *testing.B) {
44
44
45 b.ResetTimer()
45 b.ResetTimer()
46 b.ReportAllocs()
46 b.ReportAllocs()
47−
47+
48 for i := 0; i < b.N; i++ {
48 for i := 0; i < b.N; i++ {
49 _, _, exitCode, _, err := shell.Exec(context.Background(), "echo test", 0)
49 _, _, exitCode, _, err := shell.Exec(context.Background(), "echo test", 0)
50 if err != nil || exitCode != 0 {
50 if err != nil || exitCode != 0 {
51 b.Fatalf("Command failed: %v, exit code: %d", err, exitCode)
51 b.Fatalf("Command failed: %v, exit code: %d", err, exitCode)
52 }
52 }
53 }
53 }
54−}
54+}