test: extend banner guard coverage

This commit is contained in:
XYSK-lilong007 2026-03-12 01:58:14 +08:00
parent df19b8c708
commit 73a1dbc8a6
2 changed files with 24 additions and 4 deletions

View file

@ -54,7 +54,6 @@ func NewPicoclawCommand() *cobra.Command {
const ( const (
colorBlue = "\033[1;38;2;62;93;185m" colorBlue = "\033[1;38;2;62;93;185m"
colorRed = "\033[1;38;2;213;70;70m" colorRed = "\033[1;38;2;213;70;70m"
noBannerEnv = "PICOCLAW_NO_BANNER"
banner = "\r\n" + banner = "\r\n" +
colorBlue + "██████╗ ██╗ ██████╗ ██████╗ " + colorRed + " ██████╗██╗ █████╗ ██╗ ██╗\n" + colorBlue + "██████╗ ██╗ ██████╗ ██████╗ " + colorRed + " ██████╗██╗ █████╗ ██╗ ██╗\n" +
colorBlue + "██╔══██╗██║██╔════╝██╔═══██╗" + colorRed + "██╔════╝██║ ██╔══██╗██║ ██║\n" + colorBlue + "██╔══██╗██║██╔════╝██╔═══██╗" + colorRed + "██╔════╝██║ ██╔══██╗██║ ██║\n" +
@ -65,6 +64,8 @@ const (
"\033[0m\r\n" "\033[0m\r\n"
) )
const noBannerEnv = "PICOCLAW_NO_BANNER"
func bannerDisabledByEnv() bool { func bannerDisabledByEnv() bool {
value := strings.TrimSpace(strings.ToLower(os.Getenv(noBannerEnv))) value := strings.TrimSpace(strings.ToLower(os.Getenv(noBannerEnv)))
switch value { switch value {

View file

@ -79,4 +79,23 @@ func TestShouldPrintBanner(t *testing.T) {
t.Setenv(noBannerEnv, "1") t.Setenv(noBannerEnv, "1")
assert.False(t, shouldPrintBanner([]string{"picoclaw", "agent"}, true)) assert.False(t, shouldPrintBanner([]string{"picoclaw", "agent"}, true))
}) })
t.Run("common truthy env values disable banner", func(t *testing.T) {
for _, value := range []string{"true", "yes", "on"} {
t.Run(value, func(t *testing.T) {
t.Setenv(noBannerEnv, value)
assert.False(t, shouldPrintBanner([]string{"picoclaw", "agent"}, true))
})
}
})
t.Run("root command still prints banner in terminal", func(t *testing.T) {
t.Setenv(noBannerEnv, "")
assert.True(t, shouldPrintBanner([]string{"picoclaw"}, true))
})
t.Run("unknown subcommand still prints banner in terminal", func(t *testing.T) {
t.Setenv(noBannerEnv, "")
assert.True(t, shouldPrintBanner([]string{"picoclaw", "unknown"}, true))
})
} }