Place mushrooms in the bowl of a food processor and pulse until very finely chopped. Transfer the mushrooms to a clean cotton towel, gather up the edges, and twist to squeeze out as much liquid as possible.
Melt the butter in a 10 inch saute pan set over medium heat. Add the mushrooms, onions, salt and pepper and cook, stirring frequently, until the mushrooms appear dry and are beginning to brown, about 5 minutes. Add the sherry and thyme and cook, continuing to stir, until the liquid has evaporated. Remove from the heat and cool completely. Cover and chill in the refrigerator for at least an hour before using or store for up to 1 week.
Place a rack in the center of the oven and heat to 400ºF.
Combine the mushroom mixture and the foie gras in a small mixing bowl. Spread the mixture on all sides of the tenderloin, covering completely.
Whisk the egg and water together in a small bowl and set aside.
On a lightly floured surface roll out the pastry to 1/4-inch thickness and into an approximately 12-by-10-inch rectangle. Place the tenderloin in the center of the dough and gently pull up the sides to completely encase the meat. Fold the edges together, brush lightly with the egg wash and press to seal. Trim off any excess dough. Place the entire package, seam side down, on a parchment-lined half-sheet pan and brush all over with the egg wash. Cut 4 to 5 small holes on the top of the pastry for steam to escape. Bake until the crust is golden and the internal temperature of the meat reaches 125 to 130ºF for medium rare, 25 to 30 minutes. Remove from the oven and rest, uncovered for 15 minutes before slicing and serving.