fix: keep MCP test controls responsive

This commit is contained in:
bvz rays committed 2026-12-03 02:11:17 +08:00
1 parent 4c7b4bb052
commit 40740f7cd0
3 files changed
+44 -2

No files matched your search

+5 -2
View File
@@ -136,8 +136,11 @@ func (s *Server) Handle(ctx context.Context, raw json.RawMessage) (json.RawMessa
var tool struct {
Name string `json:"name"`
}
if json.Unmarshal(req.Params, &tool) == nil && tool.Name == "test_wait" {
serialized = false
if json.Unmarshal(req.Params, &tool) == nil {
switch tool.Name {
case "test_wait", "test_status", "test_logs", "test_result", "test_cancel":
serialized = false
}
}
}
if serialized {
+37
View File
@@ -323,6 +323,43 @@ func TestTestWaitDoesNotBlockBehindSerializedToolCall(t *testing.T) {
}
}
func TestTestCancelDoesNotBlockBehindSerializedToolCall(t *testing.T) {
server := New()
server.BindHost(&testHost{})
cancelled := make(chan struct{})
run := &testRun{ID: "run-cancel", Status: "running", Done: make(chan struct{}), Cancel: func() { close(cancelled) }}
server.state.mu.Lock()
server.state.runs[run.ID] = run
server.state.mu.Unlock()
server.callMu.Lock()
result := make(chan json.RawMessage, 1)
go func() {
response, _ := server.Handle(context.Background(), json.RawMessage(`{"jsonrpc":"2.0","id":46,"method":"tools/call","params":{"name":"test_cancel","arguments":{"run_id":"run-cancel"}}}`))
result <- response
}()
select {
case raw := <-result:
server.callMu.Unlock()
response := parseResponse(t, raw)
if response["error"] != nil {
t.Fatalf("test_cancel response = %s", raw)
}
result := response["result"].(map[string]any)
content := result["content"].([]any)[0].(map[string]any)["text"].(string)
if result["isError"] == true {
t.Fatalf("test_cancel returned tool error: %s", content)
}
case <-time.After(time.Second):
server.callMu.Unlock()
t.Fatal("test_cancel blocked behind another tool call")
}
select {
case <-cancelled:
case <-time.After(time.Second):
t.Fatal("test_cancel did not cancel its run")
}
}
func TestTestRunReportsTemporaryVMCleanupFailure(t *testing.T) {
server := New()
host := &testHost{deleteErr: errors.New("delete failed")}
+2
View File
@@ -529,6 +529,8 @@ func (s *Server) waitTestRun(ctx context.Context, raw json.RawMessage) (any, err
}
if args.Timeout <= 0 {
args.Timeout = 30000
} else if args.Timeout > 300000 {
args.Timeout = 300000
}
timer := time.NewTimer(time.Duration(args.Timeout) * time.Millisecond)
defer timer.Stop()