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") } }