feat(embed): scope OAuth and sessions per visitor principal

Add embed visitor principals (X-Embed-Visitor), widen sessions.user_id,
embed MCP OAuth/approval routes, OAuth callback context detachment, and
CloneContext principal preservation for async QA streams.
This commit is contained in:
wizardchen
2026-06-30 18:16:44 +08:00
committed by lyingbug
parent 168b1d4cfe
commit 5074344c16
23 changed files with 438 additions and 43 deletions
+13
View File
@@ -1,10 +1,12 @@
package logger
import (
"context"
"strings"
"testing"
"time"
"github.com/Tencent/WeKnora/internal/types"
"github.com/sirupsen/logrus"
)
@@ -164,3 +166,14 @@ func TestLevelColorFor(t *testing.T) {
}
}
}
func TestCloneContextPreservesPrincipal(t *testing.T) {
t.Parallel()
ctx := types.WithPrincipal(context.Background(), types.EmbedSessionPrincipal(10000, "ch1", "sess1"))
cloned := CloneContext(ctx)
if got := types.SessionOwnerIDFromContext(cloned); got != "embed_session:10000:ch1:sess1" {
t.Fatalf("SessionOwnerIDFromContext(cloned) = %q", got)
}
}