@@ -155,7 +155,7 @@ func TestServerCmd_AllArgs_Defaults(t *testing.T) {
155155 {"chat-base-path default" , FlagChatBasePath , "/chat" , func () any { return viper .GetString (FlagChatBasePath ) }},
156156 {"term-width default" , FlagTermWidth , uint16 (80 ), func () any { return viper .GetUint16 (FlagTermWidth ) }},
157157 {"term-height default" , FlagTermHeight , uint16 (1000 ), func () any { return viper .GetUint16 (FlagTermHeight ) }},
158- {"allowed-hosts default" , FlagAllowedHosts , []string {"localhost" }, func () any { return viper .GetStringSlice (FlagAllowedHosts ) }},
158+ {"allowed-hosts default" , FlagAllowedHosts , []string {"localhost" , "127.0.0.1" , "[::1]" }, func () any { return viper .GetStringSlice (FlagAllowedHosts ) }},
159159 {"allowed-origins default" , FlagAllowedOrigins , []string {"http://localhost:3284" , "http://localhost:3000" , "http://localhost:3001" }, func () any { return viper .GetStringSlice (FlagAllowedOrigins ) }},
160160 }
161161
@@ -341,37 +341,6 @@ func TestServerCmd_AllowedHosts(t *testing.T) {
341341 args : []string {},
342342 expected : []string {"localhost" , "example.com" },
343343 },
344- {
345- name : "env: host with comma (invalid)" ,
346- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "localhost:3284,example.com" },
347- args : []string {},
348- expectedErr : "contains comma characters" ,
349- },
350- {
351- name : "env: host with port (invalid)" ,
352- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "localhost:3284" },
353- args : []string {},
354- expectedErr : "must not include a port" ,
355- },
356- {
357- name : "env: ipv6 literal" ,
358- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "2001:db8::1" },
359- args : []string {},
360- expected : []string {"2001:db8::1" },
361- },
362- {
363- name : "env: ipv6 bracketed literal" ,
364- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "[2001:db8::1]" },
365- args : []string {},
366- expected : []string {"[2001:db8::1]" },
367- },
368- {
369- name : "env: ipv6 with port (invalid)" ,
370- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "[2001:db8::1]:443" },
371- args : []string {},
372- expectedErr : "must not include a port" ,
373- },
374-
375344 // CLI flag scenarios (comma-separated format)
376345 {
377346 name : "flag: single valid host" ,
@@ -394,30 +363,10 @@ func TestServerCmd_AllowedHosts(t *testing.T) {
394363 expected : []string {"localhost" },
395364 },
396365 {
397- name : "flag: host with space in comma-separated list (invalid)" ,
398- args : []string {"--allowed-hosts" , "localhost:3284,example .com" },
399- expectedErr : "contains whitespace characters" ,
400- },
401- {
402- name : "flag: host with port (invalid)" ,
403- args : []string {"--allowed-hosts" , "localhost:3284" },
404- expectedErr : "must not include a port" ,
366+ name : "flag: ipv6 bracketed literal" ,
367+ args : []string {"--allowed-hosts" , "[2001:db8::1]" },
368+ expected : []string {"[2001:db8::1]" },
405369 },
406- {
407- name : "flag: ipv6 literal" ,
408- args : []string {"--allowed-hosts" , "2001:db8::1" },
409- expected : []string {"2001:db8::1" },
410- },
411- {
412- name : "flag: ipv6 bracketed literal" ,
413- args : []string {"--allowed-hosts" , "[2001:db8::1]" },
414- expected : []string {"[2001:db8::1]" },
415- },
416- {
417- name : "flag: ipv6 with port (invalid)" ,
418- args : []string {"--allowed-hosts" , "[2001:db8::1]:443" },
419- expectedErr : "must not include a port" ,
420- },
421370
422371 // Mixed scenarios (env + flag precedence)
423372 {
@@ -426,26 +375,6 @@ func TestServerCmd_AllowedHosts(t *testing.T) {
426375 args : []string {"--allowed-hosts" , "override.com" },
427376 expected : []string {"override.com" },
428377 },
429- {
430- name : "mixed: flag overrides env but flag is invalid" ,
431- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "localhost" },
432- args : []string {"--allowed-hosts" , "invalid .com" },
433- expectedErr : "contains whitespace characters" ,
434- },
435-
436- // Empty hosts are not allowed
437- {
438- name : "empty host" ,
439- args : []string {"--allowed-hosts" , "" },
440- expectedErr : "the list must not be empty" ,
441- },
442-
443- // Default behavior
444- {
445- name : "default hosts when neither env nor flag provided" ,
446- args : []string {},
447- expected : []string {"localhost" },
448- },
449378 }
450379
451380 for _ , tt := range tests {
@@ -506,12 +435,6 @@ func TestServerCmd_AllowedOrigins(t *testing.T) {
506435 args : []string {},
507436 expected : []string {"https://example.com" , "http://localhost:3000" },
508437 },
509- {
510- name : "env: origin with comma (invalid)" ,
511- env : map [string ]string {"AGENTAPI_ALLOWED_ORIGINS" : "https://example.com,http://localhost:3000" },
512- args : []string {},
513- expectedErr : "contains comma characters" ,
514- },
515438
516439 // CLI flag scenarios (comma-separated format)
517440 {
@@ -539,11 +462,6 @@ func TestServerCmd_AllowedOrigins(t *testing.T) {
539462 args : []string {"--allowed-origins" , "https://example.com\n " },
540463 expected : []string {"https://example.com" },
541464 },
542- {
543- name : "flag: origin with space in comma-separated list (invalid)" ,
544- args : []string {"--allowed-origins" , "https://example.com,http://localhost :3000" },
545- expectedErr : "contains whitespace characters" ,
546- },
547465
548466 // Mixed scenarios (env + flag precedence)
549467 {
@@ -552,26 +470,6 @@ func TestServerCmd_AllowedOrigins(t *testing.T) {
552470 args : []string {"--allowed-origins" , "https://override.com" },
553471 expected : []string {"https://override.com" },
554472 },
555- {
556- name : "mixed: flag overrides env but flag is invalid" ,
557- env : map [string ]string {"AGENTAPI_ALLOWED_ORIGINS" : "https://env-example.com" },
558- args : []string {"--allowed-origins" , "invalid origin" },
559- expectedErr : "contains whitespace characters" ,
560- },
561-
562- // Empty origins are not allowed
563- {
564- name : "empty origin" ,
565- args : []string {"--allowed-origins" , "" },
566- expectedErr : "the list must not be empty" ,
567- },
568-
569- // Default behavior
570- {
571- name : "default origins when neither env nor flag provided" ,
572- args : []string {},
573- expected : []string {"http://localhost:3284" , "http://localhost:3000" , "http://localhost:3001" },
574- },
575473 }
576474
577475 for _ , tt := range tests {
0 commit comments