Files
yuan-lab-llm--clawmanager/backend/internal/aigateway/session_identity_test.go
T
heranran 71c7672545 feat: Skill Hub hardening with session usage tracking and egress governance (#163)
* feat(skill-hub): add Skill Hub catalog, publish flow, and lite materialize pipeline

Introduce Skill Hub for browsing, importing, publishing, and installing skills, with lite instance package materialization and runtime sync support.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(skill-hub): remove token-governance hooks from Skill Hub PR

Strip validateManagedRuntimeEnvironmentOverrides, network lock policy sync,
and egress proxy audit wiring that belong to the upcoming token-usage work,
so the Skill Hub branch compiles independently.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(skill-hub): update migration number in materialize docs

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(skill-hub): make RuntimeAgentClient test stub and hub tests compile-safe

Add ResyncInstanceSkills to the runtime pool handler fake client, and harden
skill hub payload helpers/tests against nil storage/instance repos so go test passes.

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat: add Skill Hub hardening with session usage tracking and egress governance

Unify Skill Hub runtime sync improvements with session-token observability,
egress network policy, and admin/instance usage reporting for reopenable PR.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(skill-hub): repair CI tests and nested skill install

* fix(ci): restore release deployment configuration

---------

Co-authored-by: heshengran <heshengran@ieisystem.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-17 12:37:01 +08:00

62 lines
2.3 KiB
Go

package aigateway
import "testing"
func TestApplyManagedInstanceSessionDefaultsUsesMainForOpenClawInstanceToken(t *testing.T) {
req := ChatCompletionRequest{
Messages: []ChatMessage{{Role: "user", Content: "hello"}},
}
ApplyManagedInstanceSessionDefaults(&req, "instance", "openclaw")
if req.OpenClawSessionKey == nil || *req.OpenClawSessionKey != "main" {
t.Fatalf("expected default session key main, got %+v", req.OpenClawSessionKey)
}
if req.ManagedAgentType == nil || *req.ManagedAgentType != "openclaw" {
t.Fatalf("expected managed agent type openclaw, got %+v", req.ManagedAgentType)
}
if got := resolveSessionID(req); got != "agent:openclaw:main" {
t.Fatalf("expected normalized session id agent:openclaw:main, got %q", got)
}
}
func TestApplyManagedInstanceSessionDefaultsUsesMainForHermesInstanceToken(t *testing.T) {
req := ChatCompletionRequest{}
ApplyManagedInstanceSessionDefaults(&req, "instance", "hermes")
if got := resolveSessionID(req); got != "agent:hermes:main" {
t.Fatalf("expected normalized session id agent:hermes:main, got %q", got)
}
}
func TestApplyManagedInstanceSessionDefaultsSkipsUserJWTCalls(t *testing.T) {
req := ChatCompletionRequest{}
ApplyManagedInstanceSessionDefaults(&req, "user", "openclaw")
if req.OpenClawSessionKey != nil {
t.Fatalf("expected no default session key for user auth, got %+v", req.OpenClawSessionKey)
}
}
func TestApplyManagedInstanceSessionDefaultsRespectsExplicitHeader(t *testing.T) {
explicit := "work"
req := ChatCompletionRequest{
OpenClawSessionKey: &explicit,
RuntimeType: stringPtr("desktop"),
}
ApplyManagedInstanceSessionDefaults(&req, "instance", "openclaw")
if got := resolveSessionID(req); got != "agent:openclaw:work" {
t.Fatalf("expected explicit session key to win, got %q", got)
}
}
func TestApplyManagedInstanceSessionDefaultsRespectsExplicitSessionID(t *testing.T) {
explicit := "agent:openclaw:custom"
req := ChatCompletionRequest{
SessionID: &explicit,
}
ApplyManagedInstanceSessionDefaults(&req, "instance", "openclaw")
if req.OpenClawSessionKey != nil {
t.Fatalf("expected body session id to prevent default header injection, got %+v", req.OpenClawSessionKey)
}
if got := resolveSessionID(req); got != explicit {
t.Fatalf("expected explicit session id %q, got %q", explicit, got)
}
}