Files
summercms/modules/pact/mcp_call_test.go
Jakub Zych 63d05e8acb feat(32.1-01): publish one MCP scope list and call context
- pact gains MemberTokenScopeCatalog, MCPAdvertisedScopes and MCPCall
- an empty MCP ScopesSupported resolves to the five fixed names including backend
- pier copies advertised scopes and sets MCPCall beside WithDispatch
2026-10-28 14:32:31 +01:00

33 lines
1.0 KiB
Go

package pact
import (
"context"
"testing"
)
// TestMCPCallRoundTrip proves the context accessor stores and reads one
// call, and that a context without one answers ok false.
func TestMCPCallRoundTrip(t *testing.T) {
want := MCPCall{
Subject: MCPSubject{Guard: "user", UserID: 7, Scopes: []string{"read"}, ClientID: "c1", TokenID: 3},
SessionID: "sess-1",
Tool: "acme_echo",
}
got, ok := MCPCallFrom(WithMCPCall(context.Background(), want))
if !ok {
t.Fatal("MCPCallFrom ok = false, want true")
}
if got.Subject.Guard != want.Subject.Guard || got.SessionID != want.SessionID || got.Tool != want.Tool {
t.Fatalf("MCPCallFrom = %+v, want guard %q session %q tool %q", got, want.Subject.Guard, want.SessionID, want.Tool)
}
if _, ok := MCPCallFrom(context.Background()); ok {
t.Fatal("MCPCallFrom(context.Background()) ok = true, want false")
}
if _, ok := MCPCallFrom(nil); ok {
t.Fatal("MCPCallFrom(nil) ok = true, want false")
}
if WithMCPCall(nil, want) != nil {
t.Fatal("WithMCPCall(nil) invented a context")
}
}