MCPcopy Index your code
hub / github.com/coder/coder / TestWorkspaceBashBackgroundIntegration

Function TestWorkspaceBashBackgroundIntegration

codersdk/toolsdk/bash_test.go:298–438  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

296}
297
298func TestWorkspaceBashBackgroundIntegration(t *testing.T) {
299 t.Parallel()
300 if runtime.GOOS == "windows" {
301 t.Skip("Skipping on Windows: Workspace MCP bash tools rely on a Unix-like shell (bash) and POSIX/SSH semantics. Use Linux/macOS or WSL for these tests.")
302 }
303
304 t.Run("BackgroundCommandCapturesOutput", func(t *testing.T) {
305 t.Parallel()
306
307 client, workspace, agentToken := setupWorkspaceForAgent(t, nil)
308
309 // Start the agent and wait for it to be fully ready
310 _ = agenttest.New(t, client.URL, agentToken)
311
312 // Wait for workspace agents to be ready
313 coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
314
315 deps, err := toolsdk.NewDeps(client)
316 require.NoError(t, err)
317
318 args := toolsdk.WorkspaceBashArgs{
319 Workspace: workspace.Name,
320 Command: `echo "started" && sleep 60 && echo "completed"`, // Command that would take 60+ seconds
321 Background: true, // Run in background
322 TimeoutMs: 2000, // 2 second timeout
323 }
324
325 result, err := testTool(t, toolsdk.WorkspaceBash, deps, args)
326
327 // Should not error
328 require.NoError(t, err)
329
330 t.Logf("Background result: exitCode=%d, output=%q", result.ExitCode, result.Output)
331
332 // Should have exit code 124 (timeout) since command times out
333 require.Equal(t, 124, result.ExitCode)
334
335 // Should capture output up to timeout point
336 require.Contains(t, result.Output, "started", "Should contain output captured before timeout")
337
338 // Should NOT contain the second echo (it never executed due to timeout)
339 require.NotContains(t, result.Output, "completed", "Should not contain output after timeout")
340
341 // Should contain background continuation message
342 require.Contains(t, result.Output, "Command continues running in background")
343 })
344
345 t.Run("BackgroundVsNormalExecution", func(t *testing.T) {
346 t.Parallel()
347
348 client, workspace, agentToken := setupWorkspaceForAgent(t, nil)
349
350 // Start the agent and wait for it to be fully ready
351 _ = agenttest.New(t, client.URL, agentToken)
352
353 // Wait for workspace agents to be ready
354 coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
355

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
NewWorkspaceAgentWaiterFunction · 0.92
NewDepsFunction · 0.92
testToolFunction · 0.85
SkipMethod · 0.80
setupWorkspaceForAgentFunction · 0.70
RunMethod · 0.65
WaitMethod · 0.65
LogfMethod · 0.65
ContextMethod · 0.65
EqualMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected