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

Function TestWorkspaceBashTimeoutIntegration

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

Source from the content-addressed store, hash-verified

206}
207
208func TestWorkspaceBashTimeoutIntegration(t *testing.T) {
209 t.Parallel()
210 if runtime.GOOS == "windows" {
211 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.")
212 }
213
214 t.Run("ActualTimeoutBehavior", func(t *testing.T) {
215 t.Parallel()
216
217 // Scenario: echo "123"; sleep 60; echo "456" with 5s timeout
218 // In this scenario, we'd expect to see "123" in the output and a cancellation message
219
220 client, workspace, agentToken := setupWorkspaceForAgent(t, nil)
221
222 // Start the agent and wait for it to be fully ready
223 _ = agenttest.New(t, client.URL, agentToken)
224
225 // Wait for workspace agents to be ready like other SSH tests do
226 coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
227
228 // Use real clock for integration test
229 deps, err := toolsdk.NewDeps(client)
230 require.NoError(t, err)
231
232 args := toolsdk.WorkspaceBashArgs{
233 Workspace: workspace.Name,
234 Command: `echo "123" && sleep 60 && echo "456"`, // This command would take 60+ seconds
235 TimeoutMs: 2000, // 2 seconds timeout - should timeout after first echo
236 }
237
238 result, err := testTool(t, toolsdk.WorkspaceBash, deps, args)
239
240 // Should not error (timeout is handled gracefully)
241 require.NoError(t, err)
242
243 t.Logf("Test results: exitCode=%d, output=%q, error=%v", result.ExitCode, result.Output, err)
244
245 // Should have a non-zero exit code (timeout or error)
246 require.NotEqual(t, 0, result.ExitCode, "Expected non-zero exit code for timeout")
247
248 t.Logf("result.Output: %s", result.Output)
249
250 // Should contain the first echo output
251 require.Contains(t, result.Output, "123")
252
253 // Should NOT contain the second echo (it never executed due to timeout)
254 require.NotContains(t, result.Output, "456", "Should not contain output after sleep")
255 })
256
257 t.Run("NormalCommandExecution", func(t *testing.T) {
258 t.Parallel()
259
260 // Test that normal commands still work with timeout functionality present
261
262 client, workspace, agentToken := setupWorkspaceForAgent(t, nil)
263
264 // Start the agent and wait for it to be fully ready
265 _ = agenttest.New(t, client.URL, agentToken)

Callers

nothing calls this directly

Calls 11

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
ContainsMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected