@@ -50,7 +50,7 @@ def test_add_server(windsurf_manager, monkeypatch):
5050
5151
5252def test_add_server_with_missing_arg (windsurf_manager , monkeypatch ):
53- """Test add server with a missing argument that should remain in the args """
53+ """Test add server with a missing argument that should be replaced with empty string """
5454 monkeypatch .setattr (ClientRegistry , "get_active_client" , Mock (return_value = "windsurf" ))
5555 monkeypatch .setattr (ClientRegistry , "get_active_client_manager" , Mock (return_value = windsurf_manager ))
5656 monkeypatch .setattr (ClientRegistry , "get_client_manager" , Mock (return_value = windsurf_manager ))
@@ -78,7 +78,7 @@ def test_add_server_with_missing_arg(windsurf_manager, monkeypatch):
7878 "arguments" : {
7979 "fmt" : {"type" : "string" , "description" : "Output format" , "required" : True },
8080 "API_KEY" : {"type" : "string" , "description" : "API key" , "required" : True },
81- # Deliberately not including TZ to test the bug fix
81+ # Deliberately not including TZ to test empty string replacement
8282 },
8383 }
8484 }
@@ -104,10 +104,84 @@ def test_add_server_with_missing_arg(windsurf_manager, monkeypatch):
104104
105105 assert result .exit_code == 0
106106
107- # Check that the server was added with alias and the missing argument is preserved
107+ # Check that the server was added with alias and the missing argument is replaced with empty string
108108 server = windsurf_manager .get_server ("test-missing-arg" )
109109 assert server is not None
110110 assert server .command == "npx"
111- # The ${TZ} argument should remain intact since it's not in the processed variables
112- assert server .args == ["-y" , "@modelcontextprotocol/server-test" , "--fmt" , "json" , "--timezone" , "${TZ} " ]
111+ # The ${TZ} argument should be replaced with empty string since it's not in processed variables
112+ assert server .args == ["-y" , "@modelcontextprotocol/server-test" , "--fmt" , "json" , "--timezone" , "" ]
113113 assert server .env ["API_KEY" ] == "test-api-key"
114+
115+
116+ def test_add_server_with_empty_args (windsurf_manager , monkeypatch ):
117+ """Test add server with missing arguments that should be replaced with empty strings"""
118+ monkeypatch .setattr (ClientRegistry , "get_active_client" , Mock (return_value = "windsurf" ))
119+ monkeypatch .setattr (ClientRegistry , "get_active_client_manager" , Mock (return_value = windsurf_manager ))
120+ monkeypatch .setattr (ClientRegistry , "get_client_manager" , Mock (return_value = windsurf_manager ))
121+ monkeypatch .setattr (
122+ RepositoryManager ,
123+ "_fetch_servers" ,
124+ Mock (
125+ return_value = {
126+ "server-test" : {
127+ "installations" : {
128+ "npm" : {
129+ "type" : "npm" ,
130+ "command" : "npx" ,
131+ "args" : [
132+ "-y" ,
133+ "@modelcontextprotocol/server-test" ,
134+ "--fmt" ,
135+ "${fmt}" ,
136+ "--optional" ,
137+ "${OPTIONAL}" , # Optional arg not in arguments list
138+ "--api-key" ,
139+ "${API_KEY}" ,
140+ ],
141+ "env" : {
142+ "API_KEY" : "${API_KEY}" ,
143+ "OPTIONAL_ENV" : "${OPTIONAL}" , # Optional env var
144+ },
145+ }
146+ },
147+ "arguments" : {
148+ "fmt" : {"type" : "string" , "description" : "Output format" , "required" : True },
149+ "API_KEY" : {"type" : "string" , "description" : "API key" , "required" : True },
150+ # OPTIONAL is not listed in arguments
151+ },
152+ }
153+ }
154+ ),
155+ )
156+
157+ # Mock prompt responses for required arguments only
158+ with (
159+ patch ("prompt_toolkit.PromptSession.prompt" , side_effect = ["json" , "test-api-key" ]),
160+ patch ("rich.progress.Progress.start" ),
161+ patch ("rich.progress.Progress.stop" ),
162+ patch ("rich.progress.Progress.add_task" ),
163+ ):
164+ runner = CliRunner (mix_stderr = False )
165+ result = runner .invoke (add , ["server-test" , "--force" , "--alias" , "test-empty-args" ])
166+
167+ assert result .exit_code == 0
168+
169+ # Check that the server was added and optional arguments are empty
170+ server = windsurf_manager .get_server ("test-empty-args" )
171+ assert server is not None
172+ assert server .command == "npx"
173+ # Optional arguments should be replaced with empty strings
174+ assert server .args == [
175+ "-y" ,
176+ "@modelcontextprotocol/server-test" ,
177+ "--fmt" ,
178+ "json" ,
179+ "--optional" ,
180+ "" , # ${OPTIONAL} replaced with empty string
181+ "--api-key" ,
182+ "test-api-key" ,
183+ ]
184+ assert server .env == {
185+ "API_KEY" : "test-api-key" ,
186+ "OPTIONAL_ENV" : "" , # Optional env var should be empty string
187+ }
0 commit comments