Bring a large pot of water to a boil. Salt it and keep it ready for the cavatelli.
Heat a wide skillet over medium-high heat. Add a little of the measured oil if needed and brown the luganega for about 6–8 minutes, breaking it into bite-size crumbles, until the largest pieces reach 160°F (71°C). Transfer the sausage to a plate, leaving a thin film of drippings in the skillet.
Add the mushrooms in a single layer, working in batches if needed. Add a little of the remaining oil if the pan is dry. Cook until the moisture evaporates and the mushrooms brown, about 6–8 minutes per batch. Return all the mushrooms to the pan, reduce the heat to medium and add the shallots. Cook for 2–3 minutes, then stir in the thyme.
If using wine, pour it into the skillet and scrape up the browned bits. Simmer until almost evaporated. Return the sausage to the pan.
Boil the cavatelli until al dente, tasting from about 3 minutes for fresh pasta or following the package timing for dried pasta. Reserve 1 cup of cooking water, then drain. If you skipped the wine, use a splash of the reserved water to loosen the browned bits in the skillet.
Toss the cavatelli with the sauce and enough reserved water to use about ¼ cup in total to start. Turn off the heat, sprinkle in the Parmigiano and toss, adding more water a tablespoon at a time as needed. Taste for salt and pepper and serve with extra Parmigiano.