MCPcopy Create free account
hub / github.com/coder/agentapi / TestServerCmd_ArgsPrecedenceOverEnv

Function TestServerCmd_ArgsPrecedenceOverEnv

cmd/server/server_test.go:290–366  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

288}
289
290func TestServerCmd_ArgsPrecedenceOverEnv(t *testing.T) {
291 tests := []struct {
292 name string
293 envVar string
294 envValue string
295 args []string
296 expected any
297 getter func() any
298 }{
299 {
300 "type: CLI overrides env",
301 "AGENTAPI_TYPE", "goose",
302 []string{"--type", "claude"},
303 "claude",
304 func() any { return viper.GetString(FlagType) },
305 },
306 {
307 "port: CLI overrides env",
308 "AGENTAPI_PORT", "8080",
309 []string{"--port", "9090"},
310 9090,
311 func() any { return viper.GetInt(FlagPort) },
312 },
313 {
314 "print-openapi: CLI overrides env",
315 "AGENTAPI_PRINT_OPENAPI", "false",
316 []string{"--print-openapi"},
317 true,
318 func() any { return viper.GetBool(FlagPrintOpenAPI) },
319 },
320 {
321 "chat-base-path: CLI overrides env",
322 "AGENTAPI_CHAT_BASE_PATH", "/env-path",
323 []string{"--chat-base-path", "/cli-path"},
324 "/cli-path",
325 func() any { return viper.GetString(FlagChatBasePath) },
326 },
327 {
328 "term-width: CLI overrides env",
329 "AGENTAPI_TERM_WIDTH", "100",
330 []string{"--term-width", "150"},
331 uint16(150),
332 func() any { return viper.GetUint16(FlagTermWidth) },
333 },
334 {
335 "term-height: CLI overrides env",
336 "AGENTAPI_TERM_HEIGHT", "500",
337 []string{"--term-height", "600"},
338 uint16(600),
339 func() any { return viper.GetUint16(FlagTermHeight) },
340 },
341 {
342 "allowed-origins: CLI overrides env",
343 "AGENTAPI_ALLOWED_ORIGINS", "https://env-example.com http://localhost:3000",
344 []string{"--allowed-origins", "https://cli-example.com"},
345 []string{"https://cli-example.com"},
346 func() any { return viper.GetStringSlice(FlagAllowedOrigins) },
347 },

Callers

nothing calls this directly

Calls 3

isolateViperFunction · 0.85
CreateServerCmdFunction · 0.85
setupCommandOutputFunction · 0.85

Tested by

no test coverage detected