44 "context"
55 "encoding/json"
66 "errors"
7- "strings"
87 "testing"
98
109 agentruntime "csgclaw/internal/runtime"
@@ -56,9 +55,6 @@ func TestMCPServersViewPreservesNilAndExplicitEmptyMaps(t *testing.T) {
5655 if err != nil {
5756 t .Fatalf ("MCPServersView() error = %v" , err )
5857 }
59- if view .ActualError != "" {
60- t .Fatalf ("ActualError = %q, want empty" , view .ActualError )
61- }
6258 data , err := json .Marshal (view )
6359 if err != nil {
6460 t .Fatalf ("json.Marshal() error = %v" , err )
@@ -67,17 +63,47 @@ func TestMCPServersViewPreservesNilAndExplicitEmptyMaps(t *testing.T) {
6763 if err := json .Unmarshal (data , & fields ); err != nil {
6864 t .Fatalf ("json.Unmarshal() error = %v" , err )
6965 }
70- if got := string (fields ["desired" ]); got != test .want {
71- t .Fatalf ("desired = %s, want %s" , got , test .want )
72- }
73- if got := string (fields ["actual" ]); got != test .want {
74- t .Fatalf ("actual = %s, want %s" , got , test .want )
66+ if got := string (fields ["servers" ]); got != test .want {
67+ t .Fatalf ("servers = %s, want %s" , got , test .want )
7568 }
7669 })
7770 }
7871}
7972
80- func TestMCPServersViewKeepsDesiredWhenRuntimeReadFails (t * testing.T ) {
73+ func TestMCPServersViewReadsRuntimeServersBeforeFirstManagement (t * testing.T ) {
74+ svc := & Service {
75+ agents : map [string ]Agent {
76+ "u-mcp" : {
77+ ID : "u-mcp" ,
78+ RuntimeKind : RuntimeKindCodex ,
79+ },
80+ },
81+ runtimeRegistry : map [string ]agentruntime.Runtime {
82+ RuntimeKindCodex : mcpServersViewTestRuntime {
83+ fakeAgentRuntime : fakeAgentRuntime {kind : RuntimeKindCodex },
84+ list : func (context.Context , agentruntime.Handle , agentruntime.MCPServersSnapshot ) (agentruntime.MCPServersSnapshot , error ) {
85+ return agentruntime.MCPServersSnapshot {Servers : map [string ]any {
86+ "manual" : map [string ]any {"command" : "uvx" },
87+ }}, nil
88+ },
89+ },
90+ },
91+ }
92+
93+ view , err := svc .MCPServersView (context .Background (), "u-mcp" )
94+ if err != nil {
95+ t .Fatalf ("MCPServersView() error = %v" , err )
96+ }
97+ server , ok := view .Servers ["manual" ].(map [string ]any )
98+ if ! ok || server ["command" ] != "uvx" {
99+ t .Fatalf ("Servers = %#v, want runtime server" , view .Servers )
100+ }
101+ if got , ok := svc .Agent ("u-mcp" ); ! ok || got .MCPServers != nil {
102+ t .Fatalf ("Agent().MCPServers = %#v, want unmanaged state preserved on read" , got .MCPServers )
103+ }
104+ }
105+
106+ func TestMCPServersViewKeepsPersistedServersWhenRuntimeReadFails (t * testing.T ) {
81107 readErr := errors .New ("native config is unreadable" )
82108 desired := map [string ]any {
83109 "context7" : map [string ]any {
@@ -107,15 +133,9 @@ func TestMCPServersViewKeepsDesiredWhenRuntimeReadFails(t *testing.T) {
107133 if err != nil {
108134 t .Fatalf ("MCPServersView() error = %v, want desired state to remain readable" , err )
109135 }
110- if view .Actual != nil {
111- t .Fatalf ("Actual = %#v, want nil when the runtime read fails" , view .Actual )
112- }
113- if ! strings .Contains (view .ActualError , readErr .Error ()) {
114- t .Fatalf ("ActualError = %q, want %q" , view .ActualError , readErr )
115- }
116- server , ok := view .Desired ["context7" ].(map [string ]any )
136+ server , ok := view .Servers ["context7" ].(map [string ]any )
117137 if ! ok || server ["command" ] != "uvx" {
118- t .Fatalf ("Desired = %#v, want raw desired server" , view .Desired )
138+ t .Fatalf ("Servers = %#v, want raw persisted server" , view .Servers )
119139 }
120140 data , err := json .Marshal (view )
121141 if err != nil {
@@ -125,7 +145,7 @@ func TestMCPServersViewKeepsDesiredWhenRuntimeReadFails(t *testing.T) {
125145 if err := json .Unmarshal (data , & fields ); err != nil {
126146 t .Fatalf ("json.Unmarshal() error = %v" , err )
127147 }
128- if got := string (fields ["actual " ]); got ! = "null" {
129- t .Fatalf ("actual = %s, want null " , got )
148+ if got := string (fields ["servers " ]); got = = "null" {
149+ t .Fatalf ("servers = %s, want persisted server map " , got )
130150 }
131151}
0 commit comments