Heat olive oil in a large pot over medium heat. Add onions and cook until softened and translucent, about 5-7 minutes.
Add minced garlic and cook for another minute until fragrant.
Pour in the canned tomatoes with their juice, breaking them up with a wooden spoon. Add vegetable broth and bring to a simmer.
Add chopped basil, sugar (if using), salt, and pepper. Simmer for 20-25 minutes.
While the soup simmers, prepare the pesto by combining all pesto ingredients except olive oil in a food processor. Pulse until finely chopped, then slowly drizzle in olive oil while processing until smooth.
Using an immersion blender, purée the soup until smooth. Alternatively, carefully transfer to a blender in batches.
Stir in heavy cream and adjust seasoning to taste.
Serve hot with a generous swirl of fresh pesto on top.