返回 DeepSeek-Reasonix
mcp_session_view_test.go
根目录 / desktop / mcp_session_view_test.go
1 package main
2
3 import (
4 "encoding/json"
5 "strings"
6 "testing"
7
8 "reasonix/internal/plugin"
9 )
10
11 func TestMCPServerViewSessionDiagnosticsRemainOptional(t *testing.T) {
12 legacy, err := json.Marshal(ServerView{Name: "legacy", Status: "connected"})
13 if err != nil {
14 t.Fatal(err)
15 }
16 for _, field := range []string{"protocolVersion", "sessionState", "reconnectAttempts", "errorKind"} {
17 if strings.Contains(string(legacy), field) {
18 t.Fatalf("legacy payload unexpectedly contains optional %s: %s", field, legacy)
19 }
20 }
21
22 var current ServerView
23 if err := json.Unmarshal([]byte(`{
24 "name":"current","status":"connected","protocolVersion":"2025-11-25",
25 "sessionState":"reconnecting","reconnectAttempts":2,"errorKind":"session_missing"
26 }`), &current); err != nil {
27 t.Fatal(err)
28 }
29 if current.ProtocolVersion != "2025-11-25" || current.SessionState != "reconnecting" ||
30 current.ReconnectAttempts != 2 || current.ErrorKind != "session_missing" {
31 t.Fatalf("current session diagnostics = %+v", current)
32 }
33
34 for state, want := range map[plugin.SessionState]string{
35 plugin.SessionStateConnecting: "connecting", plugin.SessionStateListening: "connecting",
36 plugin.SessionStateReconnecting: "connecting", plugin.SessionStateReady: "ready",
37 plugin.SessionStateFailed: "issue", plugin.SessionStateClosed: "ready",
38 } {
39 if got := mcpSessionRuntimeState(state); got != want {
40 t.Fatalf("runtime state for %q = %q, want %q", state, got, want)
41 }
42 }
43 }
44
44 lines GO