If I were Xi here's what I would do. Reach an agreement with Trump, promise that NK would back down, let Trump bluster thinking that he's already won and back him into a corner where he needs to act if NK tests a nuke. Then give NK assurances of Chinese protection, let Kim think that he can test another Nuke without any substantial consequence. Be specific to Kim in private, but be vague in public, don't promise war on Kim's behalf, say some crap like "the Chinese soldiers are prepared to sacrifice their lives for peace." If that can be done, then the wheel will be in motion already. 1) NK tests nuke 2) U.S. launches strike 3) NK retaliates with bombardment of Seoul 4) War breaks out over the peninsula, with SK blaming the Americans for starting the war.
At this stage war can probably still be contained to a limited affair, but don't let it. Rush in with the PLA and stab Kim in the back in the name of peace on the peninsula. Give most of NK to SK, creating a gigantic refugee crisis in SK and a tremendous rebuilding job that only China can take on, keeping only a border area buffer zone (call it refugee camp) as insurance. The Americans can't complain because China just helped them remove Kim and his nuclear program, the SKs can't complain because China just helped them reunite the peninsula, and all the blame for the deaths, destruction, and suffering will be blamed on Kim and secondarily Trump. After that, China would have one less nuclear threat on the border and a heck a lot more leverage over SK. Predicting any further into the future would be unwise, but that's quite a bit Xi has got to work with.