@@ -314,15 +314,15 @@ func TestWorkspaceBashTimeoutIntegration(t *testing.T) {
314
314
315
315
deps ,err := toolsdk .NewDeps (client )
316
316
require .NoError (t ,err )
317
- ctx := context .Background ()
318
317
319
318
args := toolsdk.WorkspaceBashArgs {
320
319
Workspace :workspace .Name ,
321
320
Command :`echo "normal command"` ,// Quick command that should complete normally
322
321
TimeoutMs :5000 ,// 5 second timeout - plenty of time
323
322
}
324
323
325
- result ,err := toolsdk .WorkspaceBash .Handler (ctx ,deps ,args )
324
+ // Use testTool to register the tool as tested and satisfy coverage validation
325
+ result ,err := testTool (t ,toolsdk .WorkspaceBash ,deps ,args )
326
326
327
327
// Should not error
328
328
require .NoError (t ,err )
@@ -343,7 +343,7 @@ func TestWorkspaceBashTimeoutIntegration(t *testing.T) {
343
343
func TestWorkspaceBashBackgroundIntegration (t * testing.T ) {
344
344
t .Parallel ()
345
345
346
- t .Run ("BackgroundCommandReturnsImmediately " ,func (t * testing.T ) {
346
+ t .Run ("BackgroundCommandCapturesOutput " ,func (t * testing.T ) {
347
347
t .Parallel ()
348
348
349
349
client ,workspace ,agentToken := setupWorkspaceForAgent (t )
@@ -359,8 +359,9 @@ func TestWorkspaceBashBackgroundIntegration(t *testing.T) {
359
359
360
360
args := toolsdk.WorkspaceBashArgs {
361
361
Workspace :workspace .Name ,
362
- Command :`echo "started" && sleep 5 && echo "completed"` ,// Command that would take 5+ seconds
363
- Background :true ,// Run in background
362
+ Command :`echo "started" && sleep 60 && echo "completed"` ,// Command that would take 60+ seconds
363
+ Background :true ,// Run in background
364
+ TimeoutMs :2000 ,// 2 second timeout
364
365
}
365
366
366
367
result ,err := toolsdk .WorkspaceBash .Handler (t .Context (),deps ,args )
@@ -370,18 +371,17 @@ func TestWorkspaceBashBackgroundIntegration(t *testing.T) {
370
371
371
372
t .Logf ("Background result: exitCode=%d, output=%q" ,result .ExitCode ,result .Output )
372
373
373
- // Should have exit code0 (background start successful)
374
- require .Equal (t ,0 ,result .ExitCode )
374
+ // Should have exit code124 (timeout) since command times out
375
+ require .Equal (t ,124 ,result .ExitCode )
375
376
376
- // Should contain PID and log path info, not the actual command output
377
- require .Contains (t ,result .Output ,"Command started with PID:" )
378
- require .Contains (t ,result .Output ,"Log path: /tmp/mcp-bg/" )
377
+ // Should capture output up to timeout point
378
+ require .Contains (t ,result .Output ,"started" ,"Should contain output captured before timeout" )
379
+
380
+ // Should NOT contain the second echo (it never executed due to timeout)
381
+ require .NotContains (t ,result .Output ,"completed" ,"Should not contain output after timeout" )
379
382
380
- // Should NOT contain the actual command output since it runs in background
381
- // The command was `echo "started" && sleep 5 && echo "completed"`
382
- // So we check that the quoted strings don't appear in the output
383
- require .NotContains (t ,result .Output ,`"started"` ,"Should not contain command output in background mode" )
384
- require .NotContains (t ,result .Output ,`"completed"` ,"Should not contain command output in background mode" )
383
+ // Should contain background continuation message
384
+ require .Contains (t ,result .Output ,"Command continues running in background" )
385
385
})
386
386
387
387
t .Run ("BackgroundVsNormalExecution" ,func (t * testing.T ) {
@@ -425,14 +425,12 @@ func TestWorkspaceBashBackgroundIntegration(t *testing.T) {
425
425
t .Logf ("Normal result: %q" ,normalResult .Output )
426
426
t .Logf ("Background result: %q" ,backgroundResult .Output )
427
427
428
- // Background mode should returnPID/log info, not the actual output
428
+ // Background mode shouldalso return the actual output since command completes quickly
429
429
require .Equal (t ,0 ,backgroundResult .ExitCode )
430
- require .Contains (t ,backgroundResult .Output ,"Command started with PID:" )
431
- require .Contains (t ,backgroundResult .Output ,"Log path: /tmp/mcp-bg/" )
432
- require .NotContains (t ,backgroundResult .Output ,"hello world" )
430
+ require .Equal (t ,"hello world" ,backgroundResult .Output )
433
431
})
434
432
435
- t .Run ("BackgroundIgnoresTimeout " ,func (t * testing.T ) {
433
+ t .Run ("BackgroundCommandContinuesAfterTimeout " ,func (t * testing.T ) {
436
434
t .Parallel ()
437
435
438
436
client ,workspace ,agentToken := setupWorkspaceForAgent (t )
@@ -448,36 +446,35 @@ func TestWorkspaceBashBackgroundIntegration(t *testing.T) {
448
446
449
447
args := toolsdk.WorkspaceBashArgs {
450
448
Workspace :workspace .Name ,
451
- Command :`sleep1 && echo "done" > /tmp/done` ,// Command thatwould normally timeout
452
- TimeoutMs :1 ,//1 ms timeout (shorter than command duration)
453
- Background :true ,// But running in background should ignore timeout
449
+ Command :`echo "started" && sleep10 && echo "done" > /tmp/bg-test- done` ,// Command thatwill timeout but continue
450
+ TimeoutMs :5000 ,//5000ms timeout (shorter than command duration)
451
+ Background :true ,// Run in background
454
452
}
455
453
456
454
result ,err := toolsdk .WorkspaceBash .Handler (t .Context (),deps ,args )
457
455
458
- // Should not errorand should not timeout
456
+ // Should not errorbut should timeout
459
457
require .NoError (t ,err )
460
458
461
459
t .Logf ("Background with timeout result: exitCode=%d, output=%q" ,result .ExitCode ,result .Output )
462
460
463
- // Should have exit code 0 (background start successful)
464
- require .Equal (t ,0 ,result .ExitCode )
461
+ // Should havetimeout exit code
462
+ require .Equal (t ,124 ,result .ExitCode )
465
463
466
- // Should return PID/log info, indicating the background command started successfully
467
- require .Contains (t ,result .Output ,"Command started with PID:" )
468
- require .Contains (t ,result .Output ,"Log path: /tmp/mcp-bg/" )
464
+ // Should capture output before timeout
465
+ require .Contains (t ,result .Output ,"started" ,"Should contain output captured before timeout" )
469
466
470
- // ShouldNOT containtimeout message since backgroundmode ignores timeout
471
- require .NotContains (t ,result .Output ,"Commandcanceled due to timeout " )
467
+ // Should contain backgroundcontinuation message
468
+ require .Contains (t ,result .Output ,"Commandcontinues running in background " )
472
469
473
- // Wait for the background command to complete
470
+ // Wait for the background command to complete (even though SSH session timed out)
474
471
require .Eventually (t ,func ()bool {
475
- args := toolsdk.WorkspaceBashArgs {
472
+ checkArgs := toolsdk.WorkspaceBashArgs {
476
473
Workspace :workspace .Name ,
477
- Command :`cat /tmp/done` ,
474
+ Command :`cat /tmp/bg-test- done 2>/dev/null || echo "not found" ` ,
478
475
}
479
- result ,err := toolsdk .WorkspaceBash .Handler (t .Context (),deps ,args )
480
- return err == nil && result .Output == "done"
481
- },testutil .WaitMedium ,testutil .IntervalMedium )
476
+ checkResult ,err := toolsdk .WorkspaceBash .Handler (t .Context (),deps ,checkArgs )
477
+ return err == nil && checkResult .Output == "done"
478
+ },testutil .WaitMedium ,testutil .IntervalMedium , "Background command should continue running and complete after timeout" )
482
479
})
483
480
}