10func TestBackgroundShellManager_Start(t *testing.T) {
11 t.Skip("Skipping this until I figure out why its flaky")
14 ctx := context.Background()
15 workingDir := t.TempDir()
16 manager := GetBackgroundShellManager()
18 bgShell, err := manager.Start(ctx, workingDir, nil, "echo 'hello world'", "")
20 t.Fatalf("failed to start background shell: %v", err)
24 t.Error("expected shell ID to be non-empty")
27 // Wait for the command to complete
30 stdout, stderr, done, err := bgShell.GetOutput()
32 t.Error("expected shell to be done")
36 t.Errorf("expected no error, got: %v", err)
39 if !strings.Contains(stdout, "hello world") {
40 t.Errorf("expected stdout to contain 'hello world', got: %s", stdout)
44 t.Errorf("expected empty stderr, got: %s", stderr)
48func TestBackgroundShellManager_Get(t *testing.T) {
51 ctx := context.Background()
52 workingDir := t.TempDir()
53 manager := GetBackgroundShellManager()
55 bgShell, err := manager.Start(ctx, workingDir, nil, "echo 'test'", "")
57 t.Fatalf("failed to start background shell: %v", err)
61 retrieved, ok := manager.Get(bgShell.ID)
63 t.Error("expected to find the background shell")
66 if retrieved.ID != bgShell.ID {
67 t.Errorf("expected shell ID %s, got %s", bgShell.ID, retrieved.ID)
71 manager.Kill(bgShell.ID)
74func TestBackgroundShellManager_Kill(t *testing.T) {
77 ctx := context.Background()
78 workingDir := t.TempDir()
79 manager := GetBackgroundShellManager()
81 // Start a long-running command
82 bgShell, err := manager.Start(ctx, workingDir, nil, "sleep 10", "")
84 t.Fatalf("failed to start background shell: %v", err)
88 err = manager.Kill(bgShell.ID)
90 t.Errorf("failed to kill background shell: %v", err)
93 // Verify it's no longer in the manager
94 _, ok := manager.Get(bgShell.ID)
96 t.Error("expected shell to be removed after kill")
99 // Verify the shell is done
100 if !bgShell.IsDone() {
101 t.Error("expected shell to be done after kill")
105func TestBackgroundShellManager_KillNonExistent(t *testing.T) {
108 manager := GetBackgroundShellManager()
110 err := manager.Kill("non-existent-id")
112 t.Error("expected error when killing non-existent shell")
116func TestBackgroundShell_IsDone(t *testing.T) {
119 ctx := context.Background()
120 workingDir := t.TempDir()
121 manager := GetBackgroundShellManager()
123 bgShell, err := manager.Start(ctx, workingDir, nil, "echo 'quick'", "")
125 t.Fatalf("failed to start background shell: %v", err)
128 // Wait a bit for the command to complete
129 time.Sleep(100 * time.Millisecond)
131 if !bgShell.IsDone() {
132 t.Error("expected shell to be done")
136 manager.Kill(bgShell.ID)
139func TestBackgroundShell_WithBlockFuncs(t *testing.T) {
142 ctx := context.Background()
143 workingDir := t.TempDir()
144 manager := GetBackgroundShellManager()
146 blockFuncs := []BlockFunc{
147 CommandsBlocker([]string{"curl", "wget"}),
150 bgShell, err := manager.Start(ctx, workingDir, blockFuncs, "curl example.com", "")
152 t.Fatalf("failed to start background shell: %v", err)
155 // Wait for the command to complete
158 stdout, stderr, done, execErr := bgShell.GetOutput()
160 t.Error("expected shell to be done")
163 // The command should have been blocked
164 output := stdout + stderr
165 if !strings.Contains(output, "not allowed") && execErr == nil {
166 t.Errorf("expected command to be blocked, got stdout: %s, stderr: %s, err: %v", stdout, stderr, execErr)
170 manager.Kill(bgShell.ID)
173func TestBackgroundShellManager_List(t *testing.T) {
176 ctx := context.Background()
177 workingDir := t.TempDir()
178 manager := GetBackgroundShellManager()
181 bgShell1, err := manager.Start(ctx, workingDir, nil, "sleep 1", "")
183 t.Fatalf("failed to start first background shell: %v", err)
186 bgShell2, err := manager.Start(ctx, workingDir, nil, "sleep 1", "")
188 t.Fatalf("failed to start second background shell: %v", err)
191 ids := manager.List()
193 // Check that both shells are in the list
196 for _, id := range ids {
197 if id == bgShell1.ID {
200 if id == bgShell2.ID {
206 t.Errorf("expected to find shell %s in list", bgShell1.ID)
209 t.Errorf("expected to find shell %s in list", bgShell2.ID)
213 manager.Kill(bgShell1.ID)
214 manager.Kill(bgShell2.ID)
217func TestBackgroundShellManager_KillAll(t *testing.T) {
220 ctx := context.Background()
221 workingDir := t.TempDir()
222 manager := GetBackgroundShellManager()
224 // Start multiple long-running shells
225 shell1, err := manager.Start(ctx, workingDir, nil, "sleep 10", "")
227 t.Fatalf("failed to start shell 1: %v", err)
230 shell2, err := manager.Start(ctx, workingDir, nil, "sleep 10", "")
232 t.Fatalf("failed to start shell 2: %v", err)
235 shell3, err := manager.Start(ctx, workingDir, nil, "sleep 10", "")
237 t.Fatalf("failed to start shell 3: %v", err)
240 // Verify shells are running
241 if shell1.IsDone() || shell2.IsDone() || shell3.IsDone() {
242 t.Error("shells should not be done yet")
248 // Verify all shells are done
249 if !shell1.IsDone() {
250 t.Error("shell1 should be done after KillAll")
252 if !shell2.IsDone() {
253 t.Error("shell2 should be done after KillAll")
255 if !shell3.IsDone() {
256 t.Error("shell3 should be done after KillAll")
259 // Verify they're removed from the manager
260 if _, ok := manager.Get(shell1.ID); ok {
261 t.Error("shell1 should be removed from manager")
263 if _, ok := manager.Get(shell2.ID); ok {
264 t.Error("shell2 should be removed from manager")
266 if _, ok := manager.Get(shell3.ID); ok {
267 t.Error("shell3 should be removed from manager")
270 // Verify list is empty (or doesn't contain our shells)
271 ids := manager.List()
272 for _, id := range ids {
273 if id == shell1.ID || id == shell2.ID || id == shell3.ID {
274 t.Errorf("shell %s should not be in list after KillAll", id)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list