(t *testing.T)
| 206 | } |
| 207 | |
| 208 | func 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) |
nothing calls this directly
no test coverage detected