diff --git a/frontend/src/views/embed/EmbedChatCore.vue b/frontend/src/views/embed/EmbedChatCore.vue index 7e64a735..96f8d130 100644 --- a/frontend/src/views/embed/EmbedChatCore.vue +++ b/frontend/src/views/embed/EmbedChatCore.vue @@ -47,13 +47,13 @@ class="msg-item-wrapper" >
-
diff --git a/internal/datasource/connector/yuque/client_test.go b/internal/datasource/connector/yuque/client_test.go index 008c3218..60fb06a0 100644 --- a/internal/datasource/connector/yuque/client_test.go +++ b/internal/datasource/connector/yuque/client_test.go @@ -118,7 +118,7 @@ func TestClient_Ping_403WrapsInvalidCredentials(t *testing.T) { func TestClient_TokenNeverLoggedInFull(t *testing.T) { t.Setenv("LOG_FORMAT", "") logger.ConfigureFromEnv() - defer logger.ConfigureFromEnv() + t.Cleanup(func() { logger.ConfigureFromEnv() }) // Redirect the project's internal logger to an in-memory buffer so we can // assert the raw token never appears in log output. Using stdlib `log` diff --git a/internal/im/identity_test.go b/internal/im/identity_test.go index 43ba7a78..3ecbdb02 100644 --- a/internal/im/identity_test.go +++ b/internal/im/identity_test.go @@ -44,4 +44,8 @@ func TestWithIMIdentity(t *testing.T) { if principal.Type != types.PrincipalIMUser || principal.ID != "42:channel-1:feishu:open-id-1" { t.Fatalf("Principal = %#v, want im_user for the external IM user", principal) } + + if !types.IsMCPOAuthNonInteractive(ctx) { + t.Fatal("IM context should mark MCP OAuth as non-interactive") + } } diff --git a/internal/im/oauth_notice_test.go b/internal/im/oauth_notice_test.go new file mode 100644 index 00000000..262c2277 --- /dev/null +++ b/internal/im/oauth_notice_test.go @@ -0,0 +1,75 @@ +package im + +import ( + "strings" + "testing" +) + +func TestFormatIMMCPAuthNotice(t *testing.T) { + tests := []struct { + name string + input []string + want string + contains []string + }{ + { + name: "empty input", + input: nil, + want: "", + }, + { + name: "all blank names", + input: []string{"", " ", "\t"}, + want: "", + }, + { + name: "single service", + input: []string{"GitHub MCP"}, + contains: []string{"GitHub MCP", "OAuth 授权"}, + }, + { + name: "dedupe and trim", + input: []string{" A ", "A", " B", " ", "B"}, + contains: []string{"A、B"}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := formatIMMCPAuthNotice(tt.input) + if tt.contains == nil { + if got != tt.want { + t.Fatalf("formatIMMCPAuthNotice() = %q, want %q", got, tt.want) + } + return + } + for _, sub := range tt.contains { + if !strings.Contains(got, sub) { + t.Fatalf("formatIMMCPAuthNotice() = %q, want substring %q", got, sub) + } + } + }) + } +} + +func TestAppendIMAuthNotice(t *testing.T) { + notice := "⚠️ 需要授权" + tests := []struct { + name string + body string + notice string + want string + }{ + {"empty notice", "answer", "", "answer"}, + {"empty body", "", notice, notice}, + {"whitespace body", " \n ", notice, notice}, + {"append with blank line", "answer", notice, "answer\n\n" + notice}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := appendIMAuthNotice(tt.body, tt.notice) + if got != tt.want { + t.Fatalf("appendIMAuthNotice(%q, %q) = %q, want %q", tt.body, tt.notice, got, tt.want) + } + }) + } +} diff --git a/internal/types/context_helpers_test.go b/internal/types/context_helpers_test.go index a5457e9a..745360b4 100644 --- a/internal/types/context_helpers_test.go +++ b/internal/types/context_helpers_test.go @@ -1,6 +1,7 @@ package types import ( + "context" "testing" ) @@ -98,6 +99,24 @@ func TestLanguageLocaleName(t *testing.T) { } } +func TestMCPOAuthNonInteractive(t *testing.T) { + if IsMCPOAuthNonInteractive(nil) { + t.Fatal("nil context should not be non-interactive") + } + if IsMCPOAuthNonInteractive(context.Background()) { + t.Fatal("background context should not be non-interactive") + } + + ctx := WithMCPOAuthNonInteractive(context.Background()) + if !IsMCPOAuthNonInteractive(ctx) { + t.Fatal("marked context should be non-interactive") + } + child := context.WithValue(ctx, LanguageContextKey, "en-US") + if !IsMCPOAuthNonInteractive(child) { + t.Fatal("child context should inherit non-interactive flag") + } +} + func TestLanguageFromContext(t *testing.T) { tests := []struct { name string